2
* @file geis_dbus_gesture_class.c
3
* @brief Implementations of the GEIS DBus gesture_class transport.
7
* Copyright 2011 Canonical Ltd.
9
* This library is free software; you can redistribute it and/or modify it under
10
* the terms of the GNU Lesser General Public License as published by the Free
11
* Software Foundation; either version 3 of the License, or (at your option) any
14
* This library is distributed in the hope that it will be useful, but WITHOUT
15
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19
* You should have received a copy of the GNU Lesser General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "geis_config.h"
23
#include "geis_dbus_class.h"
25
#include "geis_dbus.h"
26
#include "geis_dbus_attr.h"
27
#include "geis_class.h"
28
#include "geis_logging.h"
32
* Creates a Dbus "gesture_class available" message from a GEIS gesture_class.
34
* The Wire protocol for this message is class_id and class_name followed by
35
* the list of class attributes.
38
geis_dbus_class_available_message_from_class(GeisGestureClass gesture_class)
40
DBusMessage *message = dbus_message_new_signal(GEIS_DBUS_SERVICE_PATH,
41
GEIS_DBUS_SERVICE_INTERFACE,
42
GEIS_DBUS_CLASS_AVAILABLE);
44
dbus_message_iter_init_append(message, &iter);
46
dbus_int32_t gesture_class_id = geis_gesture_class_id(gesture_class);
47
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &gesture_class_id);
49
const char *gesture_class_name = geis_gesture_class_name(gesture_class);
50
dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &gesture_class_name);
52
DBusMessageIter array_iter;
53
dbus_message_iter_open_container(&iter,
55
GEIS_DBUS_TYPE_SIGNATURE_ATTR,
57
GeisSize attr_count = geis_gesture_class_attr_count(gesture_class);
58
for (GeisSize i = 0; i < attr_count; ++i)
60
geis_dbus_attr_marshall(geis_gesture_class_attr(gesture_class, i),
63
dbus_message_iter_close_container(&iter, &array_iter);
69
* Creates GEIS gesture_class from a DBus "gesture_class available" message.
72
geis_dbus_class_class_from_available_message(DBusMessage *message)
74
GeisGestureClass gesture_class = NULL;
76
dbus_message_iter_init(message, &iter);
78
int type = dbus_message_iter_get_arg_type(&iter);
79
if (type != DBUS_TYPE_INT32)
81
geis_error("error getting gesture_class ID from DBus message.");
84
dbus_int32_t gesture_class_id;
85
dbus_message_iter_get_basic(&iter, &gesture_class_id);
87
dbus_message_iter_next(&iter);
88
type = dbus_message_iter_get_arg_type(&iter);
89
if (type != DBUS_TYPE_STRING)
91
geis_error("error getting gesture_class name from DBus message.");
95
char *gesture_class_name;
96
dbus_message_iter_get_basic(&iter, &gesture_class_name);
97
gesture_class = geis_gesture_class_new(gesture_class_name, gesture_class_id);
99
dbus_message_iter_next(&iter);
100
type = dbus_message_iter_get_arg_type(&iter);
101
if (type != DBUS_TYPE_ARRAY)
103
geis_error("error getting gesture_class attr list from DBus message.");
107
DBusMessageIter array_iter;
108
dbus_message_iter_recurse(&iter, &array_iter);
109
int atype = dbus_message_iter_get_arg_type(&array_iter);
110
while (atype == DBUS_TYPE_DICT_ENTRY)
112
GeisAttr attr = geis_dbus_attr_unmarshall(&array_iter);
115
geis_gesture_class_add_attr(gesture_class, attr);
118
dbus_message_iter_next(&array_iter);
119
atype = dbus_message_iter_get_arg_type(&array_iter);
123
return gesture_class;