Add untested loginHelper implementation
[platform/core/uifw/at-spi2-atk.git] / login-helper / login-helper.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * LoginHelper interface 
6  * Copyright 2004 Sun Microsystems Inc.,
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 /* login-helper.c: minimal implementation of Accessibility_LoginHelper.idl */
25 #include <config.h>
26 #include "login-helper.h"
27 #include "spi-common/spi-dbus.h"
28 #include "droute/droute.h"
29
30 /* Our parent Gtk object type */
31 #define PARENT_TYPE G_TYPE_OBJECT
32
33 /* A pointer to our parent object class */
34 static GObjectClass *g_object_parent_class;
35
36 static void
37 login_helper_finalize (GObject *object)
38 {
39   (G_OBJECT_CLASS (g_object_parent_class))->finalize (object);
40 }
41
42 static gboolean
43 login_helper_set_safe (LoginHelper *helper, gboolean safe)
44 {
45   LoginHelperClass *klass = LOGIN_HELPER_GET_CLASS (helper);
46   
47   if (klass->set_safe)
48     return (* klass->set_safe)(helper, safe);
49   else
50     return FALSE;
51 }
52
53 static DBusMessage *
54 impl_set_safe (DBusConnection *bus, DBusMessage *message, void *user_data)
55 {
56   LoginHelper *helper = user_data;
57
58   DBusError error;
59   dbus_bool_t safe;
60   dbus_bool_t rv;
61   DBusMessage *reply;
62
63   dbus_error_init (&error);
64   if (!dbus_message_get_args
65       (message, &error, DBUS_TYPE_BOOLEAN, &safe, DBUS_TYPE_INVALID))
66     {
67       return SPI_DBUS_RETURN_ERROR (message, &error);
68     }
69   rv = login_helper_set_safe (helper, safe);
70   reply = dbus_message_new_method_return (message);
71   if (reply)
72     {
73       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv, DBUS_TYPE_INVALID);
74     }
75   return reply;
76 }
77
78 static LoginHelperDeviceReqFlags
79 login_helper_get_device_reqs (LoginHelper *helper)
80 {
81   LoginHelperClass *klass = LOGIN_HELPER_GET_CLASS (helper);
82   
83   if (klass->get_device_reqs)
84     return  (* klass->get_device_reqs)(helper);
85   else
86     return 0;
87 }
88
89 static DBusMessage *
90 impl_get_device_reqs (DBusConnection *bus, DBusMessage *message, void *user_data)
91 {
92   LoginHelper *helper = user_data;
93   dbus_uint32_t flags = 0;
94   DBusMessage *reply;
95
96   flags = login_helper_get_device_reqs (helper);
97
98   reply = dbus_message_new_method_return (message);
99   if (reply)
100     {
101       dbus_message_append_args (reply, DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID);
102     }
103   return reply;
104 }
105
106 static Window*
107 login_helper_get_raise_windows (LoginHelper *helper)
108 {
109   LoginHelperClass *klass = LOGIN_HELPER_GET_CLASS (helper);
110   
111   if (klass->get_raise_windows)
112     return (* klass->get_raise_windows)(helper);
113   else
114     return NULL;
115 }
116
117 static DBusMessage *
118 impl_get_raise_windows (DBusConnection *bus, DBusMessage *message, void *user_data)
119 {
120   LoginHelper *helper = user_data;
121   unsigned long *wids;
122   gint count = 0;
123   DBusMessage *reply;
124   DBusMessageIter iter, iter_array;
125
126   wids = login_helper_get_raise_windows (helper);
127   reply = dbus_message_new_method_return (message);
128   if (!reply) return NULL;
129   dbus_message_iter_init_append (message, &iter);
130   if (dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "i", &iter_array) && wids)
131   {
132     while (*wids)
133     {
134       // TODO: figure out if this will break on 64-bit systems
135       dbus_int32_t id = *wids++;
136       dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_INT32, &id);
137     }
138     dbus_message_iter_close_container (&iter, &iter_array);
139   }
140   if (wids) g_free (wids);
141   return reply;
142 }
143
144 static void
145 login_helper_class_init (LoginHelperClass *klass)
146 {
147   GObjectClass * object_class = (GObjectClass *) klass;
148
149   g_object_parent_class = g_type_class_peek_parent (klass);
150
151   object_class->finalize = login_helper_finalize;
152   
153 }
154
155 static void
156 login_helper_init (LoginHelper *object)
157 {
158 }
159
160 G_DEFINE_TYPE (LoginHelper,
161                        login_helper,
162                        PARENT_TYPE)
163