Fix types for 64bit
[platform/core/messaging/msg-service.git] / proxy / MsgHandleStorage.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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 "MsgDebug.h"
18 #include "MsgUtilFile.h"
19 #include "MsgCppTypes.h"
20 #include "MsgException.h"
21 #include "MsgUtilFunction.h"
22 #include "MsgProxyListener.h"
23 #include "MsgHandle.h"
24
25 #include "MsgVMessage.h"
26 /*==================================================================================================
27                                      IMPLEMENTATION OF MsgHandle - Storage Member Functions
28 ==================================================================================================*/
29 int MsgHandle::addMessage(MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
30 {
31         MSG_MESSAGE_INFO_S msgInfo = {0,};
32         MSG_SENDINGOPT_INFO_S sendOptInfo = {0,};
33
34         msgInfo.addressList = NULL;
35         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
36
37         // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
38         convertMsgStruct(pMsg, &msgInfo);
39
40         // Covert MSG_SENDINGOPT_S to MSG_SENDINGOPT_INFO_S
41         MSG_MESSAGE_TYPE_S msgType = {0,};
42
43         msgType.mainType = pMsg->mainType;
44         msgType.subType = pMsg->subType;
45         msgType.classType = pMsg->classType;
46
47         convertSendOptStruct(pSendOpt, &sendOptInfo, msgType);
48
49         // Allocate Memory to Command Data
50         char* encodedData = NULL;
51         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
52         int dataSize = MsgEncodeMsgInfo(&msgInfo, &sendOptInfo, &encodedData);
53
54         int cmdSize = sizeof(MSG_CMD_S) + dataSize;
55
56         char cmdBuf[cmdSize];
57         bzero(cmdBuf, cmdSize);
58         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
59
60         // Set Command Parameters
61         pCmd->cmdType = MSG_CMD_ADD_MSG;
62
63         // Copy Cookie
64         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
65
66         // Copy Command Data
67         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), encodedData, dataSize);
68
69         // Send Command to Messaging FW
70         char* pEventData = NULL;
71         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
72
73         write((char*)pCmd, cmdSize, &pEventData);
74
75         // Get Return Data
76         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
77
78         if (pEvent == NULL)
79                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
80
81         if (pEvent->eventType != MSG_EVENT_ADD_MSG)
82         {
83                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
84         }
85
86         if (pEvent->result != MSG_SUCCESS)
87                 return pEvent->result;
88
89         msg_message_id_t msgId = 0;
90
91         // Decode Return Data
92         MsgDecodeMsgId(pEvent->data, &msgId);
93
94         return (int)msgId;
95 }
96
97
98 msg_error_t MsgHandle::addSyncMLMessage(const MSG_SYNCML_MESSAGE_S *pSyncMLMsg)
99 {
100         MSG_MESSAGE_INFO_S msgInfo;
101         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
102
103         msgInfo.addressList = NULL;
104         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
105
106         // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
107         msg_struct_s *msg = (msg_struct_s *)pSyncMLMsg->msg;
108         convertMsgStruct((MSG_MESSAGE_HIDDEN_S *)msg->data, &msgInfo);
109
110         // Allocate Memory to Command Data
111         char* encodedData = NULL;
112         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
113         int dataSize = MsgEncodeMsgInfo(&msgInfo, &encodedData);
114
115         int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + sizeof(int) + dataSize;
116
117         char cmdBuf[cmdSize];
118         bzero(cmdBuf, cmdSize);
119         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
120
121         // Set Command Parameters
122         pCmd->cmdType = MSG_CMD_ADD_SYNCML_MSG;
123
124         // Copy Cookie
125         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
126
127         // Copy Command Data
128         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pSyncMLMsg->extId, sizeof(int));
129         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), &pSyncMLMsg->pinCode, sizeof(int));
130         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(int)), encodedData, dataSize);
131
132         // Send Command to Messaging FW
133         char* pEventData = NULL;
134         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
135
136
137         write((char*)pCmd, cmdSize, &pEventData);
138
139         // Get Return Data
140         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
141
142         if (pEvent == NULL)
143                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
144
145         if (pEvent->eventType != MSG_EVENT_ADD_SYNCML_MSG)
146         {
147                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
148         }
149
150         msg_message_id_t msgId = 0;
151
152         // Decode Return Data
153         MsgDecodeMsgId(pEvent->data, &msgId);
154
155         ((MSG_MESSAGE_HIDDEN_S *)msg->data)->msgId = msgId;
156
157         return pEvent->result;
158 }
159
160
161 msg_error_t MsgHandle::updateMessage(const MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
162 {
163         MSG_MESSAGE_INFO_S msgInfo = {0, };
164         MSG_SENDINGOPT_INFO_S sendOptInfo = {0, };
165
166         msgInfo.addressList = NULL;
167         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
168
169         // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
170         convertMsgStruct(pMsg, &msgInfo);
171
172         if (pSendOpt != NULL) {
173                 MSG_MESSAGE_TYPE_S msgType = {0,};
174
175                 msgType.mainType = pMsg->mainType;
176                 msgType.subType = pMsg->subType;
177                 msgType.classType = pMsg->classType;
178
179                 convertSendOptStruct(pSendOpt, &sendOptInfo, msgType);
180         }
181
182         // Allocate Memory to Command Data
183         char* encodedData = NULL;
184         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
185         int dataSize = MsgEncodeMsgInfo(&msgInfo, &sendOptInfo, &encodedData);
186
187         int cmdSize = sizeof(MSG_CMD_S) + dataSize;
188
189         char cmdBuf[cmdSize];
190         bzero(cmdBuf, cmdSize);
191         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
192
193         // Set Command Parameters
194         pCmd->cmdType = MSG_CMD_UPDATE_MSG;
195
196         // Copy Cookie
197         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
198
199         // Copy Command Data
200         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), encodedData, dataSize);
201
202         // Send Command to Messaging FW
203         char* pEventData = NULL;
204         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
205
206         write((char*)pCmd, cmdSize, &pEventData);
207
208         // Get Return Data
209         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
210
211         if (pEvent == NULL)
212                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
213
214         if (pEvent->eventType != MSG_EVENT_UPDATE_MSG)
215         {
216                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
217         }
218
219         return pEvent->result;
220 }
221
222
223 msg_error_t MsgHandle::updateReadStatus(msg_message_id_t MsgId, bool bRead)
224 {
225         // Allocate Memory to Command Data
226         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(bool);
227
228         char cmdBuf[cmdSize];
229         bzero(cmdBuf, cmdSize);
230         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
231
232         // Set Command Parameters
233         pCmd->cmdType = MSG_CMD_UPDATE_READ;
234
235         // Copy Cookie
236         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
237
238         // Copy Command Data
239         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
240         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &bRead, sizeof(bool));
241
242         // Send Command to Messaging FW
243         char* pEventData = NULL;
244         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
245
246         write((char*)pCmd, cmdSize, &pEventData);
247
248         // Get Return Data
249         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
250
251         if (pEvent == NULL)
252                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
253
254         if (pEvent->eventType != MSG_EVENT_UPDATE_READ)
255         {
256                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
257         }
258
259         return pEvent->result;
260 }
261
262
263 msg_error_t MsgHandle::setConversationToRead(msg_thread_id_t ThreadId)
264 {
265         // Allocate Memory to Command Data
266         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
267
268         char cmdBuf[cmdSize];
269         bzero(cmdBuf, cmdSize);
270         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
271
272         // Set Command Parameters
273         pCmd->cmdType = MSG_CMD_UPDATE_THREAD_READ;
274
275         // Copy Cookie
276         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
277
278         // Copy Command Data
279         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
280
281         // Send Command to Messaging FW
282         char* pEventData = NULL;
283         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
284
285         write((char*)pCmd, cmdSize, &pEventData);
286
287         // Get Return Data
288         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
289
290         if (pEvent == NULL)
291                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
292
293         if (pEvent->eventType != MSG_EVENT_UPDATE_THREAD_READ)
294         {
295                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
296         }
297
298         return pEvent->result;
299 }
300
301
302 msg_error_t MsgHandle::updateProtectedStatus(msg_message_id_t MsgId, bool bProtected)
303 {
304         // Allocate Memory to Command Data
305         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(bool);
306
307         char cmdBuf[cmdSize];
308         bzero(cmdBuf, cmdSize);
309         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
310
311         // Set Command Parameters
312         pCmd->cmdType = MSG_CMD_UPDATE_PROTECTED;
313
314         // Copy Cookie
315         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
316
317         // Copy Command Data
318         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
319         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &bProtected, sizeof(bool));
320
321         // Send Command to Messaging FW
322         char* pEventData = NULL;
323         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
324
325         write((char*)pCmd, cmdSize, &pEventData);
326
327         // Get Return Data
328         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
329
330         if (pEvent == NULL)
331                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
332
333         if (pEvent->eventType != MSG_EVENT_UPDATE_PROTECTED)
334         {
335                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
336         }
337
338         return pEvent->result;
339 }
340
341
342 msg_error_t MsgHandle::deleteMessage(msg_message_id_t MsgId)
343 {
344         // Allocate Memory to Command Data
345         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
346
347         char cmdBuf[cmdSize];
348         bzero(cmdBuf, cmdSize);
349         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
350
351         // Set Command Parameters
352         pCmd->cmdType = MSG_CMD_DELETE_MSG;
353
354         // Copy Cookie
355         memcpy((void*)pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
356
357         // Copy Command Data
358         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
359
360         // Send Command to Messaging FW
361         char* pEventData = NULL;
362         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
363
364         write((char*)pCmd, cmdSize, &pEventData);
365
366         // Get Return Data
367         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
368
369         if (pEvent == NULL)
370                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
371
372         if (pEvent->eventType != MSG_EVENT_DELETE_MSG)
373         {
374                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
375         }
376
377         return pEvent->result;
378 }
379
380
381 msg_error_t MsgHandle::deleteAllMessagesInFolder(msg_folder_id_t FolderId, bool bOnlyDB)
382 {
383         // Allocate Memory to Command Data
384         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
385
386         char cmdBuf[cmdSize];
387         bzero(cmdBuf, cmdSize);
388         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
389
390         // Set Command Parameters
391         pCmd->cmdType = MSG_CMD_DELALL_MSGINFOLDER;
392
393         // Copy Cookie
394         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
395
396         // Copy Command Data
397         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
398         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_folder_id_t)), &bOnlyDB, sizeof(bool));
399
400         // Send Command to Messaging FW
401         char* pEventData = NULL;
402         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
403
404         write((char*)pCmd, cmdSize, &pEventData);
405
406         // Get Return Data
407         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
408
409         if (pEvent == NULL)
410                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
411
412         if (pEvent->eventType != MSG_EVENT_DELALL_MSGINFOLDER)
413         {
414                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
415         }
416
417         return pEvent->result;
418 }
419
420
421 msg_error_t MsgHandle::deleteMessagesByList(msg_id_list_s *pMsgIdList)
422 {
423         // Allocate Memory to Command Data
424         int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + (sizeof(int)*pMsgIdList->nCount);
425
426         char cmdBuf[cmdSize];
427         bzero(cmdBuf, cmdSize);
428         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
429
430         // Set Command Parameters
431         pCmd->cmdType = MSG_CMD_DELETE_MESSAGE_BY_LIST;
432
433         // Copy Cookie
434         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
435
436         // Copy Command Data
437         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &(pMsgIdList->nCount), sizeof(int));
438         for (int i=0; i<pMsgIdList->nCount; i++) {
439                 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+(sizeof(int)*i)), &(pMsgIdList->msgIdList[i]), sizeof(int));
440         }
441
442         // Send Command to Messaging FW
443         char* pEventData = NULL;
444         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
445
446         write((char*)pCmd, cmdSize, &pEventData);
447
448         // Get Return Data
449         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
450
451         if (pEvent == NULL)
452                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
453
454         if (pEvent->eventType != MSG_EVENT_DELETE_MESSAGE_BY_LIST) {
455                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
456         }
457
458         return pEvent->result;
459 }
460
461
462 msg_error_t MsgHandle::moveMessageToFolder(msg_message_id_t MsgId, msg_folder_id_t DestFolderId)
463 {
464         // Allocate Memory to Command Data
465         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(msg_folder_id_t);
466
467         char cmdBuf[cmdSize];
468         bzero(cmdBuf, cmdSize);
469         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
470
471         // Set Command Parameters
472         pCmd->cmdType = MSG_CMD_MOVE_MSGTOFOLDER;
473
474         // Copy Cookie
475         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
476
477         // Copy Command Data
478         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
479         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(msg_message_id_t)+MAX_COOKIE_LEN), &DestFolderId, sizeof(msg_folder_id_t));
480
481         // Send Command to Messaging FW
482         char* pEventData = NULL;
483         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
484
485         write((char*)pCmd, cmdSize, &pEventData);
486
487         // Get Return Data
488         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
489
490         if (pEvent == NULL)
491                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
492
493         if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOFOLDER)
494         {
495                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
496         }
497
498         return pEvent->result;
499 }
500
501
502 msg_error_t MsgHandle::moveMessageToStorage(msg_message_id_t MsgId, msg_storage_id_t DestStorageId)
503 {
504         // Allocate Memory to Command Data
505         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(msg_storage_id_t);
506
507         char cmdBuf[cmdSize];
508         bzero(cmdBuf, cmdSize);
509         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
510
511         // Set Command Parameters
512         pCmd->cmdType = MSG_CMD_MOVE_MSGTOSTORAGE;
513
514         // Copy Cookie
515         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
516
517         // Copy Command Data
518         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
519         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &DestStorageId, sizeof(msg_storage_id_t));
520
521         // Send Command to Messaging FW
522         char* pEventData = NULL;
523         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
524
525         write((char*)pCmd, cmdSize, &pEventData);
526
527         // Get Return Data
528         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
529
530         if (pEvent == NULL)
531                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
532
533         if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOSTORAGE)
534         {
535                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
536         }
537
538         return pEvent->result;
539 }
540
541
542 msg_error_t MsgHandle::countMessage(msg_folder_id_t FolderId, MSG_COUNT_INFO_S *pCountInfo)
543 {
544         // Allocate Memory to Command Data
545         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
546
547         char cmdBuf[cmdSize];
548         bzero(cmdBuf, cmdSize);
549         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
550
551         // Set Command Parameters
552         pCmd->cmdType = MSG_CMD_COUNT_MSG;
553
554         // Copy Cookie
555         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
556
557         // Copy Command Data
558         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
559
560         // Send Command to Messaging FW
561         char* pEventData = NULL;
562         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
563
564         write((char*)pCmd, cmdSize, &pEventData);
565
566         // Get Return Data
567         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
568
569         if (pEvent == NULL)
570                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
571
572         if (pEvent->eventType != MSG_EVENT_COUNT_MSG)
573         {
574                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
575         }
576
577         if (pEvent->result != MSG_SUCCESS)
578                 return pEvent->result;
579
580         // Decode Return Data
581         MsgDecodeCountInfo(pEvent->data, pCountInfo);
582
583         return MSG_SUCCESS;
584 }
585
586
587 msg_error_t MsgHandle::countMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount)
588 {
589         // Allocate Memory to Command Data
590         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_TYPE_S);
591
592         char cmdBuf[cmdSize];
593         bzero(cmdBuf, cmdSize);
594         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
595
596         // Set Command Parameters
597         pCmd->cmdType = MSG_CMD_COUNT_BY_MSGTYPE;
598
599         // Copy Cookie
600         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
601
602         // Copy Command Data
603         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pMsgType, sizeof(MSG_MESSAGE_TYPE_S));
604
605         // Send Command to Messaging FW
606         char* pEventData = NULL;
607         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
608
609         write((char*)pCmd, cmdSize, &pEventData);
610
611         // Get Return Data
612         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
613
614         if (pEvent == NULL)
615                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
616
617         if (pEvent->eventType != MSG_EVENT_COUNT_BY_MSGTYPE)
618         {
619                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
620         }
621
622         if (pEvent->result != MSG_SUCCESS)
623                 return pEvent->result;
624
625         // Decode Return Data
626         memcpy(pMsgCount, (void*)((char*)pEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(int));
627
628         return MSG_SUCCESS;
629 }
630
631
632 msg_error_t MsgHandle::countMsgByContact(const MSG_THREAD_LIST_INDEX_INFO_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
633 {
634         // Allocate Memory to Command Data
635         int cmdSize = sizeof(MSG_CMD_S) +  sizeof(MSG_THREAD_LIST_INDEX_S);
636
637         char cmdBuf[cmdSize];
638         bzero(cmdBuf, cmdSize);
639         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
640
641         // Set Command Parameters
642         pCmd->cmdType = MSG_CMD_GET_CONTACT_COUNT;
643
644         // Copy Cookie
645         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
646
647         // Copy Command Data
648         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pAddrInfo, sizeof(msg_contact_id_t));
649         msg_struct_s *pAddr = (msg_struct_s *)pAddrInfo->msgAddrInfo;
650
651         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN + sizeof(msg_contact_id_t)), pAddr->data, sizeof(MSG_ADDRESS_INFO_S));
652         // Send Command to Messaging FW
653         char* pEventData = NULL;
654         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
655
656         write((char*)pCmd, cmdSize, &pEventData);
657
658         // Get Return Data
659         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
660
661         if (pEvent == NULL)
662                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
663
664         if (pEvent->eventType != MSG_EVENT_GET_CONTACT_COUNT)
665         {
666                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
667         }
668
669         if (pEvent->result != MSG_SUCCESS)
670                 return pEvent->result;
671
672         // Decode Return Data
673         MsgDecodeContactCount(pEvent->data, pMsgThreadCountList);
674
675         return MSG_SUCCESS;
676 }
677
678
679 msg_error_t MsgHandle::getMessage(msg_message_id_t MsgId, MSG_MESSAGE_HIDDEN_S *pMsg, MSG_SENDINGOPT_S *pSendOpt)
680 {
681         // Allocate Memory to Command Data
682         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
683
684         char cmdBuf[cmdSize];
685         bzero(cmdBuf, cmdSize);
686         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
687
688         // Set Command Parameters
689         pCmd->cmdType = MSG_CMD_GET_MSG;
690
691         // Copy Cookie
692         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
693
694         // Copy Command Data
695         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
696
697         // Send Command to Messaging FW
698         char* pEventData = NULL;
699         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
700
701
702         write((char*)pCmd, cmdSize, &pEventData);
703
704         // Get Return Data
705         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
706
707         if (pEvent == NULL)
708                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
709
710         if (pEvent->eventType != MSG_EVENT_GET_MSG) {
711                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
712         }
713
714         if (pEvent->result != MSG_SUCCESS)
715                 return pEvent->result;
716
717         // Decode Return Data
718         MSG_MESSAGE_INFO_S msgInfo;
719         MSG_SENDINGOPT_INFO_S sendOptInfo;
720
721         msgInfo.addressList = NULL;
722         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
723
724         MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
725
726         // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_HIDDEN_S
727         convertMsgStruct(&msgInfo, pMsg);
728
729         if (pSendOpt != NULL) {
730                 MSG_MESSAGE_TYPE_S msgType = {0,};
731
732                 msgType.mainType = pMsg->mainType;
733                 msgType.subType = pMsg->subType;
734                 msgType.classType = pMsg->classType;
735
736                 convertSendOptStruct(&sendOptInfo, pSendOpt, msgType);
737         }
738
739         // Delete Temp File
740         if (msgInfo.bTextSms == false)
741         {
742                 // Delete Temp File
743                 MsgDeleteFile(msgInfo.msgData); //ipc
744         }
745
746         return MSG_SUCCESS;
747 }
748
749
750 msg_error_t MsgHandle::addFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
751 {
752         // Allocate Memory to Command Data
753         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
754
755         char cmdBuf[cmdSize];
756         bzero(cmdBuf, cmdSize);
757         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
758
759         // Set Command Parameters
760         pCmd->cmdType = MSG_CMD_ADD_FOLDER;
761
762         // Copy Cookie
763         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
764
765         // Copy Command Data
766         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
767
768         // Send Command to Messaging FW
769         char* pEventData = NULL;
770         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
771
772         write((char*)pCmd, cmdSize, &pEventData);
773
774         // Get Return Data
775         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
776
777         if (pEvent == NULL)
778                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
779
780         if (pEvent->eventType != MSG_EVENT_ADD_FOLDER)
781         {
782                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
783         }
784
785         return pEvent->result;
786 }
787
788
789 msg_error_t MsgHandle::updateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
790 {
791         // Allocate Memory to Command Data
792         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
793
794         char cmdBuf[cmdSize];
795         bzero(cmdBuf, cmdSize);
796         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
797
798         // Set Command Parameters
799         pCmd->cmdType = MSG_CMD_UPDATE_FOLDER;
800
801         // Copy Cookie
802         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
803
804         // Copy Command Data
805         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
806
807         // Send Command to Messaging FW
808         char* pEventData = NULL;
809         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
810
811         write((char*)pCmd, cmdSize, &pEventData);
812
813         // Get Return Data
814         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
815
816         if (pEvent == NULL)
817                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
818
819         if (pEvent->eventType != MSG_EVENT_UPDATE_FOLDER)
820         {
821                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
822         }
823
824         return pEvent->result;
825 }
826
827
828 msg_error_t MsgHandle::deleteFolder(msg_folder_id_t FolderId)
829 {
830         // Allocate Memory to Command Data
831         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
832
833         char cmdBuf[cmdSize];
834         bzero(cmdBuf, cmdSize);
835         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
836
837         // Set Command Parameters
838         pCmd->cmdType = MSG_CMD_DELETE_FOLDER;
839
840         // Copy Cookie
841         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
842
843         // Copy Command Data
844         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
845
846         // Send Command to Messaging FW
847         char* pEventData = NULL;
848         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
849
850         write((char*)pCmd, cmdSize, &pEventData);
851
852         // Get Return Data
853         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
854
855         if (pEvent == NULL)
856                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
857
858         if (pEvent->eventType != MSG_EVENT_DELETE_FOLDER)
859         {
860                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
861         }
862
863         return pEvent->result;
864 }
865
866
867 msg_error_t MsgHandle::getFolderList(msg_struct_list_s *pFolderList)
868 {
869         // Allocate Memory to Command Data
870         int cmdSize = sizeof(MSG_CMD_S);
871
872         char cmdBuf[cmdSize];
873         bzero(cmdBuf, cmdSize);
874         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
875
876         // Set Command Parameters
877         pCmd->cmdType = MSG_CMD_GET_FOLDERLIST;
878
879         // Copy Cookie
880         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
881
882         // Send Command to Messaging FW
883         char* pEventData = NULL;
884         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
885
886         write((char*)pCmd, cmdSize, &pEventData);
887
888         // Get Return Data
889         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
890
891         if (pEvent == NULL)
892                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
893
894         if (pEvent->eventType != MSG_EVENT_GET_FOLDERLIST)
895         {
896                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
897         }
898
899         if (pEvent->result != MSG_SUCCESS)
900                 return pEvent->result;
901
902         // Decode Return Data
903         MsgDecodeFolderList(pEvent->data, pFolderList);
904
905         return MSG_SUCCESS;
906 }
907
908
909 msg_error_t MsgHandle::getThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList)
910 {
911         msg_error_t err = MSG_SUCCESS;
912
913 //      err = MsgStoConnectDB();
914 //
915 //      if (err != MSG_SUCCESS)
916 //      {
917 //              MSG_DEBUG("MsgStoConnectDB() Error!!");
918 //              return err;
919 //      }
920
921         err = MsgStoGetThreadViewList(pSortRule, pThreadViewList);
922
923         if (err != MSG_SUCCESS)
924         {
925                 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
926                 return err;
927         }
928
929 //      MsgStoDisconnectDB();
930
931 #if 0
932         // Allocate Memory to Command Data
933         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_SORT_RULE_S);
934
935         char cmdBuf[cmdSize];
936         bzero(cmdBuf, cmdSize);
937         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
938
939         // Set Command Parameters
940         pCmd->cmdType = MSG_CMD_GET_THREADVIEWLIST;
941
942         // Copy Command Data
943         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)), pSortRule, sizeof(MSG_SORT_RULE_S));
944
945         // Send Command to Messaging FW
946         char* pEventData = NULL;
947         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
948
949         write((char*)pCmd, cmdSize, &pEventData);
950
951         // Get Return Data
952         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
953
954         if (pEvent == NULL)
955                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
956
957         if (pEvent->eventType != MSG_EVENT_GET_THREADVIEWLIST)
958         {
959                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
960         }
961
962         if (pEvent->result != MSG_SUCCESS)
963                 return pEvent->result;
964
965         // Decode Return Data
966         MsgDecodeThreadViewList(pEvent->data, pMsgThreadViewList);
967 #endif
968
969         return err;
970 }
971
972 msg_error_t MsgHandle::getConversationViewItem(msg_message_id_t MsgId, MSG_CONVERSATION_VIEW_S *pConv)
973 {
974         MSG_BEGIN();
975
976         msg_error_t err = MSG_SUCCESS;
977
978 //      MsgStoConnectDB();
979         err = MsgStoGetConversationViewItem(MsgId, pConv);
980 //      MsgStoDisconnectDB();
981
982         return err;
983 }
984
985 msg_error_t MsgHandle::getConversationViewList(msg_thread_id_t ThreadId, msg_struct_list_s *pConvViewList)
986 {
987         MSG_BEGIN();
988
989         msg_error_t err = MSG_SUCCESS;
990
991 //      MsgStoConnectDB();
992         err = MsgStoGetConversationViewList(ThreadId, pConvViewList);
993 //      MsgStoDisconnectDB();
994
995         if (err != MSG_SUCCESS)
996                 return err;
997
998         MSG_END();
999
1000         return err;
1001 }
1002
1003
1004 msg_error_t MsgHandle::deleteThreadMessageList(msg_thread_id_t ThreadId, bool include_protected_msg)
1005 {
1006         // Allocate Memory to Command Data
1007         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t) + sizeof(bool);
1008
1009         char cmdBuf[cmdSize];
1010         bzero(cmdBuf, cmdSize);
1011         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1012
1013         // Set Command Parameters
1014         pCmd->cmdType = MSG_CMD_DELETE_THREADMESSAGELIST;
1015
1016         // Copy Cookie
1017         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1018
1019         // Copy Command Data
1020         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
1021         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_thread_id_t)), &include_protected_msg, sizeof(bool));
1022
1023         // Send Command to Messaging FW
1024         char* pEventData = NULL;
1025         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1026
1027         write((char*)pCmd, cmdSize, &pEventData);
1028
1029         // Get Return Data
1030         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1031
1032         if (pEvent == NULL)
1033                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1034
1035         if (pEvent->eventType != MSG_EVENT_DELETE_THREADMESSAGELIST)
1036         {
1037                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1038         }
1039
1040         if (pEvent->result != MSG_SUCCESS)
1041                 return pEvent->result;
1042
1043         return MSG_SUCCESS;
1044 }
1045
1046
1047 msg_error_t MsgHandle::getQuickPanelData(msg_quickpanel_type_t Type, MSG_MESSAGE_HIDDEN_S *pMsg)
1048 {
1049         // Allocate Memory to Command Data
1050         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_quickpanel_type_t);
1051
1052         char cmdBuf[cmdSize];
1053         bzero(cmdBuf, cmdSize);
1054         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1055
1056         // Set Command Parameters
1057         pCmd->cmdType = MSG_CMD_GET_QUICKPANEL_DATA;
1058
1059         // Copy Cookie
1060         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1061
1062         // Copy Command Data
1063         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &Type, sizeof(msg_quickpanel_type_t));
1064
1065         // Send Command to Messaging FW
1066         char* pEventData = NULL;
1067         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1068
1069         write((char*)pCmd, cmdSize, &pEventData);
1070
1071         // Get Return Data
1072         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1073
1074         if (pEvent == NULL)
1075                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1076
1077         if (pEvent->eventType != MSG_EVENT_GET_QUICKPANEL_DATA)
1078         {
1079                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1080         }
1081
1082         if (pEvent->result != MSG_SUCCESS)
1083                 return pEvent->result;
1084
1085         // Decode Return Data
1086         MSG_MESSAGE_INFO_S msgInfo;
1087
1088         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1089
1090         msgInfo.addressList = NULL;
1091         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1092
1093         MsgDecodeMsgInfo((char *)pEvent->data, &msgInfo);
1094
1095         // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_S
1096         convertMsgStruct(&msgInfo, pMsg);
1097
1098         // Delete Temp File
1099         if (msgInfo.bTextSms == false)
1100         {
1101                 // Delete Temp File
1102                 MsgDeleteFile(msgInfo.msgData); //ipc
1103         }
1104
1105         return MSG_SUCCESS;
1106 }
1107
1108
1109 msg_error_t MsgHandle::resetDatabase()
1110 {
1111         // Allocate Memory to Command Data
1112         int cmdSize = sizeof(MSG_CMD_S);
1113
1114         char cmdBuf[cmdSize];
1115         bzero(cmdBuf, cmdSize);
1116         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1117
1118         // Set Command Parameters
1119         pCmd->cmdType = MSG_CMD_RESET_DB;
1120
1121         // Copy Cookie
1122         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1123
1124         // Send Command to Messaging FW
1125         char* pEventData = NULL;
1126         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1127
1128         write((char*)pCmd, cmdSize, &pEventData);
1129
1130         // Get Return Data
1131         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1132
1133         if (pEvent == NULL)
1134                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1135
1136         if (pEvent->eventType != MSG_EVENT_RESET_DB)
1137         {
1138                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1139         }
1140
1141         return pEvent->result;
1142 }
1143
1144
1145 msg_error_t MsgHandle::getMemSize(unsigned int* memsize)
1146 {
1147         // Allocate Memory to Command Data
1148         int cmdSize = sizeof(MSG_CMD_S);
1149
1150         char cmdBuf[cmdSize];
1151         bzero(cmdBuf, cmdSize);
1152         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1153
1154         // Set Command Parameters
1155         pCmd->cmdType = MSG_CMD_GET_MEMSIZE;
1156
1157         // Copy Cookie
1158         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1159
1160         // Send Command to Messaging FW
1161         char* pEventData = NULL;
1162         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1163
1164         write((char*)pCmd, cmdSize, &pEventData);
1165
1166         // Get Return Data
1167         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1168
1169         if (pEvent == NULL)
1170                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1171
1172         if (pEvent->eventType != MSG_EVENT_GET_MEMSIZE)
1173         {
1174                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1175         }
1176
1177         if (pEvent->result != MSG_SUCCESS)
1178                 return pEvent->result;
1179
1180         // Decode Return Data
1181         MsgDecodeMemSize(pEvent->data, memsize);
1182
1183         return MSG_SUCCESS;
1184 }
1185
1186 msg_error_t MsgHandle::backupMessage(msg_message_backup_type_t type, const char *backup_filepath)
1187 {
1188         if (backup_filepath == NULL)
1189                 return MSG_ERR_NULL_POINTER;
1190
1191         //Create an empty file for writing.
1192         //If a file with the same name already exists its content is erased
1193         //and the file is treated as a new empty file.
1194
1195         FILE *pFile = MsgOpenFile(backup_filepath, "w");
1196         if (pFile == NULL) {
1197                 MSG_DEBUG("File Open error");
1198                 return MSG_ERR_STORAGE_ERROR;
1199         }
1200         MsgCloseFile(pFile);
1201
1202         char path[MSG_FILEPATH_LEN_MAX+1] = {0,};
1203         strncpy(path, backup_filepath, MSG_FILEPATH_LEN_MAX);
1204
1205         // Allocate Memory to Command Data
1206         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_backup_type_t) + sizeof(path);
1207
1208         char cmdBuf[cmdSize];
1209         bzero(cmdBuf, cmdSize);
1210         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1211
1212         // Set Command Parameters
1213         pCmd->cmdType = MSG_CMD_BACKUP_MESSAGE;
1214
1215         // Copy Cookie
1216         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1217         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &type, sizeof(msg_message_backup_type_t));
1218         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_backup_type_t)), (char *)path, sizeof(path));
1219
1220         // Send Command to Messaging FW
1221         char* pEventData = NULL;
1222         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1223
1224         write((char*)pCmd, cmdSize, &pEventData);
1225
1226         // Get Return Data
1227         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1228
1229         if (pEvent == NULL)
1230                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1231
1232         if (pEvent->eventType != MSG_EVENT_BACKUP_MESSAGE)
1233         {
1234                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1235         }
1236
1237         return pEvent->result;
1238 }
1239
1240 msg_error_t MsgHandle::restoreMessage(const char *backup_filepath)
1241 {
1242         if (backup_filepath == NULL)
1243                 return MSG_ERR_NULL_POINTER;
1244
1245         if (MsgAccessFile(backup_filepath, R_OK) == false) {
1246                 MSG_DEBUG("File access error");
1247                 return MSG_ERR_UNKNOWN;
1248         }
1249
1250         char path[MSG_FILEPATH_LEN_MAX+1] = {0,};
1251         strncpy(path, backup_filepath, MSG_FILEPATH_LEN_MAX);
1252
1253         // Allocate Memory to Command Data
1254         int cmdSize = sizeof(MSG_CMD_S) + sizeof(path);
1255
1256         char cmdBuf[cmdSize];
1257         bzero(cmdBuf, cmdSize);
1258         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1259
1260         // Set Command Parameters
1261         pCmd->cmdType = MSG_CMD_RESTORE_MESSAGE;
1262
1263         // Copy Cookie
1264         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1265         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), (char *)path, sizeof(path));
1266
1267         // Send Command to Messaging FW
1268         char* pEventData = NULL;
1269         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1270
1271         write((char*)pCmd, cmdSize, &pEventData);
1272
1273         // Get Return Data
1274         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1275
1276         if (pEvent == NULL)
1277                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1278
1279         if (pEvent->eventType != MSG_EVENT_RESTORE_MESSAGE)
1280         {
1281                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1282         }
1283
1284         return pEvent->result;
1285 }
1286
1287
1288 msg_error_t MsgHandle::searchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList)
1289 {
1290         msg_error_t err = MSG_SUCCESS;
1291
1292 //      err = MsgStoConnectDB();
1293 //
1294 //      if (err != MSG_SUCCESS)
1295 //      {
1296 //              MSG_DEBUG("MsgStoConnectDB() Error!!");
1297 //              return err;
1298 //      }
1299
1300         err = MsgStoSearchMessage(pSearchString, pThreadViewList);
1301
1302         if (err != MSG_SUCCESS)
1303         {
1304                 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1305                 return err;
1306         }
1307
1308 //      MsgStoDisconnectDB();
1309
1310         return err;
1311 }
1312
1313
1314 msg_error_t MsgHandle::getRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList)
1315 {
1316         msg_error_t err = MSG_SUCCESS;
1317
1318 //      err = MsgStoConnectDB();
1319 //
1320 //      if (err != MSG_SUCCESS)
1321 //      {
1322 //              MSG_DEBUG("MsgStoConnectDB() Error!!");
1323 //              return err;
1324 //      }
1325
1326         err = MsgStoGetRejectMsgList(pNumber, pRejectMsgList);
1327
1328         if (err != MSG_SUCCESS)
1329         {
1330                 MSG_DEBUG("MsgStoGetRejectMsgList() Error!!");
1331                 return err;
1332         }
1333
1334 //      MsgStoDisconnectDB();
1335
1336         return err;
1337 }
1338
1339
1340 msg_error_t MsgHandle::regStorageChangeCallback(msg_storage_change_cb onStorageChange, void *pUserParam)
1341 {
1342         if (!onStorageChange)
1343                 THROW(MsgException::INVALID_PARAM, "onStorageChange is null");
1344
1345         MsgProxyListener* eventListener = MsgProxyListener::instance();
1346
1347         eventListener->start(this);
1348
1349         int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
1350
1351         if (remoteFd == -1 )
1352                 return MSG_ERR_INVALID_MSGHANDLE;
1353
1354         if (eventListener->regStorageChangeEventCB(this, onStorageChange, pUserParam) == false)
1355                 return MSG_ERR_INVALID_PARAMETER;
1356
1357         // Allocate Memory to Command Data
1358         int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
1359         char cmdBuf[cmdSize];
1360         bzero(cmdBuf, cmdSize);
1361         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
1362
1363         // Set Command Parameters
1364         pCmd->cmdType = MSG_CMD_REG_STORAGE_CHANGE_CB;
1365
1366         // Copy Cookie
1367         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1368
1369         MSG_DEBUG("remote fd %d", remoteFd);
1370
1371         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
1372
1373         MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
1374
1375         // Send Command to Messaging FW
1376         char* pEventData = NULL;
1377         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1378
1379         write((char*)pCmd, cmdSize, &pEventData);
1380
1381         // Get Return Data
1382         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1383
1384         if (pEvent == NULL)
1385                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1386
1387         if (pEvent->eventType != MSG_EVENT_REG_STORAGE_CHANGE_CB)
1388         {
1389                 THROW(MsgException::INVALID_PARAM, "Event Data Error");
1390         }
1391
1392         return pEvent->result;
1393 }
1394
1395 msg_error_t MsgHandle::getReportStatus(msg_message_id_t msg_id, msg_struct_list_s *report_list)
1396 {
1397         // Allocate Memory to Command Data
1398         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1399
1400         char cmdBuf[cmdSize];
1401         bzero(cmdBuf, cmdSize);
1402         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1403
1404         report_list->nCount = 0;
1405         report_list->msg_struct_info = NULL;
1406
1407         // Set Command Parameters
1408         pCmd->cmdType = MSG_CMD_GET_REPORT_STATUS;
1409
1410         // Copy Cookie
1411         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1412
1413         // Copy Command Data
1414         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msg_id, sizeof(msg_message_id_t));
1415
1416         // Send Command to Messaging FW
1417         char* pEventData = NULL;
1418         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1419
1420         write((char*)pCmd, cmdSize, &pEventData);
1421
1422         // Get Return Data
1423         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1424
1425         if (pEvent == NULL)
1426                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1427
1428         if (pEvent->eventType != MSG_EVENT_GET_REPORT_STATUS)
1429         {
1430                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1431         }
1432
1433         if (pEvent->result != MSG_SUCCESS)
1434                 return pEvent->result;
1435
1436         // Decode Return Data
1437         MsgDecodeReportStatus(pEvent->data, report_list);
1438
1439         return MSG_SUCCESS;
1440 }
1441
1442
1443 msg_error_t MsgHandle::getAddressList(const msg_thread_id_t threadId, msg_struct_list_s *pAddrList)
1444 {
1445         msg_error_t err = MSG_SUCCESS;
1446
1447 //      err = MsgStoConnectDB();
1448 //
1449 //      if (err != MSG_SUCCESS)
1450 //      {
1451 //              MSG_DEBUG("MsgStoConnectDB() Error!!");
1452 //              return err;
1453 //      }
1454
1455         err = MsgStoGetAddressList(threadId, (msg_struct_list_s *)pAddrList);
1456
1457         if (err != MSG_SUCCESS)
1458         {
1459                 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
1460                 return err;
1461         }
1462
1463 //      MsgStoDisconnectDB();
1464
1465         return err;
1466 }
1467
1468
1469 msg_error_t MsgHandle::getThreadIdByAddress(msg_struct_list_s *pAddrList, msg_thread_id_t *pThreadId)
1470 {
1471         // Allocate Memory to Command Data
1472         int cmdSize = sizeof(MSG_CMD_S) + sizeof(pAddrList->nCount) + (sizeof(MSG_ADDRESS_INFO_S)*pAddrList->nCount);
1473
1474         char cmdBuf[cmdSize];
1475         bzero(cmdBuf, cmdSize);
1476         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1477
1478         // Set Command Parameters
1479         pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1480
1481         // Copy Cookie
1482         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1483
1484         // Copy Command Data
1485         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pAddrList->nCount, sizeof(pAddrList->nCount));
1486         int addSize = sizeof(MSG_ADDRESS_INFO_S);
1487         for(int i=0; i<pAddrList->nCount; i++) {
1488                 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(pAddrList->nCount)+(addSize*i)+MAX_COOKIE_LEN), ((msg_struct_s *)(pAddrList->msg_struct_info[i]))->data, sizeof(MSG_ADDRESS_INFO_S));
1489         }
1490
1491         // Send Command to Messaging FW
1492         char* pEventData = NULL;
1493         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1494
1495         write((char*)pCmd, cmdSize, &pEventData);
1496
1497         // Get Return Data
1498         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1499
1500         if (pEvent == NULL)
1501                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1502
1503         if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS)
1504         {
1505                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1506         }
1507
1508         if (pEvent->result != MSG_SUCCESS)
1509                 return pEvent->result;
1510
1511         // Decode Return Data
1512         MsgDecodeThreadId(pEvent->data, pThreadId);
1513
1514         return MSG_SUCCESS;
1515 }
1516
1517
1518 msg_error_t MsgHandle::getThreadIdByAddress(msg_list_handle_t msg_address_list, msg_thread_id_t *pThreadId)
1519 {
1520         int addrCnt = (int)g_list_length((GList *)msg_address_list);
1521
1522         // Allocate Memory to Command Data
1523         int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*addrCnt);
1524
1525         char cmdBuf[cmdSize];
1526         bzero(cmdBuf, cmdSize);
1527         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1528
1529         // Set Command Parameters
1530         pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1531
1532         // Copy Cookie
1533         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1534
1535         // Copy Command Data
1536         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &addrCnt, sizeof(int));
1537         int addSize = sizeof(MSG_ADDRESS_INFO_S);
1538         for(int i=0; i<addrCnt; i++) {
1539                 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(addrCnt)+(addSize*i)+MAX_COOKIE_LEN), ((msg_struct_s *)(g_list_nth_data((GList *)msg_address_list,(guint)i)))->data, sizeof(MSG_ADDRESS_INFO_S));
1540         }
1541
1542         // Send Command to Messaging FW
1543         char* pEventData = NULL;
1544         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1545
1546         write((char*)pCmd, cmdSize, &pEventData);
1547
1548         // Get Return Data
1549         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1550
1551         if (pEvent == NULL)
1552                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1553
1554         if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS)
1555         {
1556                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1557         }
1558
1559         if (pEvent->result != MSG_SUCCESS)
1560                 return pEvent->result;
1561
1562         // Decode Return Data
1563         MsgDecodeThreadId(pEvent->data, pThreadId);
1564
1565         return MSG_SUCCESS;
1566 }
1567
1568
1569 msg_error_t MsgHandle::getThread(msg_thread_id_t threadId, MSG_THREAD_VIEW_S* pThreadInfo)
1570 {
1571         // Allocate Memory to Command Data
1572         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
1573
1574         char cmdBuf[cmdSize];
1575         bzero(cmdBuf, cmdSize);
1576         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1577
1578         // Set Command Parameters
1579         pCmd->cmdType = MSG_CMD_GET_THREAD_INFO;
1580
1581         // Copy Cookie
1582         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1583
1584         // Copy Command Data
1585         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &threadId, sizeof(msg_thread_id_t));
1586
1587         // Send Command to Messaging FW
1588         char* pEventData = NULL;
1589         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1590
1591         write((char*)pCmd, cmdSize, &pEventData);
1592
1593         // Get Return Data
1594         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1595
1596         if (pEvent == NULL)
1597                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1598
1599         if (pEvent->eventType != MSG_EVENT_GET_THREAD_INFO)
1600         {
1601                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1602         }
1603
1604         // Decode Return Data
1605         MsgDecodeThreadInfo(pEvent->data, pThreadInfo);
1606
1607         return MSG_SUCCESS;
1608 }
1609
1610
1611 msg_error_t MsgHandle::getMessageList(const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pMsgList)
1612 {
1613         msg_error_t err = MSG_SUCCESS;
1614
1615 //      err = MsgStoConnectDB();
1616 //
1617 //      if (err != MSG_SUCCESS) {
1618 //              MSG_DEBUG("MsgStoConnectDB() Error!!");
1619 //              return err;
1620 //      }
1621
1622         err = MsgStoGetMessageList(pListCond, pMsgList);
1623
1624         if (err != MSG_SUCCESS) {
1625                 MSG_DEBUG("MsgStoGetMessageList() Error!!");
1626                 return err;
1627         }
1628
1629 //      MsgStoDisconnectDB();
1630
1631         return err;
1632 }
1633
1634
1635 msg_error_t MsgHandle::getMediaList(const msg_thread_id_t thread_id, msg_list_handle_t *pMediaList)
1636 {
1637         msg_error_t err = MSG_SUCCESS;
1638
1639         err = MsgStoGetMediaList(thread_id, pMediaList);
1640
1641         if (err != MSG_SUCCESS) {
1642                 MSG_DEBUG("MsgStoGetFmMediaList() Error!!");
1643                 return err;
1644         }
1645
1646         return err;
1647 }
1648
1649
1650 int MsgHandle::addPushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1651 {
1652         // Allocate Memory to Command Data
1653         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1654
1655         char cmdBuf[cmdSize];
1656         bzero(cmdBuf, cmdSize);
1657         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1658
1659         // Set Command Parameters
1660         pCmd->cmdType = MSG_CMD_ADD_PUSH_EVENT;
1661
1662         // Copy Cookie
1663         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1664
1665         // Copy Command Data
1666         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1667
1668         // Send Command to Messaging FW
1669         char* pEventData = NULL;
1670         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1671
1672         write((char*)pCmd, cmdSize, &pEventData);
1673
1674         // Get Return Data
1675         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1676
1677         if (pEvent == NULL)
1678                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1679
1680         if (pEvent->eventType != MSG_EVENT_ADD_PUSH_EVENT)
1681         {
1682                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1683         }
1684
1685         return pEvent->result;
1686 }
1687
1688
1689 int MsgHandle::deletePushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1690 {
1691         // Allocate Memory to Command Data
1692         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1693
1694         char cmdBuf[cmdSize];
1695         bzero(cmdBuf, cmdSize);
1696         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1697
1698         // Set Command Parameters
1699         pCmd->cmdType = MSG_CMD_DELETE_PUSH_EVENT;
1700
1701         // Copy Cookie
1702         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1703
1704         // Copy Command Data
1705         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1706
1707         // Send Command to Messaging FW
1708         char* pEventData = NULL;
1709         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1710
1711         write((char*)pCmd, cmdSize, &pEventData);
1712
1713         // Get Return Data
1714         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1715
1716         if (pEvent == NULL)
1717                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1718
1719         if (pEvent->eventType != MSG_EVENT_DELETE_PUSH_EVENT)
1720         {
1721                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1722         }
1723
1724         return pEvent->result;
1725 }
1726
1727 int MsgHandle::updatePushEvent(MSG_PUSH_EVENT_INFO_S *pSrc, MSG_PUSH_EVENT_INFO_S *pDst)
1728 {
1729         // Allocate Memory to Command Data
1730         int cmdSize = sizeof(MSG_CMD_S) +  2 * sizeof(MSG_PUSH_EVENT_INFO_S);
1731
1732         char cmdBuf[cmdSize];
1733         bzero(cmdBuf, cmdSize);
1734         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1735
1736         // Set Command Parameters
1737         pCmd->cmdType = MSG_CMD_UPDATE_PUSH_EVENT;
1738
1739         // Copy Cookie
1740         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1741
1742         // Copy Command Data
1743         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pSrc, sizeof(MSG_PUSH_EVENT_INFO_S));
1744         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_PUSH_EVENT_INFO_S)), pDst, sizeof(MSG_PUSH_EVENT_INFO_S));
1745
1746         // Send Command to Messaging FW
1747         char* pEventData = NULL;
1748         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1749
1750         write((char*)pCmd, cmdSize, &pEventData);
1751
1752         // Get Return Data
1753         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1754
1755         if (pEvent == NULL)
1756                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1757
1758         if (pEvent->eventType != MSG_EVENT_UPDATE_PUSH_EVENT)
1759         {
1760                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1761         }
1762
1763         return pEvent->result;
1764 }
1765
1766 msg_error_t MsgHandle::getVobject(msg_message_id_t MsgId, void** encodedData)
1767 {
1768         // Allocate Memory to Command Data
1769         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1770         char *encode_data = NULL;
1771         char cmdBuf[cmdSize];
1772         bzero(cmdBuf, cmdSize);
1773         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1774
1775         // Set Command Parameters
1776         pCmd->cmdType = MSG_CMD_GET_MSG;
1777
1778         // Copy Cookie
1779         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1780
1781         // Copy Command Data
1782         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
1783
1784         // Send Command to Messaging FW
1785         char* pEventData = NULL;
1786         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1787
1788
1789         write((char*)pCmd, cmdSize, &pEventData);
1790
1791         // Get Return Data
1792         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1793
1794         if (pEvent == NULL)
1795                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1796
1797         if (pEvent->eventType != MSG_EVENT_GET_MSG)
1798         {
1799                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1800         }
1801
1802         if (pEvent->result != MSG_SUCCESS)
1803                 return pEvent->result;
1804
1805         // Decode Return Data
1806         MSG_MESSAGE_INFO_S msgInfo = {0,};
1807         MSG_SENDINGOPT_INFO_S sendOptInfo = {0,};
1808
1809         msgInfo.addressList = NULL;
1810         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1811
1812         MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
1813
1814         //Convert MSG_MESSAGE_INFO_S to
1815         encode_data = MsgVMessageEncode(&msgInfo);
1816         if (encode_data) {
1817                 *encodedData = (void*)encode_data;
1818         } else {
1819                 MSG_DEBUG("Error Encode data");
1820                 *encodedData = NULL;
1821         }
1822
1823         // Delete Temp File
1824         if (msgInfo.bTextSms == false)
1825         {
1826                 // Delete Temp File
1827                 MsgDeleteFile(msgInfo.msgData); //ipc
1828         }
1829
1830         return MSG_SUCCESS;
1831 }