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