2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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.
19 * @defgroup MESSAGE MessagingFW
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.
25 <h2 class="pg">Scope</h2>
26 The scope of this document is limited to Messaging Framework APIs usage.
28 <h2 class="pg">Abbreviations</h2>
30 <tr><td>API</td><td>Application Programming Interface</td></tr>
34 @defgroup Message_Architecture 1.Archtecture
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
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)
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
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
70 - Transport & control API
76 @defgroup Message_Feature 2.Feature
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)
94 @defgroup MESSAGE_USECASES_1 Initialize/Finalization
95 @ingroup MESSAGE_USECASES
97 <h2 class="pg">Messaging Framework Functions</h2>
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.
113 #include <MapiControl.h>
114 #include <MapiTransport.h>
116 void sentStatusCB(MSG_HANDLE_T hMsgHandle, MSG_SENT_STATUS_S *pMsgStatus, void *user_param)
118 // Application can handle message sent status event
121 void incomingSmsMessageCB (MSG_HANDLE_T hMsgHandle, msg_message_t msg, void *user_param)
123 // Application can handle SMS incoming message.
126 void incomingMmsConfMessageCB(MSG_HANDLE_T hMsgHandle, msg_message_t msg, void *user_param)
128 // Application can handle MMS incoming message.
133 MSG_HANDLE_T msgHandle = NULL;
135 err = msg_open_msg_handle(&msgHandle);
137 if (err != MSG_SUCCESS)
139 printf("msg_open_msg_handle() Fail [%d]", err);
143 // Register sent status handler
144 err = msg_reg_sent_status_callback(msgHandle, &sentStatusCB, NULL);
146 if (err != MSG_SUCCESS)
148 printf("msg_reg_sent_status_callback() Fail [%d]", err);
152 // Register SMS incoming message handler
153 err = msg_reg_sms_message_callback(msgHandle, &incomingSmsMessageCB, 0, NULL);
155 if (err != MSG_SUCCESS)
157 printf("msg_reg_sms_message_callback() Fail [%d]", err);
161 // Register MMS incoming message handler
162 err = msg_reg_mms_conf_message_callback(msgHandle, &incomingMmsConfMessageCB, NULL, NULL);
164 if (err != MSG_SUCCESS)
166 printf("msg_reg_mms_conf_message_callback() Fail [%d]", err);
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);
174 msg_close_msg_handle(&msgHandle);
181 @defgroup MESSAGE_USECASES_2 Adding a SMS Message
182 @ingroup MESSAGE_USECASES
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).
199 #include <MapiStorage.h>
200 #include <MapiMessage.h>
202 void test_add_sms_message(MSG_HANDLE_T hMsgHandle)
204 MSG_ERROR_T err = MSG_SUCCESS;
206 MSG_SENDINGOPT_S sendOpt = {0, };
207 sendOpt.bSetting = false;
209 msg_message_t msgInfo = msg_new_message();
212 err = msg_set_message_type(msgInfo, MSG_TYPE_SMS);
214 if (err != MSG_SUCCESS) goto free_memory;
218 memset(msgText, 0x00, 1024);
219 strncpy(msgText, "Test SMS Message", sizeof(msgText)-1);
220 int dataSize = strlen(msgText);
223 err = msg_sms_set_message_body(msgInfo, msgText, dataSize);
225 if (err != MSG_SUCCESS) goto free_memory;
227 char number[MAX_ADDRESS_VAL_LEN];
229 memset(number, 0x00, MAX_ADDRESS_VAL_LEN);
230 strncpy(number, "+821030011234", sizeof(number)-1);
232 // Set Recipient Address
233 err = msg_add_address(msgInfo, number, MSG_RECIPIENTS_TYPE_TO);
235 if (err != MSG_SUCCESS) goto free_memory;
237 err = msg_add_message(hMsgHandle, msgInfo, &sendOpt);
239 if (err == MSG_SUCCESS)
240 printf("Saving Message is OK!");
242 printf("Saving Message is failed!");
245 msg_release_message(&msgInfo);
250 @defgroup MESSAGE_USECASES_3 Adding a MMS Message
251 @ingroup MESSAGE_USECASES
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).
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.
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.
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.
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.
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.
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.
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.
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.
282 #include <MapiStorage.h>
283 #include <MapiMessage.h>
285 void test_add_mms_message(MSG_HANDLE_T hMsgHandle)
287 MSG_ERROR_T err = MSG_SUCCESS;
289 MSG_SENDINGOPT_S sendOpt = {0, };
290 sendOpt.bSetting = false;
292 msg_message_t msgInfo = msg_new_message();
295 err = msg_set_message_type(msgInfo, MSG_TYPE_MMS);
297 if (err != MSG_SUCCESS) goto free_memory;
299 MMS_MESSAGE_DATA_S* data;
301 MMS_MEDIA_S* media[3];
302 MMS_ATTACH_S* attach;
306 char subject[MAX_SUBJECT_LEN];
308 memset(subject, 0x00, MAX_SUBJECT_LEN);
309 strncpy(subject, "hello mms", sizeof(subject)-1);
311 err = msg_set_subject(msgInfo, subject);
313 if (err != MSG_SUCCESS) goto free_memory;
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");
326 err = msg_mms_set_message_body(msgInfo, data);
328 if (err != MSG_SUCCESS)
330 msg_mms_destroy_message(data);
334 msg_mms_destroy_message(data);
336 // Set Recipient Address
337 char number[MAX_ADDRESS_VAL_LEN];
339 memset(number, 0x00, MAX_ADDRESS_VAL_LEN);
340 strncpy(number, "+821030011234", sizeof(number)-1);
342 err = msg_add_address(msgInfo, number, MSG_RECIPIENTS_TYPE_TO);
344 if (err != MSG_SUCCESS) goto free_memory;
346 err = msg_add_message(hMsgHandle, msgInfo, &sendOpt);
348 if (err == MSG_SUCCESS)
349 printf("Saving Message is OK!");
351 printf("Saving Message is failed!");
354 msg_release_message(&msgInfo);
359 @defgroup MESSAGE_USECASES_4 Sending a SMS/MMS Message
360 @ingroup MESSAGE_USECASES
362 <h3 class="pg">Sending a SMS/MMS Message</h3>
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.
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.
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.
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.
376 #include <MapiTransport.h>
377 #include <MapiMessage.h>
379 int MsgTestSendMsg(MSG_HANDLE_T hMsgHandle, msg_message_t pMsg)
381 if (hMsgHandle == NULL)
383 printf("Handle is NULL\n");
384 return MSG_ERR_NULL_MSGHANDLE;
387 MSG_ERROR_T err = MSG_SUCCESS;
389 MSG_REQUEST_S req = {0};
393 printf("Message is NULL\n");
394 return MSG_ERR_NULL_MESSAGE;
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);
404 if (err == MSG_SUCCESS)
405 printf("Request to Send Message is successful!!!");
407 printf("Request to Send Message is failed!!!");
414 @defgroup MESSAGE_USECASES_5 Sending Simple SMS Message
415 @ingroup MESSAGE_USECASES
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.
424 #include <MapiTransport.h>
434 void sent_status_cb(MSG_SENT_STATUS_S *pMsgStatus, void *userData)
436 if (pMsgStatus->status == MSG_NETWORK_SEND_SUCCESS)
437 printf("reqId : %d MSG SENT SUCCESS !!!\n", pMsgStatus->reqId);
439 printf("reqId : %d MSG SENT FAIL !!! [%d]\n", pMsgStatus->reqId, pMsgStatus->status);
443 gboolean send_func(gpointer data)
445 send_data* sms_input = (send_data*)data;
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);
450 if (err != MSG_SUCCESS)
451 printf("Send failed [%d]\n", err);
457 int main(int argc, char* argv[])
459 if (argc != 3 && argc != 4)
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");
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);
471 strncpy(sms_input.userdata, argv[3], sizeof(sms_input.userdata)-1);
473 // Add Sending Function to GMainLoop
474 g_idle_add(&send_func, (gpointer) &sms_input);
477 mainloop = g_main_loop_new(NULL, FALSE);
479 printf("Entering GMain Loop to Receive Notifications in Thread...\n");
481 g_main_loop_run(mainloop);
483 printf("==== End Test App. Bye...===\n");
490 @defgroup MESSAGE_USECASES_6 Retrieving a MMS Message
491 @ingroup MESSAGE_USECASES
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.
497 void MsgTestRetrieveMessage(MSG_HANDLE_T hMsgHandle, MSG_MESSAGE_ID_T nMsgId)
499 if (hMsgHandle == NULL)
501 printf("Handle is NULL");
505 MSG_ERROR_T err = MSG_SUCCESS;
507 msg_message_t msg = msg_new_message();
508 MSG_SENDINGOPT_S sendOpt = {0, };
510 err = msg_get_message(hMsgHandle, (MSG_MESSAGE_ID_T)nMsgId, msg, &sendOpt);
512 if (err != MSG_SUCCESS)
513 printf("Get Message Failed!");
515 MSG_REQUEST_S req = {0, msg, sendOpt};
517 err = msg_mms_retrieve_message(hMsgHandle, &req);
519 if (err != MSG_SUCCESS)
520 printf("Retrieve MMS Message Failed!");
522 msg_release_message(&msg);
527 @defgroup MESSAGE_USECASES_7 Getting a SMS Message
528 @ingroup MESSAGE_USECASES
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.
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).
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).
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).
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).
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.
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.
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).
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.
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.
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).
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.
567 void MsgTestGetSmsMessage(MSG_HANDLE_T hMsgHandle, int MsgId)
569 if (hMsgHandle == NULL)
571 printf("Handle is NULL\n");
575 MSG_ERROR_T err = MSG_SUCCESS;
577 msg_message_t msg = msg_new_message();
578 MSG_SENDINGOPT_S sendOpt = {0, };
581 err = msg_get_message(hMsgHandle, (MSG_MESSAGE_ID_T)MsgId, msg, &sendOpt);
583 if (err != MSG_SUCCESS) goto free_memory;
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));
597 msg_release_message(&msg);
602 @defgroup MESSAGE_USECASES_8 Getting a MMS Message
603 @ingroup MESSAGE_USECASES
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.
619 void MsgTestGetMmsMessage(MSG_HANDLE_T hMsgHandle, int MsgId)
621 if (hMsgHandle == NULL)
623 printf("Handle is NULL\n");
627 MSG_ERROR_T err = MSG_SUCCESS;
629 msg_message_t msg = msg_new_message();
630 MSG_SENDINGOPT_S sendOpt = {0, };
633 err = msg_get_message(hMsgHandle, (MSG_MESSAGE_ID_T)MsgId, msg, &sendOpt);
635 if (err != MSG_SUCCESS) goto free_memory;
637 if (msg_is_mms(msg) == false)
639 printf("It is not MMS Message!");
643 MMS_MESSAGE_DATA_S* msgBody = msg_mms_create_message();
646 msg_mms_get_message_body(msg, msgBody);
648 //Print root-layout info
652 msgBody->rootlayout.width.value,
653 msgBody->rootlayout.height.value,
654 msgBody->rootlayout.bgColor);
657 for (int i = 0; i < msgBody->regionCnt; ++i)
659 MMS_SMIL_REGION* pRegion = msg_mms_get_smil_region(msgBody, i);
661 printf("region id: %s\n
666 region bgColor : %x\n
668 pRegion->szID,pRegion->nLeft.value,
669 pRegion->nTop.value,pRegion->width.value,
670 pRegion->height.value, pRegion->bgColor,
675 for (int i = 0; i< msgBody->pageCnt; ++i)
677 MMS_PAGE_S* pPage = msg_mms_get_page(msgBody, i);
679 printf("page's duration: %d msec\n
680 page's media count: %d\n",
681 pPage->nDur, pPage->mediaCnt);
683 // Print Contents Info
684 for(int j = 0; j < pPage->mediaCnt; ++j)
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",
694 pMedia->sMedia.sText.bBold,
695 pMedia->sMedia.sText.bItalic);
697 if(pMedia->drmType != MSG_DRM_TYPE_NONE)
699 printf("media's drmtype: %d\n
700 media's drmpath: %s\n",
701 pMedia->drmType, pMedia->szDrm2FullPath);
706 for (int i = 0; i < msgBody->attachCnt; ++i)
708 MMS_ATTACH_S* pAttach = msg_mms_get_attachment(msgBody, i);
710 printf("Attachment file Name: %s\n
711 Attachment file Path: %s\n
712 Attached file size: %d\n",
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);
723 printf("Subject: %s\n", msg_get_subject(pMsg));
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));
734 msg_mms_destroy_message(msgBody);
736 msg_release_message(&msg);
741 @defgroup MESSAGE_USECASES_9 Delete a Message
742 @ingroup MESSAGE_USECASES
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.
748 void MsgTestDeleteMessage(MSG_HANDLE_T hMsgHandle, MSG_MESSAGE_ID_T nMsgId)
752 if (msg_delete_message(hMsgHandle, nMsgId) != MSG_SUCCESS)
753 printf("Failed to delete Message");
759 @defgroup MESSAGE_USECASES_10 Set/Get Message Setting
760 @ingroup MESSAGE_USECASES
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.
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.
770 void MsgTestSetGeneralOpt(MSG_HANDLE_T hMsgHandle)
772 MSG_ERROR_T err = MSG_SUCCESS;
773 MSG_SETTING_S setting = {0, };
775 setting.type = MSG_GENERAL_OPT;
777 setting.option.generalOpt.bKeepCopy = true;
778 setting.option.generalOpt.alertTone = MSG_ALERT_TONE_ONCE;
780 err = msg_set_config(hMsgHandle, &setting);
782 if (err == MSG_SUCCESS)
783 printf("Setting Config Data is OK!");
785 printf("Setting Config Data is failed!");
788 void MsgTestGetGeneralOpt(MSG_HANDLE_T hMsgHandle)
790 MSG_ERROR_T err = MSG_SUCCESS;
791 MSG_SETTING_S setting = {0, };
793 err = msg_get_config(hMsgHandle, &setting);
795 if (err == MSG_SUCCESS)
797 printf("Setting Config Data is OK!\n");
798 printf("bKeepCopy : [%d], AlertTone : [%d]\n", setting.option.generalOpt.bKeepCopy, setting.option.generalOpt.alertTone);
801 printf("Setting Config Data is failed!\n");
806 @defgroup MESSAGE_USECASES_11 Filtering a Message
807 @ingroup MESSAGE_USECASES
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().
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
817 void MsgTestAddFilter(MSG_HANDLE_T hMsgHandle)
819 if (hMsgHandle == NULL)
821 printf("Handle is NULL");
825 MSG_ERROR_T err = MSG_SUCCESS;
826 MSG_FILTER_S filter[2]= {0, };
828 // Add filter by address
829 filter[0].filterType = MSG_FILTER_BY_ADDRESS;
830 strncpy(filter[0].filterValue, "+821234567890", MAX_FILTER_VALUE_LEN);
832 err = msg_add_filter(hMsgHandle, &filter[0]);
834 if (err == MSG_SUCCESS)
835 printf("msg_add_filter success");
837 printf("msg_add_filter fail - err [%d]", err);
839 // Add filter by subject
840 filter[1].filterType = MSG_FILTER_BY_SUBJECT;
841 strncpy(filter[1].filterValue, "test filter", MAX_FILTER_VALUE_LEN);
843 err = msg_add_filter(hMsgHandle, &filter[1]);
845 if (err == MSG_SUCCESS)
846 printf("msg_add_filter success");
848 printf("msg_add_filter fail - err [%d]", err);
853 void MsgTestDeleteFilter(MSG_HANDLE_T hMsgHandle, MSG_FILTER_ID_T filterId)
855 if (hMsgHandle == NULL)
857 printf("Handle is NULL");
861 MSG_ERROR_T err = MSG_SUCCESS;
862 err = msg_delete_filter(hMsgHandle, filterId);
864 if (MSG_SUCCESS == err)
866 printf("msg_delete_filter success");
870 printf("msg_delete_filter fail - err [%d]", err);
882 @defgroup MESSAGE_USECASES Use Cases