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)
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.
30 #include "gsmd-error.h"
31 #include "dbus_objects.h"
32 #include "dbus_call_object.h"
33 #include "dbus_sms_object.h"
34 #include "dbus_sim_object.h"
35 #include "dbus_network_object.h"
36 #include "dbus_pdp_object.h"
37 #include "dbus_device_object.h"
40 gpointer
gsmd_dbus_initialize(ModemInterface
*modem
)
45 DBusObjects
*dbus
= g_try_new0 (DBusObjects
, 1);
49 dbus
->connection
= dbus_g_bus_get (DBUS_BUS_SYSTEM
, &error
);
51 if (!dbus
->connection
) {
52 g_printerr ("Failed to open connection to bus: %s\n",
55 gsmd_dbus_uninitialize(dbus
);
59 dbus
->call_object
= gsmd_dbus_call_initialize(modem
->call_ipc
,modem
->call
);
60 dbus
->sms_object
= gsmd_dbus_sms_initialize(modem
->sms_ipc
,modem
->sms
);
61 dbus
->sim_object
= gsmd_dbus_sim_initialize(modem
->sim_ipc
, modem
->sim
);
62 dbus
->network_object
= gsmd_dbus_network_initialize(modem
->network_ipc
, modem
->network
);
63 dbus
->pdp_object
= gsmd_dbus_pdp_initialize(modem
->pdp_ipc
,modem
->pdp
);
64 dbus
->device_object
= gsmd_dbus_device_initialize(modem
->device_ipc
, modem
->device
);
66 if (!dbus
->sms_object
||
69 !dbus
->network_object
||
71 !dbus
->device_object
) {
72 g_error("Failed to initialize dbus objects!\n");
73 gsmd_dbus_uninitialize(dbus
);
78 // The proxy is needed to register our object as a service
79 dbus
->proxy
= dbus_g_proxy_new_for_name (dbus
->connection
,
85 g_printerr ("Failed to create proxy: %s\n", error
->message
);
87 gsmd_dbus_uninitialize(dbus
);
92 //Register each object to the dbus
93 dbus_g_connection_register_g_object (dbus
->connection
,
94 "/org/freesmartphone/GSM/SMS",
95 G_OBJECT(dbus
->sms_object
));
96 dbus_g_connection_register_g_object (dbus
->connection
,
97 "/org/freesmartphone/GSM/SIM",
98 G_OBJECT(dbus
->sim_object
));
99 dbus_g_connection_register_g_object (dbus
->connection
,
100 "/org/freesmartphone/GSM/Call",
101 G_OBJECT(dbus
->call_object
));
102 dbus_g_connection_register_g_object (dbus
->connection
,
103 "/org/freesmartphone/GSM/Network",
104 G_OBJECT(dbus
->network_object
));
105 dbus_g_connection_register_g_object (dbus
->connection
,
106 "/org/freesmartphone/GSM/PDP",
107 G_OBJECT(dbus
->pdp_object
));
108 dbus_g_connection_register_g_object (dbus
->connection
,
109 "/org/freesmartphone/GSM/Device",
110 G_OBJECT(dbus
->device_object
));
113 // Make our service available to the dbus daemon
114 if (!org_freedesktop_DBus_request_name (dbus
->proxy
,
116 DBUS_NAME_FLAG_REPLACE_EXISTING
117 | DBUS_NAME_FLAG_ALLOW_REPLACEMENT
,
120 g_printerr("Failed to register service");
122 gsmd_dbus_uninitialize(dbus
);
129 void gsmd_dbus_uninitialize(DBusObjects
*dbus
)
132 g_assert(dbus
->proxy
);
133 GError
*error
= NULL
;
136 //Release service name from dbus
137 if (!org_freedesktop_DBus_release_name (dbus
->proxy
,GSM_SERVICE_NAME
,
138 &request_ret
, &error
)) {
139 g_error("%s: release failed: %s",__func__
, error
->message
);
142 gsmd_dbus_call_uninitialize(dbus
->call_object
);
143 gsmd_dbus_sms_uninitialize(dbus
->sms_object
);
144 gsmd_dbus_sim_uninitialize(dbus
->sim_object
);
145 gsmd_dbus_network_uninitialize(dbus
->network_object
);
146 gsmd_dbus_pdp_uninitialize(dbus
->pdp_object
);
147 gsmd_dbus_device_uninitialize(dbus
->device_object
);
151 g_object_unref (dbus
->proxy
);