Fixed network Status signal signature
[gsmd2.git] / src / dbus_network_object.c
blob0d4253898cb97afa7f48ab9d005c3b737a197113
1 /*
2 * dbus_network_object.c
4 * Copyright(C) 2007,2008 Ixonos Plc
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Boston, MA 02111.
22 * Written by
23 * Jukka Honkela
24 * Yi Zheng
25 * Matti Katila
26 * Vesa Pikki
27 * Heikki Paajanen
31 #include "dbus_network_object.h"
32 #include "dbus_network_glue.h"
33 #include "dbus_marshal.h"
34 #include "dbus_objects.h"
35 #include "network_interface.h"
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <dbus/dbus-glib-bindings.h>
39 #include <dbus/dbus-glib.h>
40 #include <dbus/dbus-glib-lowlevel.h>
43 #define GSMD_NETWORK_LISTPROVIDER_TYPE (dbus_g_type_get_struct ("GValueArray", \
44 G_TYPE_INT, \
45 G_TYPE_STRING, \
46 G_TYPE_STRING, \
47 G_TYPE_STRING, \
48 G_TYPE_INVALID))
50 G_DEFINE_TYPE(DBusNetworkObject, dbus_network_object, G_TYPE_OBJECT)
54 static void
55 dbus_network_object_class_init(DBusNetworkObjectClass *klass)
57 /* Make the local system aware of our kind */
59 /** Register our signals so that they can be emitted */
60 klass->status = g_signal_new("status",
61 G_OBJECT_CLASS_TYPE (klass),
62 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
63 0, NULL, NULL, g_cclosure_marshal_VOID__POINTER,
64 G_TYPE_NONE, 1, dbus_g_type_get_map ("GHashTable",
65 G_TYPE_STRING, G_TYPE_VALUE));
68 klass->subscriber_numbers = g_signal_new ("subscriber_numbers",
69 G_OBJECT_CLASS_TYPE (klass),
70 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
71 0, NULL, NULL, g_cclosure_marshal_VOID__STRING,
72 G_TYPE_NONE, 1, G_TYPE_STRING);
76 static void dbus_network_object_init(DBusNetworkObject *gsm)
78 dbus_g_object_type_install_info (DBUS_NETWORK_TYPE_OBJECT,
79 &dbus_glib_smartphone_network_object_info);
83 void dbus_network_object_finalize(GObject *obj)
85 //G_OBJECT_CLASS (parent_class)->finalize (obj);
86 //DBusNetworkObject *gsm = (DBusNetworkObject *) obj;
91 void gsmd_dbus_network_uninitialize(DBusNetworkObject *obj)
93 g_object_unref(obj);
98 /*********************Signal functions***********************/
101 void smartphone_network_status (NetworkIPCInterface *network_ipc,
102 GHashTable *status)
104 DBusNetworkObject *obj = (DBusNetworkObject*)network_ipc->priv;
105 g_signal_emit (obj,
106 DBUS_NETWORK_OBJECT_GET_CLASS(obj)->status,
107 0, status);
110 void smartphone_network_subscriber_numbers (NetworkIPCInterface *network_ipc,
111 const gchar** number)
113 DBusNetworkObject *obj = (DBusNetworkObject*)network_ipc->priv;
114 g_signal_emit (obj,
115 DBUS_NETWORK_OBJECT_GET_CLASS(obj)->subscriber_numbers,
116 0, number);
122 /*****************************Methods******************************************/
124 gboolean smartphone_network_get_country_code(DBusNetworkObject *obj,
125 DBusGMethodInvocation *method_context)
127 obj->network->get_country_code(obj->network, method_context);
128 return TRUE;
132 gboolean smartphone_network_register(DBusNetworkObject *obj,
133 DBusGMethodInvocation *method_context)
135 obj->network->register_network(obj->network, method_context);
136 return TRUE;
139 gboolean smartphone_network_unregister(DBusNetworkObject *obj,
140 DBusGMethodInvocation *method_context)
142 obj->network->unregister(obj->network, method_context);
143 return TRUE;
147 gboolean smartphone_network_get_status(DBusNetworkObject *obj,
148 DBusGMethodInvocation *method_context)
150 obj->network->get_status(obj->network,
151 method_context);
152 return TRUE;
155 gboolean smartphone_network_list_providers(DBusNetworkObject *obj,
156 DBusGMethodInvocation *method_context)
158 obj->network->list_providers(obj->network,
159 method_context);
161 return TRUE;
164 gboolean smartphone_network_register_with_provider(DBusNetworkObject *obj,
165 const gint index,
166 DBusGMethodInvocation *method_context)
168 obj->network->register_with_provider(obj->network,
169 method_context,
170 index);
171 return TRUE;
177 /*****************************Method replies***********************************/
178 void smartphone_network_get_country_code_reply(NetworkIPCInterface *network_ipc,
179 gpointer ipc_data,
180 const char *dial_code)
182 g_debug("%s", __func__);
183 if (ipc_data)
184 dbus_g_method_return((DBusGMethodInvocation*) ipc_data,
185 dial_code);
188 void smartphone_network_unregister_reply(NetworkIPCInterface *network_ipc,
189 gpointer ipc_data)
191 g_debug("%s", __func__);
192 if (ipc_data)
193 dbus_g_method_return((DBusGMethodInvocation*) ipc_data);
196 void smartphone_network_get_home_country_code_reply(NetworkIPCInterface *network_ipc,
197 gpointer ipc_data,
198 const char *dial_code)
200 g_debug("%s", __func__);
201 if (ipc_data)
202 dbus_g_method_return((DBusGMethodInvocation*) ipc_data,
203 dial_code);
206 void smartphone_network_register_reply(NetworkIPCInterface *network_ipc, gpointer ipc_data)
208 g_debug("%s", __func__);
209 if (ipc_data)
210 dbus_g_method_return((DBusGMethodInvocation*) ipc_data);
213 void smartphone_network_get_status_reply(NetworkIPCInterface *network_ipc,
214 gpointer ipc_data,
215 GHashTable *status)
218 if (ipc_data)
219 dbus_g_method_return((DBusGMethodInvocation*) ipc_data,
220 status);
226 void smartphone_network_list_providers_reply(NetworkIPCInterface *network_ipc,
227 gpointer ipc_data,
228 GArray *providers)
230 g_debug("%s", __func__);
231 GPtrArray *result = NULL;
232 guint i;
233 NetworkProvider *provider = NULL;
235 result = g_ptr_array_sized_new (providers->len);
237 for (i = 0; i < providers->len; i++) {
238 provider = g_array_index(providers,NetworkProvider*,i);
239 GValue entry = { 0, };
242 g_value_init (&entry, GSMD_NETWORK_LISTPROVIDER_TYPE);
243 g_value_take_boxed (&entry,
244 dbus_g_type_specialized_construct (GSMD_NETWORK_LISTPROVIDER_TYPE));
246 dbus_g_type_struct_set (&entry,
247 0, provider->index,
248 1, provider->status,
249 2, provider->name,
250 3, provider->nickname,
251 G_MAXUINT);
253 g_ptr_array_add (result, g_value_get_boxed (&entry));
256 if (ipc_data)
257 dbus_g_method_return((DBusGMethodInvocation*) ipc_data, result);
258 g_ptr_array_free (result, TRUE);
262 void smartphone_network_register_with_provider_reply(NetworkIPCInterface *network_ipc,
263 gpointer ipc_data)
265 g_debug("%s", __func__);
266 if (ipc_data)
267 dbus_g_method_return((DBusGMethodInvocation*) ipc_data);
272 /**************************Method error replies********************************/
273 void smartphone_network_get_country_code_error(NetworkIPCInterface *network_ipc,
274 gpointer ipc_data,
275 GError *error)
277 g_debug("%s", __func__);
278 if (ipc_data)
279 dbus_g_method_return_error((DBusGMethodInvocation*) ipc_data,error);
282 void smartphone_network_get_home_country_code_error(NetworkIPCInterface *network_ipc,
283 gpointer ipc_data,
284 GError *error)
286 g_debug("%s", __func__);
287 if (ipc_data)
288 dbus_g_method_return_error((DBusGMethodInvocation*) ipc_data,error);
291 void smartphone_network_register_error(NetworkIPCInterface *network_ipc,
292 gpointer ipc_data,
293 GError *error)
295 g_debug("%s", __func__);
296 if (ipc_data)
297 dbus_g_method_return_error((DBusGMethodInvocation*) ipc_data,error);
300 void smartphone_network_unregister_error(NetworkIPCInterface *network_ipc,
301 gpointer ipc_data,
302 GError *error)
304 g_debug("%s", __func__);
305 if (ipc_data)
306 dbus_g_method_return_error((DBusGMethodInvocation*) ipc_data,error);
309 void smartphone_network_get_status_error(NetworkIPCInterface *network_ipc,
310 gpointer ipc_data,
311 GError *error)
313 g_debug("%s", __func__);
314 if (ipc_data)
315 dbus_g_method_return_error((DBusGMethodInvocation*) ipc_data,error);
318 void smartphone_network_list_providers_error(NetworkIPCInterface *network_ipc,
319 gpointer ipc_data,
320 GError *error)
322 g_debug("%s", __func__);
323 if (ipc_data)
324 dbus_g_method_return_error((DBusGMethodInvocation*) ipc_data,error);
327 void smartphone_network_register_with_provider_error(NetworkIPCInterface *network_ipc,
328 gpointer ipc_data,
329 GError *error)
331 g_debug("%s", __func__);
332 if (ipc_data)
333 dbus_g_method_return_error((DBusGMethodInvocation*) ipc_data,error);
340 DBusNetworkObject *gsmd_dbus_network_initialize ( NetworkIPCInterface *network_ipc,
341 NetworkInterface *network)
343 DBusNetworkObject *obj = g_object_new (DBUS_NETWORK_TYPE_OBJECT, NULL);
344 network_ipc->priv = obj;
345 obj->network = network;
347 //Signals
348 network_ipc->status = &smartphone_network_status;
349 network_ipc->subscriber_numbers = &smartphone_network_subscriber_numbers;
351 //Replies
352 network_ipc->register_network_reply = &smartphone_network_register_reply;
353 network_ipc->unregister_reply = &smartphone_network_unregister_reply;
354 network_ipc->get_status_reply = &smartphone_network_get_status_reply;
355 network_ipc->list_providers_reply = &smartphone_network_list_providers_reply;
356 network_ipc->register_with_provider_reply = &smartphone_network_register_with_provider_reply;
357 network_ipc->get_country_code_reply = &smartphone_network_get_country_code_reply;
359 //Errors
360 network_ipc->register_network_error = &smartphone_network_register_error;
361 network_ipc->unregister_error = &smartphone_network_unregister_error;
362 network_ipc->get_status_error = &smartphone_network_get_status_error;
363 network_ipc->list_providers_error = &smartphone_network_list_providers_error;
364 network_ipc->register_with_provider_error = &smartphone_network_register_with_provider_error;
365 network_ipc->get_country_code_error = &smartphone_network_get_country_code_error;
371 return obj;