3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 * Sangkoo Kim <sangkoo.kim@samsung.com>
9 * Seunghwan Lee <sh.cat.lee@samsung.com>
10 * SoonMin Jung <sm0415.jung@samsung.com>
11 * Jae-Young Lee <jy4710.lee@samsung.com>
12 * KeeBum Kim <keebum.kim@samsung.com>
14 * PROPRIETARY/CONFIDENTIAL
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
32 /*==================================================================================================
34 ==================================================================================================*/
42 #include <sys/syscall.h>
47 #include "MapiControl.h"
48 #include "MapiStorage.h"
49 #include "MapiTransport.h"
50 #include "MapiMessage.h"
51 #include "MsgTestStorage.h"
52 #include "MsgTestSetting.h"
53 #include "MsgTestThreadView.h"
54 #include "MsgTestConvert.h"
58 /*==================================================================================================
60 ==================================================================================================*/
61 extern MSG_FOLDER_LIST_S g_folderList;
63 static MSG_HANDLE_T msgHandle = NULL;
67 /*==================================================================================================
68 FUNCTION IMPLEMENTATION
69 ==================================================================================================*/
72 print("======================================");
73 print("==== Start Messaging FW Test App. ====");
74 print("======================================");
76 if (init_app() != MSG_SUCCESS)
83 void print(const char* string)
85 cout << string << endl;
97 return syscall(__NR_gettid);
101 void printMessageS(msg_message_t pNewMsg)
103 MSG_DEBUG("msgId = %d", msg_get_message_id(pNewMsg));
104 MSG_DEBUG("folderId = %d", msg_get_folder_id(pNewMsg));
105 MSG_DEBUG("msgType = %d", msg_get_message_type(pNewMsg));
106 MSG_DEBUG("nAddressCnt = %d", msg_get_address_count(pNewMsg));
107 MSG_DEBUG("addressList[0].threadId = %d", msg_get_ith_thread_id(pNewMsg, 0));
108 MSG_DEBUG("addressList[0].addressVal = %s", msg_get_ith_address(pNewMsg, 0));
109 MSG_DEBUG("addressList[0].displayname = %s", msg_get_ith_name(pNewMsg, 0));
110 MSG_DEBUG("displayTime = %s", ctime(msg_get_time(pNewMsg)));
111 MSG_DEBUG("networkStatus = %d", msg_get_network_status(pNewMsg));
112 MSG_DEBUG("bRead = %d", msg_is_read(pNewMsg));
113 MSG_DEBUG("bProtected = %d", msg_is_protected(pNewMsg));
114 MSG_DEBUG("priority = %d", msg_get_priority_info(pNewMsg));
115 MSG_DEBUG("dataSize = %d", msg_get_message_body_size(pNewMsg));
117 int msgType = msg_get_message_type(pNewMsg);
119 if(msgType==MSG_TYPE_MMS_NOTI || msgType==MSG_TYPE_MMS_JAVA || msgType==MSG_TYPE_MMS)
120 MSG_DEBUG("msgData = %s", msg_mms_get_text_contents(pNewMsg));
122 MSG_DEBUG("msgData = %s", msg_sms_get_message_body(pNewMsg));
126 void sentStatusCB(MSG_HANDLE_T Handle, MSG_SENT_STATUS_S *pStatus, void *pUserParam)
128 MSG_DEBUG("Receive SentStatus !!!!!!!!!!!!!!!!!");
130 if (pStatus->status == MSG_NETWORK_SEND_SUCCESS)
131 MSG_DEBUG("reqId : %d MSG SENT SUCCESS !!! ", pStatus->reqId);
133 MSG_DEBUG("reqId : %d MSG SENT FAIL !!! [%d]", pStatus->reqId, pStatus->status);
135 MSG_DEBUG("User Param [%s]", (char*)pUserParam);
139 void incomingSmsCB(MSG_HANDLE_T Handle, msg_message_t msg, void *pUserParam)
141 MSG_DEBUG("Receive New Message !!!!!!!!!!!!!!!!!");
145 MSG_DEBUG("User Param [%s]", (char*)pUserParam);
149 void incomingMmsConfCB(MSG_HANDLE_T Handle, msg_message_t msg, void *pUserParam)
151 if ( msg_get_network_status(msg) == MSG_NETWORK_RETRIEVE_SUCCESS)
153 MSG_DEBUG("Receive New MMS Message !!!!!!!!!!!!!!!!!msg Id [%d]", msg_get_message_id(msg));
156 MSG_DEBUG("MMS RETRIEVE FAIL !!!!!!! [%d]", msg_get_network_status(msg));
160 void appPortCB (MSG_HANDLE_T Handle, msg_message_t msg, void *pUserParam)
162 MSG_DEBUG("Receive App Port Message - Port Number [%d] !!!!!!!!!!!!!!!!!", msg_get_dest_port(msg));
168 void syncMLCB(MSG_HANDLE_T hMsgHandle, MSG_SYNCML_MESSAGE_TYPE_T msgType, const char* pPushBody, int PushBodyLen, const char* wspHeader, int wspHeaderLen, void *pUserParam)
170 MSG_DEBUG("syncMLCB() called");
172 MSG_DEBUG("msgType [%d]", msgType);
174 // MSG_DEBUG("PushHeaderLen [%d]", PushHeaderLen);
176 // MSG_DEBUG("pPushHeader [%s]", pPushHeader);
178 MSG_DEBUG("PushBodyLen [%d]", PushBodyLen);
180 MSG_DEBUG("[pPushBody]");
181 for (int i = 0; i < PushBodyLen; i++)
183 printf("[%02x]", pPushBody[i]);
187 MSG_SYNCML_MESSAGE_S syncMLMsg;
189 memset(&syncMLMsg, 0x00, sizeof(MSG_SYNCML_MESSAGE_S));
191 syncMLMsg.extId = 11;
192 syncMLMsg.pinCode = 1111;
194 syncMLMsg.msg = msg_new_message();
196 msg_set_folder_id(syncMLMsg.msg, MSG_INBOX_ID); // syncMLMsg.msg.folderId = 1;
197 msg_set_message_type(syncMLMsg.msg, MSG_TYPE_SMS_SYNCML);
198 msg_set_network_status(syncMLMsg.msg, MSG_NETWORK_RECEIVED); //syncMLMsg.msg.networkStatus = MSG_NETWORK_RECEIVED;
199 msg_set_direction_info(syncMLMsg.msg, MSG_DIRECTION_TYPE_MT);
201 msg_add_address(syncMLMsg.msg, "+1004", MSG_RECIPIENTS_TYPE_TO);
203 // setting received time
204 time_t t = time(NULL);
205 time_t utfTime = time(&t);
206 msg_set_time(syncMLMsg.msg, utfTime);
208 char msg_body[]="SyncML Message";
209 msg_sms_set_message_body(syncMLMsg.msg, msg_body, strlen(msg_body));
211 int err = msg_add_syncml_message(msgHandle, &syncMLMsg);
213 if (err != MSG_SUCCESS)
215 MSG_DEBUG("MsgAddSyncMLMessage() Fail [%d]", err);
221 void syncMLOperationCB(MSG_HANDLE_T handle, int msgId, int extId, void *user_param)
223 MSG_DEBUG("syncMLOperationCB() called");
225 MSG_DEBUG("msgId [%d]", msgId);
227 MSG_DEBUG("extId [%d]", extId);
229 //SyncML operation proccess hsa to be place here.
233 void lbsCB(MSG_HANDLE_T hMsgHandle, const char* pPushHeader, const char* pPushBody, int pushBodyLen, void *pUserParam)
235 MSG_DEBUG("lbsCB() called");
237 MSG_DEBUG("pPushHeader : [%s]", pPushHeader);
239 MSG_DEBUG("pushBodyLen [%d]", pushBodyLen);
241 MSG_DEBUG("[pPushBody]");
242 for (int i = 0; i < pushBodyLen; i++)
244 printf("[%02x]", pPushBody[i]);
250 void storageChangeCB(MSG_HANDLE_T hMsgHandle, MSG_STORAGE_CHANGE_TYPE_T storageChangeType, MSG_MSGID_LIST_S *pMsgIdList, void *pUserParam)
252 MSG_DEBUG("storageChangeCB() called");
254 MSG_DEBUG("storageChangeType[%d]", storageChangeType);
256 MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
258 if (pMsgIdList->nCount > 0) {
259 for (int i = 0; i < pMsgIdList->nCount; i++)
260 MSG_DEBUG("pMsgIdList->msgIdList[%d] [%d]", i, pMsgIdList->msgIdList[i]);
265 MSG_ERROR_T init_app()
267 MSG_ERROR_T err = MSG_SUCCESS;
269 char str[TEST_APP_PIRNT_STR_LEN+1] = {0,};
271 err = msg_open_msg_handle(&msgHandle);
273 if (err != MSG_SUCCESS)
275 snprintf(str, TEST_APP_PIRNT_STR_LEN+1, "msg_open_msg_handle() Fail [%d]", err);
281 err = msg_reg_sent_status_callback(msgHandle, &sentStatusCB, (void*)"sent status callback");
283 if (err != MSG_SUCCESS)
285 snprintf(str, TEST_APP_PIRNT_STR_LEN+1, "msg_reg_sent_status_callback() Fail [%d]", err);
291 err = msg_reg_sms_message_callback(msgHandle, &incomingSmsCB, 0, (void*)"sms message callback");
293 if (err != MSG_SUCCESS)
295 snprintf(str, TEST_APP_PIRNT_STR_LEN+1, "msg_reg_sms_message_callback() Fail [%d]", err);
301 err = msg_reg_sms_message_callback(msgHandle, &appPortCB, 4010, (void*)"sms message callback with port");
303 if (err != MSG_SUCCESS)
305 snprintf(str, TEST_APP_PIRNT_STR_LEN+1, "msg_reg_sms_message_callback() Fail [%d]", err);
311 err = msg_reg_syncml_message_callback(msgHandle, &syncMLCB, NULL);
313 if (err != MSG_SUCCESS)
315 snprintf(str, TEST_APP_PIRNT_STR_LEN+1, "msg_reg_syncml_message_callback() Fail [%d]", err);
321 err = msg_reg_syncml_message_operation_callback(msgHandle, &syncMLOperationCB, NULL);
323 if (err != MSG_SUCCESS)
325 snprintf(str, TEST_APP_PIRNT_STR_LEN+1, "msg_reg_syncml_message_operation_callback() Fail [%d]", err);
331 err = msg_reg_lbs_message_callback(msgHandle, &lbsCB, NULL);
333 if (err != MSG_SUCCESS)
335 snprintf(str, TEST_APP_PIRNT_STR_LEN+1, "msg_reg_lbs_message_callback() Fail [%d]", err);
341 err = msg_reg_mms_conf_message_callback(msgHandle, &incomingMmsConfCB, NULL, NULL);
343 if (err != MSG_SUCCESS)
345 snprintf(str, TEST_APP_PIRNT_STR_LEN+1, "msg_reg_mms_conf_message_callback() Fail [%d]", err);
351 err = msg_reg_storage_change_callback(msgHandle, &storageChangeCB, NULL);
353 if (err != MSG_SUCCESS)
355 snprintf(str, TEST_APP_PIRNT_STR_LEN+1, "msg_reg_storage_change_callback() Fail [%d]", err);
363 if (pthread_create(&tid, NULL, show_menu, NULL) != 0)
365 MSG_DEBUG("MsgInitThread not invoked: %s", strerror(errno));
366 return MSG_ERR_UNKNOWN;
369 mainloop = g_main_loop_new(NULL, FALSE);
371 MSG_DEBUG("Entering GMain Loop to Receive Notifications...");
373 g_main_loop_run(mainloop);
379 void* show_menu(void*)
381 MSG_ERROR_T err = MSG_SUCCESS;
385 char strPrint[TEST_APP_PIRNT_STR_LEN+1] = {0,};
388 MSG_COUNT_INFO_S countInfo;
392 msg_release_folder_list(&g_folderList);
395 err = msg_get_folder_list(msgHandle, &g_folderList);
397 if (err != MSG_SUCCESS)
399 MSG_DEBUG("MsgGetFolderList() Fail [%d]", err);
405 print("======================================");
406 print("============== Box List ==============");
407 print("======================================");
409 for (int i = 0; i < g_folderList.nCount; i++)
411 if (msg_count_message(msgHandle, g_folderList.folderInfo[i].folderId, &countInfo) != MSG_SUCCESS)
414 memset(strPrint, 0x00, sizeof(strPrint));
415 snprintf(strPrint, TEST_APP_PIRNT_STR_LEN+1, "[%d] %s \t [%d/%d] [SMS %d/MMS %d]",
416 g_folderList.folderInfo[i].folderId, g_folderList.folderInfo[i].folderName, countInfo.nUnreadCnt, countInfo.nUnreadCnt + countInfo.nReadCnt, countInfo.nSms, countInfo.nMms);
420 print("======================================");
421 print("================ Menu ================");
422 print("======================================");
423 print("[C] Create Message");
424 print("[S] Setting");
425 print("[A] Add New Folder");
426 print("[D] Delete a Folder");
427 print("[U] Update Folder Name");
428 print("[V] Convert(Encode/Decode) Charset");
429 print("[M] Msg Generator");
430 print("[T] Thread View Test");
431 print("[G] Search Message");
433 print("======================================");
437 memset(menu, 0x00, sizeof(menu));
438 cin.getline(menu, 3);
442 while (strcmp(menu, "Q"));
444 msg_release_folder_list(&g_folderList);
446 msg_close_msg_handle(&msgHandle);
448 if (msgHandle != NULL)
450 MSG_DEBUG("msgHandle is not NULL [%p]", msgHandle);
453 if (g_main_loop_is_running(mainloop))
454 g_main_loop_quit(mainloop);
456 print("======================================");
457 print("==== End Messaging FW Test App. Bye===");
458 print("======================================");
464 void run_app(char *pMenu)
466 if (!strcmp(pMenu, "C") || !strcmp(pMenu, "c"))
468 MsgTestAddMessage(msgHandle);
470 else if (!strcmp(pMenu, "S") || !strcmp(pMenu, "s"))
472 MsgTestSettingMain(msgHandle);
474 else if (!strcmp(pMenu, "A") || !strcmp(pMenu, "a"))
476 MsgTestAddFolder(msgHandle);
478 else if (!strcmp(pMenu, "D") || !strcmp(pMenu, "d"))
480 MsgTestDeleteFolder(msgHandle);
482 else if (!strcmp(pMenu, "U") || !strcmp(pMenu, "u"))
484 MsgTestUpdateFolder(msgHandle);
486 else if (!strcmp(pMenu, "V") || !strcmp(pMenu, "v"))
488 // MsgTestConvertMain();
490 else if (!strcmp(pMenu, "M") || !strcmp(pMenu, "m"))
492 MsgTestMsgGen(msgHandle);
494 else if (!strcmp(pMenu, "T") || !strcmp(pMenu, "t"))
496 MsgThreadViewMain(msgHandle);
498 else if (!strcmp(pMenu, "G") || !strcmp(pMenu, "g"))
500 MsgSearchViewMain(msgHandle);
502 else if (!strcmp(pMenu, "Q") || !strcmp(pMenu, "q"))
508 int folderId = atoi(pMenu);
510 if (folderId > 0 && folderId < 100)
512 // Query Msg List in Msg Box
513 MsgTestGetMessageList(msgHandle, folderId);
516 print("Not Supported");