2009-08-01 19:51:07 +03:00
|
|
|
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
2008-09-07 01:48:05 +03:00
|
|
|
/*
|
2009-08-01 19:51:07 +03:00
|
|
|
* LADI Session Handler (ladish)
|
2008-09-07 01:48:05 +03:00
|
|
|
*
|
2009-08-09 19:23:04 +03:00
|
|
|
* Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
2009-08-01 19:51:07 +03:00
|
|
|
* Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
|
2008-09-07 01:48:05 +03:00
|
|
|
*
|
2009-08-01 19:51:07 +03:00
|
|
|
**************************************************************************
|
|
|
|
* This file contains interface to D-Bus methods helpers
|
|
|
|
**************************************************************************
|
2008-09-07 01:48:05 +03:00
|
|
|
*
|
2009-08-01 19:51:07 +03:00
|
|
|
* 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.
|
2008-09-07 01:48:05 +03:00
|
|
|
*
|
2009-08-01 19:51:07 +03:00
|
|
|
* 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.
|
2008-09-07 01:48:05 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LASH_DBUS_METHOD_H__
|
|
|
|
#define __LASH_DBUS_METHOD_H__
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <dbus/dbus.h>
|
|
|
|
|
2009-07-12 22:56:19 +03:00
|
|
|
#include "types.h"
|
2008-09-07 01:48:05 +03:00
|
|
|
|
|
|
|
struct _method_msg
|
|
|
|
{
|
2009-07-13 00:15:44 +03:00
|
|
|
const service_t *service;
|
|
|
|
DBusMessage *message;
|
|
|
|
void *context;
|
|
|
|
DBusFreeFunction context_free_func;
|
|
|
|
DBusPendingCallNotifyFunction return_handler;
|
2008-09-07 01:48:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _method_call
|
|
|
|
{
|
2009-07-13 00:15:44 +03:00
|
|
|
DBusConnection *connection;
|
|
|
|
const char *method_name;
|
|
|
|
DBusMessage *message;
|
|
|
|
DBusMessage *reply;
|
|
|
|
const interface_t *interface;
|
|
|
|
void *context;
|
2008-09-07 01:48:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _method_arg
|
|
|
|
{
|
2009-07-13 00:15:44 +03:00
|
|
|
const char *name;
|
|
|
|
const char *type;
|
2009-08-09 19:23:04 +03:00
|
|
|
const bool direction_in; /* false == out, true == in */
|
2008-09-07 01:48:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _method
|
|
|
|
{
|
2009-07-13 00:15:44 +03:00
|
|
|
const char *name;
|
|
|
|
const method_handler_t handler;
|
|
|
|
const method_arg_t *args;
|
2008-09-07 01:48:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
method_return_new_void(method_call_t *call);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2009-08-09 19:23:04 +03:00
|
|
|
#define METHOD_ARGS_BEGIN(method_name, descr) \
|
2008-09-07 01:48:05 +03:00
|
|
|
static const struct _method_arg method_name ## _args_dtor[] = \
|
|
|
|
{
|
|
|
|
|
2009-08-09 19:23:04 +03:00
|
|
|
#define METHOD_ARG_DESCRIBE_IN(arg_name, arg_type, descr) \
|
|
|
|
{ \
|
|
|
|
.name = arg_name, \
|
|
|
|
.type = arg_type, \
|
|
|
|
.direction_in = true \
|
|
|
|
},
|
|
|
|
|
|
|
|
#define METHOD_ARG_DESCRIBE_OUT(arg_name, arg_type, descr) \
|
2008-09-07 01:48:05 +03:00
|
|
|
{ \
|
|
|
|
.name = arg_name, \
|
|
|
|
.type = arg_type, \
|
2009-08-09 19:23:04 +03:00
|
|
|
.direction_in = false \
|
2008-09-07 01:48:05 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
#define METHOD_ARGS_END \
|
|
|
|
{ \
|
|
|
|
.name = NULL, \
|
|
|
|
} \
|
|
|
|
};
|
|
|
|
|
|
|
|
#define METHODS_BEGIN \
|
|
|
|
static const struct _method methods_dtor[] = \
|
|
|
|
{
|
|
|
|
|
|
|
|
#define METHOD_DESCRIBE(method_name, handler_name) \
|
|
|
|
{ \
|
|
|
|
.name = # method_name, \
|
|
|
|
.handler = handler_name, \
|
|
|
|
.args = method_name ## _args_dtor \
|
|
|
|
},
|
|
|
|
|
|
|
|
#define METHODS_END \
|
|
|
|
{ \
|
|
|
|
.name = NULL, \
|
|
|
|
.handler = NULL, \
|
|
|
|
.args = NULL \
|
|
|
|
} \
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __LASH_DBUS_METHOD_H__ */
|