1 /* PipeWire
2  *
3  * Copyright © 2020 Wim Taymans
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef PIPEWIRE_MANAGER_H
26 #define PIPEWIRE_MANAGER_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <spa/utils/defs.h>
33 #include <spa/pod/pod.h>
34 
35 #include <pipewire/pipewire.h>
36 
37 struct pw_manager_object;
38 
39 struct pw_manager_events {
40 #define PW_VERSION_MANAGER_EVENTS	0
41 	uint32_t version;
42 
43 	void (*destroy) (void *data);
44 
45 	void (*sync) (void *data);
46 
47 	void (*added) (void *data, struct pw_manager_object *object);
48 
49 	void (*updated) (void *data, struct pw_manager_object *object);
50 
51 	void (*removed) (void *data, struct pw_manager_object *object);
52 
53 	void (*metadata) (void *data, struct pw_manager_object *object,
54 			uint32_t subject, const char *key,
55 			const char *type, const char *value);
56 
57 	void (*disconnect) (void *data);
58 };
59 
60 struct pw_manager {
61 	struct pw_core *core;
62 	struct pw_registry *registry;
63 
64 	struct pw_core_info *info;
65 
66 	uint32_t n_objects;
67 	struct spa_list object_list;
68 };
69 
70 struct pw_manager_param {
71 	uint32_t id;
72 	struct spa_list link;           /**< link in manager_object param_list */
73 	struct spa_pod *param;
74 };
75 
76 struct pw_manager_object {
77 	struct spa_list link;           /**< link in manager object_list */
78 	uint32_t id;
79 	uint32_t permissions;
80 	const char *type;
81 	uint32_t version;
82 	struct pw_properties *props;
83 	struct pw_proxy *proxy;
84 	char *message_object_path;
85 	int (*message_handler)(struct pw_manager *m, struct pw_manager_object *o,
86 	                       const char *message, const char *params, char **response);
87 
88 	int changed;
89 	void *info;
90 	struct spa_list param_list;
91 	unsigned int creating:1;
92 	unsigned int removing:1;
93 };
94 
95 struct pw_manager *pw_manager_new(struct pw_core *core);
96 
97 void pw_manager_add_listener(struct pw_manager *manager,
98 		struct spa_hook *listener,
99 		const struct pw_manager_events *events, void *data);
100 
101 int pw_manager_sync(struct pw_manager *manager);
102 
103 void pw_manager_destroy(struct pw_manager *manager);
104 
105 int pw_manager_set_metadata(struct pw_manager *manager,
106 		struct pw_manager_object *metadata,
107 		uint32_t subject, const char *key, const char *type,
108 		const char *format, ...) SPA_PRINTF_FUNC(6,7);
109 
110 int pw_manager_for_each_object(struct pw_manager *manager,
111 		int (*callback) (void *data, struct pw_manager_object *object),
112 		void *data);
113 
114 void *pw_manager_object_add_data(struct pw_manager_object *o, const char *id, size_t size);
115 void *pw_manager_object_get_data(struct pw_manager_object *obj, const char *id);
116 
117 bool pw_manager_object_is_client(struct pw_manager_object *o);
118 bool pw_manager_object_is_module(struct pw_manager_object *o);
119 bool pw_manager_object_is_card(struct pw_manager_object *o);
120 bool pw_manager_object_is_sink(struct pw_manager_object *o);
121 bool pw_manager_object_is_source(struct pw_manager_object *o);
122 bool pw_manager_object_is_monitor(struct pw_manager_object *o);
123 bool pw_manager_object_is_virtual(struct pw_manager_object *o);
124 bool pw_manager_object_is_source_or_monitor(struct pw_manager_object *o);
125 bool pw_manager_object_is_sink_input(struct pw_manager_object *o);
126 bool pw_manager_object_is_source_output(struct pw_manager_object *o);
127 bool pw_manager_object_is_recordable(struct pw_manager_object *o);
128 bool pw_manager_object_is_link(struct pw_manager_object *o);
129 
130 #ifdef __cplusplus
131 } /* extern "C" */
132 #endif
133 
134 #endif /* PIPEWIRE_MANAGER_H */
135