Fixed typo in error message.
[gsmd2.git] / libfreesmartphone / freesmartphone-sms.c
blob6713db29b12625b94b704c04fbc319685b4fbc56
1 /*
2 * freesmartphone-sms.c
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)
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 * Heikki Paajanen
24 * Vesa Pikki
28 #include "freesmartphone-internal.h"
29 #include "freesmartphone-sms.h"
30 #include "freesmartphone-sms-binding.h"
31 #include "fso-marshallers.h"
33 #define FSO_MESSAGE_SENT_SIGNAL_NAME "MessageSent"
34 #define FSO_CALL_INCOMING_MESSAGE_SIGNAL_NAME "IncomingMessage"
37 /**
38 * @brief Initializes SMS interface, it is called automatically
39 * when necessary
41 * @param fs pointer to freesmartphone struct
43 void fso_gsm_sms_init(FreeSmartphone *fs)
45 g_debug("%s", __func__);
47 /* Message Sent */
48 dbus_g_object_register_marshaller (fso_marshaller_VOID__BOOLEAN_STRING,
49 G_TYPE_NONE,
50 G_TYPE_BOOLEAN,
51 G_TYPE_STRING,
52 G_TYPE_INVALID);
55 static
56 void fso_gsm_sms_send_message_reply(DBusGProxy *proxy,
57 GError *error,
58 gpointer userdata)
60 g_debug("%s", __func__);
61 ReplyData *reply = (ReplyData*)userdata;
62 FSGSMSMSReply reply_cb = (FSGSMSMSReply)reply->cb;
63 gpointer data = reply->data;
64 fso_reply_data_free(reply);
65 reply_cb(error, data);
70 gboolean fso_gsm_sms_send_message(FreeSmartphone *fs,
71 const gchar *message,
72 const gchar *number,
73 const gboolean want_report,
74 FSGSMSMSReply cb,
75 gpointer userdata)
77 g_return_val_if_fail(fs, FALSE);
78 g_debug("%s : '%s' to %s", __func__, message, number);
81 ReplyData *replydata = fso_prepare_method(fs,
82 G_CALLBACK(cb),
83 userdata,
84 FSO_SMS);
85 if ( !replydata )
86 return FALSE;
88 DBusGProxy *proxy = fso_get_proxy(fs,FSO_SMS);
90 org_freesmartphone_GSM_SMS_send_message_async (proxy,
91 message,
92 number,
93 want_report,
94 &fso_gsm_sms_send_message_reply,
95 (gpointer)replydata);
97 return TRUE;
101 static
102 void fso_gsm_sms_message_sent_handler(DBusGProxy *proxy,
103 gboolean success,
104 gchar *reason,
105 gpointer data)
107 g_debug("%s", __func__);
108 FreeSmartphone *fs = (FreeSmartphone*)data;
109 g_return_if_fail(fs);
110 GList *list = NULL;
112 list = fso_get_signal_handler(fs,FSO_SIGNAL_MESSAGE_SENT);
113 while ( list ) {
114 ReplyData *rd = (ReplyData*)list->data;
115 FSGSMSMSMessageSent status_cb = (FSGSMSMSMessageSent)rd->cb;
116 status_cb (success,reason,rd->data);
117 list = g_list_next(list);
121 gboolean fso_gsm_sms_message_sent_signal(FreeSmartphone *fs,
122 FSGSMSMSMessageSent cb,
123 gpointer userdata)
125 g_return_val_if_fail(fs, FALSE);
126 g_debug("%s", __func__);
128 ReplyData *replydata = fso_prepare_method(fs,
129 G_CALLBACK(cb),
130 userdata,
131 FSO_SMS);
132 if ( !replydata )
133 return FALSE;
135 DBusGProxy *proxy = fso_get_proxy(fs,FSO_SMS);
137 if ( fso_append_data_to_signal_handler(fs,
138 FSO_SIGNAL_MESSAGE_SENT,
139 replydata) ) {
140 dbus_g_proxy_add_signal(proxy,
141 FSO_MESSAGE_SENT_SIGNAL_NAME,
142 G_TYPE_BOOLEAN,
143 G_TYPE_STRING,
144 G_TYPE_INVALID);
145 dbus_g_proxy_connect_signal (proxy, FSO_MESSAGE_SENT_SIGNAL_NAME,
146 G_CALLBACK(fso_gsm_sms_message_sent_handler),
147 fs, NULL);
151 return TRUE;
154 gboolean fso_gsm_sms_message_sent_signal_remove(FreeSmartphone *fs,
155 FSGSMSMSMessageSent cb,
156 gpointer userdata)
158 g_return_val_if_fail(fs, FALSE);
159 g_debug("%s", __func__);
161 return fso_signal_remove(fs,
162 FSO_SMS,
163 FSO_MESSAGE_SENT_SIGNAL_NAME,
164 FSO_SIGNAL_MESSAGE_SENT,
165 G_CALLBACK(fso_gsm_sms_message_sent_handler),
166 (gpointer)fs,
167 G_CALLBACK(cb),
168 userdata);
173 static
174 void fso_gsm_sms_incoming_message_handler(DBusGProxy *proxy,
175 gint index,
176 gpointer data)
178 g_debug("%s", __func__);
179 FreeSmartphone *fs = (FreeSmartphone*)data;
180 g_return_if_fail(fs);
181 GList *list = NULL;
183 list = fso_get_signal_handler(fs,FSO_SIGNAL_CALL_INCOMING_MESSAGE);
184 while ( list ) {
185 ReplyData *rd = (ReplyData*)list->data;
186 FSGSMSMSIncomingMessage status_cb = (FSGSMSMSIncomingMessage)rd->cb;
187 status_cb (index,rd->data);
188 list = g_list_next(list);
192 gboolean fso_gsm_sms_incoming_message_signal(FreeSmartphone *fs,
193 FSGSMSMSIncomingMessage cb,
194 gpointer userdata)
196 g_return_val_if_fail(fs, FALSE);
197 g_debug("%s", __func__);
199 ReplyData *replydata = fso_prepare_method(fs,
200 G_CALLBACK(cb),
201 userdata,
202 FSO_SMS);
203 if ( !replydata )
204 return FALSE;
206 DBusGProxy *proxy = fso_get_proxy(fs,FSO_SMS);
208 if ( fso_append_data_to_signal_handler(fs,
209 FSO_SIGNAL_CALL_INCOMING_MESSAGE,
210 replydata) ) {
211 dbus_g_proxy_add_signal(proxy,
212 FSO_CALL_INCOMING_MESSAGE_SIGNAL_NAME,
213 G_TYPE_INT,
214 G_TYPE_INVALID);
215 dbus_g_proxy_connect_signal (proxy, FSO_CALL_INCOMING_MESSAGE_SIGNAL_NAME,
216 G_CALLBACK(fso_gsm_sms_incoming_message_handler),
217 fs, NULL);
220 return TRUE;
223 gboolean fso_gsm_sms_incoming_message_signal_remove(FreeSmartphone *fs,
224 FSGSMSMSIncomingMessage cb,
225 gpointer userdata)
227 g_return_val_if_fail(fs, FALSE);
228 g_debug("%s", __func__);
230 return fso_signal_remove(fs,
231 FSO_SMS,
232 FSO_CALL_INCOMING_MESSAGE_SIGNAL_NAME,
233 FSO_SIGNAL_CALL_INCOMING_MESSAGE,
234 G_CALLBACK(fso_gsm_sms_incoming_message_handler),
235 (gpointer)fs,
236 G_CALLBACK(cb),
237 userdata);