4 * Copyright(C) 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.
28 * @mainpage Libfreesmartphone
30 * \section intro Introduction
32 * This is the documentation of libfreesmartphone, a library to access
33 * GSMD2's dbus methods conveniently.
38 #include <dbus/dbus-glib.h>
40 #include "freesmartphone.h"
41 #include "freesmartphone-internal.h"
42 #include "freesmartphone-call.h"
43 #include "freesmartphone-sms.h"
45 static InterfaceDetails
49 "/org/freesmartphone/GSM/Call",
50 "org.freesmartphone.GSM.Call",
55 "/org/freesmartphone/GSM/Device",
56 "org.freesmartphone.GSM.Device",
60 "/org/freesmartphone/GSM/Network",
61 "org.freesmartphone.GSM.Network",
62 fso_gsm_network_init
},
65 "/org/freesmartphone/GSM/PDP",
66 "org.freesmartphone.GSM.PDP",
70 "/org/freesmartphone/GSM/SIM",
71 "org.freesmartphone.GSM.SIM",
75 "/org/freesmartphone/GSM/SMS",
76 "org.freesmartphone.GSM.SMS",
82 * Initialize libfreesmartphone library
85 * @return Handle for the library or NULL if initialization fails
87 FreeSmartphone
* fso_init()
89 g_debug("%s", __func__
);
92 FreeSmartphone
*fs
= g_try_new0(FreeSmartphone
, 1);
94 g_warning("%s : Out of memory", __func__
);
98 fs
->conn
= dbus_g_bus_get(DBUS_BUS_SYSTEM
, &error
);
99 if ( !fs
->conn
|| error
) {
100 g_warning("%s : Failed connect to system bus: %s",
101 __func__
, error
->message
);
102 g_error_free( error
);
108 fs
->proxies
= g_hash_table_new_full(g_int_hash
,
114 dbus_g_connection_ref (fs
->conn
);
123 void fso_reply_data_free(ReplyData
*rd
)
128 void fso_free_signal_handler(FreeSmartphone
*fs
,FSOSignal signal
)
130 GList
*list
= fso_get_signal_handler(fs
,signal
);
133 fso_reply_data_free((ReplyData
*)list
->data
);
134 list
= g_list_next(list
);
137 list
= fso_get_signal_handler(fs
,signal
);
143 void fso_free(FreeSmartphone
*fs
)
149 dbus_g_connection_unref (fs
->conn
);
152 g_hash_table_destroy(fs
->proxies
);
155 FSOSignal signal
= FSO_SIGNAL_CALL_STATUS
;
157 for(;signal
<FSO_SIGNAL_LAST
;signal
++) {
158 fso_free_signal_handler(fs
,signal
);
167 ReplyData
*fso_reply_data_new(GCallback cb
,
170 ReplyData
*rd
= g_try_new0(ReplyData
, 1);
180 gboolean
fso_signal_remove(FreeSmartphone
*fs
,
181 FSOInterface interface
,
182 const gchar
*signal_name
,
184 GCallback signal_handler
,
185 gpointer signal_handler_data
,
189 GList
*list
= fso_get_signal_handler(fs
,signal
);
190 DBusGProxy
*proxy
= fso_get_proxy(fs
,interface
);
192 ReplyData
*match
= NULL
;
194 ReplyData
*rd
= (ReplyData
*)list
->data
;
195 if ( rd
->cb
== G_CALLBACK(usercb
) && rd
->data
== userdata
) {
199 list
= g_list_next(list
);
202 fs
->signal_handlers
[signal
] = g_list_remove_all(fs
->signal_handlers
[signal
], match
);
203 if ( fs
->signal_handlers
[signal
] == NULL
) {
204 g_debug("%s : '%s'", __func__
, signal_name
);
205 dbus_g_proxy_disconnect_signal(proxy
, signal_name
,
206 G_CALLBACK(signal_handler
),
207 signal_handler_data
);
209 fso_reply_data_free( match
);
215 * @brief Returns and ensures that specific interface's proxy exists,
216 * creates it if necessary
218 * @param fs pointer to freesmartphone strucht
219 * @param interface interface whose proxy to ensure
220 * @return true if proxy exists, false if it couldn't be created
222 DBusGProxy
*fso_get_proxy(FreeSmartphone
*fs
,FSOInterface interface
)
225 g_assert(fs
->proxies
);
227 //Try to find the proxy
228 DBusGProxy
* proxy
= g_hash_table_lookup(fs
->proxies
,
229 &details
[interface
].key
);
232 //If no proxy found, create
233 proxy
= dbus_g_proxy_new_for_name(fs
->conn
,
234 FSO_GSM_SERVICE_NAME
,
235 details
[interface
].path
,
236 details
[interface
].interface
);
242 g_hash_table_insert(fs
->proxies
,
243 &details
[interface
].key
,
246 if (details
[interface
].init
)
247 details
[interface
].init(fs
);
254 * @brief Appends replydata to signal handler
256 * @param fs pointer to freesmartphone struct
257 * @param signal signal handler to append replydata to
258 * @param replydata replydata to append
259 * @return true if signal handler needs to be initialized
261 gboolean
fso_append_data_to_signal_handler(FreeSmartphone
*fs
,
263 ReplyData
*replydata
)
265 g_return_val_if_fail(fs
, FALSE
);
266 gboolean result
= FALSE
;
268 if (!fs
->signal_handlers
[signal
])
271 fs
->signal_handlers
[signal
] = g_list_append(fs
->signal_handlers
[signal
],
276 GList
*fso_get_signal_handler(FreeSmartphone
*fs
, FSOSignal signal
)
278 g_return_val_if_fail(fs
, NULL
);
279 return fs
->signal_handlers
[signal
];
286 * @brief Prepares replydata for a method call
287 * Ensures that a proper proxy is present.
289 * @param fs pointer to freesmartphone data
290 * @param cb Callback function
291 * @param userdata user data
292 * @param interface interface to which the method (we are preparing for) belongs
293 * @return new replydata (that has to be freed) or null if failed
295 ReplyData
*fso_prepare_method(FreeSmartphone
*fs
,
298 FSOInterface interface
)
302 g_warning("%s : No callback function provided!", __func__
);
306 ReplyData
*replydata
= fso_reply_data_new(cb
, userdata
);
308 g_warning("%s : Out of memory", __func__
);
313 DBusGProxy
*proxy
= fso_get_proxy(fs
,interface
);