Debian Codegraph @

lib/wp/port.c

raw
1 /* WirePlumber
2 *
3 * Copyright © 2019-2020 Collabora Ltd.
4 * @author Julian Bouzas <[email protected]>
5 *
6 * SPDX-License-Identifier: MIT
7 */
8
9 #include "port.h"
10 #include "log.h"
11 #include "private/pipewire-object-mixin.h"
12
13 WP_DEFINE_LOCAL_LOG_TOPIC ("wp-port")
14
15 /*! \defgroup wpport WpPort */
16 /*!
17 * \struct WpPort
18 *
19 * The WpPort class allows accessing the properties
20 * and methods of a PipeWire port object (`struct pw_port`).
21 *
22 * A WpPort is constructed internally when a new port appears
23 * on the PipeWire registry and it is made available through the
24 * WpObjectManager API.
25 */
26
27 struct _WpPort
28 {
29 WpGlobalProxy parent;
30 };
31
32 static void wp_port_pw_object_mixin_priv_interface_init (
33 WpPwObjectMixinPrivInterface * iface);
34
35 G_DEFINE_TYPE_WITH_CODE (WpPort, wp_port, WP_TYPE_GLOBAL_PROXY,
36 G_IMPLEMENT_INTERFACE (WP_TYPE_PIPEWIRE_OBJECT,
37 wp_pw_object_mixin_object_interface_init)
38 G_IMPLEMENT_INTERFACE (WP_TYPE_PW_OBJECT_MIXIN_PRIV,
39 wp_port_pw_object_mixin_priv_interface_init))
40
41 static void
42 wp_port_init (WpPort * self)
43 {
44 }
45
46 static void
47 wp_port_activate_execute_step (WpObject * object,
48 WpFeatureActivationTransition * transition, guint step,
49 WpObjectFeatures missing)
50 {
51 switch (step) {
52 case WP_PW_OBJECT_MIXIN_STEP_BIND:
53 case WP_TRANSITION_STEP_ERROR:
54 /* base class can handle BIND and ERROR */
55 WP_OBJECT_CLASS (wp_port_parent_class)->
56 activate_execute_step (object, transition, step, missing);
57 break;
58 case WP_PW_OBJECT_MIXIN_STEP_WAIT_INFO:
59 /* just wait, info will be emitted anyway after binding */
60 break;
61 case WP_PW_OBJECT_MIXIN_STEP_CACHE_PARAMS:
62 wp_pw_object_mixin_cache_params (object, missing);
63 break;
64 default:
65 g_assert_not_reached ();
66 }
67 }
68
69 static void
70 wp_port_deactivate (WpObject * object, WpObjectFeatures features)
71 {
72 wp_pw_object_mixin_deactivate (object, features);
73 WP_OBJECT_CLASS (wp_port_parent_class)->deactivate (object, features);
74 }
75
76 static const struct pw_port_events port_events = {
77 PW_VERSION_PORT_EVENTS,
78 .info = (HandleEventInfoFunc(port)) wp_pw_object_mixin_handle_event_info,
79 .param = wp_pw_object_mixin_handle_event_param,
80 };
81
82 static void
83 wp_port_pw_proxy_created (WpProxy * proxy, struct pw_proxy * pw_proxy)
84 {
85 wp_pw_object_mixin_handle_pw_proxy_created (proxy, pw_proxy,
86 port, &port_events);
87 }
88
89 static void
90 wp_port_pw_proxy_destroyed (WpProxy * proxy)
91 {
92 wp_pw_object_mixin_handle_pw_proxy_destroyed (proxy);
93
94 WP_PROXY_CLASS (wp_port_parent_class)->pw_proxy_destroyed (proxy);
95 }
96
97 static void
98 wp_port_class_init (WpPortClass * klass)
99 {
100 GObjectClass *object_class = (GObjectClass *) klass;
101 WpObjectClass *wpobject_class = (WpObjectClass *) klass;
102 WpProxyClass *proxy_class = (WpProxyClass *) klass;
103
104 object_class->get_property = wp_pw_object_mixin_get_property;
105
106 wpobject_class->get_supported_features =
107 wp_pw_object_mixin_get_supported_features;
108 wpobject_class->activate_get_next_step =
109 wp_pw_object_mixin_activate_get_next_step;
110 wpobject_class->activate_execute_step = wp_port_activate_execute_step;
111 wpobject_class->deactivate = wp_port_deactivate;
112
113 proxy_class->pw_iface_type = PW_TYPE_INTERFACE_Port;
114 proxy_class->pw_iface_version = PW_VERSION_PORT;
115 proxy_class->pw_proxy_created = wp_port_pw_proxy_created;
116 proxy_class->pw_proxy_destroyed = wp_port_pw_proxy_destroyed;
117
118 wp_pw_object_mixin_class_override_properties (object_class);
119 }
120
121 static gint
122 wp_port_enum_params (gpointer instance, guint32 id,
123 guint32 start, guint32 num, WpSpaPod *filter)
124 {
125 WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (instance);
126 return pw_port_enum_params (d->iface, 0, id, start, num,
127 filter ? wp_spa_pod_get_spa_pod (filter) : NULL);
128 }
129
130 static void
131 wp_port_pw_object_mixin_priv_interface_init (
132 WpPwObjectMixinPrivInterface * iface)
133 {
134 wp_pw_object_mixin_priv_interface_info_init (iface, port, PORT);
135 iface->enum_params = wp_port_enum_params;
136 }
137
138 /*!
139 * \brief Gets the current direction of the port
140 * \remarks Requires WP_PIPEWIRE_OBJECT_FEATURE_INFO
141 * \ingroup wpport
142 * \param self the port
143 * \returns the current direction of the port
144 */
145 WpDirection
146 wp_port_get_direction (WpPort * self)
147 {
148 g_return_val_if_fail (WP_IS_PORT (self), 0);
149 g_return_val_if_fail (wp_object_test_active_features (WP_OBJECT (self),
150 WP_PIPEWIRE_OBJECT_FEATURE_INFO), 0);
151
152 WpPwObjectMixinData *d = wp_pw_object_mixin_get_data (self);
153 const struct pw_port_info *info = d->info;
154
155 return (WpDirection) info->direction;
156 }