153a5a1b3Sopenharmony_ci#ifndef fooprotocoldbushfoo 253a5a1b3Sopenharmony_ci#define fooprotocoldbushfoo 353a5a1b3Sopenharmony_ci 453a5a1b3Sopenharmony_ci/*** 553a5a1b3Sopenharmony_ci This file is part of PulseAudio. 653a5a1b3Sopenharmony_ci 753a5a1b3Sopenharmony_ci Copyright 2009 Tanu Kaskinen 853a5a1b3Sopenharmony_ci 953a5a1b3Sopenharmony_ci PulseAudio is free software; you can redistribute it and/or modify 1053a5a1b3Sopenharmony_ci it under the terms of the GNU Lesser General Public License as published 1153a5a1b3Sopenharmony_ci by the Free Software Foundation; either version 2.1 of the License, 1253a5a1b3Sopenharmony_ci or (at your option) any later version. 1353a5a1b3Sopenharmony_ci 1453a5a1b3Sopenharmony_ci PulseAudio is distributed in the hope that it will be useful, but 1553a5a1b3Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 1653a5a1b3Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1753a5a1b3Sopenharmony_ci General Public License for more details. 1853a5a1b3Sopenharmony_ci 1953a5a1b3Sopenharmony_ci You should have received a copy of the GNU Lesser General Public License 2053a5a1b3Sopenharmony_ci along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 2153a5a1b3Sopenharmony_ci***/ 2253a5a1b3Sopenharmony_ci 2353a5a1b3Sopenharmony_ci#include <dbus/dbus.h> 2453a5a1b3Sopenharmony_ci 2553a5a1b3Sopenharmony_ci#include <pulsecore/core.h> 2653a5a1b3Sopenharmony_ci#include <pulsecore/macro.h> 2753a5a1b3Sopenharmony_ci 2853a5a1b3Sopenharmony_ci#define PA_DBUS_DEFAULT_PORT 24883 2953a5a1b3Sopenharmony_ci#define PA_DBUS_SOCKET_NAME "dbus-socket" 3053a5a1b3Sopenharmony_ci 3153a5a1b3Sopenharmony_ci#define PA_DBUS_SYSTEM_SOCKET_PATH PA_SYSTEM_RUNTIME_PATH PA_PATH_SEP PA_DBUS_SOCKET_NAME 3253a5a1b3Sopenharmony_ci 3353a5a1b3Sopenharmony_ci#define PA_DBUS_CORE_INTERFACE "org.PulseAudio.Core1" 3453a5a1b3Sopenharmony_ci#define PA_DBUS_CORE_OBJECT_PATH "/org/pulseaudio/core1" 3553a5a1b3Sopenharmony_ci 3653a5a1b3Sopenharmony_ci#define PA_DBUS_ERROR_NO_SUCH_INTERFACE PA_DBUS_CORE_INTERFACE ".NoSuchInterfaceError" 3753a5a1b3Sopenharmony_ci#define PA_DBUS_ERROR_NO_SUCH_PROPERTY PA_DBUS_CORE_INTERFACE ".NoSuchPropertyError" 3853a5a1b3Sopenharmony_ci#define PA_DBUS_ERROR_NOT_FOUND PA_DBUS_CORE_INTERFACE ".NotFoundError" 3953a5a1b3Sopenharmony_ci 4053a5a1b3Sopenharmony_ci/* Returns the default address of the server type in the escaped form. For 4153a5a1b3Sopenharmony_ci * PA_SERVER_TYPE_NONE an empty string is returned. The caller frees the 4253a5a1b3Sopenharmony_ci * string. */ 4353a5a1b3Sopenharmony_cichar *pa_get_dbus_address_from_server_type(pa_server_type_t server_type); 4453a5a1b3Sopenharmony_ci 4553a5a1b3Sopenharmony_citypedef struct pa_dbus_protocol pa_dbus_protocol; 4653a5a1b3Sopenharmony_ci 4753a5a1b3Sopenharmony_ci/* This function either creates a new pa_dbus_protocol object, or if one 4853a5a1b3Sopenharmony_ci * already exists, increases the reference count. */ 4953a5a1b3Sopenharmony_cipa_dbus_protocol* pa_dbus_protocol_get(pa_core *c); 5053a5a1b3Sopenharmony_ci 5153a5a1b3Sopenharmony_cipa_dbus_protocol* pa_dbus_protocol_ref(pa_dbus_protocol *p); 5253a5a1b3Sopenharmony_civoid pa_dbus_protocol_unref(pa_dbus_protocol *p); 5353a5a1b3Sopenharmony_ci 5453a5a1b3Sopenharmony_ci/* Called when a received message needs handling. Completely ignoring the 5553a5a1b3Sopenharmony_ci * message isn't a good idea; if you can't handle the message, reply with an 5653a5a1b3Sopenharmony_ci * error. 5753a5a1b3Sopenharmony_ci * 5853a5a1b3Sopenharmony_ci * The message signature is already checked against the introspection data, so 5953a5a1b3Sopenharmony_ci * you don't have to do that yourself. 6053a5a1b3Sopenharmony_ci * 6153a5a1b3Sopenharmony_ci * All messages are method calls. */ 6253a5a1b3Sopenharmony_citypedef void (*pa_dbus_receive_cb_t)(DBusConnection *conn, DBusMessage *msg, void *userdata); 6353a5a1b3Sopenharmony_ci 6453a5a1b3Sopenharmony_ci/* A specialized version of pa_dbus_receive_cb_t: the additional iterator 6553a5a1b3Sopenharmony_ci * argument points to the element inside the new value variant. 6653a5a1b3Sopenharmony_ci * 6753a5a1b3Sopenharmony_ci * The new value signature is checked against the introspection data, so you 6853a5a1b3Sopenharmony_ci * don't have to do that yourself. */ 6953a5a1b3Sopenharmony_citypedef void (*pa_dbus_set_property_cb_t)(DBusConnection *conn, DBusMessage *msg, DBusMessageIter *iter, void *userdata); 7053a5a1b3Sopenharmony_ci 7153a5a1b3Sopenharmony_citypedef struct pa_dbus_arg_info { 7253a5a1b3Sopenharmony_ci const char *name; 7353a5a1b3Sopenharmony_ci const char *type; 7453a5a1b3Sopenharmony_ci const char *direction; /* NULL for signal arguments. */ 7553a5a1b3Sopenharmony_ci} pa_dbus_arg_info; 7653a5a1b3Sopenharmony_ci 7753a5a1b3Sopenharmony_citypedef struct pa_dbus_signal_info { 7853a5a1b3Sopenharmony_ci const char *name; 7953a5a1b3Sopenharmony_ci const pa_dbus_arg_info *arguments; /* NULL, if the signal has no args. */ 8053a5a1b3Sopenharmony_ci unsigned n_arguments; 8153a5a1b3Sopenharmony_ci} pa_dbus_signal_info; 8253a5a1b3Sopenharmony_ci 8353a5a1b3Sopenharmony_citypedef struct pa_dbus_method_handler { 8453a5a1b3Sopenharmony_ci const char *method_name; 8553a5a1b3Sopenharmony_ci const pa_dbus_arg_info *arguments; /* NULL, if the method has no args. */ 8653a5a1b3Sopenharmony_ci unsigned n_arguments; 8753a5a1b3Sopenharmony_ci pa_dbus_receive_cb_t receive_cb; 8853a5a1b3Sopenharmony_ci} pa_dbus_method_handler; 8953a5a1b3Sopenharmony_ci 9053a5a1b3Sopenharmony_citypedef struct pa_dbus_property_handler { 9153a5a1b3Sopenharmony_ci const char *property_name; 9253a5a1b3Sopenharmony_ci const char *type; 9353a5a1b3Sopenharmony_ci 9453a5a1b3Sopenharmony_ci /* The access mode for the property is determined by checking whether 9553a5a1b3Sopenharmony_ci * get_cb or set_cb is NULL. */ 9653a5a1b3Sopenharmony_ci pa_dbus_receive_cb_t get_cb; 9753a5a1b3Sopenharmony_ci pa_dbus_set_property_cb_t set_cb; 9853a5a1b3Sopenharmony_ci} pa_dbus_property_handler; 9953a5a1b3Sopenharmony_ci 10053a5a1b3Sopenharmony_citypedef struct pa_dbus_interface_info { 10153a5a1b3Sopenharmony_ci const char* name; 10253a5a1b3Sopenharmony_ci const pa_dbus_method_handler *method_handlers; /* NULL, if the interface has no methods. */ 10353a5a1b3Sopenharmony_ci unsigned n_method_handlers; 10453a5a1b3Sopenharmony_ci const pa_dbus_property_handler *property_handlers; /* NULL, if the interface has no properties. */ 10553a5a1b3Sopenharmony_ci unsigned n_property_handlers; 10653a5a1b3Sopenharmony_ci const pa_dbus_receive_cb_t get_all_properties_cb; /* May be NULL, in which case GetAll returns an error. */ 10753a5a1b3Sopenharmony_ci const pa_dbus_signal_info *signals; /* NULL, if the interface has no signals. */ 10853a5a1b3Sopenharmony_ci unsigned n_signals; 10953a5a1b3Sopenharmony_ci} pa_dbus_interface_info; 11053a5a1b3Sopenharmony_ci 11153a5a1b3Sopenharmony_ci/* The following functions may only be called from the main thread. */ 11253a5a1b3Sopenharmony_ci 11353a5a1b3Sopenharmony_ci/* Registers the given interface to the given object path. It doesn't matter 11453a5a1b3Sopenharmony_ci * whether or not the object has already been registered; if it is, then its 11553a5a1b3Sopenharmony_ci * interface set is extended. 11653a5a1b3Sopenharmony_ci * 11753a5a1b3Sopenharmony_ci * Introspection requests are handled automatically. 11853a5a1b3Sopenharmony_ci * 11953a5a1b3Sopenharmony_ci * Userdata is passed to all the callbacks. 12053a5a1b3Sopenharmony_ci * 12153a5a1b3Sopenharmony_ci * Fails and returns a negative number if the object already has the interface 12253a5a1b3Sopenharmony_ci * registered. */ 12353a5a1b3Sopenharmony_ciint pa_dbus_protocol_add_interface(pa_dbus_protocol *p, const char *path, const pa_dbus_interface_info *info, void *userdata); 12453a5a1b3Sopenharmony_ci 12553a5a1b3Sopenharmony_ci/* Returns a negative number if the given object doesn't have the given 12653a5a1b3Sopenharmony_ci * interface registered. */ 12753a5a1b3Sopenharmony_ciint pa_dbus_protocol_remove_interface(pa_dbus_protocol *p, const char* path, const char* interface); 12853a5a1b3Sopenharmony_ci 12953a5a1b3Sopenharmony_ci/* Fails and returns a negative number if the connection is already 13053a5a1b3Sopenharmony_ci * registered. */ 13153a5a1b3Sopenharmony_ciint pa_dbus_protocol_register_connection(pa_dbus_protocol *p, DBusConnection *conn, pa_client *client); 13253a5a1b3Sopenharmony_ci 13353a5a1b3Sopenharmony_ci/* Returns a negative number if the connection isn't registered. */ 13453a5a1b3Sopenharmony_ciint pa_dbus_protocol_unregister_connection(pa_dbus_protocol *p, DBusConnection *conn); 13553a5a1b3Sopenharmony_ci 13653a5a1b3Sopenharmony_ci/* Returns NULL if the connection isn't registered. */ 13753a5a1b3Sopenharmony_cipa_client *pa_dbus_protocol_get_client(pa_dbus_protocol *p, DBusConnection *conn); 13853a5a1b3Sopenharmony_ci 13953a5a1b3Sopenharmony_ci/* Enables signal receiving for the given connection. The connection must have 14053a5a1b3Sopenharmony_ci * been registered earlier. The signal string must contain both the signal 14153a5a1b3Sopenharmony_ci * interface and the signal name, concatenated using a period as the separator. 14253a5a1b3Sopenharmony_ci * 14353a5a1b3Sopenharmony_ci * If the signal argument is NULL, all signals will be sent to the connection, 14453a5a1b3Sopenharmony_ci * otherwise calling this function only adds the given signal to the list of 14553a5a1b3Sopenharmony_ci * signals that will be delivered to the connection. 14653a5a1b3Sopenharmony_ci * 14753a5a1b3Sopenharmony_ci * The objects argument is a list of object paths. If the list is not empty, 14853a5a1b3Sopenharmony_ci * only signals from the given objects are delivered. If this function is 14953a5a1b3Sopenharmony_ci * called multiple time for the same connection and signal, the latest call 15053a5a1b3Sopenharmony_ci * always replaces the previous object list. */ 15153a5a1b3Sopenharmony_civoid pa_dbus_protocol_add_signal_listener( 15253a5a1b3Sopenharmony_ci pa_dbus_protocol *p, 15353a5a1b3Sopenharmony_ci DBusConnection *conn, 15453a5a1b3Sopenharmony_ci const char *signal, 15553a5a1b3Sopenharmony_ci char **objects, 15653a5a1b3Sopenharmony_ci unsigned n_objects); 15753a5a1b3Sopenharmony_ci 15853a5a1b3Sopenharmony_ci/* Disables the delivery of the signal for the given connection. The connection 15953a5a1b3Sopenharmony_ci * must have been registered. If signal is NULL, all signals are disabled. If 16053a5a1b3Sopenharmony_ci * signal is non-NULL and _add_signal_listener() was previously called with 16153a5a1b3Sopenharmony_ci * NULL signal (causing all signals to be enabled), this function doesn't do 16253a5a1b3Sopenharmony_ci * anything. Also, if the signal wasn't enabled before, this function doesn't 16353a5a1b3Sopenharmony_ci * do anything in that case either. */ 16453a5a1b3Sopenharmony_civoid pa_dbus_protocol_remove_signal_listener(pa_dbus_protocol *p, DBusConnection *conn, const char *signal); 16553a5a1b3Sopenharmony_ci 16653a5a1b3Sopenharmony_ci/* Sends the given signal to all interested clients. By default no signals are 16753a5a1b3Sopenharmony_ci * sent - clients have to explicitly to request signals by calling 16853a5a1b3Sopenharmony_ci * .Core1.ListenForSignal. That method's handler then calls 16953a5a1b3Sopenharmony_ci * pa_dbus_protocol_add_signal_listener(). */ 17053a5a1b3Sopenharmony_civoid pa_dbus_protocol_send_signal(pa_dbus_protocol *p, DBusMessage *signal); 17153a5a1b3Sopenharmony_ci 17253a5a1b3Sopenharmony_ci/* Returns an array of extension identifier strings. The strings pointers point 17353a5a1b3Sopenharmony_ci * to the internal copies, so don't free the strings. The caller must free the 17453a5a1b3Sopenharmony_ci * array, however. Also, do not save the returned pointer or any of the string 17553a5a1b3Sopenharmony_ci * pointers, because the contained strings may be freed at any time. If you 17653a5a1b3Sopenharmony_ci * need to save the array, copy it. */ 17753a5a1b3Sopenharmony_ciconst char **pa_dbus_protocol_get_extensions(pa_dbus_protocol *p, unsigned *n); 17853a5a1b3Sopenharmony_ci 17953a5a1b3Sopenharmony_ci/* Modules that want to provide a D-Bus interface for clients should register 18053a5a1b3Sopenharmony_ci * an identifier that the clients can use to check whether the additional 18153a5a1b3Sopenharmony_ci * functionality is available. 18253a5a1b3Sopenharmony_ci * 18353a5a1b3Sopenharmony_ci * This function registers the extension with the given name. It is recommended 18453a5a1b3Sopenharmony_ci * that the name follows the D-Bus interface naming convention, so that the 18553a5a1b3Sopenharmony_ci * names remain unique in case there will be at some point in the future 18653a5a1b3Sopenharmony_ci * extensions that aren't included with the main PulseAudio source tree. For 18753a5a1b3Sopenharmony_ci * in-tree extensions the convention is to use the org.PulseAudio.Ext 18853a5a1b3Sopenharmony_ci * namespace. 18953a5a1b3Sopenharmony_ci * 19053a5a1b3Sopenharmony_ci * It is suggested that the name contains a version number, and whenever the 19153a5a1b3Sopenharmony_ci * extension interface is modified in non-backwards compatible way, the version 19253a5a1b3Sopenharmony_ci * number is incremented. 19353a5a1b3Sopenharmony_ci * 19453a5a1b3Sopenharmony_ci * Fails and returns a negative number if the extension is already registered. 19553a5a1b3Sopenharmony_ci */ 19653a5a1b3Sopenharmony_ciint pa_dbus_protocol_register_extension(pa_dbus_protocol *p, const char *name); 19753a5a1b3Sopenharmony_ci 19853a5a1b3Sopenharmony_ci/* Returns a negative number if the extension isn't registered. */ 19953a5a1b3Sopenharmony_ciint pa_dbus_protocol_unregister_extension(pa_dbus_protocol *p, const char *name); 20053a5a1b3Sopenharmony_ci 20153a5a1b3Sopenharmony_ci/* All hooks have the pa_dbus_protocol object as hook data. */ 20253a5a1b3Sopenharmony_citypedef enum pa_dbus_protocol_hook { 20353a5a1b3Sopenharmony_ci PA_DBUS_PROTOCOL_HOOK_EXTENSION_REGISTERED, /* Extension name as call data. */ 20453a5a1b3Sopenharmony_ci PA_DBUS_PROTOCOL_HOOK_EXTENSION_UNREGISTERED, /* Extension name as call data. */ 20553a5a1b3Sopenharmony_ci PA_DBUS_PROTOCOL_HOOK_MAX 20653a5a1b3Sopenharmony_ci} pa_dbus_protocol_hook_t; 20753a5a1b3Sopenharmony_ci 20853a5a1b3Sopenharmony_cipa_hook_slot *pa_dbus_protocol_hook_connect( 20953a5a1b3Sopenharmony_ci pa_dbus_protocol *p, 21053a5a1b3Sopenharmony_ci pa_dbus_protocol_hook_t hook, 21153a5a1b3Sopenharmony_ci pa_hook_priority_t prio, 21253a5a1b3Sopenharmony_ci pa_hook_cb_t cb, 21353a5a1b3Sopenharmony_ci void *data); 21453a5a1b3Sopenharmony_ci 21553a5a1b3Sopenharmony_ci#endif 216