fababacf26c0445c554b8ef0c68c35f4f1f05a46
[framework/messaging/msg-service.git] / SLP_MessagingFW_PG.h
1  /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *    http://www.tizenopensource.org/license
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16 /**
17  *
18  * @ingroup   SLP_PG
19  * @defgroup   MESSAGE MessagingFW
20 @{
21 <h1 class="pg">Introduction</h1>
22         <h2 class="pg">Purpose</h2>
23 The purpose of this document is to describe how applications can use the Messaging Framework APIs to send and receive SMS and MMS messages. This document gives programming guidelines to application engineers.
24
25         <h2 class="pg">Scope</h2>
26 The scope of this document is limited to Messaging Framework APIs usage.
27
28         <h2 class="pg">Abbreviations</h2>
29 <table>
30 <tr><td>API</td><td>Application Programming Interface</td></tr>
31 </table>
32 @}
33
34 @defgroup Message_Architecture 1.Archtecture
35 @ingroup MESSAGE
36 @{
37 <h1>Messaging Framework Architecture</h1>
38 The Messaging framework supports various messaging services such as SMS, MMS, Cell Broadcast, WAP Push, and Provisioning message. The Messaging framework architecture consists of a Messaging daemon and a library. The messaging library works on application process and provides various APIs to support transport, control, storage, filter and setting services for application. The messaging daemon has three components (transaction manager, transaction handler, and plug-in manager) to provide message services. The socket IPC is used to communicate (request & event) between Messaging daemon and library.
39 @image html messaging_image001.png
40
41 - Transaction Manager
42         - Receive the IPC message (request) on socket.
43         - Manage list of pairs (request ID, transaction proxy) for synchronous return.
44         - Determine the transaction flow based on request/event information. (Mapping the request to one of the handlers)
45         - Store the transaction information for asynchronous events (Find which transaction proxy want to receive SMS)
46 - Transaction Handler
47         - Submit handler deals with submit requests.
48         - Deliver handler deals with the incoming message from plug-ins.
49         - Storage handler deals with the messages, accounts and folder requests
50         - Filter handler deals with the filter requests
51         - Setting handler deals with the service-specific attributes
52 - Plug-in Manager
53         - Initialize all plug-ins after loading plug-in configuration files
54         - Holding the list of plug-ins and the state of plug-ins
55         - Providing the interface between handlers and plug-ins
56 - Transaction Handlers
57         - Initialize all plug-ins after loading plug-in configuration files
58         - Receiving IPC messages from messaging daemon.
59         - Handling synchronous calls
60                 - Condition variable is used for waiting the return from msg. server)
61         - Handling asynchronous calls or events
62                 - Proxy listener is a component of transaction proxy
63                 - Proxy listener is waiting for the event
64                 - Invoking callback function in the msg. handle list
65                 - i.e. calling incoming callback function of MSG APP handle, when incoming msg
66         - Holding list of message handles
67                 - Message handle is created by MsgOpenMsgHandle(msgHandle)
68                 - Message handle holds some info such as callback func
69 - Message API
70         - Transport & control API
71         - Storage API
72         - Filter API
73         - Setting API
74 @}
75
76 @defgroup Message_Feature 2.Feature
77 @ingroup MESSAGE
78 @{
79         <h2 class="pg">Messaging Framework Features</h2>
80 -# Message Control Features:
81         -# Open/Close message handle
82 -# Message Transport Features:
83         -# Submit request to send, forward, reply, retrieve message.
84         -# Register callback functions to listen to invoked events from messaging daemon. (message status callback, incoming message callback)
85 -# Message Storage Features:
86         -# Add / Update / Move / Delete / Count / Get message or message list.
87         -# Add / Update / Delete / Get folder or folder list.
88 -# Message Filter Features:
89         -# Add / Update / Delete filter or filter list.
90 -# Message Setting Features:
91         -# Set / Get various message setting (i.e. whether to send read/delivery report or not)
92 @}
93
94 @defgroup MESSAGE_USECASES_1 Initialize/Finalization
95 @ingroup MESSAGE_USECASES
96 @{
97         <h2 class="pg">Messaging Framework Functions</h2>
98
99                 <h3 class="pg">Initialization / Finalization to use Messaging Service </h3>
100 - int msg_open_msg_handle(MSG_HANDLE_T *handle);
101 @n msg_open_msg_handle() should be called before using the messaging service. This function opens a channel between the application and the messaging framework.
102 - int msg_close_msg_handle(MSG_HANDLE_T *handle);
103 @n msg_close_msg_handle() should be called after using the messaging service. This function closes a channel between the application and the messaging framework.
104 - int msg_reg_sent_status_callback(MSG_HANDLE_T handle, msg_sent_status_cb cb);
105 @n Application should implement a msg_sent_status_cb function and register it into message handle. If the application sends a message, this callback function will be called to report its sending status. msg_reg_set_status_callback function should be called after creation of message handle.
106 - int msg_reg_sms_message_callback(MSG_HANDLE_T handle, msg_sms_incoming_cb cb, unsigned short port);
107 @n Application should implement a msg_sms_incoming_cb function and register it into message handle. It’s used to listen to the SMS incoming event invoked by messaging daemon. The incoming message information structure (MSG_MESSAGE_S) can be delivered as a parameter of the callback function.
108 - int msg_reg_mms_conf_message_callback(MSG_HANDLE_T handle, msg_mms_conf_msg_incoming_cb cb, char *app_id);
109 @n Application should implement a msg_mms_conf_msg_incoming_cb function and register it into message handle. It’s used to listen to the MMS incoming event invoked by messaging daemon. The incoming message information structure (MSG_MESSAGE_S) can be delivered as a parameter of the callback function.
110 @code
111 #include <stdio.h>
112 #include <glib.h>
113 #include <MapiControl.h>
114 #include <MapiTransport.h>
115
116 void sentStatusCB(MSG_HANDLE_T hMsgHandle, MSG_SENT_STATUS_S *pMsgStatus, void *user_param)
117 {
118         // Application can handle message sent status event
119 }
120
121 void incomingSmsMessageCB (MSG_HANDLE_T hMsgHandle, msg_message_t msg, void *user_param)
122 {
123         // Application can handle SMS incoming message.
124 }
125
126 void incomingMmsConfMessageCB(MSG_HANDLE_T hMsgHandle, msg_message_t msg, void *user_param)
127 {
128         // Application can handle MMS incoming message.
129 }
130
131 int main(void)
132 {
133         MSG_HANDLE_T msgHandle = NULL;
134
135         err = msg_open_msg_handle(&msgHandle);
136
137         if (err != MSG_SUCCESS)
138         {
139                 printf("msg_open_msg_handle() Fail [%d]", err);
140                 return err;
141         }
142
143         // Register sent status handler
144         err = msg_reg_sent_status_callback(msgHandle, &sentStatusCB, NULL);
145
146         if (err != MSG_SUCCESS)
147         {
148                 printf("msg_reg_sent_status_callback() Fail [%d]", err);
149                 return err;
150         }
151
152         // Register SMS incoming message handler
153         err = msg_reg_sms_message_callback(msgHandle, &incomingSmsMessageCB, 0, NULL);
154
155         if (err != MSG_SUCCESS)
156         {
157                 printf("msg_reg_sms_message_callback() Fail [%d]", err);
158                 return err;
159         }
160
161         // Register MMS incoming message handler
162         err = msg_reg_mms_conf_message_callback(msgHandle, &incomingMmsConfMessageCB, NULL, NULL);
163
164         if (err != MSG_SUCCESS)
165         {
166                 printf("msg_reg_mms_conf_message_callback() Fail [%d]", err);
167                 return err;
168         }
169
170         // g_main_loop should be used to listen CB event from messaging daemon
171         mainloop = g_main_loop_new(NULL, FALSE);
172         g_main_loop_run(mainloop);
173
174         msg_close_msg_handle(&msgHandle);
175
176         return err;
177 }
178 @endcode
179 @}
180
181 @defgroup MESSAGE_USECASES_2 Adding a SMS Message
182 @ingroup MESSAGE_USECASES
183 @{
184                 <h3 class="pg">Adding a SMS Message</h3>
185 - msg_message_t msg_new_message();
186 @n msg_new_message() is a function to create a message object which can store the message information. You should call this function to set the message that you want to add or send.
187 - int msg_set_message_type(msg_message_t msg, MSG_MESSAGE_TYPE_T msg_type);
188 @n msg_set_message_type() is a function to set the message type such as SMS or MMS. The first parameter is the message object which is created by msg_new_message(). The second parameter is the message type you want to set. It should be one of enum type ( _MSG_MESSAGE_TYPE_E). If setting is successful, the function returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
189 - int msg_sms_set_message_body(msg_message_t msg, const char* mdata, int size);
190 @n msg_sms_set_message_body() is a function to set the SMS body data. The first parameter is the message object which is created by msg_new_message(). The second parameter is the SMS body data you want to set. The third parameter is the length of SMS body data. If setting is successful, the function returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
191 - int msg_add_address(msg_message_t msg, const char* phone_num_list, MSG_RECIPIENT_TYPE_T to_type);
192 @n msg_add_address() is a function to add the phone numbers for the message. The first parameter is the message object which is created by msg_new_message(). The second parameter is the list of phone number you want to set. You can add several phone numbers at once. The phone numbers should be separated by ','. The third parameter is the recipient type of phone number. It should be one of enum type (_MSG_RECIPIENT_TYPE_E). If setting is successful, the function returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
193 - int msg_add_message(MSG_HANDLE_T handle, const msg_message_t msg, const MSG_SENDINGOPT_S *send_opt);
194 @n msg_add_message() is a function to add a composed message into the database of messaging framework. Before calling this function, the application should set the message object and the sending option structure and then pass them as parameters. If you don't want to change the current sending option, set the variable 'bSetting' to false. If saving a message is successful, the function returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
195 - int msg_release_message(msg_message_t *msg);
196 @n msg_release_message() is a function to free the memory of a message object which is create by msg_new_message(). If freeing the memory is successful, the function returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
197 @code
198 #include <string.h>
199 #include <MapiStorage.h>
200 #include <MapiMessage.h>
201
202 void test_add_sms_message(MSG_HANDLE_T hMsgHandle)
203 {
204         MSG_ERROR_T err = MSG_SUCCESS;
205
206         MSG_SENDINGOPT_S sendOpt = {0, };
207         sendOpt.bSetting = false;
208
209         msg_message_t msgInfo = msg_new_message();
210
211         // Set Message Type
212         err = msg_set_message_type(msgInfo, MSG_TYPE_SMS);
213
214         if (err != MSG_SUCCESS) goto free_memory;
215
216         char msgText[1024];
217
218         memset(msgText, 0x00, 1024);
219         strncpy(msgText, "Test SMS Message", sizeof(msgText)-1);
220         int dataSize = strlen(msgText);
221
222         // Set SMS text
223         err = msg_sms_set_message_body(msgInfo, msgText, dataSize);
224
225         if (err != MSG_SUCCESS) goto free_memory;
226
227         char number[MAX_ADDRESS_VAL_LEN];
228
229         memset(number, 0x00, MAX_ADDRESS_VAL_LEN);
230         strncpy(number, "+821030011234", sizeof(number)-1);
231
232         // Set Recipient Address
233         err = msg_add_address(msgInfo, number, MSG_RECIPIENTS_TYPE_TO);
234
235         if (err != MSG_SUCCESS) goto free_memory;
236
237         err = msg_add_message(hMsgHandle, msgInfo, &sendOpt);
238
239         if (err == MSG_SUCCESS)
240                 printf("Saving Message is OK!");
241         else
242                 printf("Saving Message is failed!");
243
244 free_memory:
245         msg_release_message(&msgInfo);
246 }
247 @endcode
248 @}
249
250 @defgroup MESSAGE_USECASES_3 Adding a MMS Message
251 @ingroup MESSAGE_USECASES
252 @{
253                 <h3 class="pg">Adding a MMS Message</h3>
254 - int msg_set_subject(msg_message_t msg, const char* subject);
255 @n msg_set_subject() is a function to set the subject of MMS. The first parameter is the message object which is created by msg_new_message(). The second parameter is the subject you want to set. If setting is successful, the function returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
256
257 - MMS_MESSAGE_DATA_S* msg_mms_create_message(void);
258 @n msg_mms_create_message() allocates a MMS_MESSAGE_DATA_S structure and returns it’s address. MMS_MESSAGE_DATA_S is needed to represent mms specific data and transfer it to the messaging daemon in the pData parameter of the MSG_MESSAGE_S structure.
259
260 - MMS_SMIL_ROOTLAYOUT* msg_mms_set_rootlayout(MMS_MESSAGE_DATA_S* msg, const int width, const int height, const int bgcolor);
261 @n msg_mms_set_rootlayout() is a function to set smil root layout. The parameters representing the size and background color of smil root layout should be set.
262
263 - MMS_SMIL_REGION* msg_mms_add_region(MMS_MESSAGE_DATA_S *msg_data, const char* szID, const int x, const int y, const int width, const int height, const int bgcolor);
264 @n msg_mms_add_region() is a function to add a smil region. Smil region is needed to display text message, image, and video data (Each content has its own region). This function is called to allocate a region for each contents.
265
266 - MMS_PAGE_S* msg_mms_add_page(MMS_MESSAGE_DATA_S *msg_data, const int duration);
267 @n msg_mms_add_page() is a function to add a smil page.
268
269 - MMS_MEDIA_S* msg_mms_add_media(MMS_PAGE_S *page, const MmsSmilMediaType mediatype, const char* regionid, char* filepath);
270 @n msg_mms_add_media() is a function to add multimedia content to a mms message. If some content should be played with smil player, this function can be used.
271
272 - MMS_ATTACH_S* msg_mms_add_attachment(MMS_MESSAGE_DATA_S *msg_data, char *filepath);
273 @n msg_mms_add_attachment() is a function to add a content as an attached file. With this function a content might be attached as a multipart mixed type.
274
275 - int msg_mms_set_message_body(msg_message_t msg, const MMS_MESSAGE_DATA_S *msg_data);
276 @n msg_mms_set_message_body() is a function to set the MMS body data. The first parameter is the message object which is created by msg_new_message(). The second parameter is the structure which is allocated by msg_mms_create_message() and is set by the APIs for MMS.
277
278 - int msg_mms_destroy_message(MMS_MESSAGE_DATA_S* msg);
279 @n msg_mms_destroy_message() should be called to deallocate the MMS_MESSAGE_DATA_S structure and internal region, page, media, and attach list.
280 @code
281 #include <string.h>
282 #include <MapiStorage.h>
283 #include <MapiMessage.h>
284
285 void test_add_mms_message(MSG_HANDLE_T hMsgHandle)
286 {
287         MSG_ERROR_T err = MSG_SUCCESS;
288
289         MSG_SENDINGOPT_S sendOpt = {0, };
290         sendOpt.bSetting = false;
291
292         msg_message_t msgInfo = msg_new_message();
293
294         // Set Message Type
295         err = msg_set_message_type(msgInfo, MSG_TYPE_MMS);
296
297         if (err != MSG_SUCCESS) goto free_memory;
298
299         MMS_MESSAGE_DATA_S* data;
300         MMS_PAGE_S* page;
301         MMS_MEDIA_S* media[3];
302         MMS_ATTACH_S* attach;
303         int nSize = 0;
304
305         // Set MMS subject
306         char subject[MAX_SUBJECT_LEN];
307
308         memset(subject, 0x00, MAX_SUBJECT_LEN);
309         strncpy(subject, "hello mms", sizeof(subject)-1);
310
311         err = msg_set_subject(msgInfo, subject);
312
313         if (err != MSG_SUCCESS) goto free_memory;
314
315         // Set MMS Body data
316         data = msg_mms_create_message();
317         msg_mms_set_rootlayout(data, 100, 100, 0xffffff);
318         msg_mms_add_region(data, "Image", 0, 50, 100, 50, 0xffffff);
319         msg_mms_add_region(data, "Text", 0, 0, 100, 50, 0xffffff);
320         page = msg_mms_add_page(data, 5000);
321         media[0] = msg_mms_add_media(page, MMS_SMIL_MEDIA_IMG, "Image", "/tmp/image.jpg");
322         media[1] = msg_mms_add_media(page, MMS_SMIL_MEDIA_AUDIO, NULL, "/tmp/audio.amr");
323         media[2] = msg_mms_add_media(page, MMS_SMIL_MEDIA_TEXT, "Text", "/tmp/message.txt");
324         attach = msg_mms_add_attachment(data, "attachment.3gp");
325
326         err = msg_mms_set_message_body(msgInfo, data);
327
328         if (err != MSG_SUCCESS)
329         {
330                 msg_mms_destroy_message(data);
331                 goto free_memory;
332         }
333
334         msg_mms_destroy_message(data);
335
336         // Set Recipient Address
337         char number[MAX_ADDRESS_VAL_LEN];
338
339         memset(number, 0x00, MAX_ADDRESS_VAL_LEN);
340         strncpy(number, "+821030011234", sizeof(number)-1);
341
342         err = msg_add_address(msgInfo, number, MSG_RECIPIENTS_TYPE_TO);
343
344         if (err != MSG_SUCCESS) goto free_memory;
345
346         err = msg_add_message(hMsgHandle, msgInfo, &sendOpt);
347
348         if (err == MSG_SUCCESS)
349                 printf("Saving Message is OK!");
350         else
351                 printf("Saving Message is failed!");
352
353 free_memory:
354         msg_release_message(&msgInfo);
355 }
356 @endcode
357 @}
358
359 @defgroup MESSAGE_USECASES_4 Sending a SMS/MMS Message
360 @ingroup MESSAGE_USECASES
361 @{
362                 <h3 class="pg">Sending a SMS/MMS Message</h3>
363
364 - bool msg_is_sms(msg_message_t msg);
365 @n msg_is_sms() is a function to check whether the message type of message object is SMS or not. The first parameter is the message object which is created by msg_new_message(). The function returns true if the message object is a SMS message. Otherwise, it returns false.
366
367 - bool msg_is_mms(msg_message_t msg);
368 @n msg_is_mms() is a function to check whether the message type of message object is MMS or not. The first parameter is the message object which is created by msg_new_message(). The function returns true if the message object is a MMS message. Otherwise, it returns false.
369
370 - int msg_sms_send_message(MSG_HANDLE_T handle, MSG_REQUEST_S* req);
371 @n msg_sms_send_message() is a function to send SMS through messaging framework. The first parameter is the handle which is created by msg_open_msg_handle (). The second parameter is the structure that includes the message information to send. You can get the result of sending on sent status callback.
372
373 - int msg_mms_send_message(MSG_HANDLE_T handle, MSG_REQUEST_S* req);
374 @n msg_sms_send_message() is a function to send SMS through messaging framework. The first parameter is the handle which is created by msg_open_msg_handle (). The second parameter is the structure that includes the message information to send. You can get the result of sending on sent status callback.
375 @code
376 #include <MapiTransport.h>
377 #include <MapiMessage.h>
378
379 int MsgTestSendMsg(MSG_HANDLE_T hMsgHandle, msg_message_t pMsg)
380 {
381         if (hMsgHandle == NULL)
382         {
383                 printf("Handle is NULL\n");
384                 return MSG_ERR_NULL_MSGHANDLE;
385         }
386
387         MSG_ERROR_T err = MSG_SUCCESS;
388
389         MSG_REQUEST_S req = {0};
390
391         if (pMsg == NULL)
392         {
393                 printf("Message is NULL\n");
394                 return MSG_ERR_NULL_MESSAGE;
395         }
396
397         req.msg = pMsg;
398
399         if (msg_is_sms(req.msg))
400                 err = msg_sms_send_message(hMsgHandle, &req);
401         else if (msg_is_mms(req.msg))
402                 err = msg_mms_send_message(hMsgHandle, &req);
403
404         if (err == MSG_SUCCESS)
405                 printf("Request to Send Message is successful!!!");
406         else
407                 printf("Request to Send Message is failed!!!");
408
409         return err;
410 }
411 @endcode
412 @}
413
414 @defgroup MESSAGE_USECASES_5 Sending Simple SMS Message
415 @ingroup MESSAGE_USECASES
416 @{
417                 <h3 class="pg">Simple SMS Sending</h3>
418 - int msg_sms_send(const char *phone_num_list, const char *sms_text, msg_simple_sent_status_cb cb, void *user_param);
419 @n msg_sms_send() is a simple function to send an SMS message. Without this API, in order to send a message the application should allocate a channel with messaging daemon for IPC, register sent-status callback function to monitor the sending result, and fulfill many member variables of MSG_MESSAGE_S. This function implicitly makes a connection with messaging daemon and registers the callback function. In addition, member variables of the MSG_MESSAGE_S structure are filled with default values except for the recipient phone_number and sms_text.
420 @code
421 #include <stdio.h>
422 #include <string.h>
423 #include <glib.h>
424 #include <MapiTransport.h>
425
426 GMainLoop *mainloop;
427
428 typedef struct {
429         char number[256];
430         char text[256];
431         char userdata[256];
432 } send_data;
433
434 void sent_status_cb(MSG_SENT_STATUS_S *pMsgStatus, void *userData)
435 {
436         if (pMsgStatus->status == MSG_NETWORK_SEND_SUCCESS)
437                 printf("reqId : %d  MSG SENT SUCCESS !!!\n", pMsgStatus->reqId);
438         else
439                 printf("reqId : %d  MSG SENT FAIL !!! [%d]\n", pMsgStatus->reqId, pMsgStatus->status);
440 }
441
442 // count from here
443 gboolean send_func(gpointer data)
444 {
445         send_data* sms_input = (send_data*)data;
446
447         printf("Begin to send [%s] to [%s]\n", sms_input->number, sms_input->text);
448         MSG_ERROR_T err = msg_sms_send(sms_input->number, sms_input->text, &sent_status_cb, (void*)sms_input->userdata);
449
450         if (err != MSG_SUCCESS)
451                 printf("Send failed [%d]\n", err);
452
453         return FALSE;
454 }
455 // end
456
457 int main(int argc, char* argv[])
458 {
459         if (argc != 3 && argc != 4)
460         {
461                 printf("Usage: %s  {phone_num_list} {sms_text} [user_data]\n", argv[0]);
462                 printf("phone_num_list: phone_num1, phone_num2, ..., phone_numN\n");
463                 return 0;
464         }
465
466         // Set sms input parameters : phone numbers and text
467         send_data sms_input = {};
468         strncpy(sms_input.number, argv[1], sizeof(sms_input.number)-1);
469         strncpy(sms_input.text, argv[2], sizeof(sms_input.text)-1);
470         if (argc == 4)
471                 strncpy(sms_input.userdata, argv[3], sizeof(sms_input.userdata)-1);
472
473         // Add Sending Function to GMainLoop
474         g_idle_add(&send_func, (gpointer) &sms_input);
475
476         // start GMainLoop
477         mainloop = g_main_loop_new(NULL, FALSE);
478
479         printf("Entering GMain Loop to Receive Notifications in Thread...\n");
480
481         g_main_loop_run(mainloop);
482
483         printf("==== End Test App. Bye...===\n");
484
485         return 0;
486 }
487 @endcode
488 @}
489
490 @defgroup MESSAGE_USECASES_6 Retrieving a MMS Message
491 @ingroup MESSAGE_USECASES
492 @{
493                 <h3 class="pg">Retrieving a MMS Message</h3>
494 - int msg_mms_retrieve_message(MSG_HANDLE_T handle, MSG_REQUEST_S* req);
495 @n msg_mms_retrieve_message() is a function to submit a retrieve MMS request.
496 @code
497 void MsgTestRetrieveMessage(MSG_HANDLE_T hMsgHandle, MSG_MESSAGE_ID_T nMsgId)
498 {
499         if (hMsgHandle == NULL)
500         {
501                 printf("Handle is NULL");
502                 return;
503         }
504
505         MSG_ERROR_T err = MSG_SUCCESS;
506
507         msg_message_t msg = msg_new_message();
508         MSG_SENDINGOPT_S sendOpt = {0, };
509
510         err = msg_get_message(hMsgHandle, (MSG_MESSAGE_ID_T)nMsgId, msg, &sendOpt);
511
512         if (err != MSG_SUCCESS)
513                 printf("Get Message Failed!");
514
515         MSG_REQUEST_S req = {0, msg, sendOpt};
516
517         err = msg_mms_retrieve_message(hMsgHandle, &req);
518
519         if (err != MSG_SUCCESS)
520                 printf("Retrieve MMS Message Failed!");
521
522         msg_release_message(&msg);
523 }
524 @endcode
525 @}
526
527 @defgroup MESSAGE_USECASES_7 Getting a SMS Message
528 @ingroup MESSAGE_USECASES
529 @{
530                 <h3 class="pg">Getting a SMS Message</h3>
531 - int msg_get_message(MSG_HANDLE_T handle, MSG_MESSAGE_ID_T msg_id, msg_message_t msg, MSG_SENDINGOPT_S *send_opt);
532 @n msg_get_message() is a function to get a message. The first parameter is the handle which is created by msg_open_msg_handle (). The second parameter is the message ID you want to get. The third parameter is the message object to receive the message information. The last parameter is the structure to receive the message sending options.
533
534 - int msg_get_message_id(msg_message_t msg);
535 @n msg_get_message_id() is a function to get the message ID. The parameter is the message object. If the function is successful, it returns the message ID. Otherwise it returns an error in enum type (_MSG_ERROR_E).
536
537 - int msg_get_folder_id(msg_message_t msg);
538 @n msg_get_folder_id() is a function to get the ID of the folder  that the message is saved within. The parameter is the message object. If the function is successful, it returns one of the enum type in (_MSG_FOLDER_ID_E) . Otherwise it returns an error in enum type (_MSG_ERROR_E).
539
540 - int msg_get_message_type(msg_message_t msg);
541 @n msg_get_message_type() is a function to get the message type. The parameter is the message object. If the function is successful, it returns one of the enum type in (_MSG_MESSAGE_TYPE_E). Otherwise it returns an error in enum type (_MSG_ERROR_E).
542
543 - int msg_get_address_count(msg_message_t msg);
544 @n msg_get_address_count() is a function to get the number of addresses. The parameter is the message object. If the function is successful, it returns the number of addresses. Otherwise it returns an error in enum type (_MSG_ERROR_E).
545
546 - const char* msg_get_ith_address(msg_message_t msg, int ith);
547 @n msg_get_ith_address() is a function to get the ith address of message. The first parameter is the message object. The second parameter is the index of address you want to get. If the function is successful, it returns the address string. Otherwise it returns NULL.
548
549 - time_t* msg_get_time(msg_message_t msg);
550 @n msg_get_time() is a function to get the time value of message. The parameter is the message object. If the function is successful, it returns the time value. Otherwise it returns NULL.
551
552 - int msg_get_network_status(msg_message_t msg);
553 @n msg_get_network_status() is a function to get the network status of message. The parameter is the message object. If the function is successful, it returns one of the enum type in (_MSG_NETWORK_STATUS_E). Otherwise it returns an error in enum type (_MSG_ERROR_E).
554
555 - bool msg_is_read(msg_message_t msg);
556 @n msg_is_read() is a function to check whether the message was read or not. The parameter is the message object. If the message was read, it returns true. Otherwise it returns false.
557
558 - bool msg_is_protected(msg_message_t msg);
559 @n msg_is_protected() is a function to check whether the message is protected or not. The parameter is the message object. If the the message was protected, it returns true. Otherwise it returns false.
560
561 - int msg_get_message_body_size(msg_message_t msg);
562 @n msg_get_message_body_size() is a function to get the byte size of message. The parameter is the message object. If the function is successful, it returns the byte size of message. Otherwise it returns an error in enum type (_MSG_ERROR_E).
563
564 - const char* msg_sms_get_message_body(msg_message_t msg);
565 @n msg_sms_get_message_body() is a function to get the body data of message. The first parameter is the message object. If the function is successful, it returns the body data. Otherwise it returns NULL.
566 @code
567 void MsgTestGetSmsMessage(MSG_HANDLE_T hMsgHandle, int MsgId)
568 {
569         if (hMsgHandle == NULL)
570         {
571                 printf("Handle is NULL\n");
572                 return;
573         }
574
575         MSG_ERROR_T err = MSG_SUCCESS;
576
577         msg_message_t msg = msg_new_message();
578         MSG_SENDINGOPT_S sendOpt = {0, };
579
580         // Get Message
581         err = msg_get_message(hMsgHandle, (MSG_MESSAGE_ID_T)MsgId, msg, &sendOpt);
582
583         if (err != MSG_SUCCESS) goto free_memory;
584
585         printf("msgId = %d\n", msg_get_message_id(msg));
586         printf("folderId = %d\n", msg_get_folder_id(msg));
587         printf("msgType = %d\n", msg_get_message_type(msg));
588         printf("phone number = %s\n", msg_get_ith_address(msg, 0));
589         printf("displayTime = %s\n", ctime(msg_get_time(msg)));
590         printf("networkStatus = %d\n", msg_get_network_status(msg));
591         printf("bRead = %d\n", msg_is_read(msg));
592         printf("bProtected = %d\n", msg_is_protected(msg));
593         printf("dataSize = %d\n", msg_get_message_body_size(msg));
594         printf("msgData = %s\n", msg_sms_get_message_body(msg));
595
596 free_memory:
597         msg_release_message(&msg);
598 }
599 @endcode
600 @}
601
602 @defgroup MESSAGE_USECASES_8 Getting a MMS Message
603 @ingroup MESSAGE_USECASES
604 @{
605                 <h3 class="pg">Getting a MMS Message</h3>
606 - int msg_mms_get_message_body(msg_message_t msg, MMS_MESSAGE_DATA_S *body);
607 @n msg_get_address_count. The parameter is the message object. The second parameter is the structure to receive MMS data as output. If the function is successful, it returns MSG_SUCCESS. Otherwise it returns an error in enum type (_MSG_ERROR_E).
608 - MMS_SMIL_REGION* msg_mms_get_smil_region(MMS_MESSAGE_DATA_S msgBody, int region_idx);
609 @n msg_mms_get_smil_region() is a function to get a SMIL region information. The first parameter is the structure of MMS data. The second parameter is the index of SMIL region you want to get. If the function is successful, it returns the structure which contains the SMIL region information. Otherwise it returns NULL.
610 - MMS_PAGE_S* msg_mms_get_page(MMS_MESSAGE_DATA_S msgBody, int page_idx);
611 @n msg_mms_get_page() is a function to get a SMIL page information. The first parameter is the structure of MMS data. The second parameter is the index of SMIL page you want to get. If the function is successful, it returns the structure which contains the SMIL page information. Otherwise it returns NULL.
612 - MMS_MEDIA_S* msg_mms_get_media(MMS_PAGE_S *page, int media_idx);
613 @n msg_mms_get_media() is a function to get a media information in a SMIL page. The first parameter is the structure of SMIL page you want to get the media from. The second parameter is the index of media you want to get. If the function is successful, it returns the structure which contains the media information. Otherwise it returns NULL.
614 - MMS_ATTACH_S* msg_mms_get_attachment(MMS_MESSAGE_DATA_S msgBody, int attach_idx);
615 @n msg_mms_get_attachment() is a function to get the file information of  an attachment. The first parameter is the structure of MMS data. The second parameter is the index of attachment you want to get. If the function is successful, it returns the structure which contains the attachment file information. Otherwise it returns NULL.
616 - const char* msg_get_subject(msg_message_t msg);
617 @n msg_get_subject() is a function to get the subject of MMS. The parameter is the message object. If the function is successful, it returns the subject string. Otherwise it returns NULL.
618 @code
619 void MsgTestGetMmsMessage(MSG_HANDLE_T hMsgHandle, int MsgId)
620 {
621         if (hMsgHandle == NULL)
622         {
623                 printf("Handle is NULL\n");
624                 return;
625         }
626
627         MSG_ERROR_T err = MSG_SUCCESS;
628
629         msg_message_t msg = msg_new_message();
630         MSG_SENDINGOPT_S sendOpt = {0, };
631
632         // Get Message
633         err = msg_get_message(hMsgHandle, (MSG_MESSAGE_ID_T)MsgId, msg, &sendOpt);
634
635         if (err != MSG_SUCCESS) goto free_memory;
636
637         if (msg_is_mms(msg) == false)
638         {
639                 printf("It is not MMS Message!");
640                 goto free_memory;
641         }
642
643         MMS_MESSAGE_DATA_S* msgBody = msg_mms_create_message();
644
645         // Get MMS Body Data
646         msg_mms_get_message_body(msg, msgBody);
647
648         //Print root-layout info
649         printf("width: %d \n
650                 height: %d \n
651                 nbgColor:%x \n",
652                 msgBody->rootlayout.width.value,
653                 msgBody->rootlayout.height.value,
654                 msgBody->rootlayout.bgColor);
655
656         // Print Region Info
657         for (int i = 0; i < msgBody->regionCnt; ++i)
658         {
659                 MMS_SMIL_REGION* pRegion = msg_mms_get_smil_region(msgBody, i);
660
661                 printf("region id: %s\n
662                         region left : %d\n
663                         region top : %d\n
664                         region width : %d\n
665                         region height : %d\n
666                         region bgColor : %x\n
667                         region fit : %d\n",
668                         pRegion->szID,pRegion->nLeft.value,
669                         pRegion->nTop.value,pRegion->width.value,
670                         pRegion->height.value, pRegion->bgColor,
671                         pRegion->fit);
672         }
673
674         // Print Page info
675         for (int i = 0; i< msgBody->pageCnt; ++i)
676         {
677                 MMS_PAGE_S* pPage = msg_mms_get_page(msgBody, i);
678
679                 printf("page's duration: %d msec\n
680                         page's media count: %d\n",
681                         pPage->nDur, pPage->mediaCnt);
682
683                 // Print Contents Info
684                 for(int j = 0; j < pPage->mediaCnt; ++j)
685                 {
686                         MMS_MEDIA_S* pMedia = msg_mms_get_media(pPage, j);
687                         printf("media's filename: %s\n
688                                 media's filepath: %s\n
689                                 media's regionId: %s\n
690                                 Bold: %d Italic: %d\n",
691                                 pMedia->szFileName,
692                                 pMedia->szFilePath,
693                                 pMedia->regionId,
694                                 pMedia->sMedia.sText.bBold,
695                                 pMedia->sMedia.sText.bItalic);
696
697                         if(pMedia->drmType != MSG_DRM_TYPE_NONE)
698                         {
699                                 printf("media's drmtype: %d\n
700                                         media's drmpath: %s\n",
701                                         pMedia->drmType, pMedia->szDrm2FullPath);
702                         }
703                 }
704         }
705
706         for (int i = 0; i < msgBody->attachCnt; ++i)
707         {
708                 MMS_ATTACH_S* pAttach = msg_mms_get_attachment(msgBody, i);
709
710                 printf("Attachment file Name: %s\n
711                         Attachment file Path: %s\n
712                         Attached file size: %d\n",
713                         pAttach->szFileName,
714                         pAttach->szFilePath,
715                         pAttach->fileSize);
716
717                 if(pAttach->drmType != MSG_DRM_TYPE_NONE)
718                         printf("media's drmtype: %d\n
719                                 media's drmpath: %s\n",
720                                 pAttach->drmType, pAttach->szDrm2FullPath);
721         }
722
723         printf("Subject: %s\n", msg_get_subject(pMsg));
724
725         printf("msgId = %d", msg_get_message_id(msg));
726         printf("folderId = %d", msg_get_folder_id(msg));
727         printf("phone number = %s", msg_get_ith_address(msg, 0));
728         printf("displayTime = %s", ctime(msg_get_time(msg)));
729         printf("networkStatus = %d", msg_get_network_status(msg));
730         printf("bRead = %d", msg_is_read(msg));
731         printf("bProtected = %d", msg_is_protected(msg));
732
733 free_memory:
734         msg_mms_destroy_message(msgBody);
735
736         msg_release_message(&msg);
737 }
738 @endcode
739 @}
740
741 @defgroup MESSAGE_USECASES_9 Delete a Message
742 @ingroup MESSAGE_USECASES
743 @{
744                 <h3 class="pg">Delete a Message</h3>
745 - int msg_delete_message(MSG_HANDLE_T handle, MSG_MESSAGE_ID_T msg_id);
746 @n msg_delete_message() is a function to delete a message from message box by msg_id.
747 @code
748 void MsgTestDeleteMessage(MSG_HANDLE_T hMsgHandle, MSG_MESSAGE_ID_T nMsgId)
749 {
750         MSG_ERROR_T err;
751
752         if (msg_delete_message(hMsgHandle, nMsgId) != MSG_SUCCESS)
753                 printf("Failed to delete Message");
754
755 }
756 @endcode
757 @}
758
759 @defgroup MESSAGE_USECASES_10 Set/Get Message Setting
760 @ingroup MESSAGE_USECASES
761 @{
762                 <h3 class="pg">Set / Get Message setting</h3>
763 msg_set_config() and msg_get_cofig() is used to set or to get the message setting options. MSG_SETTING_S structure includes various setting information and is shared between message application and messaging daemon.
764
765 - int msg_set_config(MSG_HANDLE_T handle, const MSG_SETTING_S *setting);
766 @n msg_set_config() sets a message option.
767 - int msg_get_config(MSG_HANDLE_T handle, MSG_SETTING_S *setting);
768 @n msg_get_config() gets a message option.
769 @code
770 void MsgTestSetGeneralOpt(MSG_HANDLE_T hMsgHandle)
771 {
772         MSG_ERROR_T err = MSG_SUCCESS;
773         MSG_SETTING_S setting = {0, };
774
775         setting.type = MSG_GENERAL_OPT;
776
777         setting.option.generalOpt.bKeepCopy = true;
778         setting.option.generalOpt.alertTone = MSG_ALERT_TONE_ONCE;
779
780         err = msg_set_config(hMsgHandle, &setting);
781
782         if (err == MSG_SUCCESS)
783                 printf("Setting Config Data is OK!");
784         else
785                 printf("Setting Config Data is failed!");
786 }
787
788 void MsgTestGetGeneralOpt(MSG_HANDLE_T hMsgHandle)
789 {
790         MSG_ERROR_T err = MSG_SUCCESS;
791         MSG_SETTING_S setting = {0, };
792
793         err = msg_get_config(hMsgHandle, &setting);
794
795         if (err == MSG_SUCCESS)
796         {
797                 printf("Setting Config Data is OK!\n");
798                 printf("bKeepCopy : [%d], AlertTone : [%d]\n", setting.option.generalOpt.bKeepCopy, setting.option.generalOpt.alertTone);
799         }
800         else
801                 printf("Setting Config Data is failed!\n");
802 }
803 @endcode
804 @}
805
806 @defgroup MESSAGE_USECASES_11 Filtering a Message
807 @ingroup MESSAGE_USECASES
808 @{
809                 <h3 class="pg">Filtering a Message</h3>
810 Messaging framework provides a filtering function for incoming message. New incoming message can be blocked (Move to spam-box or discard) by adding a filtering rule. A incoming message can be blocked by its originating address or by subject matching. If address matching filter rule is applied, only messages with exactly the same phone number can be blocked. Whereas, if a subject matching filter rule is applied, all messages that include the registered subject string might be blocked. An application can add or remove a filtering rule by calling msg_add_filter() or msg_delete_filter().
811
812 - int msg_add_filter(MSG_HANDLE_T handle, const MSG_FILTER_S *filter);
813 @n msg_add_filter() inserts a filtering rule to filter list and returns filter id.
814 - int msg_delete_filter(MSG_HANDLE_T handle, MSG_FILTER_ID_T filter_id);
815 @n msg_delete_filter()removes a filtering rule from filter list by filter id
816 @code
817 void MsgTestAddFilter(MSG_HANDLE_T hMsgHandle)
818 {
819         if (hMsgHandle == NULL)
820         {
821                 printf("Handle is NULL");
822                 return;
823         }
824
825         MSG_ERROR_T err = MSG_SUCCESS;
826         MSG_FILTER_S filter[2]= {0, };
827
828         // Add filter by address
829         filter[0].filterType = MSG_FILTER_BY_ADDRESS;
830         strncpy(filter[0].filterValue, "+821234567890", MAX_FILTER_VALUE_LEN);
831
832         err = msg_add_filter(hMsgHandle, &filter[0]);
833
834         if (err == MSG_SUCCESS)
835                 printf("msg_add_filter success");
836         else
837                 printf("msg_add_filter fail - err [%d]", err);
838
839         // Add filter by subject
840         filter[1].filterType = MSG_FILTER_BY_SUBJECT;
841         strncpy(filter[1].filterValue, "test filter", MAX_FILTER_VALUE_LEN);
842
843         err = msg_add_filter(hMsgHandle, &filter[1]);
844
845         if (err == MSG_SUCCESS)
846                 printf("msg_add_filter success");
847         else
848                 printf("msg_add_filter fail - err [%d]", err);
849
850         return;
851 }
852
853 void MsgTestDeleteFilter(MSG_HANDLE_T hMsgHandle, MSG_FILTER_ID_T filterId)
854 {
855         if (hMsgHandle == NULL)
856         {
857                 printf("Handle is NULL");
858                 return;
859         }
860
861         MSG_ERROR_T err = MSG_SUCCESS;
862         err = msg_delete_filter(hMsgHandle, filterId);
863
864         if (MSG_SUCCESS == err)
865         {
866                 printf("msg_delete_filter success");
867         }
868         else
869         {
870                 printf("msg_delete_filter fail - err [%d]", err);
871         }
872
873         return;
874 }
875 @endcode
876 @}
877 */
878
879 /**
880 @addtogroup MESSAGE
881 @{
882         @defgroup MESSAGE_USECASES Use Cases
883 @}
884 */