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_CONTEXT_H 26 #define PIPEWIRE_CONTEXT_H 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 #include <spa/utils/defs.h> 33 #include <spa/utils/hook.h> 34 35 /** \class pw_context 36 * 37 * \brief the PipeWire context 38 * 39 * The context object manages all locally available resources. It 40 * is used by both clients and servers. 41 * 42 * The context is used to: 43 * 44 * - Load modules and extend the functionality. This includes 45 * extending the protocol with new object types or creating 46 * any of the available objects. 47 * 48 * - Create implementations of various objects like nodes, 49 * devices, factories, modules, etc.. This will usually also 50 * create pw_global objects that can then be shared with 51 * clients. 52 * 53 * - Connect to another PipeWire instance (the main daemon, for 54 * example) and interact with it (See \subpage page_core_api). 55 * 56 * - Export a local implementation of an object to another 57 * instance. 58 */ 59 struct pw_context; 60 61 struct pw_global; 62 struct pw_impl_client; 63 64 #include <pipewire/core.h> 65 #include <pipewire/loop.h> 66 #include <pipewire/properties.h> 67 68 /** \page page_context_api Core API 69 * 70 * \section page_context_overview Overview 71 * 72 * \subpage page_context 73 * 74 * \subpage page_global 75 * 76 * \subpage page_client 77 * 78 * \subpage page_resource 79 * 80 * \subpage page_node 81 * 82 * \subpage page_port 83 * 84 * \subpage page_link 85 */ 86 87 /** \page page_context Context 88 * 89 * \section page_context_overview Overview 90 * 91 * The context object is an object that manages the state and 92 * resources of a PipeWire instance. 93 */ 94 95 /** context events emitted by the context object added with \ref pw_context_add_listener */ 96 struct pw_context_events { 97 #define PW_VERSION_CONTEXT_EVENTS 0 98 uint32_t version; 99 100 /** The context is being destroyed */ 101 void (*destroy) (void *data); 102 /** The context is being freed */ 103 void (*free) (void *data); 104 /** a new client object is added */ 105 void (*check_access) (void *data, struct pw_impl_client *client); 106 /** a new global object was added */ 107 void (*global_added) (void *data, struct pw_global *global); 108 /** a global object was removed */ 109 void (*global_removed) (void *data, struct pw_global *global); 110 }; 111 112 /** Make a new context object for a given main_loop. Ownership of the properties is taken */ 113 struct pw_context * pw_context_new(struct pw_loop *main_loop, /**< a main loop to run in */ 114 struct pw_properties *props, /**< extra properties */ 115 size_t user_data_size /**< extra user data size */); 116 117 /** destroy a context object, all resources except the main_loop will be destroyed */ 118 void pw_context_destroy(struct pw_context *context); 119 120 /** Get the context user data */ 121 void *pw_context_get_user_data(struct pw_context *context); 122 123 /** Add a new event listener to a context */ 124 void pw_context_add_listener(struct pw_context *context, 125 struct spa_hook *listener, 126 const struct pw_context_events *events, 127 void *data); 128 129 /** Get the context properties */ 130 const struct pw_properties *pw_context_get_properties(struct pw_context *context); 131 132 /** Update the context properties */ 133 int pw_context_update_properties(struct pw_context *context, const struct spa_dict *dict); 134 135 /** Get the context support objects */ 136 const struct spa_support *pw_context_get_support(struct pw_context *context, uint32_t *n_support); 137 138 /** get the context main loop */ 139 struct pw_loop *pw_context_get_main_loop(struct pw_context *context); 140 141 /** Iterate the globals of the context. The callback should return 142 * 0 to fetch the next item, any other value stops the iteration and returns 143 * the value. When all callbacks return 0, this function returns 0 when all 144 * globals are iterated. */ 145 int pw_context_for_each_global(struct pw_context *context, /**< the context */ 146 int (*callback) (void *data, struct pw_global *global), 147 void *data); 148 149 /** Find a context global by id */ 150 struct pw_global *pw_context_find_global(struct pw_context *context, /**< the context */ 151 uint32_t id /**< the global id */); 152 153 /** add a spa library for the given factory_name regex */ 154 int pw_context_add_spa_lib(struct pw_context *context, const char *factory_regex, const char *lib); 155 156 /** find the library name for a spa factory */ 157 const char * pw_context_find_spa_lib(struct pw_context *context, const char *factory_name); 158 159 struct spa_handle *pw_context_load_spa_handle(struct pw_context *context, 160 const char *factory_name, 161 const struct spa_dict *info); 162 163 164 /** data for registering export functions */ 165 struct pw_export_type { 166 struct spa_list link; 167 const char *type; 168 struct pw_proxy * (*func) (struct pw_core *core, 169 const char *type, const struct spa_dict *props, void *object, 170 size_t user_data_size); 171 }; 172 173 /** register a type that can be exported on a context_proxy. This is usually used by 174 * extension modules */ 175 int pw_context_register_export_type(struct pw_context *context, struct pw_export_type *type); 176 /** find information about registered export type */ 177 const struct pw_export_type *pw_context_find_export_type(struct pw_context *context, const char *type); 178 179 /** add an object to the context */ 180 int pw_context_set_object(struct pw_context *context, const char *type, void *value); 181 /** get an object from the context */ 182 void *pw_context_get_object(struct pw_context *context, const char *type); 183 184 #ifdef __cplusplus 185 } 186 #endif 187 188 #endif /* PIPEWIRE_CONTEXT_H */ 189