/
mms_handler.c
306 lines (280 loc) · 7.23 KB
/
mms_handler.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "mms_handler.h"
/* Logging */
#define MMS_LOG_MODULE_NAME mms_handler_log
#include "mms_lib_log.h"
G_DEFINE_ABSTRACT_TYPE(MMSHandler, mms_handler, G_TYPE_OBJECT)
#define MMS_HANDLER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), MMS_TYPE_HANDLER, MMSHandler))
#define MMS_HANDLER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), MMS_TYPE_HANDLER, MMSHandlerClass))
#define MMS_HANDLER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), MMS_TYPE_HANDLER, MMSHandlerClass))
enum {
MMS_HANDLER_SIGNAL_DONE,
MMS_HANDLER_SIGNAL_COUNT
};
#define MMS_HANDLER_SIGNAL_DONE_NAME "done"
static guint mms_handler_signals[MMS_HANDLER_SIGNAL_COUNT] = { 0 };
static
void
mms_handler_finalize(
GObject* object)
{
MMS_VERBOSE_("%p", object);
MMS_ASSERT(!MMS_HANDLER(object)->busy);
G_OBJECT_CLASS(mms_handler_parent_class)->finalize(object);
}
static
void
mms_handler_class_init(
MMSHandlerClass* klass)
{
GObjectClass* object_class = G_OBJECT_CLASS(klass);
mms_handler_signals[MMS_HANDLER_SIGNAL_DONE] =
g_signal_new(MMS_HANDLER_SIGNAL_DONE_NAME,
G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL, G_TYPE_NONE, 0);
object_class->finalize = mms_handler_finalize;
}
static
void
mms_handler_init(
MMSHandler* h)
{
MMS_VERBOSE_("%p", h);
}
MMSHandler*
mms_handler_ref(
MMSHandler* h)
{
if (h) {
MMS_ASSERT(MMS_HANDLER(h));
g_object_ref(h);
}
return h;
}
void
mms_handler_unref(
MMSHandler* h)
{
if (h) {
MMS_ASSERT(MMS_HANDLER(h));
g_object_unref(h);
}
}
gulong
mms_handler_add_done_callback(
MMSHandler* h,
mms_handler_event_fn fn,
void* param)
{
if (h && fn) {
return g_signal_connect_data(h, MMS_HANDLER_SIGNAL_DONE_NAME,
G_CALLBACK(fn), param, NULL, 0);
}
return 0;
}
void
mms_handler_remove_callback(
MMSHandler* h,
gulong handler_id)
{
if (h && handler_id) g_signal_handler_disconnect(h, handler_id);
}
MMSHandlerMessageNotifyCall*
mms_handler_message_notify(
MMSHandler* h,
const char* imsi,
const char* from,
const char* subject,
time_t expiry,
GBytes* push,
mms_handler_message_notify_complete_fn cb,
void* param)
{
if (h) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_message_notify) {
if (!from) from = "";
if (!subject) subject = "";
return klass->fn_message_notify(h, imsi, from, subject, expiry,
push, cb, param);
}
MMS_ERR("mms_handler_message_notify not implemented");
}
return NULL;
}
void
mms_handler_message_notify_cancel(
MMSHandler* h,
MMSHandlerMessageNotifyCall* call)
{
if (h && call) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_message_notify_cancel) {
klass->fn_message_notify_cancel(h, call);
} else {
MMS_ERR("mms_handler_message_notify_cancel not implemented");
}
}
}
MMSHandlerMessageReceivedCall*
mms_handler_message_received(
MMSHandler* h,
MMSMessage* msg,
mms_handler_message_received_complete_fn cb,
void* param)
{
if (h) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_message_received) {
return klass->fn_message_received(h, msg, cb, param);
}
MMS_ERR("mms_handler_message_received not implemented");
}
return NULL;
}
void
mms_handler_message_received_cancel(
MMSHandler* h,
MMSHandlerMessageReceivedCall* call)
{
if (h && call) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_message_received_cancel) {
klass->fn_message_received_cancel(h, call);
} else {
MMS_ERR("mms_handler_message_notify_cancel not implemented");
}
}
}
gboolean
mms_handler_message_receive_state_changed(
MMSHandler* h,
const char* id,
MMS_RECEIVE_STATE state)
{
if (h) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_message_receive_state_changed) {
return klass->fn_message_receive_state_changed(h, id, state);
}
MMS_ERR("mms_handler_message_receive_state_changed not implemented");
}
return FALSE;
}
gboolean
mms_handler_message_send_state_changed(
MMSHandler* h,
const char* id,
MMS_SEND_STATE state,
const char* details)
{
if (h) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_message_send_state_changed) {
return klass->fn_message_send_state_changed(h, id, state, details);
}
MMS_ERR("mms_handler_message_send_state_changed not implemented");
}
return FALSE;
}
gboolean
mms_handler_message_sent(
MMSHandler* h,
const char* id,
const char* msgid)
{
if (h) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_message_sent) {
return klass->fn_message_sent(h, id, msgid);
}
MMS_ERR("mms_handler_message_sent not implemented");
}
return FALSE;
}
gboolean
mms_handler_delivery_report(
MMSHandler* h,
const char* imsi,
const char* msgid,
const char* recipient,
MMS_DELIVERY_STATUS ds)
{
if (h) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_delivery_report) {
return klass->fn_delivery_report(h, imsi, msgid, recipient, ds);
}
MMS_ERR("mms_handler_delivery_report not implemented");
}
return FALSE;
}
gboolean
mms_handler_read_report(
MMSHandler* h,
const char* imsi,
const char* msgid,
const char* recipient,
MMS_READ_STATUS rs)
{
if (h) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_read_report) {
return klass->fn_read_report(h, imsi, msgid, recipient, rs);
}
MMS_ERR("mms_handler_read_report not implemented");
}
return FALSE;
}
gboolean
mms_handler_read_report_send_status(
MMSHandler* h,
const char* id,
MMS_READ_REPORT_STATUS status)
{
if (h) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_read_report_send_status) {
return klass->fn_read_report_send_status(h, id, status);
}
MMS_ERR("mms_handler_read_report_send_status not implemented");
}
return FALSE;
}
void
mms_handler_busy_update(
MMSHandler* h,
int change)
{
MMS_ASSERT(change);
if (h && change) {
h->busy += change;
MMS_ASSERT(h->busy >= 0);
if (h->busy < 1) {
g_signal_emit(h, mms_handler_signals[MMS_HANDLER_SIGNAL_DONE], 0);
}
}
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/