Modify flora license version.
[platform/core/messaging/msg-service.git] / framework / transaction-manager / MsgCmdHandlerStorage.cpp
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.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 #include <stdlib.h>
18
19 #include "MsgDebug.h"
20 #include "MsgUtilFile.h"
21 #include "MsgException.h"
22 #include "MsgCppTypes.h"
23 //#include "MsgSoundPlayer.h"
24 #include "MsgUtilFunction.h"
25 #include "MsgStorageHandler.h"
26 #include "MsgPluginManager.h"
27 #include "MsgTransManager.h"
28 #include "MsgCmdHandler.h"
29
30
31 /*==================================================================================================
32                                      FUNCTION IMPLEMENTATION
33 ==================================================================================================*/
34 int MsgAddMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
35 {
36         msg_error_t err = MSG_SUCCESS;
37
38         char* encodedData = NULL;
39         AutoPtr<char> buf(&encodedData);
40
41         int dataSize = 0, eventSize = 0;
42
43         // Get Message Info
44         MSG_MESSAGE_INFO_S* pMsgInfo = (MSG_MESSAGE_INFO_S*)pCmd->cmdData;
45
46         // Get Sending Option
47         MSG_SENDINGOPT_INFO_S* pSendOptInfo = (MSG_SENDINGOPT_INFO_S*)(pCmd->cmdData + sizeof(MSG_MESSAGE_INFO_S));
48
49         // Add Message
50         err = MsgStoAddMessage(pMsgInfo, pSendOptInfo);
51
52         if (err == MSG_SUCCESS) {
53                         MSG_DEBUG("Command Handle Success : MsgStoAddMessage()");
54
55                         // Encoding Message ID
56                         dataSize = MsgEncodeMsgId(&(pMsgInfo->msgId), &encodedData);
57                 } else {
58                         MSG_DEBUG("Command Handle Fail : MsgStoAddMessage()");
59                 }
60
61         // Delete Temp File for Message Data
62         if (pMsgInfo->bTextSms == false)
63                 MsgDeleteFile(pMsgInfo->msgData); //ipc
64
65         //storage change CB
66         msg_id_list_s msgIdList;
67         msg_message_id_t msgIds[1];
68         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
69
70         msgIdList.nCount = 1;
71         msgIds[0] = pMsgInfo->msgId;
72         msgIdList.msgIdList = msgIds;
73
74         MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
75
76         // Make Event Data
77         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_ADD_MSG, err, (void**)ppEvent);
78
79         return eventSize;
80 }
81
82
83 int MsgAddSyncMLMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
84 {
85         msg_error_t err = MSG_SUCCESS;
86
87         int eventSize = 0;
88
89         int extId = 0, pinCode = 0;
90
91         MSG_MESSAGE_INFO_S msgInfo = {};
92
93         memcpy(&extId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(int));
94         memcpy(&pinCode, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), sizeof(int));
95         memcpy(&msgInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(int)), sizeof(MSG_MESSAGE_INFO_S));
96
97         // Add Message
98         err = MsgStoAddSyncMLMessage(&msgInfo, extId, pinCode);
99
100         if (err == MSG_SUCCESS)
101         {
102                 MSG_DEBUG("Command Handle Success : MsgStoAddSyncMLMessage()");
103
104                 // broadcast to listener threads, here
105                 MsgTransactionManager::instance()->broadcastIncomingMsgCB(err, &msgInfo);
106                 //storage change CB
107                 msg_id_list_s msgIdList;
108                 msg_message_id_t msgIds[1];
109                 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
110
111                 msgIdList.nCount = 1;
112                 msgIds[0] = msgInfo.msgId;
113                 msgIdList.msgIdList = msgIds;
114
115                 MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_INSERT, &msgIdList);
116         }
117         else
118         {
119                 MSG_DEBUG("Command Handle Fail : MsgStoAddSyncMLMessage()");
120         }
121
122         // Make Event Data
123         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_ADD_SYNCML_MSG, err, (void**)ppEvent);
124
125         return eventSize;
126 }
127
128
129 int MsgUpdateMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
130 {
131         msg_error_t err = MSG_SUCCESS;
132
133         int eventSize = 0;
134
135         // Get Message Info
136         MSG_MESSAGE_INFO_S* pMsgInfo = (MSG_MESSAGE_INFO_S*)pCmd->cmdData;
137
138         // Get Sending Option
139         MSG_SENDINGOPT_INFO_S* pSendOptInfo = (MSG_SENDINGOPT_INFO_S*)(pCmd->cmdData + sizeof(MSG_MESSAGE_INFO_S));
140
141         // Update Message
142         err = MsgStoUpdateMessage(pMsgInfo, pSendOptInfo);
143
144         if (err == MSG_SUCCESS)
145                 MSG_DEBUG("Command Handle Success : MsgStoUpdateMessage()");
146         else
147                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateMessage()");
148
149         // Delete Temp File for Message Data
150         if (pMsgInfo->bTextSms == false)
151                 MsgDeleteFile(pMsgInfo->msgData); //ipc
152
153         //storage change CB
154         msg_id_list_s msgIdList;
155         msg_message_id_t msgIds[1];
156         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
157
158         msgIdList.nCount = 1;
159         msgIds[0] = pMsgInfo->msgId;
160         msgIdList.msgIdList = msgIds;
161
162         MsgTransactionManager::instance()->broadcastStorageChangeCB(err, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
163
164         // Make Event Data
165         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_MSG, err, (void**)ppEvent);
166
167         return eventSize;
168 }
169
170
171 int MsgUpdateReadStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
172 {
173         msg_error_t err = MSG_SUCCESS;
174
175         int eventSize = 0;
176
177         msg_message_id_t msgId;
178         bool readStatus;
179
180         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_id_t));
181         memcpy(&readStatus, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), sizeof(bool));
182
183         // Update Read Status
184         err = MsgStoUpdateReadStatus(msgId, readStatus);
185
186         if (err == MSG_SUCCESS)
187         {
188                 MSG_DEBUG("Command Handle Success : MsgStoUpdateReadStatus()");
189         }
190         else
191         {
192                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateReadStatus()");
193         }
194
195         // Make Event Data
196         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_READ, err, (void**)ppEvent);
197
198         return eventSize;
199 }
200
201
202 int MsgUpdateThreadReadStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
203 {
204         msg_error_t err = MSG_SUCCESS;
205
206         int eventSize = 0;
207
208         msg_thread_id_t threadId;
209         int unReadCnt = 0;
210
211         memcpy(&threadId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_thread_id_t));
212
213         MsgStoGetThreadUnreadCnt(threadId, &unReadCnt);
214
215         MSG_DEBUG("unReadCnt [%d]", unReadCnt);
216
217         if (unReadCnt > 0) {
218
219                 err = MsgStoUpdateThreadReadStatus(threadId);
220
221                 if (err == MSG_SUCCESS)
222                         MSG_DEBUG("Command Handle Success : MsgStoUpdateThreadReadStatus()");
223                 else
224                         MSG_DEBUG("Command Handle Fail : MsgStoUpdateThreadReadStatus()");
225         }
226
227         // Make Event Data
228         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_THREAD_READ, err, (void**)ppEvent);
229
230         return eventSize;
231
232 }
233
234
235 int MsgUpdateProtectedStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
236 {
237         msg_error_t err = MSG_SUCCESS;
238
239         int eventSize = 0;
240
241         msg_message_id_t msgId;
242         bool protectedStatus;
243
244         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_id_t));
245         memcpy(&protectedStatus, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), sizeof(bool));
246
247         // Update Protected Status
248         err = MsgStoUpdateProtectedStatus(msgId, protectedStatus);
249
250         if (err == MSG_SUCCESS)
251         {
252                 MSG_DEBUG("Command Handle Success : MsgStoUpdateProtectedStatus()");
253         }
254         else
255         {
256                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateProtectedStatus()");
257         }
258
259         // Make Event Data
260         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_PROTECTED, err, (void**)ppEvent);
261
262         return eventSize;
263 }
264
265
266 int MsgDeleteMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
267 {
268         msg_error_t err = MSG_SUCCESS;
269
270         int eventSize = 0;
271
272         int extId = 0;
273
274         msg_message_id_t* msgId = (msg_message_id_t*)pCmd->cmdData;
275
276         MsgStoGetSyncMLExtId(*msgId, &extId);
277
278         // Delete Message
279         err = MsgStoDeleteMessage(*msgId, true);
280
281         if (err == MSG_SUCCESS) {
282                 MSG_DEBUG("Command Handle Success : MsgStoDeleteMessage()");
283
284                 if(extId > 0) {
285                         // broadcast to listener threads, here
286                         MsgTransactionManager::instance()->broadcastSyncMLMsgOperationCB(err, -1, extId);
287                 }
288
289                 msg_id_list_s msgIdList;
290                 msg_message_id_t msgIds[1];
291                 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
292
293                 msgIdList.nCount = 1;
294                 msgIds[0] = *msgId;
295                 msgIdList.msgIdList = msgIds;
296
297                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
298         } else {
299                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteMessage()");
300         }
301
302         // Make Event Data
303         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_MSG, err, (void**)ppEvent);
304
305         return eventSize;
306 }
307
308
309 int MsgDeleteAllMessageInFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
310 {
311         msg_error_t err = MSG_SUCCESS;
312
313         int eventSize = 0;
314
315         msg_folder_id_t* folderId = (msg_folder_id_t*)pCmd->cmdData;
316
317         bool bOnlyDB;
318         memcpy(&bOnlyDB, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_folder_id_t)), sizeof(bool));
319
320
321         msg_id_list_s msgIdList;
322         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
323
324         // Delete Message
325         err = MsgStoDeleteAllMessageInFolder(*folderId, bOnlyDB, &msgIdList);
326
327         if (err == MSG_SUCCESS) {
328                 MSG_DEBUG("Command Handle Success : MsgStoDeleteAllMessageInFolder()");
329                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
330                 if(msgIdList.msgIdList != NULL)
331                         delete [] (char*)msgIdList.msgIdList;
332         } else {
333                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteAllMessageInFolder()");
334         }
335
336         // Make Event Data
337         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELALL_MSGINFOLDER, err, (void**)ppEvent);
338
339         return eventSize;
340
341 }
342
343
344 int MsgDeleteMessageByListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
345 {
346         msg_error_t err = MSG_SUCCESS;
347
348         int eventSize = 0;
349
350         msg_id_list_s msgIdList;
351         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
352
353         msgIdList.nCount = *((int *)pCmd->cmdData);
354
355         MSG_DEBUG("msgIdList.nCount [%d]", msgIdList.nCount);
356
357         msg_message_id_t msgIds[msgIdList.nCount];
358         memset(msgIds, 0x00, sizeof(msgIds));
359
360         msgIdList.msgIdList = msgIds;
361
362         for (int i=0; i<msgIdList.nCount; i++) {
363                 msgIds[i] = *(msg_message_id_t *)(((char*)pCmd->cmdData) + (sizeof(int)*(i+1)));
364         }
365
366         // Delete Message
367         err = MsgStoDeleteMessageByList(&msgIdList);
368
369         if (err == MSG_SUCCESS) {
370                 MSG_DEBUG("Command Handle Success : MsgStoDeleteMessageByList()");
371                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
372         } else {
373                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteMessageByList()");
374         }
375
376         // Make Event Data
377         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_MESSAGE_BY_LIST, err, (void**)ppEvent);
378
379         return eventSize;
380 }
381
382
383 int MsgMoveMessageToFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
384 {
385         msg_error_t err = MSG_SUCCESS;
386
387         int eventSize = 0;
388
389         msg_message_id_t msgId;
390         msg_folder_id_t folderId;
391
392         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_id_t));
393         memcpy(&folderId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), sizeof(msg_folder_id_t));
394
395         // Move Message
396         err = MsgStoMoveMessageToFolder(msgId, folderId);
397
398         if (err == MSG_SUCCESS) {
399                 MSG_DEBUG("Command Handle Success : MsgStoMoveMessageToFolder()");
400
401                 msg_id_list_s msgIdList;
402                 msg_message_id_t msgIds[1];
403                 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
404
405                 msgIdList.nCount = 1;
406                 msgIds[0] = msgId;
407                 msgIdList.msgIdList = msgIds;
408
409                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_UPDATE, &msgIdList);
410         } else {
411                 MSG_DEBUG("Command Handle Fail : MsgStoMoveMessageToFolder()");
412         }
413
414         // Make Event Data
415         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_MOVE_MSGTOFOLDER, err, (void**)ppEvent);
416
417         return eventSize;
418 }
419
420
421 int MsgMoveMessageToStorageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
422 {
423         msg_error_t err = MSG_SUCCESS;
424
425         int eventSize = 0;
426
427         msg_message_id_t msgId;
428         msg_storage_id_t storageId;
429
430         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_id_t));
431         memcpy(&storageId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), sizeof(msg_storage_id_t));
432
433         // Move Message
434         err = MsgStoMoveMessageToStorage(msgId, storageId);
435
436         if (err == MSG_SUCCESS)
437         {
438                 MSG_DEBUG("Command Handle Success : MsgStoMoveMessageToStorage()");
439         }
440         else
441         {
442                 MSG_DEBUG("Command Handle Fail : MsgStoMoveMessageToStorage()");
443         }
444
445         // Make Event Data
446         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_MOVE_MSGTOSTORAGE, err, (void**)ppEvent);
447
448         return eventSize;
449 }
450
451
452 int MsgCountMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
453 {
454         msg_error_t err = MSG_SUCCESS;
455
456         char* encodedData = NULL;
457         AutoPtr<char> buf(&encodedData);
458
459         int dataSize = 0, eventSize = 0;
460
461         // Get Folder ID
462         msg_folder_id_t* folderId = (msg_folder_id_t*)pCmd->cmdData;
463
464         // Get Message Count
465         MSG_COUNT_INFO_S countInfo;
466
467         err = MsgStoCountMessage(*folderId, &countInfo);
468
469         if (err == MSG_SUCCESS)
470         {
471                 MSG_DEBUG("Command Handle Success : MsgStoCountMessage()");
472
473                 // Encoding Messaging Count Data
474                 dataSize = MsgEncodeCountInfo(&countInfo, &encodedData);
475         }
476         else
477         {
478                 MSG_DEBUG("Command Handle Fail : MsgStoCountMessage()");
479         }
480
481         // Make Event Data
482         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_COUNT_MSG, err, (void**)ppEvent);
483
484         return eventSize;
485 }
486
487
488 int MsgCountMsgByTypeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
489 {
490         msg_error_t err = MSG_SUCCESS;
491
492         char* encodedData = NULL;
493         AutoPtr<char> buf(&encodedData);
494
495         int dataSize = 0, eventSize = 0;
496
497         // Get Folder ID
498         MSG_MESSAGE_TYPE_S* pMsgType = (MSG_MESSAGE_TYPE_S*)pCmd->cmdData;
499
500         int nMsgCnt = 0;
501
502         // Get Message Count
503         err = MsgStoCountMsgByType(pMsgType, &nMsgCnt);
504
505         if (err == MSG_SUCCESS)
506         {
507                 MSG_DEBUG("Command Handle Success : MsgStoCountMsgByType()");
508
509                 // Encoding Messaging Count Data
510                 dataSize = MsgEncodeCountByMsgType(nMsgCnt, &encodedData);
511         }
512         else
513         {
514                 MSG_DEBUG("Command Handle Fail : MsgStoCountMsgByType()");
515         }
516
517         // Make Event Data
518         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_COUNT_BY_MSGTYPE, err, (void**)ppEvent);
519
520         return eventSize;
521 }
522
523
524 int MsgGetMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
525 {
526         msg_error_t err = MSG_SUCCESS;
527
528         // Get Message ID
529         msg_message_id_t* msgId = (msg_message_id_t*)pCmd->cmdData;
530
531         char* encodedData = NULL;
532         AutoPtr<char> buf(&encodedData);
533
534         int dataSize = 0, eventSize = 0;
535
536         // Get Message
537         MSG_MESSAGE_INFO_S msgInfo;
538         MSG_SENDINGOPT_INFO_S sendOptInfo;
539
540         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
541         memset(&sendOptInfo, 0x00, sizeof(MSG_SENDINGOPT_INFO_S));
542
543         err = MsgStoGetMessage(*msgId, &msgInfo, &sendOptInfo);
544
545         if (err == MSG_SUCCESS)
546         {
547                 MSG_DEBUG("Command Handle Success : MsgStoGetMessage()");
548
549                 // Encoding Message Info  Data
550                 dataSize = MsgEncodeMsgInfo(&msgInfo, &sendOptInfo, &encodedData);
551         }
552         else
553         {
554                 MSG_DEBUG("Command Handle Fail : MsgStoGetMessage()");
555         }
556
557 //      MsgSoundPlayStop();
558
559         // Make Event Data
560         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_MSG, err, (void**)ppEvent);
561
562         return eventSize;
563 }
564
565
566 int MsgGetFolderViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
567 {
568         msg_error_t err = MSG_SUCCESS;
569
570         // Get Folder ID
571         msg_folder_id_t folderId;
572         MSG_SORT_RULE_S sortRule;
573
574         memcpy(&folderId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_folder_id_t));
575         memcpy(&sortRule, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_folder_id_t)), sizeof(MSG_SORT_RULE_S));
576
577         char* encodedData = NULL;
578         AutoPtr<char> buf(&encodedData);
579
580         int dataSize = 0, eventSize = 0;
581
582         // Get Message Common Info
583         msg_struct_list_s folderViewList;
584
585         err = MsgStoGetFolderViewList(folderId, &sortRule, &folderViewList);
586
587         if (err == MSG_SUCCESS)
588         {
589                 MSG_DEBUG("Command Handle Success : MsgStoGetFolderViewList()");
590
591                 // Encoding Folder View List Data
592 //              dataSize = MsgEncodeFolderViewList(&folderViewList, &encodedData);
593
594                 MSG_DEBUG("dataSize [%d]", dataSize);
595
596                 if (folderViewList.msg_struct_info != NULL)
597                 {
598                         delete [] folderViewList.msg_struct_info;
599                         folderViewList.msg_struct_info = NULL;
600                 }
601         }
602         else
603         {
604                 MSG_DEBUG("Command Handle Fail : MsgStoGetFolderViewList()");
605                 return err;
606         }
607
608         // Make Event Data
609         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FOLDERVIEWLIST, MSG_SUCCESS, (void**)ppEvent);
610
611         return eventSize;
612 }
613
614
615 int MsgAddFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
616 {
617         msg_error_t err = MSG_SUCCESS;
618
619         int eventSize = 0;
620
621         // Get Folder Info
622         MSG_FOLDER_INFO_S* pFolderInfo = (MSG_FOLDER_INFO_S*)pCmd->cmdData;
623
624         // Add Folder
625         err = MsgStoAddFolder(pFolderInfo);
626
627         if (err == MSG_SUCCESS)
628         {
629                 MSG_DEBUG("Command Handle Success : MsgStoAddFolder()");
630         }
631         else
632         {
633                 MSG_DEBUG("Command Handle Fail : MsgStoAddFolder()");
634         }
635
636         // Make Event Data
637         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_ADD_FOLDER, err, (void**)ppEvent);
638
639         return eventSize;
640 }
641
642
643 int MsgUpdateFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
644 {
645         msg_error_t err = MSG_SUCCESS;
646
647         int eventSize = 0;
648
649         // Get Folder Info
650         MSG_FOLDER_INFO_S* pFolderInfo = (MSG_FOLDER_INFO_S*)pCmd->cmdData;
651
652         // Update Folder
653         err = MsgStoUpdateFolder(pFolderInfo);
654
655         if (err == MSG_SUCCESS)
656         {
657                 MSG_DEBUG("Command Handle Success : MsgStoUpdateFolder()");
658         }
659         else
660         {
661                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateFolder()");
662         }
663
664         // Make Event Data
665         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_FOLDER, err, (void**)ppEvent);
666
667         return eventSize;
668 }
669
670
671 int MsgDeleteFolderHandler(const MSG_CMD_S *pCmd, char **ppEvent)
672 {
673         msg_error_t err = MSG_SUCCESS;
674
675         int eventSize = 0;
676
677         // Get Folder Info
678         msg_folder_id_t* pFolderInfo = (msg_folder_id_t*)pCmd->cmdData;
679
680         // Delete Folder
681         err = MsgStoDeleteFolder(*pFolderInfo);
682
683         if (err == MSG_SUCCESS)
684         {
685                 MSG_DEBUG("Command Handle Success : MsgStoDeleteFolder()");
686         }
687         else
688         {
689                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteFolder()");
690         }
691
692         // Make Event Data
693         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_FOLDER, err, (void**)ppEvent);
694
695         return eventSize;
696 }
697
698
699 int MsgGetFolderListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
700 {
701         msg_error_t err = MSG_SUCCESS;
702
703         char* encodedData = NULL;
704         AutoPtr<char> buf(&encodedData);
705
706         int dataSize = 0, eventSize = 0;
707
708         // Get Storage List
709         msg_struct_list_s folderList;
710
711         err = MsgStoGetFolderList(&folderList);
712
713         if (err == MSG_SUCCESS)
714         {
715                 MSG_DEBUG("Command Handle Success : MsgStoGetFolderList()");
716
717                 // Encoding Folder List Data
718                 dataSize = MsgEncodeFolderList(&folderList, &encodedData);
719
720                 delete [] folderList.msg_struct_info;
721         }
722         else
723         {
724                 MSG_DEBUG("Command Handle Fail : MsgStoGetFolderList()");
725         }
726
727         // Make Event Data
728         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_FOLDERLIST, err, (void**)ppEvent);
729
730         return eventSize;
731 }
732
733
734 int MsgInitSimBySatHandler(const MSG_CMD_S *pCmd, char **ppEvent)
735 {
736         msg_error_t err = MSG_SUCCESS;
737
738         int eventSize = 0;
739
740         // Sim Init - Later
741         //Run msg-init-app
742
743         // Make Event Data
744         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_PLG_INIT_SIM_BY_SAT, err, (void**)ppEvent);
745
746         return eventSize;
747 }
748
749
750 int MsgGetMsgTypeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
751 {
752         msg_error_t err = MSG_SUCCESS;
753
754         char* encodedData = NULL;
755         AutoPtr<char> buf(&encodedData);
756
757
758         int dataSize = 0, eventSize = 0;
759
760         // Get Message ID
761         msg_message_id_t msgId;
762
763         memcpy(&msgId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_id_t));
764
765         // Get Msg Type
766         MSG_MESSAGE_TYPE_S msgType;
767
768         err = MsgStoGetMsgType(msgId, &msgType);
769
770         if (err == MSG_SUCCESS)
771         {
772                 MSG_DEBUG("Command Handle Success : MsgStoGetMsgType()");
773
774                 // Encoding Storage List Data
775                 dataSize = MsgEncodeMsgType(&msgType, &encodedData);
776
777         }
778         else
779         {
780                 MSG_DEBUG("Command Handle Fail : MsgStoGetMsgType()");
781         }
782
783         // Make Event Data
784         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_MSG_TYPE, err, (void**)ppEvent);
785
786         return eventSize;
787 }
788
789
790 int MsgGetThreadViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
791 {
792         msg_error_t err = MSG_SUCCESS;
793
794         MSG_SORT_RULE_S sortRule = {0};
795
796         memcpy(&sortRule, pCmd->cmdData, sizeof(MSG_SORT_RULE_S));
797
798         char* encodedData = NULL;
799         AutoPtr<char> buf(&encodedData);
800
801         int dataSize = 0, eventSize = 0;
802
803         // Get Thread View List
804         msg_struct_list_s msgThreadViewList;
805
806         err = MsgStoGetThreadViewList(&sortRule, &msgThreadViewList);
807
808         if (err == MSG_SUCCESS)
809         {
810                 MSG_DEBUG("Command Handle Success : MsgStoGetThreadViewList()");
811
812                 // Encoding Folder View List Data
813                 dataSize = MsgEncodeThreadViewList(&msgThreadViewList, &encodedData);
814
815                 MSG_DEBUG("dataSize [%d]", dataSize);
816
817                 if (msgThreadViewList.msg_struct_info != NULL)
818                 {
819                         delete [] msgThreadViewList.msg_struct_info;
820                         msgThreadViewList.msg_struct_info = NULL;
821                 }
822         }
823         else
824         {
825                 MSG_DEBUG("Command Handle Fail : MsgStoGetThreadViewList()");
826                 return err;
827         }
828
829         // Make Event Data
830         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_THREADVIEWLIST, err, (void**)ppEvent);
831
832         return eventSize;
833 }
834
835
836 int MsgGetConversationViewListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
837 {
838         msg_error_t err = MSG_SUCCESS;
839
840         msg_thread_id_t threadId;
841
842         memcpy(&threadId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_thread_id_t));
843
844         char* encodedData = NULL;
845         AutoPtr<char> buf(&encodedData);
846
847         int dataSize = 0, eventSize = 0;
848
849         msg_struct_list_s convViewList;
850
851         err = MsgStoGetConversationViewList(threadId, &convViewList);
852
853         if (err == MSG_SUCCESS)
854         {
855                 MSG_DEBUG("Command Handle Success : MsgStoGetConversationViewList()");
856
857                 // Encoding Folder View List Data
858                 dataSize = MsgEncodeConversationViewList(&convViewList, &encodedData);
859
860                 MSG_DEBUG("dataSize [%d]", dataSize);
861
862                 if (convViewList.msg_struct_info != NULL)
863                 {
864                         delete [] convViewList.msg_struct_info;
865                         convViewList.msg_struct_info = NULL;
866                 }
867         }
868         else
869         {
870                 MSG_DEBUG("Command Handle Fail : MsgStoGetConversationViewList()");
871         }
872
873         // Make Event Data
874         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_CONVERSATIONVIEWLIST, err, (void**)ppEvent);
875
876         return eventSize;
877 }
878
879
880 int MsgDeleteThreadMessageListHandler(const MSG_CMD_S *pCmd, char **ppEvent)
881 {
882         msg_error_t err = MSG_SUCCESS;
883
884         msg_thread_id_t threadId;
885         bool bIncludeProtect = false;
886         bool isSyncMLMsg = false;
887
888         memcpy(&threadId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_thread_id_t));
889         memcpy(&bIncludeProtect, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_thread_id_t)), sizeof(bool));
890
891         int eventSize = 0;
892
893         isSyncMLMsg = MsgStoCheckSyncMLMsgInThread(threadId);
894
895         msg_id_list_s msgIdList;
896         memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
897
898         err = MsgStoDeleteThreadMessageList(threadId, bIncludeProtect, &msgIdList);
899
900         if (err == MSG_SUCCESS) {
901                 MSG_DEBUG("Command Handle Success : MsgStoDeleteThreadMessageList()");
902
903                 if(isSyncMLMsg == true) {
904                         // broadcast to listener threads, here
905                         MsgTransactionManager::instance()->broadcastSyncMLMsgOperationCB(err, -1, -1);
906                 }
907
908                 MsgTransactionManager::instance()->broadcastStorageChangeCB(MSG_SUCCESS, MSG_STORAGE_CHANGE_DELETE, &msgIdList);
909                 if(msgIdList.msgIdList != NULL)
910                         delete [] (char*)msgIdList.msgIdList;
911         }
912         else
913         {
914                 MSG_DEBUG("Command Handle Fail : MsgStoDeleteThreadMessageList()");
915                 if(msgIdList.msgIdList != NULL)
916                         delete [] (char*)msgIdList.msgIdList;
917         }
918
919         // Make Event Data
920         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_THREADMESSAGELIST, err, (void**)ppEvent);
921
922         return eventSize;
923 }
924
925
926 int MsgCountMsgByContactHandler(const MSG_CMD_S *pCmd, char **ppEvent)
927 {
928         msg_error_t err = MSG_SUCCESS;
929
930         // Get From address
931         MSG_THREAD_LIST_INDEX_S addrInfo;
932
933         memcpy(&addrInfo, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(MSG_THREAD_LIST_INDEX_S));
934
935         char* encodedData = NULL;
936         AutoPtr<char> buf(&encodedData);
937
938         int dataSize = 0, eventSize = 0;
939
940         // Get Message Common Info
941         MSG_THREAD_COUNT_INFO_S threadCountInfo = {0};
942
943         err = MsgStoCountMsgByContact(&addrInfo, &threadCountInfo);
944
945         if (err == MSG_SUCCESS)
946         {
947                 MSG_DEBUG("Command Handle Success : MsgStoCountMsgByContact()");
948
949                 // Encoding Folder View List Data
950                 dataSize = MsgEncodeMsgGetContactCount(&threadCountInfo, &encodedData);
951
952                 MSG_DEBUG("dataSize [%d]", dataSize);
953         }
954         else
955         {
956                 MSG_DEBUG("Command Handle Fail : MsgStoCountMsgByContact()");
957         }
958
959         // Make Event Data
960         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_CONTACT_COUNT, err, (void**)ppEvent);
961
962         return eventSize;
963 }
964
965
966 int MsgGetQuickPanelDataHandler(const MSG_CMD_S *pCmd, char **ppEvent)
967 {
968         msg_error_t err = MSG_SUCCESS;
969
970         // Get Message ID
971         msg_quickpanel_type_t* type = (msg_quickpanel_type_t*)pCmd->cmdData;
972
973         char* encodedData = NULL;
974         AutoPtr<char> buf(&encodedData);
975
976         int dataSize = 0, eventSize = 0;
977
978         // Get Message
979         MSG_MESSAGE_INFO_S msgInfo;
980
981         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
982
983         err = MsgStoGetQuickPanelData(*type, &msgInfo);
984
985         if (err == MSG_SUCCESS)
986         {
987                 MSG_DEBUG("Command Handle Success : MsgStoGetQuickPanelData()");
988
989                 // Encoding Message Info Data
990                 dataSize = MsgEncodeMsgInfo(&msgInfo, &encodedData);
991         }
992         else
993         {
994                 MSG_DEBUG("Command Handle Fail : MsgStoGetQuickPanelData()");
995         }
996
997         // Make Event Data
998         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_QUICKPANEL_DATA, err, (void**)ppEvent);
999
1000         return eventSize;
1001 }
1002
1003
1004 int MsgResetDatabaseHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1005 {
1006         msg_error_t err = MSG_SUCCESS;
1007
1008         int eventSize = 0;
1009
1010         // Reset DB
1011         err = MsgStoResetDatabase();
1012
1013         if (err == MSG_SUCCESS)
1014                 MSG_DEBUG("Command Handle Success : MsgStoResetDatabase()");
1015         else
1016                 MSG_DEBUG("Command Handle Fail : MsgStoResetDatabase()");
1017
1018         // Make Event Data
1019         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_RESET_DB, err, (void**)ppEvent);
1020
1021         return eventSize;
1022 }
1023
1024
1025 int MsgGetMemSizeHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1026 {
1027         msg_error_t err = MSG_SUCCESS;
1028
1029         char* encodedData = NULL;
1030         AutoPtr<char> buf(&encodedData);
1031
1032         int dataSize = 0, eventSize = 0;
1033
1034         // Get Memory size
1035         unsigned int memsize = 0;
1036
1037         memsize = MsgDu(MSG_DATA_ROOT_PATH);
1038
1039         dataSize = MsgEncodeMemSize(&memsize, &encodedData);
1040
1041         // Make Event Data
1042         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_MEMSIZE, err, (void**)ppEvent);
1043
1044         return eventSize;
1045 }
1046
1047
1048 int MsgBackupMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1049 {
1050         msg_error_t err = MSG_SUCCESS;
1051
1052         int eventSize = 0;
1053         char path[MSG_FILEPATH_LEN_MAX+1] = {0,};
1054         msg_message_backup_type_t type;
1055
1056         memcpy(&type, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_message_backup_type_t));
1057         memcpy(&path, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_backup_type_t)), sizeof(path));
1058
1059         MSG_DEBUG("type = %d, path = %s", type, path);
1060
1061         err = MsgStoBackupMessage(type, path);
1062         if (err == MSG_SUCCESS)
1063                 MSG_DEBUG("Command Handle Success : MsgBackupMessageHandler()");
1064         else
1065                 MSG_DEBUG("Command Handle Fail : MsgBackupMessageHandler()");
1066
1067         // Make Event Data
1068         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_BACKUP_MESSAGE, err, (void**)ppEvent);
1069
1070         return eventSize;
1071 }
1072
1073
1074 int MsgRestoreMessageHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1075 {
1076         msg_error_t err = MSG_SUCCESS;
1077
1078         int eventSize = 0;
1079         char path[MSG_FILEPATH_LEN_MAX+1] = {0,};
1080         memcpy(&path, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(path));
1081         MSG_DEBUG("path = %s", path);
1082         // Reset DB
1083         err = MsgStoRestoreMessage(path);
1084
1085         if (err == MSG_SUCCESS)
1086                 MSG_DEBUG("Command Handle Success : MsgStoRestoreMessage()");
1087         else
1088                 MSG_DEBUG("Command Handle Fail : MsgStoRestoreMessage()");
1089
1090         // Make Event Data
1091         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_RESTORE_MESSAGE, err, (void**)ppEvent);
1092
1093         return eventSize;
1094 }
1095
1096
1097 int MsgGetReportStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1098 {
1099         msg_error_t err = MSG_SUCCESS;
1100
1101         // Get Message ID
1102         msg_message_id_t* msgId = (msg_message_id_t*)pCmd->cmdData;
1103
1104         char* encodedData = NULL;
1105         AutoPtr<char> buf(&encodedData);
1106
1107         int dataSize = 0, eventSize = 0;
1108
1109         MSG_REPORT_STATUS_INFO_S *reportStatus = NULL;
1110         int report_count = 0;
1111
1112         err = MsgStoGetReportStatus(*msgId, &report_count, &reportStatus);
1113
1114         if (err == MSG_SUCCESS)
1115         {
1116                 MSG_DEBUG("Command Handle Success : MsgGetReportStatusHandler()");
1117
1118                 // Encoding Report Status Data
1119                 dataSize = MsgEncodeReportStatus(reportStatus, report_count, &encodedData);
1120         }
1121         else
1122         {
1123                 MSG_DEBUG("Command Handle Fail : MsgGetReportStatusHandler()");
1124         }
1125
1126         // Make Event Data
1127         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_REPORT_STATUS, err, (void**)ppEvent);
1128
1129         return eventSize;
1130 }
1131
1132
1133 int MsgGetThreadIdByAddressHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1134 {
1135         msg_error_t err = MSG_SUCCESS;
1136
1137         MSG_MESSAGE_INFO_S msgInfo;
1138         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1139
1140         int *addrCnt = (int *)pCmd->cmdData;
1141         MSG_DEBUG("*addrCnt [%d]", *addrCnt);
1142
1143         msgInfo.nAddressCnt = *addrCnt;
1144         for(int i=0; i<msgInfo.nAddressCnt; i++)
1145                 memcpy(&msgInfo.addressList[i], (MSG_ADDRESS_INFO_S *)(pCmd->cmdData+sizeof(int)+(sizeof(MSG_ADDRESS_INFO_S)*i)), sizeof(MSG_ADDRESS_INFO_S));
1146
1147         char* encodedData = NULL;
1148         AutoPtr<char> buf(&encodedData);
1149
1150         int dataSize = 0, eventSize = 0;
1151
1152         msg_thread_id_t threadId;
1153
1154         err = MsgStoGetThreadIdByAddress(&msgInfo, &threadId);
1155
1156         if (err == MSG_SUCCESS)
1157         {
1158                 MSG_DEBUG("threadId [%d]", threadId);
1159                 MSG_DEBUG("Command Handle Success : MsgGetThreadIdByAddressHandler()");
1160
1161                 // Encoding threadId Data
1162                 dataSize = MsgEncodeThreadId(&threadId, &encodedData);
1163         }
1164         else
1165         {
1166                 MSG_DEBUG("Command Handle Fail : MsgGetThreadIdByAddressHandler()");
1167         }
1168
1169         // Make Event Data
1170         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_THREAD_ID_BY_ADDRESS, err, (void**)ppEvent);
1171
1172         return eventSize;
1173 }
1174
1175
1176 int MsgGetThreadInfoHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1177 {
1178         msg_error_t err = MSG_SUCCESS;
1179
1180         char* encodedData = NULL;
1181         AutoPtr<char> buf(&encodedData);
1182
1183         int dataSize = 0;
1184         int eventSize = 0;
1185
1186         msg_thread_id_t threadId;
1187
1188         memcpy(&threadId, (void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), sizeof(msg_thread_id_t));
1189
1190         MSG_THREAD_VIEW_S threadInfo;
1191         memset(&threadInfo, 0x00, sizeof(threadInfo));
1192
1193         err = MsgStoGetThreadInfo(threadId, &threadInfo);
1194
1195         if (err == MSG_SUCCESS) {
1196                 MSG_DEBUG("Command Handle Success : MsgStoGetThreadInfo()");
1197
1198                 // Encoding thread Info Data
1199                 dataSize = MsgEncodeThreadInfo(&threadInfo, &encodedData);
1200         } else {
1201                 MSG_DEBUG("Command Handle Fail : MsgStoGetThreadInfo()");
1202         }
1203
1204         // Make Event Data
1205         eventSize = MsgMakeEvent(encodedData, dataSize, MSG_EVENT_GET_THREAD_INFO, err, (void**)ppEvent);
1206
1207         return eventSize;
1208 }
1209
1210
1211 #ifdef MMS_REPORT_OPERATIONS
1212 int MsgCheckReadReportRequestedHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1213 {
1214         MSG_DEBUG();
1215         msg_error_t err = MSG_SUCCESS;
1216
1217         char* encodedData = NULL;
1218         AutoPtr<char> buf(&encodedData);
1219
1220         int dataSize = 0, eventSize = 0;
1221
1222         // Get Message ID
1223         msg_message_id_t* MsgId = (msg_message_id_t*)pCmd->cmdData;
1224
1225         // Check ReadReport Is Requested
1226         bool    bReadReportRequested;
1227
1228         bReadReportRequested = MsgStoCheckReadReportRequested(*MsgId);
1229         if (err == MSG_SUCCESS)
1230         {
1231                 MSG_DEBUG("Command Handle Success : MsgStoCheckSendReadReport()");
1232
1233                 // Encoding ReadReportIsSent Data
1234                 dataSize = MsgEncodeReadReportRequested(bReadReportRequested, &encodedData);
1235         }
1236         else
1237         {
1238                 MSG_DEBUG("Command Handle Fail : MsgStoCheckReadReportIsSent()");
1239         }
1240
1241         // Make Event Data
1242         eventSize = MsgMakeStorageEvent(encodedData, dataSize, MSG_EVENT_PLG_CHECK_READ_REPORT_REQUESTED, err, (void**)ppEvent);
1243
1244         return eventSize;
1245 }
1246
1247
1248 int MsgCheckReadReportIsSentHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1249 {
1250         MSG_DEBUG();
1251         msg_error_t err = MSG_SUCCESS;
1252
1253         char* encodedData = NULL;
1254         AutoPtr<char> buf(&encodedData);
1255
1256         int dataSize = 0, eventSize = 0;
1257
1258         // Get Message ID
1259         msg_message_id_t* MsgId = (msg_message_id_t*)pCmd->cmdData;
1260
1261         // Check ReadReport Is Sent
1262         bool    bReadReportIsSent;
1263
1264         MSG_DEBUG("#### MSGID = %d ####", *MsgId);
1265
1266         bReadReportIsSent = MsgStoCheckReadReportIsSent(*MsgId);
1267         MSG_DEBUG("######## 1. bReadStatusIsSent = %d #######", bReadReportIsSent);
1268         if (err == MSG_SUCCESS)
1269         {
1270                 MSG_DEBUG("Command Handle Success : MsgStoCheckReadReportIsSent()");
1271
1272                 // Encoding ReadReportIsSent Data
1273                 dataSize = MsgEncodeReadReportIsSent(bReadReportIsSent, &encodedData);
1274         }
1275         else
1276         {
1277                 MSG_DEBUG("Command Handle Fail : MsgStoCheckReadReportIsSent()");
1278         }
1279
1280         // Make Event Data
1281         eventSize = MsgMakeStorageEvent(encodedData, dataSize, MSG_EVENT_PLG_CHECK_READ_REPORT_IS_SENT, err, (void**)ppEvent);
1282
1283         return eventSize;
1284 }
1285
1286
1287 int MsgSetReadReportSendStatusHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1288 {
1289         MSG_DEBUG();
1290         msg_error_t err = MSG_SUCCESS;
1291
1292         char* encodedData = NULL;
1293         AutoPtr<char> buf(&encodedData);
1294
1295         int dataSize = 0, eventSize = 0;
1296
1297         // Get Message ID
1298         msg_message_id_t msgId;
1299         int     readReportSendStatus;
1300
1301         memcpy(&msgId, (char*)pCmd + sizeof(MSG_CMD_TYPE_T), sizeof(msg_message_id_t));
1302         memcpy(&readReportSendStatus, (char*)pCmd + sizeof(MSG_CMD_TYPE_T) + sizeof(msg_message_id_t), sizeof(int));
1303
1304         // Set Read Report Send Status
1305         err = MsgStoSetReadReportSendStatus(msgId, readReportSendStatus);
1306
1307         if (err == MSG_SUCCESS)
1308         {
1309                 MSG_DEBUG("Command Handle Success : MsgStoUpdateReadStatus()");
1310         }
1311         else
1312         {
1313                 MSG_DEBUG("Command Handle Fail : MsgStoUpdateReadStatus()");
1314         }
1315
1316         // Make Event Data
1317         eventSize = MsgMakeStorageEvent(encodedData, dataSize, MSG_EVENT_PLG_SET_READ_REPORT_SEND_STATUS, err, (void**)ppEvent);
1318
1319         return eventSize;
1320 }
1321
1322
1323 int MsgGetMmsVersionHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1324 {
1325         MSG_DEBUG();
1326         msg_error_t err = MSG_SUCCESS;
1327
1328         char* encodedData = NULL;
1329         AutoPtr<char> buf(&encodedData);
1330
1331         int dataSize = 0, eventSize = 0;
1332
1333         // Get Message ID
1334         msg_message_id_t* MsgId = (msg_message_id_t*)pCmd->cmdData;
1335
1336         // Check ReadReport Is Sent
1337         int     version;
1338
1339         MSG_DEBUG("#### MSGID = %d ####", *MsgId);
1340
1341         version = MsgStoGetMmsVersion(*MsgId);
1342         MSG_DEBUG("######## 1. version = %x #######", version);
1343         if (err == MSG_SUCCESS)
1344         {
1345                 MSG_DEBUG("Command Handle Success : MsgStoCheckReadReportIsSent()");
1346
1347                 // Encoding ReadReportIsSent Data
1348                 dataSize = MsgEncodeMmsVersion(version, &encodedData);
1349         }
1350         else
1351         {
1352                 MSG_DEBUG("Command Handle Fail : MsgStoCheckReadReportIsSent()");
1353         }
1354
1355         // Make Event Data
1356         eventSize = MsgMakeStorageEvent(encodedData, dataSize, MSG_EVENT_PLG_GET_MMS_VERSION, err, (void**)ppEvent);
1357
1358         return eventSize;
1359 }
1360
1361
1362 int MsgGetMmsStatusInfoHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1363 {
1364         MSG_DEBUG();
1365         msg_error_t err = MSG_SUCCESS;
1366
1367         char* encodedData = NULL;
1368         AutoPtr<char> buf(&encodedData);
1369
1370         int dataSize = 0, eventSize = 0;
1371
1372         // Get Message ID
1373         msg_message_id_t* MsgId = (msg_message_id_t*)pCmd->cmdData;
1374
1375         MMS_STATUS_INFO_S mmsStatusInfo;
1376
1377         MSG_DEBUG("#### MSGID = %d ####", *MsgId);
1378
1379         err = MsgStoGetMmsStatusInfo(*MsgId,&mmsStatusInfo);
1380         if (err == MSG_SUCCESS)
1381         {
1382                 MSG_DEBUG("Command Handle Success : MsgGetMmsStatusInfoHandler()");
1383
1384                 // Encoding ReadReportIsSent Data
1385                 dataSize = MsgEncodeMmsStatusInfo(&mmsStatusInfo, &encodedData);
1386         }
1387         else
1388         {
1389                 MSG_DEBUG("Command Handle Fail : MsgGetMmsStatusInfoHandler()");
1390         }
1391
1392         // Make Event Data
1393         eventSize = MsgMakeStorageEvent(encodedData, dataSize, MSG_EVENT_PLG_GET_MMS_STATUS_INFO, err, (void**)ppEvent);
1394
1395         return eventSize;
1396 }
1397 #endif
1398
1399
1400 int MsgAddPushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1401 {
1402         msg_error_t err = MSG_SUCCESS;
1403
1404         int eventSize = 0;
1405
1406         // Get Message Info
1407         MSG_PUSH_EVENT_INFO_S* pPushEvent = (MSG_PUSH_EVENT_INFO_S*)pCmd->cmdData;
1408
1409         // Add Message
1410         err = MsgStoAddPushEvent(pPushEvent);
1411
1412         if (err == MSG_SUCCESS) {
1413                 MSG_DEBUG("Command Handle Success : MsgStoAddPushEvent()");
1414         } else {
1415                 MSG_DEBUG("Command Handle Fail : MsgStoAddMessage()");
1416         }
1417
1418         // Make Event Data
1419         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_ADD_PUSH_EVENT, err, (void**)ppEvent);
1420
1421         return eventSize;
1422 }
1423
1424 int MsgDeletePushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1425 {
1426         msg_error_t err = MSG_SUCCESS;
1427
1428         int eventSize = 0;
1429
1430         // Get Message Info
1431         MSG_PUSH_EVENT_INFO_S* pPushEvent = (MSG_PUSH_EVENT_INFO_S*)pCmd->cmdData;
1432
1433         // Add Message
1434         err = MsgStoDeletePushEvent(pPushEvent);
1435
1436         if (err == MSG_SUCCESS) {
1437                 MSG_DEBUG("Command Handle Success : MsgStoDeletePushEvent()");
1438         } else {
1439                 MSG_DEBUG("Command Handle Fail : MsgStoDeletePushEvent()");
1440         }
1441
1442         // Make Event Data
1443         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_DELETE_PUSH_EVENT, err, (void**)ppEvent);
1444
1445         return eventSize;
1446 }
1447
1448 int MsgUpdatePushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent)
1449 {
1450         msg_error_t err = MSG_SUCCESS;
1451
1452
1453         int eventSize = 0;
1454
1455         // Get Message Info
1456         MSG_PUSH_EVENT_INFO_S* pSrc = (MSG_PUSH_EVENT_INFO_S*)pCmd->cmdData;
1457         MSG_PUSH_EVENT_INFO_S* pDst = (MSG_PUSH_EVENT_INFO_S*)(pCmd->cmdData + sizeof(MSG_PUSH_EVENT_INFO_S));
1458
1459         // Add Message
1460         err = MsgStoUpdatePushEvent(pSrc, pDst);
1461
1462         if (err == MSG_SUCCESS) {
1463                 MSG_DEBUG("Command Handle Success : MsgStoUpdatePushEvent()");
1464         } else {
1465                 MSG_DEBUG("Command Handle Fail : MsgStoUpdatePushEvent()");
1466         }
1467
1468         // Make Event Data
1469         eventSize = MsgMakeEvent(NULL, 0, MSG_EVENT_UPDATE_PUSH_EVENT, err, (void**)ppEvent);
1470
1471         return eventSize;
1472 }