From 33e67f2189cd92debbdb098d7e0cc04905bb171e Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Tue, 21 Apr 2020 17:08:10 +0300
Subject: [PATCH] port: add wp_port_get_direction()

---
 lib/wp/endpoint.h | 13 +------------
 lib/wp/port.c     | 10 ++++++++++
 lib/wp/port.h     | 15 +++++++++++++++
 3 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/lib/wp/endpoint.h b/lib/wp/endpoint.h
index 91464ebe..bfaeda1e 100644
--- a/lib/wp/endpoint.h
+++ b/lib/wp/endpoint.h
@@ -11,23 +11,12 @@
 
 #include "spa-pod.h"
 #include "proxy.h"
+#include "port.h"
 #include "endpoint-stream.h"
 #include "iterator.h"
 
 G_BEGIN_DECLS
 
-/**
- * WpDirection:
- * @WP_DIRECTION_INPUT: a sink, consuming input
- * @WP_DIRECTION_OUTPUT: a source, producing output
- *
- * The different directions the endpoint can have
- */
-typedef enum {
-  WP_DIRECTION_INPUT,
-  WP_DIRECTION_OUTPUT,
-} WpDirection;
-
 /**
  * WpEndpointFeatures:
  * @WP_ENDPOINT_FEATURE_STREAMS: caches information about streams, enabling
diff --git a/lib/wp/port.c b/lib/wp/port.c
index 735e7337..de1dff95 100644
--- a/lib/wp/port.c
+++ b/lib/wp/port.c
@@ -138,3 +138,13 @@ wp_port_class_init (WpPortClass * klass)
 
   proxy_class->pw_proxy_created = wp_port_pw_proxy_created;
 }
+
+WpDirection
+wp_port_get_direction (WpPort * self)
+{
+  g_return_val_if_fail (WP_IS_PORT (self), 0);
+  g_return_val_if_fail (wp_proxy_get_features (WP_PROXY (self)) &
+          WP_PROXY_FEATURE_INFO, 0);
+
+  return (WpDirection) self->info->direction;
+}
diff --git a/lib/wp/port.h b/lib/wp/port.h
index d6d91fc1..e9de692d 100644
--- a/lib/wp/port.h
+++ b/lib/wp/port.h
@@ -13,6 +13,18 @@
 
 G_BEGIN_DECLS
 
+/**
+ * WpDirection:
+ * @WP_DIRECTION_INPUT: a sink, consuming input
+ * @WP_DIRECTION_OUTPUT: a source, producing output
+ *
+ * The different directions the endpoint can have
+ */
+typedef enum {
+  WP_DIRECTION_INPUT,
+  WP_DIRECTION_OUTPUT,
+} WpDirection;
+
 /**
  * WP_TYPE_PORT:
  *
@@ -22,6 +34,9 @@ G_BEGIN_DECLS
 WP_API
 G_DECLARE_FINAL_TYPE (WpPort, wp_port, WP, PORT, WpProxy)
 
+WP_API
+WpDirection wp_port_get_direction (WpPort * self);
+
 G_END_DECLS
 
 #endif
-- 
GitLab