1 /* PipeWire
2  *
3  * Copyright © 2018 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_IMPL_FACTORY_H
26 #define PIPEWIRE_IMPL_FACTORY_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /** \class pw_impl_factory
33  *
34  * \brief PipeWire factory interface.
35  *
36  * The factory is used to make objects on demand.
37  */
38 struct pw_impl_factory;
39 
40 #include <pipewire/context.h>
41 #include <pipewire/impl-client.h>
42 #include <pipewire/global.h>
43 #include <pipewire/properties.h>
44 #include <pipewire/resource.h>
45 
46 /** Factory events, listen to them with \ref pw_impl_factory_add_listener */
47 struct pw_impl_factory_events {
48 #define PW_VERSION_IMPL_FACTORY_EVENTS	0
49 	uint32_t version;
50 
51 	/** the factory is destroyed */
52         void (*destroy) (void *data);
53 	/** the factory is freed */
54         void (*free) (void *data);
55 	/** the factory is initialized */
56         void (*initialized) (void *data);
57 };
58 
59 struct pw_impl_factory_implementation {
60 #define PW_VERSION_IMPL_FACTORY_IMPLEMENTATION	0
61 	uint32_t version;
62 
63 	/** The function to create an object from this factory */
64 	void *(*create_object) (void *data,
65 				struct pw_resource *resource,
66 				const char *type,
67 				uint32_t version,
68 				struct pw_properties *properties,
69 				uint32_t new_id);
70 };
71 
72 struct pw_impl_factory *pw_context_create_factory(struct pw_context *context,
73 				  const char *name,
74 				  const char *type,
75 				  uint32_t version,
76 				  struct pw_properties *properties,
77 				  size_t user_data_size);
78 
79 /** Get the factory properties */
80 const struct pw_properties *pw_impl_factory_get_properties(struct pw_impl_factory *factory);
81 
82 /** Get the factory info */
83 const struct pw_factory_info *pw_impl_factory_get_info(struct pw_impl_factory *factory);
84 
85 /** Update the factory properties */
86 int pw_impl_factory_update_properties(struct pw_impl_factory *factory, const struct spa_dict *dict);
87 
88 int pw_impl_factory_register(struct pw_impl_factory *factory,
89 			struct pw_properties *properties);
90 
91 void pw_impl_factory_destroy(struct pw_impl_factory *factory);
92 
93 void *pw_impl_factory_get_user_data(struct pw_impl_factory *factory);
94 
95 /** Get the global of this factory */
96 struct pw_global *pw_impl_factory_get_global(struct pw_impl_factory *factory);
97 
98 /** Add an event listener */
99 void pw_impl_factory_add_listener(struct pw_impl_factory *factory,
100 			     struct spa_hook *listener,
101 			     const struct pw_impl_factory_events *events,
102 			     void *data);
103 
104 void pw_impl_factory_set_implementation(struct pw_impl_factory *factory,
105 				   const struct pw_impl_factory_implementation *implementation,
106 				   void *data);
107 
108 void *pw_impl_factory_create_object(struct pw_impl_factory *factory,
109 			       struct pw_resource *resource,
110 			       const char *type,
111 			       uint32_t version,
112 			       struct pw_properties *properties,
113 			       uint32_t new_id);
114 
115 /** Find a factory by name */
116 struct pw_impl_factory *
117 pw_context_find_factory(struct pw_context *context	/**< the context */,
118 		     const char *name			/**< the factory name */);
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 #endif /* PIPEWIRE_IMPL_FACTORY_H */
125