dbus.h
Go to the documentation of this file.
/* Simple Plugin API
*
* Copyright © 2018 Wim Taymans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef SPA_DBUS_H
#define SPA_DBUS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/support/loop.h>
#define SPA_TYPE_INTERFACE_DBus SPA_TYPE_INFO_INTERFACE_BASE "DBus"
#define SPA_VERSION_DBUS 0
struct spa_dbus { struct spa_interface iface; };
enum spa_dbus_type {
SPA_DBUS_TYPE_SESSION,
SPA_DBUS_TYPE_SYSTEM,
SPA_DBUS_TYPE_STARTER
};
#define SPA_DBUS_CONNECTION_EVENT_DESTROY 0
#define SPA_DBUS_CONNECTION_EVENT_DISCONNECTED 1
#define SPA_DBUS_CONNECTION_EVENT_NUM 2
struct spa_dbus_connection_events {
#define SPA_VERSION_DBUS_CONNECTION_EVENTS 0
uint32_t version;
/* a connection is destroyed */
void (*destroy) (void *data);
/* a connection disconnected */
void (*disconnected) (void *data);
};
struct spa_dbus_connection {
#define SPA_VERSION_DBUS_CONNECTION 1
uint32_t version;
void *(*get) (struct spa_dbus_connection *conn);
void (*destroy) (struct spa_dbus_connection *conn);
void (*add_listener) (struct spa_dbus_connection *conn,
struct spa_hook *listener,
const struct spa_dbus_connection_events *events,
void *data);
};
#define spa_dbus_connection_call(c,method,vers,...) \
({ \
if (SPA_LIKELY(SPA_CALLBACK_CHECK(c,method,vers))) \
c->method((c), ## __VA_ARGS__); \
})
#define spa_dbus_connection_call_vp(c,method,vers,...) \
({ \
void *_res = NULL; \
if (SPA_LIKELY(SPA_CALLBACK_CHECK(c,method,vers))) \
_res = c->method((c), ## __VA_ARGS__); \
_res; \
})
#define spa_dbus_connection_get(c) spa_dbus_connection_call_vp(c,get,0)
#define spa_dbus_connection_destroy(c) spa_dbus_connection_call(c,destroy,0)
#define spa_dbus_connection_add_listener(c,...) spa_dbus_connection_call(c,add_listener,1,__VA_ARGS__)
struct spa_dbus_methods {
#define SPA_VERSION_DBUS_METHODS 0
uint32_t version;
struct spa_dbus_connection * (*get_connection) (void *object,
enum spa_dbus_type type);
};
static inline struct spa_dbus_connection *
spa_dbus_get_connection(struct spa_dbus *dbus, enum spa_dbus_type type)
{
struct spa_dbus_connection *res = NULL;
spa_interface_call_res(&dbus->iface,
struct spa_dbus_methods, res,
get_connection, 0, type);
return res;
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SPA_DBUS_H */
spa_dbus_type
spa_dbus_type
Definition: dbus.h:55
spa_dbus_get_connection
static struct spa_dbus_connection * spa_dbus_get_connection(struct spa_dbus *dbus, enum spa_dbus_type type)
Get a new connection wrapper for the given bus type.
Definition: dbus.h:163
SPA_DBUS_TYPE_SESSION
@ SPA_DBUS_TYPE_SESSION
The login session bus.
Definition: dbus.h:56
SPA_DBUS_TYPE_STARTER
@ SPA_DBUS_TYPE_STARTER
The bus that started us, if any.
Definition: dbus.h:58
SPA_DBUS_TYPE_SYSTEM
@ SPA_DBUS_TYPE_SYSTEM
The systemwide bus.
Definition: dbus.h:57
spa_interface_call_res
#define spa_interface_call_res(iface, method_type, res, method, vers,...)
Invoke method named method in the callbacks on the given interface object.
Definition: hook.h:255
loop.h
spa/support/loop.h
spa_dbus_connection_events
Definition: dbus.h:68
spa_dbus_connection_events::destroy
void(* destroy)(void *data)
Definition: dbus.h:74
spa_dbus_connection_events::version
uint32_t version
Definition: dbus.h:71
spa_dbus_connection_events::disconnected
void(* disconnected)(void *data)
Definition: dbus.h:77
spa_dbus_connection
Definition: dbus.h:80
spa_dbus_connection::destroy
void(* destroy)(struct spa_dbus_connection *conn)
Destroy a dbus connection wrapper.
Definition: dbus.h:101
spa_dbus_connection::add_listener
void(* add_listener)(struct spa_dbus_connection *conn, struct spa_hook *listener, const struct spa_dbus_connection_events *events, void *data)
Add a listener for events.
Definition: dbus.h:108
spa_dbus_methods
Definition: dbus.h:138
spa_dbus_methods::version
uint32_t version
Definition: dbus.h:141
spa_dbus
Definition: dbus.h:53
spa_dbus::iface
struct spa_interface iface
Definition: dbus.h:53
spa_hook
A hook, contains the structure with functions and the data passed to the functions.
Definition: hook.h:342
spa_interface
Definition: hook.h:158