/
mms_handler.c
306 lines (280 loc) · 7.23 KB
1
/*
2
* Copyright (C) 2013-2016 Jolla Ltd.
3
* Contact: Slava Monich <slava.monich@jolla.com>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
*
* 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"
22
G_DEFINE_ABSTRACT_TYPE(MMSHandler, mms_handler, G_TYPE_OBJECT)
23
24
25
26
27
28
29
30
#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))
31
32
33
34
35
36
37
38
39
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 };
40
41
42
43
44
45
static
void
mms_handler_finalize(
GObject* object)
{
MMS_VERBOSE_("%p", object);
46
MMS_ASSERT(!MMS_HANDLER(object)->busy);
47
48
49
50
51
52
53
54
G_OBJECT_CLASS(mms_handler_parent_class)->finalize(object);
}
static
void
mms_handler_class_init(
MMSHandlerClass* klass)
{
55
56
57
58
59
60
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;
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
}
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);
}
}
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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*
114
115
116
117
mms_handler_message_notify(
MMSHandler* h,
const char* imsi,
const char* from,
118
119
120
121
122
const char* subject,
time_t expiry,
GBytes* push,
mms_handler_message_notify_complete_fn cb,
void* param)
123
124
125
126
127
{
if (h) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_message_notify) {
if (!from) from = "";
128
129
130
if (!subject) subject = "";
return klass->fn_message_notify(h, imsi, from, subject, expiry,
push, cb, param);
131
132
133
134
135
136
}
MMS_ERR("mms_handler_message_notify not implemented");
}
return NULL;
}
137
138
void
mms_handler_message_notify_cancel(
139
MMSHandler* h,
140
MMSHandlerMessageNotifyCall* call)
141
{
142
if (h && call) {
143
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
144
if (klass->fn_message_notify_cancel) {
145
klass->fn_message_notify_cancel(h, call);
146
147
} else {
MMS_ERR("mms_handler_message_notify_cancel not implemented");
148
149
150
151
}
}
}
152
MMSHandlerMessageReceivedCall*
153
154
mms_handler_message_received(
MMSHandler* h,
155
156
157
MMSMessage* msg,
mms_handler_message_received_complete_fn cb,
void* param)
158
159
160
161
{
if (h) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_message_received) {
162
return klass->fn_message_received(h, msg, cb, param);
163
164
165
}
MMS_ERR("mms_handler_message_received not implemented");
}
166
return NULL;
167
168
}
169
170
171
172
173
174
175
176
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) {
177
klass->fn_message_received_cancel(h, call);
178
179
} else {
MMS_ERR("mms_handler_message_notify_cancel not implemented");
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
}
}
}
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;
}
200
201
202
203
gboolean
mms_handler_message_send_state_changed(
MMSHandler* h,
const char* id,
204
205
MMS_SEND_STATE state,
const char* details)
206
207
208
209
{
if (h) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_message_send_state_changed) {
210
return klass->fn_message_send_state_changed(h, id, state, details);
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
}
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;
}
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
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;
}
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
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;
}
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
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;
}
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
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);
}
}
}
300
301
302
303
304
305
306
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/