1
/*
2
 * AT-SPI - Assistive Technology Service Provider Interface
3
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4
 *
5
 * Copyright 2008 Novell, Inc.
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, write to the
19
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
 * Boston, MA 02110-1301, USA.
21
 */
22

            
23
#include <dbus/dbus.h>
24
#include <glib-object.h>
25
#include <glib.h>
26
#include <stdlib.h>
27

            
28
#include "de-types.h"
29

            
30
dbus_bool_t
31
spi_dbus_message_iter_get_struct (DBusMessageIter *iter, ...)
32
{
33
  va_list args;
34
  DBusMessageIter iter_struct;
35
  int type;
36
  void *ptr;
37

            
38
  dbus_message_iter_recurse (iter, &iter_struct);
39
  va_start (args, iter);
40
  for (;;)
41
    {
42
      type = va_arg (args, int);
43
      if (type == DBUS_TYPE_INVALID)
44
        break;
45
      if (type != dbus_message_iter_get_arg_type (&iter_struct))
46
        {
47
          va_end (args);
48
          return FALSE;
49
        }
50
      ptr = va_arg (args, void *);
51
      dbus_message_iter_get_basic (&iter_struct, ptr);
52
      dbus_message_iter_next (&iter_struct);
53
    }
54
  dbus_message_iter_next (iter);
55
  va_end (args);
56
  return TRUE;
57
}
58

            
59
dbus_bool_t
60
spi_dbus_message_iter_append_struct (DBusMessageIter *iter, ...)
61
{
62
  va_list args;
63
  DBusMessageIter iter_struct;
64
  int type;
65
  void *ptr;
66

            
67
  if (!dbus_message_iter_open_container (iter, DBUS_TYPE_STRUCT, NULL, &iter_struct))
68
    return FALSE;
69
  va_start (args, iter);
70
  for (;;)
71
    {
72
      type = va_arg (args, int);
73
      if (type == DBUS_TYPE_INVALID)
74
        break;
75
      ptr = va_arg (args, void *);
76
      dbus_message_iter_append_basic (&iter_struct, type, ptr);
77
    }
78
  if (!dbus_message_iter_close_container (iter, &iter_struct))
79
    {
80
      va_end (args);
81
      return FALSE;
82
    }
83
  va_end (args);
84
  return TRUE;
85
}
86

            
87
dbus_bool_t
88
spi_dbus_marshal_deviceEvent (DBusMessage *message, const Accessibility_DeviceEvent *e)
89
{
90
  DBusMessageIter iter;
91

            
92
  if (!message)
93
    return FALSE;
94
  dbus_message_iter_init_append (message, &iter);
95
  return spi_dbus_message_iter_append_struct (&iter, DBUS_TYPE_UINT32, &e->type, DBUS_TYPE_INT32, &e->id, DBUS_TYPE_UINT32, &e->hw_code, DBUS_TYPE_UINT32, &e->modifiers, DBUS_TYPE_INT32, &e->timestamp, DBUS_TYPE_STRING, &e->event_string, DBUS_TYPE_BOOLEAN, &e->is_text, DBUS_TYPE_INVALID);
96
}
97

            
98
dbus_bool_t
99
spi_dbus_demarshal_deviceEvent (DBusMessage *message, Accessibility_DeviceEvent *e)
100
{
101
  DBusMessageIter iter;
102
  dbus_uint16_t hw_code;
103
  dbus_uint16_t modifiers;
104

            
105
  dbus_message_iter_init (message, &iter);
106
  if (spi_dbus_message_iter_get_struct (&iter, DBUS_TYPE_UINT32, &e->type, DBUS_TYPE_INT32, &e->id, DBUS_TYPE_INT32, &e->hw_code, DBUS_TYPE_INT32, &e->modifiers, DBUS_TYPE_INT32, &e->timestamp, DBUS_TYPE_STRING, &e->event_string, DBUS_TYPE_BOOLEAN, &e->is_text, DBUS_TYPE_INVALID))
107
    return TRUE;
108
  /* TODO: Perhaps remove the below code for 2.1 */
109
  if (!spi_dbus_message_iter_get_struct (&iter, DBUS_TYPE_UINT32, &e->type, DBUS_TYPE_INT32, &e->id, DBUS_TYPE_INT16, &hw_code, DBUS_TYPE_INT16, &modifiers, DBUS_TYPE_INT32, &e->timestamp, DBUS_TYPE_STRING, &e->event_string, DBUS_TYPE_BOOLEAN, &e->is_text, DBUS_TYPE_INVALID))
110
    return FALSE;
111
  e->hw_code = hw_code;
112
  e->modifiers = modifiers;
113
  return TRUE;
114
}