parent
867f06a597
commit
68d4ac0eca
|
@ -27,14 +27,13 @@
|
|||
|
||||
#include "common.h"
|
||||
|
||||
#include "../dbus/interface.h"
|
||||
#include "../dbus/error.h"
|
||||
#include "control.h"
|
||||
#include "../dbus_constants.h"
|
||||
|
||||
#define INTERFACE_NAME IFACE_CONTROL
|
||||
|
||||
static void ladish_is_studio_loaded(method_call_t * call_ptr)
|
||||
static void ladish_is_studio_loaded(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
DBusMessageIter iter;
|
||||
dbus_bool_t is_loaded;
|
||||
|
@ -103,7 +102,7 @@ exit:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void ladish_get_studio_list(method_call_t * call_ptr)
|
||||
static void ladish_get_studio_list(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
DBusMessageIter iter, array_iter;
|
||||
|
||||
|
@ -145,7 +144,7 @@ fail:
|
|||
lash_error("Ran out of memory trying to construct method return");
|
||||
}
|
||||
|
||||
static void ladish_load_studio(method_call_t * call_ptr)
|
||||
static void ladish_load_studio(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
const char * name;
|
||||
|
||||
|
@ -164,7 +163,7 @@ static void ladish_load_studio(method_call_t * call_ptr)
|
|||
}
|
||||
}
|
||||
|
||||
static void ladish_delete_studio(method_call_t * call_ptr)
|
||||
static void ladish_delete_studio(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
const char * name;
|
||||
|
||||
|
@ -183,7 +182,7 @@ static void ladish_delete_studio(method_call_t * call_ptr)
|
|||
}
|
||||
}
|
||||
|
||||
static void ladish_new_studio(method_call_t * call_ptr)
|
||||
static void ladish_new_studio(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
const char * name;
|
||||
|
||||
|
@ -202,7 +201,7 @@ static void ladish_new_studio(method_call_t * call_ptr)
|
|||
}
|
||||
}
|
||||
|
||||
static void ladish_get_application_list(method_call_t * call_ptr)
|
||||
static void ladish_get_application_list(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
DBusMessageIter iter;
|
||||
DBusMessageIter array_iter;
|
||||
|
@ -276,7 +275,7 @@ fail:
|
|||
return;
|
||||
}
|
||||
|
||||
static void ladish_exit(method_call_t * call_ptr)
|
||||
static void ladish_exit(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
lash_info("Exit command received through D-Bus");
|
||||
g_quit = true;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#ifndef __LASHD_DBUS_IFACE_CONTROL_H__
|
||||
#define __LASHD_DBUS_IFACE_CONTROL_H__
|
||||
|
||||
extern const interface_t g_lashd_interface_control;
|
||||
extern const struct dbus_interface_descriptor g_lashd_interface_control;
|
||||
|
||||
void emit_studio_appeared();
|
||||
void emit_studio_disappeared();
|
||||
|
|
|
@ -29,9 +29,9 @@
|
|||
#include "graph_iface.h"
|
||||
#include "../dbus/error.h"
|
||||
|
||||
#define impl_ptr ((struct graph_implementator *)call_ptr->context)
|
||||
#define impl_ptr ((struct graph_implementator *)call_ptr->iface_context)
|
||||
|
||||
static void get_all_ports(method_call_t * call_ptr)
|
||||
static void get_all_ports(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
DBusMessageIter iter, sub_iter;
|
||||
|
||||
|
@ -63,7 +63,7 @@ fail:
|
|||
lash_error("Ran out of memory trying to construct method return");
|
||||
}
|
||||
|
||||
static void get_graph(method_call_t * call_ptr)
|
||||
static void get_graph(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
dbus_uint64_t known_version;
|
||||
dbus_uint64_t current_version;
|
||||
|
@ -306,32 +306,32 @@ exit:
|
|||
return;
|
||||
}
|
||||
|
||||
static void connect_ports_by_name(method_call_t * call_ptr)
|
||||
static void connect_ports_by_name(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
method_return_new_void(call_ptr);
|
||||
}
|
||||
|
||||
static void connect_ports_by_id(method_call_t * call_ptr)
|
||||
static void connect_ports_by_id(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
method_return_new_void(call_ptr);
|
||||
}
|
||||
|
||||
static void disconnect_ports_by_name(method_call_t * call_ptr)
|
||||
static void disconnect_ports_by_name(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
method_return_new_void(call_ptr);
|
||||
}
|
||||
|
||||
static void disconnect_ports_by_id(method_call_t * call_ptr)
|
||||
static void disconnect_ports_by_id(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
method_return_new_void(call_ptr);
|
||||
}
|
||||
|
||||
static void disconnect_ports_by_connection_id(method_call_t * call_ptr)
|
||||
static void disconnect_ports_by_connection_id(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
method_return_new_void(call_ptr);
|
||||
}
|
||||
|
||||
static void get_client_pid(method_call_t * call_ptr)
|
||||
static void get_client_pid(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
int64_t pid = 0;
|
||||
method_return_new_single(call_ptr, DBUS_TYPE_INT64, &pid);
|
||||
|
|
|
@ -34,6 +34,6 @@ struct graph_implementator
|
|||
uint64_t (* get_graph_version)(void * this);
|
||||
};
|
||||
|
||||
extern const interface_t g_interface_patchbay;
|
||||
extern const struct dbus_interface_descriptor g_interface_patchbay;
|
||||
|
||||
#endif /* #ifndef PATCHBAY_H__30334B9A_8847_4E8C_AFF9_73DB13406C8E__INCLUDED */
|
||||
|
|
|
@ -47,7 +47,7 @@ char * g_studios_dir;
|
|||
|
||||
#define STUDIO_HEADER_TEXT BASE_NAME " Studio configuration.\n"
|
||||
|
||||
extern const interface_t g_interface_studio;
|
||||
extern const struct dbus_interface_descriptor g_interface_studio;
|
||||
|
||||
struct studio
|
||||
{
|
||||
|
@ -1691,12 +1691,12 @@ void emit_studio_renamed()
|
|||
signal_new_valist(g_dbus_connection, STUDIO_OBJECT_PATH, IFACE_STUDIO, "StudioRenamed", DBUS_TYPE_STRING, &g_studio.name, DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
||||
static void ladish_get_studio_name(method_call_t * call_ptr)
|
||||
static void ladish_get_studio_name(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
method_return_new_single(call_ptr, DBUS_TYPE_STRING, &g_studio.name);
|
||||
}
|
||||
|
||||
static void ladish_rename_studio(method_call_t * call_ptr)
|
||||
static void ladish_rename_studio(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
const char * new_name;
|
||||
char * new_name_dup;
|
||||
|
@ -1724,7 +1724,7 @@ static void ladish_rename_studio(method_call_t * call_ptr)
|
|||
emit_studio_renamed();
|
||||
}
|
||||
|
||||
static void ladish_save_studio(method_call_t * call_ptr)
|
||||
static void ladish_save_studio(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
if (studio_save(call_ptr))
|
||||
{
|
||||
|
@ -1732,7 +1732,7 @@ static void ladish_save_studio(method_call_t * call_ptr)
|
|||
}
|
||||
}
|
||||
|
||||
static void ladish_unload_studio(method_call_t * call_ptr)
|
||||
static void ladish_unload_studio(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
lash_info("Unload studio request");
|
||||
studio_clear();
|
||||
|
@ -1770,7 +1770,7 @@ bool studio_new(void * call_ptr, const char * studio_name)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void ladish_stop_studio(method_call_t * call_ptr)
|
||||
static void ladish_stop_studio(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
lash_info("Studio stop requested");
|
||||
|
||||
|
@ -1784,7 +1784,7 @@ static void ladish_stop_studio(method_call_t * call_ptr)
|
|||
}
|
||||
}
|
||||
|
||||
static void ladish_start_studio(method_call_t * call_ptr)
|
||||
static void ladish_start_studio(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
lash_info("Studio start requested");
|
||||
|
||||
|
|
18
dbus/error.c
18
dbus/error.c
|
@ -27,20 +27,12 @@
|
|||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#include "../common.h"
|
||||
#include "helpers.h"
|
||||
#include "error.h"
|
||||
#include "../common/debug.h"
|
||||
|
||||
#include "error.h"
|
||||
#include "method.h"
|
||||
#include "interface.h"
|
||||
|
||||
void
|
||||
lash_dbus_error(method_call_t *call_ptr,
|
||||
const char *err_name,
|
||||
const char *format,
|
||||
...)
|
||||
void lash_dbus_error(struct dbus_method_call * call_ptr, const char * err_name, const char * format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char message[1024];
|
||||
|
@ -55,7 +47,7 @@ lash_dbus_error(method_call_t *call_ptr,
|
|||
|
||||
if (call_ptr != NULL)
|
||||
{
|
||||
interface_name = (call_ptr->interface && call_ptr->interface->name && call_ptr->interface->name[0]) ? call_ptr->interface->name : "<unknown>";
|
||||
interface_name = (call_ptr->iface && call_ptr->iface->name && call_ptr->iface->name[0]) ? call_ptr->iface->name : "<unknown>";
|
||||
|
||||
lash_error("In method %s.%s: %s", interface_name, call_ptr->method_name, message);
|
||||
|
||||
|
|
10
dbus/error.h
10
dbus/error.h
|
@ -2,7 +2,7 @@
|
|||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2008 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
* Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
* Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
|
||||
*
|
||||
**************************************************************************
|
||||
|
@ -30,8 +30,6 @@
|
|||
#ifndef __LASH_DBUS_ERROR_H__
|
||||
#define __LASH_DBUS_ERROR_H__
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define LASH_DBUS_ERROR_UNKNOWN_METHOD DBUS_NAME_BASE ".Error.UnknownMethod"
|
||||
#define LASH_DBUS_ERROR_SERVER_NOT_RUNNING DBUS_NAME_BASE ".Error.ServerNotRunning"
|
||||
#define LASH_DBUS_ERROR_INVALID_ARGS DBUS_NAME_BASE ".Error.InvalidArgs"
|
||||
|
@ -43,10 +41,6 @@
|
|||
#define LASH_DBUS_ERROR_UNFINISHED_TASK DBUS_NAME_BASE ".Error.UnfinishedTask"
|
||||
#define LASH_DBUS_ERROR_INVALID_TASK DBUS_NAME_BASE ".Error.InvalidTask"
|
||||
|
||||
void
|
||||
lash_dbus_error(method_call_t *call_ptr,
|
||||
const char *err_name,
|
||||
const char *format,
|
||||
...);
|
||||
void lash_dbus_error(struct dbus_method_call * call_ptr, const char * err_name, const char * format, ...);
|
||||
|
||||
#endif /* __LASH_DBUS_ERROR_H__ */
|
||||
|
|
|
@ -63,6 +63,8 @@ dbus_unregister_object_signal_handler(
|
|||
|
||||
#define DBUS_CALL_DEFAULT_TIMEOUT 1000 // in milliseconds
|
||||
|
||||
#include "method.h"
|
||||
#include "signal.h"
|
||||
#include "interface.h"
|
||||
#include "object_path.h"
|
||||
|
||||
|
|
|
@ -27,53 +27,42 @@
|
|||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "../common.h"
|
||||
#include "helpers.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "../common/debug.h"
|
||||
|
||||
#include "interface.h"
|
||||
#include "error.h"
|
||||
#include "object_path.h"
|
||||
|
||||
/*
|
||||
* Execute a method's function if the method specified in the method call
|
||||
* object exists in the method array. Return true if the method was found,
|
||||
* false otherwise.
|
||||
* TODO: rewrite description ^
|
||||
*/
|
||||
bool
|
||||
interface_default_handler(const interface_t *interface,
|
||||
method_call_t *call)
|
||||
bool dbus_interface_default_handler(const struct dbus_interface_descriptor * iface_ptr, struct dbus_method_call * call_ptr)
|
||||
{
|
||||
const method_t *ptr;
|
||||
const struct dbus_method_descriptor * method_ptr;
|
||||
|
||||
for (ptr = (const method_t *) interface->methods;
|
||||
ptr && ptr->name;
|
||||
++ptr) {
|
||||
if (strcmp(call->method_name, ptr->name) == 0) {
|
||||
if (ptr->handler) {
|
||||
call->interface = interface;
|
||||
ptr->handler(call);
|
||||
|
||||
/* If the method handler didn't construct a return
|
||||
message create a void one here */
|
||||
// TODO: Also handle cases where the sender doesn't need a reply
|
||||
if (!call->reply
|
||||
&& !(call->reply = dbus_message_new_method_return(call->message))) {
|
||||
for (method_ptr = iface_ptr->methods; method_ptr->name != NULL; method_ptr++)
|
||||
{
|
||||
if (strcmp(call_ptr->method_name, method_ptr->name) == 0)
|
||||
{
|
||||
call_ptr->iface = iface_ptr;
|
||||
method_ptr->handler(call_ptr);
|
||||
/* If the method handler didn't construct a return message create a void one here */
|
||||
// TODO: Also handle cases where the sender doesn't need a reply
|
||||
if (call_ptr->reply == NULL)
|
||||
{
|
||||
call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
|
||||
if (call_ptr->reply == NULL)
|
||||
{
|
||||
lash_error("Failed to construct void method return");
|
||||
}
|
||||
} else {
|
||||
lash_dbus_error(call, LASH_DBUS_ERROR_GENERIC,
|
||||
"Handler for method \"%s\" is NULL", ptr->name);
|
||||
}
|
||||
|
||||
/* Found method */
|
||||
/* Known method */
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Didn't find method */
|
||||
/* Unknown method */
|
||||
return false;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2008 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
* Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
* Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
|
||||
*
|
||||
**************************************************************************
|
||||
|
@ -30,42 +30,36 @@
|
|||
#ifndef __LASH_DBUS_INTERFACE_H__
|
||||
#define __LASH_DBUS_INTERFACE_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
typedef bool (* dbus_interface_handler)(const struct dbus_interface_descriptor *, struct dbus_method_call *);
|
||||
|
||||
#include "types.h"
|
||||
#include "method.h"
|
||||
#include "signal.h"
|
||||
|
||||
struct _interface
|
||||
struct dbus_interface_descriptor
|
||||
{
|
||||
const char *name;
|
||||
const interface_handler_t handler;
|
||||
const method_t *methods;
|
||||
const signal_t *signals;
|
||||
const char * name;
|
||||
dbus_interface_handler handler;
|
||||
const struct dbus_method_descriptor * methods;
|
||||
const struct dbus_signal_descriptor * signals;
|
||||
};
|
||||
|
||||
bool
|
||||
interface_default_handler(const interface_t *interface,
|
||||
method_call_t *call);
|
||||
bool dbus_interface_default_handler(const struct dbus_interface_descriptor * interface, struct dbus_method_call * call_ptr);
|
||||
|
||||
#define INTERFACE_BEGIN(iface_var, iface_name) \
|
||||
const struct _interface iface_var = \
|
||||
{ \
|
||||
.name = iface_name,
|
||||
#define INTERFACE_BEGIN(iface_var, iface_name) \
|
||||
const struct dbus_interface_descriptor iface_var = \
|
||||
{ \
|
||||
.name = iface_name,
|
||||
|
||||
#define INTERFACE_DEFAULT_HANDLER \
|
||||
.handler = interface_default_handler,
|
||||
#define INTERFACE_DEFAULT_HANDLER \
|
||||
.handler = dbus_interface_default_handler,
|
||||
|
||||
#define INTERFACE_HANDLER(handler_func) \
|
||||
.handler = handler_func,
|
||||
#define INTERFACE_HANDLER(handler_func) \
|
||||
.handler = handler_func,
|
||||
|
||||
#define INTERFACE_EXPOSE_METHODS \
|
||||
.methods = methods_dtor,
|
||||
#define INTERFACE_EXPOSE_METHODS \
|
||||
.methods = methods_dtor,
|
||||
|
||||
#define INTERFACE_EXPOSE_SIGNALS \
|
||||
.signals = signals_dtor,
|
||||
#define INTERFACE_EXPOSE_SIGNALS \
|
||||
.signals = signals_dtor,
|
||||
|
||||
#define INTERFACE_END \
|
||||
#define INTERFACE_END \
|
||||
};
|
||||
|
||||
#endif /* __LASH_DBUS_INTERFACE_H__ */
|
||||
|
|
|
@ -37,12 +37,12 @@
|
|||
*
|
||||
* The operation can only fail due to lack of memory, in which case
|
||||
* there's no sense in trying to construct an error return. Instead,
|
||||
* call->reply will be set to NULL and handled in send_method_return().
|
||||
* call_ptr->reply will be set to NULL and handled in send_method_return().
|
||||
*/
|
||||
void
|
||||
method_return_new_void(method_call_t *call)
|
||||
method_return_new_void(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
if (!(call->reply = dbus_message_new_method_return(call->message))) {
|
||||
if (!(call_ptr->reply = dbus_message_new_method_return(call_ptr->message))) {
|
||||
lash_error("Ran out of memory trying to construct method return");
|
||||
}
|
||||
}
|
||||
|
@ -54,21 +54,21 @@ method_return_new_void(method_call_t *call)
|
|||
*
|
||||
* The operation can only fail due to lack of memory, in which case
|
||||
* there's no sense in trying to construct an error return. Instead,
|
||||
* call->reply will be set to NULL and handled in send_method_return().
|
||||
* call_ptr->reply will be set to NULL and handled in send_method_return().
|
||||
*/
|
||||
void
|
||||
method_return_new_single(method_call_t *call,
|
||||
method_return_new_single(struct dbus_method_call * call_ptr,
|
||||
int type,
|
||||
const void *arg)
|
||||
{
|
||||
if (!call || !arg) {
|
||||
if (!call_ptr || !arg) {
|
||||
lash_error("Invalid arguments");
|
||||
return;
|
||||
}
|
||||
|
||||
call->reply = dbus_message_new_method_return(call->message);
|
||||
call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
|
||||
|
||||
if (!call->reply)
|
||||
if (!call_ptr->reply)
|
||||
goto fail_no_mem;
|
||||
|
||||
/* Void method return requested by caller. */
|
||||
|
@ -82,24 +82,24 @@ method_return_new_single(method_call_t *call,
|
|||
|
||||
DBusMessageIter iter;
|
||||
|
||||
dbus_message_iter_init_append(call->reply, &iter);
|
||||
dbus_message_iter_init_append(call_ptr->reply, &iter);
|
||||
|
||||
if (dbus_message_iter_append_basic(&iter, type, arg))
|
||||
return;
|
||||
|
||||
dbus_message_unref(call->reply);
|
||||
call->reply = NULL;
|
||||
dbus_message_unref(call_ptr->reply);
|
||||
call_ptr->reply = NULL;
|
||||
|
||||
fail_no_mem:
|
||||
lash_error("Ran out of memory trying to construct method return");
|
||||
}
|
||||
|
||||
void
|
||||
method_return_new_valist(method_call_t *call,
|
||||
method_return_new_valist(struct dbus_method_call * call_ptr,
|
||||
int type,
|
||||
...)
|
||||
{
|
||||
if (!call) {
|
||||
if (!call_ptr) {
|
||||
lash_error("Call pointer is NULL");
|
||||
return;
|
||||
}
|
||||
|
@ -111,21 +111,21 @@ method_return_new_valist(method_call_t *call,
|
|||
|
||||
va_list argp;
|
||||
|
||||
call->reply = dbus_message_new_method_return(call->message);
|
||||
if (!call->reply)
|
||||
call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
|
||||
if (!call_ptr->reply)
|
||||
goto fail_no_mem;
|
||||
|
||||
va_start(argp, type);
|
||||
|
||||
if (dbus_message_append_args_valist(call->reply, type, argp)) {
|
||||
if (dbus_message_append_args_valist(call_ptr->reply, type, argp)) {
|
||||
va_end(argp);
|
||||
return;
|
||||
}
|
||||
|
||||
va_end(argp);
|
||||
|
||||
dbus_message_unref(call->reply);
|
||||
call->reply = NULL;
|
||||
dbus_message_unref(call_ptr->reply);
|
||||
call_ptr->reply = NULL;
|
||||
|
||||
fail_no_mem:
|
||||
lash_error("Ran out of memory trying to construct method return");
|
||||
|
@ -134,26 +134,26 @@ fail_no_mem:
|
|||
/*
|
||||
* Send a method return.
|
||||
*
|
||||
* If call->reply is NULL, i.e. a previous attempt to construct
|
||||
* If call_ptr->reply is NULL, i.e. a previous attempt to construct
|
||||
* a return has failed, attempt to send a void return.
|
||||
*/
|
||||
void
|
||||
method_return_send(method_call_t *call)
|
||||
method_return_send(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
if (call->reply) {
|
||||
if (call_ptr->reply) {
|
||||
retry_send:
|
||||
if (!dbus_connection_send(call->connection, call->reply, NULL))
|
||||
if (!dbus_connection_send(call_ptr->connection, call_ptr->reply, NULL))
|
||||
lash_error("Ran out of memory trying to queue "
|
||||
"method return");
|
||||
else
|
||||
dbus_connection_flush(call->connection);
|
||||
dbus_connection_flush(call_ptr->connection);
|
||||
|
||||
dbus_message_unref(call->reply);
|
||||
call->reply = NULL;
|
||||
dbus_message_unref(call_ptr->reply);
|
||||
call_ptr->reply = NULL;
|
||||
} else {
|
||||
lash_debug("Message was NULL, trying to construct a void return");
|
||||
|
||||
if ((call->reply = dbus_message_new_method_return(call->message))) {
|
||||
if ((call_ptr->reply = dbus_message_new_method_return(call_ptr->message))) {
|
||||
lash_debug("Constructed a void return, trying to queue it");
|
||||
goto retry_send;
|
||||
} else {
|
||||
|
|
101
dbus/method.h
101
dbus/method.h
|
@ -30,89 +30,44 @@
|
|||
#ifndef __LASH_DBUS_METHOD_H__
|
||||
#define __LASH_DBUS_METHOD_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
struct _method_msg
|
||||
struct dbus_method_call
|
||||
{
|
||||
const service_t *service;
|
||||
DBusMessage *message;
|
||||
void *context;
|
||||
DBusFreeFunction context_free_func;
|
||||
DBusPendingCallNotifyFunction return_handler;
|
||||
DBusConnection * connection;
|
||||
const char * method_name;
|
||||
DBusMessage * message;
|
||||
DBusMessage * reply;
|
||||
const struct dbus_interface_descriptor * iface;
|
||||
void * iface_context;
|
||||
};
|
||||
|
||||
struct _method_call
|
||||
struct dbus_method_arg_descriptor
|
||||
{
|
||||
DBusConnection *connection;
|
||||
const char *method_name;
|
||||
DBusMessage *message;
|
||||
DBusMessage *reply;
|
||||
const interface_t *interface;
|
||||
void *context;
|
||||
};
|
||||
|
||||
struct _method_arg
|
||||
{
|
||||
const char *name;
|
||||
const char *type;
|
||||
const char * name;
|
||||
const char * type;
|
||||
const bool direction_in; /* false == out, true == in */
|
||||
};
|
||||
|
||||
struct _method
|
||||
typedef void (* dbus_method_handler)(struct dbus_method_call * call_ptr);
|
||||
|
||||
struct dbus_method_descriptor
|
||||
{
|
||||
const char *name;
|
||||
const method_handler_t handler;
|
||||
const method_arg_t *args;
|
||||
const char * name;
|
||||
const dbus_method_handler handler;
|
||||
const struct dbus_method_arg_descriptor * args;
|
||||
};
|
||||
|
||||
void
|
||||
method_return_new_void(method_call_t *call);
|
||||
void method_return_new_void(struct dbus_method_call * call_ptr);
|
||||
void method_return_new_single(struct dbus_method_call * call_ptr, int type, const void * arg);
|
||||
void method_return_new_valist(struct dbus_method_call * call_ptr, int type, ...);
|
||||
bool method_return_verify(DBusMessage * msg, const char ** str);
|
||||
bool method_iter_append_variant(DBusMessageIter *iter, int type, const void * arg);
|
||||
bool method_iter_append_dict_entry(DBusMessageIter *iter, int type, const char * key, const void * value, int length);
|
||||
void method_return_send(struct dbus_method_call * call_ptr);
|
||||
void method_default_handler(DBusPendingCall * pending, void * data);
|
||||
bool method_iter_get_dict_entry(DBusMessageIter * iter, const char ** key_ptr, void * value_ptr, int * type_ptr, int * size_ptr);
|
||||
|
||||
void
|
||||
method_return_new_single(method_call_t *call,
|
||||
int type,
|
||||
const void *arg);
|
||||
|
||||
void
|
||||
method_return_new_valist(method_call_t *call,
|
||||
int type,
|
||||
...);
|
||||
|
||||
bool
|
||||
method_return_verify(DBusMessage *msg,
|
||||
const char **str);
|
||||
|
||||
bool
|
||||
method_iter_append_variant(DBusMessageIter *iter,
|
||||
int type,
|
||||
const void *arg);
|
||||
|
||||
bool
|
||||
method_iter_append_dict_entry(DBusMessageIter *iter,
|
||||
int type,
|
||||
const char *key,
|
||||
const void *value,
|
||||
int length);
|
||||
|
||||
void
|
||||
method_return_send(method_call_t *call);
|
||||
|
||||
void
|
||||
method_default_handler(DBusPendingCall *pending,
|
||||
void *data);
|
||||
|
||||
bool
|
||||
method_iter_get_dict_entry(DBusMessageIter *iter,
|
||||
const char **key_ptr,
|
||||
void *value_ptr,
|
||||
int *type_ptr,
|
||||
int *size_ptr);
|
||||
|
||||
#define METHOD_ARGS_BEGIN(method_name, descr) \
|
||||
static const struct _method_arg method_name ## _args_dtor[] = \
|
||||
#define METHOD_ARGS_BEGIN(method_name, descr) \
|
||||
static const struct dbus_method_arg_descriptor method_name ## _args_dtor[] = \
|
||||
{
|
||||
|
||||
#define METHOD_ARG_DESCRIBE_IN(arg_name, arg_type, descr) \
|
||||
|
@ -136,7 +91,7 @@ static const struct _method_arg method_name ## _args_dtor[] = \
|
|||
};
|
||||
|
||||
#define METHODS_BEGIN \
|
||||
static const struct _method methods_dtor[] = \
|
||||
static const struct dbus_method_descriptor methods_dtor[] = \
|
||||
{
|
||||
|
||||
#define METHOD_DESCRIBE(method_name, handler_name) \
|
||||
|
|
|
@ -28,13 +28,13 @@
|
|||
*/
|
||||
|
||||
#include "../common.h"
|
||||
#include "object_path.h"
|
||||
#include "helpers.h"
|
||||
#include "../common/safety.h"
|
||||
#include "error.h" /* lash_dbus_error() */
|
||||
|
||||
struct dbus_object_path_interface
|
||||
{
|
||||
const interface_t * iface;
|
||||
const struct dbus_interface_descriptor * iface;
|
||||
void * iface_context;
|
||||
};
|
||||
|
||||
|
@ -52,10 +52,10 @@ introspection_new(struct dbus_object_path * opath_ptr)
|
|||
{
|
||||
char *xml_data, *buf_ptr;
|
||||
const struct dbus_object_path_interface * iface_ptr;
|
||||
const method_t * method_ptr;
|
||||
const method_arg_t * method_arg_ptr;
|
||||
const signal_t * signal_ptr;
|
||||
const signal_arg_t * signal_arg_ptr;
|
||||
const struct dbus_method_descriptor * method_ptr;
|
||||
const struct dbus_method_arg_descriptor * method_arg_ptr;
|
||||
const struct dbus_signal_descriptor * signal_ptr;
|
||||
const struct dbus_signal_arg_descriptor * signal_arg_ptr;
|
||||
DBusMessage * msg;
|
||||
DBusMessageIter iter;
|
||||
|
||||
|
@ -150,7 +150,7 @@ introspection_destroy(struct dbus_object_path *path)
|
|||
#endif
|
||||
}
|
||||
|
||||
static bool introspection_handler(const interface_t * interface, method_call_t * call_ptr)
|
||||
static bool introspection_handler(const struct dbus_interface_descriptor * interface, struct dbus_method_call * call_ptr)
|
||||
{
|
||||
if (strcmp(call_ptr->method_name, "Introspect") != 0)
|
||||
{
|
||||
|
@ -159,7 +159,7 @@ static bool introspection_handler(const interface_t * interface, method_call_t *
|
|||
}
|
||||
|
||||
/* Try to construct the instrospection message */
|
||||
call_ptr->reply = dbus_message_copy(call_ptr->context); /* context contains the reply message */
|
||||
call_ptr->reply = dbus_message_copy(call_ptr->iface_context); /* context contains the reply message */
|
||||
if (call_ptr->reply == NULL)
|
||||
{
|
||||
lash_error("Ran out of memory trying to copy introspection message");
|
||||
|
@ -204,13 +204,11 @@ INTERFACE_BEGIN(g_dbus_interface_dtor_introspectable, "org.freedesktop.DBus.Intr
|
|||
INTERFACE_EXPOSE_METHODS
|
||||
INTERFACE_END
|
||||
|
||||
extern const interface_t g_dbus_interface_dtor_introspectable;
|
||||
|
||||
dbus_object_path dbus_object_path_new(const char *name, const interface_t * iface1_ptr, ...)
|
||||
dbus_object_path dbus_object_path_new(const char *name, const struct dbus_interface_descriptor * iface1_ptr, ...)
|
||||
{
|
||||
struct dbus_object_path * opath_ptr;
|
||||
va_list ap;
|
||||
const interface_t * iface_src_ptr;
|
||||
const struct dbus_interface_descriptor * iface_src_ptr;
|
||||
struct dbus_object_path_interface * iface_dst_ptr;
|
||||
void * iface_context;
|
||||
size_t len;
|
||||
|
@ -237,7 +235,7 @@ dbus_object_path dbus_object_path_new(const char *name, const interface_t * ifac
|
|||
while (iface_src_ptr != NULL)
|
||||
{
|
||||
iface_context = va_arg(ap, void *);
|
||||
iface_src_ptr = va_arg(ap, const interface_t *);
|
||||
iface_src_ptr = va_arg(ap, const struct dbus_interface_descriptor *);
|
||||
len++;
|
||||
}
|
||||
va_end(ap);
|
||||
|
@ -256,7 +254,7 @@ dbus_object_path dbus_object_path_new(const char *name, const interface_t * ifac
|
|||
{
|
||||
iface_dst_ptr->iface = iface_src_ptr;
|
||||
iface_dst_ptr->iface_context = va_arg(ap, void *);
|
||||
iface_src_ptr = va_arg(ap, const interface_t *);
|
||||
iface_src_ptr = va_arg(ap, const struct dbus_interface_descriptor *);
|
||||
iface_dst_ptr++;
|
||||
len--;
|
||||
}
|
||||
|
@ -310,7 +308,7 @@ static DBusHandlerResult dbus_object_path_handler(DBusConnection * connection, D
|
|||
{
|
||||
const char * iface_name;
|
||||
const struct dbus_object_path_interface * iface_ptr;
|
||||
method_call_t call;
|
||||
struct dbus_method_call call;
|
||||
|
||||
/* Check if the message is a method call. If not, ignore it. */
|
||||
if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
|
||||
|
@ -329,7 +327,7 @@ static DBusHandlerResult dbus_object_path_handler(DBusConnection * connection, D
|
|||
/* Initialize our data. */
|
||||
call.connection = connection;
|
||||
call.message = message;
|
||||
call.interface = NULL; /* To be set by the default interface handler */
|
||||
call.iface = NULL; /* To be set by the default interface handler */
|
||||
call.reply = NULL;
|
||||
|
||||
/* Check if there's an interface specified for this method call. */
|
||||
|
@ -340,7 +338,7 @@ static DBusHandlerResult dbus_object_path_handler(DBusConnection * connection, D
|
|||
{
|
||||
if (strcmp(iface_name, iface_ptr->iface->name) == 0)
|
||||
{
|
||||
call.context = iface_ptr->iface_context;
|
||||
call.iface_context = iface_ptr->iface_context;
|
||||
if (!iface_ptr->iface->handler(iface_ptr->iface, &call))
|
||||
{
|
||||
/* unknown method */
|
||||
|
@ -363,7 +361,7 @@ static DBusHandlerResult dbus_object_path_handler(DBusConnection * connection, D
|
|||
*/
|
||||
for (iface_ptr = opath_ptr->ifaces; iface_ptr->iface != NULL; iface_ptr++)
|
||||
{
|
||||
call.context = iface_ptr->iface_context;
|
||||
call.iface_context = iface_ptr->iface_context;
|
||||
if (!iface_ptr->iface->handler(iface_ptr->iface, &call))
|
||||
{
|
||||
/* known method */
|
||||
|
|
|
@ -30,14 +30,9 @@
|
|||
#ifndef __LASH_DBUS_OBJECT_PATH_H__
|
||||
#define __LASH_DBUS_OBJECT_PATH_H__
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "interface.h"
|
||||
|
||||
typedef struct dbus_object_path_tag { int unused; } * dbus_object_path;
|
||||
|
||||
dbus_object_path dbus_object_path_new(const char * name, const interface_t * iface, ...);
|
||||
dbus_object_path dbus_object_path_new(const char * name, const struct dbus_interface_descriptor * iface, ...);
|
||||
bool dbus_object_path_register(DBusConnection * connection_ptr, dbus_object_path opath);
|
||||
void dbus_object_path_destroy(DBusConnection * connection_ptr, dbus_object_path opath);
|
||||
|
||||
|
|
|
@ -29,10 +29,23 @@
|
|||
|
||||
#include "../common.h"
|
||||
#include <stdarg.h>
|
||||
#include "signal.h"
|
||||
#include "helpers.h"
|
||||
|
||||
static void
|
||||
signal_send(signal_msg_t *signal);
|
||||
struct dbus_signal_msg
|
||||
{
|
||||
DBusConnection * connection;
|
||||
DBusMessage * message;
|
||||
};
|
||||
|
||||
static void signal_send(struct dbus_signal_msg * signal)
|
||||
{
|
||||
if (!dbus_connection_send(signal->connection, signal->message, NULL))
|
||||
{
|
||||
lash_error("Ran out of memory trying to queue signal");
|
||||
}
|
||||
|
||||
dbus_connection_flush(signal->connection);
|
||||
}
|
||||
|
||||
void
|
||||
signal_new_single(
|
||||
|
@ -43,7 +56,7 @@ signal_new_single(
|
|||
int type,
|
||||
const void * arg)
|
||||
{
|
||||
signal_msg_t signal;
|
||||
struct dbus_signal_msg signal;
|
||||
DBusMessageIter iter;
|
||||
|
||||
lash_debug("Sending signal %s.%s from %s", interface, name, path);
|
||||
|
@ -75,7 +88,7 @@ signal_new_valist(
|
|||
int type,
|
||||
...)
|
||||
{
|
||||
signal_msg_t signal;
|
||||
struct dbus_signal_msg signal;
|
||||
va_list argp;
|
||||
|
||||
lash_debug("Sending signal %s.%s from %s", interface, name, path);
|
||||
|
@ -98,15 +111,3 @@ signal_new_valist(
|
|||
|
||||
lash_error("Ran out of memory trying to create new signal");
|
||||
}
|
||||
|
||||
static void
|
||||
signal_send(signal_msg_t *signal)
|
||||
{
|
||||
if (!dbus_connection_send(signal->connection, signal->message, NULL)) {
|
||||
lash_error("Ran out of memory trying to queue signal");
|
||||
}
|
||||
|
||||
dbus_connection_flush(signal->connection);
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -30,26 +30,16 @@
|
|||
#ifndef __LASH_DBUS_SIGNAL_H__
|
||||
#define __LASH_DBUS_SIGNAL_H__
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
struct _signal_msg
|
||||
struct dbus_signal_arg_descriptor
|
||||
{
|
||||
DBusConnection *connection;
|
||||
DBusMessage *message;
|
||||
const char * name;
|
||||
const char * type;
|
||||
};
|
||||
|
||||
struct _signal_arg
|
||||
struct dbus_signal_descriptor
|
||||
{
|
||||
const char *name;
|
||||
const char *type;
|
||||
};
|
||||
|
||||
struct _signal
|
||||
{
|
||||
const char *name;
|
||||
const signal_arg_t *args;
|
||||
const char * name;
|
||||
const struct dbus_signal_arg_descriptor * args;
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -70,8 +60,8 @@ signal_new_valist(
|
|||
int type,
|
||||
...);
|
||||
|
||||
#define SIGNAL_ARGS_BEGIN(signal_name, descr) \
|
||||
static const struct _signal_arg signal_name ## _args_dtor[] = \
|
||||
#define SIGNAL_ARGS_BEGIN(signal_name, descr) \
|
||||
static const struct dbus_signal_arg_descriptor signal_name ## _args_dtor[] = \
|
||||
{
|
||||
|
||||
#define SIGNAL_ARG_DESCRIBE(arg_name, arg_type, descr) \
|
||||
|
@ -88,7 +78,7 @@ static const struct _signal_arg signal_name ## _args_dtor[] = \
|
|||
};
|
||||
|
||||
#define SIGNALS_BEGIN \
|
||||
static const struct _signal signals_dtor[] = \
|
||||
static const struct dbus_signal_descriptor signals_dtor[] = \
|
||||
{
|
||||
|
||||
#define SIGNAL_DESCRIBE(signal_name) \
|
||||
|
|
54
dbus/types.h
54
dbus/types.h
|
@ -1,54 +0,0 @@
|
|||
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
* Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
|
||||
*
|
||||
**************************************************************************
|
||||
* This file contains typdefs for internal structs (obsolete)
|
||||
**************************************************************************
|
||||
*
|
||||
* Licensed under the Academic Free License version 2.1
|
||||
*
|
||||
* LADI Session Handler is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LADI Session Handler is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
||||
* or write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __LASH_DBUS_TYPES_H__
|
||||
#define __LASH_DBUS_TYPES_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/* signal types */
|
||||
typedef struct _signal_msg signal_msg_t;
|
||||
typedef struct _signal_arg signal_arg_t;
|
||||
typedef struct _signal signal_t;
|
||||
|
||||
/* method types */
|
||||
typedef struct _method_msg method_msg_t;
|
||||
typedef struct _method_call method_call_t;
|
||||
typedef struct _method_arg method_arg_t;
|
||||
typedef struct _method method_t;
|
||||
typedef void (*method_handler_t) (method_call_t *call);
|
||||
|
||||
/* interface types */
|
||||
typedef struct _interface interface_t;
|
||||
typedef bool (*interface_handler_t) (const interface_t *, method_call_t *);
|
||||
|
||||
/* service types */
|
||||
typedef struct _service service_t;
|
||||
|
||||
#endif /* __LASH_DBUS_TYPES_H__ */
|
|
@ -26,14 +26,11 @@
|
|||
|
||||
//#define LASH_DEBUG
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "jack_proxy.h"
|
||||
#include "dbus/helpers.h"
|
||||
#include "common/debug.h"
|
||||
#include "dbus_constants.h"
|
||||
#include "dbus/method.h"
|
||||
|
||||
jack_proxy_callback_server_started g_on_server_started;
|
||||
jack_proxy_callback_server_stopped g_on_server_stopped;
|
||||
|
|
Loading…
Reference in New Issue