~ubuntu-branches/ubuntu/trusty/geis/trusty

« back to all changes in this revision

Viewing changes to libs/geis-dbus/geis_dbus_class.c

  • Committer: Package Import Robot
  • Author(s): Chase Douglas
  • Date: 2012-07-30 08:51:42 UTC
  • Revision ID: package-import@ubuntu.com-20120730085142-jrc33ygjvt0ob1wl
Tags: upstream-2.2.11
ImportĀ upstreamĀ versionĀ 2.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file geis_dbus_gesture_class.c
 
3
 * @brief Implementations of the GEIS DBus gesture_class transport.
 
4
 */
 
5
 
 
6
/*
 
7
 * Copyright 2011 Canonical Ltd.
 
8
 *
 
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
 
12
 * later version.
 
13
 *
 
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
 
17
 * details.
 
18
 *
 
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/>.
 
21
 */
 
22
#include "geis_config.h"
 
23
#include "geis_dbus_class.h"
 
24
 
 
25
#include "geis_dbus.h"
 
26
#include "geis_dbus_attr.h"
 
27
#include "geis_class.h"
 
28
#include "geis_logging.h"
 
29
 
 
30
 
 
31
/*
 
32
 * Creates a Dbus "gesture_class available" message from a GEIS gesture_class.
 
33
 *
 
34
 * The Wire protocol for this message is class_id and class_name followed by
 
35
 * the list of class attributes.
 
36
 */
 
37
DBusMessage *
 
38
geis_dbus_class_available_message_from_class(GeisGestureClass gesture_class)
 
39
{
 
40
  DBusMessage *message = dbus_message_new_signal(GEIS_DBUS_SERVICE_PATH,
 
41
                                                 GEIS_DBUS_SERVICE_INTERFACE,
 
42
                                                 GEIS_DBUS_CLASS_AVAILABLE);
 
43
  DBusMessageIter iter;
 
44
  dbus_message_iter_init_append(message, &iter);
 
45
 
 
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);
 
48
 
 
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);
 
51
 
 
52
  DBusMessageIter array_iter;
 
53
  dbus_message_iter_open_container(&iter,
 
54
                                   DBUS_TYPE_ARRAY,
 
55
                                   GEIS_DBUS_TYPE_SIGNATURE_ATTR,
 
56
                                   &array_iter);
 
57
  GeisSize attr_count = geis_gesture_class_attr_count(gesture_class);
 
58
  for (GeisSize i = 0; i < attr_count; ++i)
 
59
  {
 
60
    geis_dbus_attr_marshall(geis_gesture_class_attr(gesture_class, i),
 
61
                            &array_iter);
 
62
  }
 
63
  dbus_message_iter_close_container(&iter, &array_iter);
 
64
  return message;
 
65
}
 
66
 
 
67
 
 
68
/*
 
69
 * Creates GEIS gesture_class from a DBus "gesture_class available" message.
 
70
 */
 
71
GeisGestureClass
 
72
geis_dbus_class_class_from_available_message(DBusMessage *message)
 
73
{
 
74
  GeisGestureClass gesture_class = NULL;
 
75
  DBusMessageIter iter;
 
76
  dbus_message_iter_init(message, &iter);
 
77
 
 
78
  int type = dbus_message_iter_get_arg_type(&iter);
 
79
  if (type != DBUS_TYPE_INT32)
 
80
  {
 
81
    geis_error("error getting gesture_class ID from DBus message.");
 
82
    goto final_exit;
 
83
  }
 
84
  dbus_int32_t gesture_class_id;
 
85
  dbus_message_iter_get_basic(&iter, &gesture_class_id);
 
86
 
 
87
  dbus_message_iter_next(&iter);
 
88
  type = dbus_message_iter_get_arg_type(&iter);
 
89
  if (type != DBUS_TYPE_STRING)
 
90
  {
 
91
    geis_error("error getting gesture_class name from DBus message.");
 
92
    goto final_exit;
 
93
  }
 
94
 
 
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);
 
98
 
 
99
  dbus_message_iter_next(&iter);
 
100
  type = dbus_message_iter_get_arg_type(&iter);
 
101
  if (type != DBUS_TYPE_ARRAY)
 
102
  {
 
103
    geis_error("error getting gesture_class attr list from DBus message.");
 
104
    goto final_exit;
 
105
  }
 
106
 
 
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)
 
111
  {
 
112
    GeisAttr attr = geis_dbus_attr_unmarshall(&array_iter);
 
113
    if (attr)
 
114
    {
 
115
      geis_gesture_class_add_attr(gesture_class, attr);
 
116
    }
 
117
 
 
118
    dbus_message_iter_next(&array_iter);
 
119
    atype = dbus_message_iter_get_arg_type(&array_iter);
 
120
  }
 
121
 
 
122
final_exit:
 
123
  return gesture_class;
 
124
}
 
125
 
 
126