Sync with tizen 2.4
[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         AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
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         AutoPtr<char> buf(&encodedData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
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         AutoPtr<char> buf(&encodedData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
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         AutoPtr<char> buf(&encodedData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<char> eventBuf(&pEventData);
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         AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
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::getFolderViewList(msg_folder_id_t FolderId, const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pMsgFolderViewList)
751 {
752         msg_error_t err = MSG_SUCCESS;
753
754 //      err = MsgStoConnectDB();
755 //
756 //      if (err != MSG_SUCCESS)
757 //      {
758 //              MSG_DEBUG("MsgStoConnectDB() Error!!");
759 //              return err;
760 //      }
761
762         err = MsgStoGetFolderViewList(FolderId, (MSG_SORT_RULE_S *)pSortRule, pMsgFolderViewList);
763
764         if (err != MSG_SUCCESS)
765         {
766                 MSG_DEBUG("MsgStoGetFolderViewList() Error!!");
767                 return err;
768         }
769
770 //      MsgStoDisconnectDB();
771
772         return err;
773 }
774
775
776 msg_error_t MsgHandle::addFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
777 {
778         // Allocate Memory to Command Data
779         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
780
781         char cmdBuf[cmdSize];
782         bzero(cmdBuf, cmdSize);
783         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
784
785         // Set Command Parameters
786         pCmd->cmdType = MSG_CMD_ADD_FOLDER;
787
788         // Copy Cookie
789         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
790
791         // Copy Command Data
792         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
793
794         // Send Command to Messaging FW
795         char* pEventData = NULL;
796         AutoPtr<char> eventBuf(&pEventData);
797
798         write((char*)pCmd, cmdSize, &pEventData);
799
800         // Get Return Data
801         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
802
803         if (pEvent == NULL)
804                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
805
806         if (pEvent->eventType != MSG_EVENT_ADD_FOLDER)
807         {
808                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
809         }
810
811         return pEvent->result;
812 }
813
814
815 msg_error_t MsgHandle::updateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
816 {
817         // Allocate Memory to Command Data
818         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
819
820         char cmdBuf[cmdSize];
821         bzero(cmdBuf, cmdSize);
822         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
823
824         // Set Command Parameters
825         pCmd->cmdType = MSG_CMD_UPDATE_FOLDER;
826
827         // Copy Cookie
828         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
829
830         // Copy Command Data
831         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
832
833         // Send Command to Messaging FW
834         char* pEventData = NULL;
835         AutoPtr<char> eventBuf(&pEventData);
836
837         write((char*)pCmd, cmdSize, &pEventData);
838
839         // Get Return Data
840         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
841
842         if (pEvent == NULL)
843                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
844
845         if (pEvent->eventType != MSG_EVENT_UPDATE_FOLDER)
846         {
847                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
848         }
849
850         return pEvent->result;
851 }
852
853
854 msg_error_t MsgHandle::deleteFolder(msg_folder_id_t FolderId)
855 {
856         // Allocate Memory to Command Data
857         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
858
859         char cmdBuf[cmdSize];
860         bzero(cmdBuf, cmdSize);
861         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
862
863         // Set Command Parameters
864         pCmd->cmdType = MSG_CMD_DELETE_FOLDER;
865
866         // Copy Cookie
867         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
868
869         // Copy Command Data
870         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
871
872         // Send Command to Messaging FW
873         char* pEventData = NULL;
874         AutoPtr<char> eventBuf(&pEventData);
875
876         write((char*)pCmd, cmdSize, &pEventData);
877
878         // Get Return Data
879         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
880
881         if (pEvent == NULL)
882                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
883
884         if (pEvent->eventType != MSG_EVENT_DELETE_FOLDER)
885         {
886                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
887         }
888
889         return pEvent->result;
890 }
891
892
893 msg_error_t MsgHandle::getFolderList(msg_struct_list_s *pFolderList)
894 {
895         // Allocate Memory to Command Data
896         int cmdSize = sizeof(MSG_CMD_S);
897
898         char cmdBuf[cmdSize];
899         bzero(cmdBuf, cmdSize);
900         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
901
902         // Set Command Parameters
903         pCmd->cmdType = MSG_CMD_GET_FOLDERLIST;
904
905         // Copy Cookie
906         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
907
908         // Send Command to Messaging FW
909         char* pEventData = NULL;
910         AutoPtr<char> eventBuf(&pEventData);
911
912         write((char*)pCmd, cmdSize, &pEventData);
913
914         // Get Return Data
915         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
916
917         if (pEvent == NULL)
918                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
919
920         if (pEvent->eventType != MSG_EVENT_GET_FOLDERLIST)
921         {
922                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
923         }
924
925         if (pEvent->result != MSG_SUCCESS)
926                 return pEvent->result;
927
928         // Decode Return Data
929         MsgDecodeFolderList(pEvent->data, pFolderList);
930
931         return MSG_SUCCESS;
932 }
933
934
935 msg_error_t MsgHandle::getThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList)
936 {
937         msg_error_t err =  MSG_SUCCESS;
938
939 //      err = MsgStoConnectDB();
940 //
941 //      if (err != MSG_SUCCESS)
942 //      {
943 //              MSG_DEBUG("MsgStoConnectDB() Error!!");
944 //              return err;
945 //      }
946
947         err = MsgStoGetThreadViewList(pSortRule, pThreadViewList);
948
949         if (err != MSG_SUCCESS)
950         {
951                 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
952                 return err;
953         }
954
955 //      MsgStoDisconnectDB();
956
957 #if 0
958         // Allocate Memory to Command Data
959         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_SORT_RULE_S);
960
961         char cmdBuf[cmdSize];
962         bzero(cmdBuf, cmdSize);
963         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
964
965         // Set Command Parameters
966         pCmd->cmdType = MSG_CMD_GET_THREADVIEWLIST;
967
968         // Copy Command Data
969         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)), pSortRule, sizeof(MSG_SORT_RULE_S));
970
971         // Send Command to Messaging FW
972         char* pEventData = NULL;
973         AutoPtr<char> eventBuf(&pEventData);
974
975         write((char*)pCmd, cmdSize, &pEventData);
976
977         // Get Return Data
978         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
979
980         if (pEvent == NULL)
981                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
982
983         if (pEvent->eventType != MSG_EVENT_GET_THREADVIEWLIST)
984         {
985                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
986         }
987
988         if (pEvent->result != MSG_SUCCESS)
989                 return pEvent->result;
990
991         // Decode Return Data
992         MsgDecodeThreadViewList(pEvent->data, pMsgThreadViewList);
993 #endif
994
995         return err;
996 }
997
998 msg_error_t MsgHandle::getConversationViewItem(msg_message_id_t MsgId, MSG_CONVERSATION_VIEW_S *pConv)
999 {
1000         MSG_BEGIN();
1001
1002         msg_error_t err =  MSG_SUCCESS;
1003
1004 //      MsgStoConnectDB();
1005         err = MsgStoGetConversationViewItem(MsgId, pConv);
1006 //      MsgStoDisconnectDB();
1007
1008         return err;
1009 }
1010
1011 msg_error_t MsgHandle::getConversationViewList(msg_thread_id_t ThreadId, msg_struct_list_s *pConvViewList)
1012 {
1013         MSG_BEGIN();
1014
1015         msg_error_t err =  MSG_SUCCESS;
1016
1017 //      MsgStoConnectDB();
1018         err = MsgStoGetConversationViewList(ThreadId, pConvViewList);
1019 //      MsgStoDisconnectDB();
1020
1021         if (err != MSG_SUCCESS)
1022                 return err;
1023
1024         MSG_END();
1025
1026         return err;
1027 }
1028
1029
1030 msg_error_t MsgHandle::deleteThreadMessageList(msg_thread_id_t ThreadId, bool include_protected_msg)
1031 {
1032         // Allocate Memory to Command Data
1033         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t) + sizeof(bool);
1034
1035         char cmdBuf[cmdSize];
1036         bzero(cmdBuf, cmdSize);
1037         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1038
1039         // Set Command Parameters
1040         pCmd->cmdType = MSG_CMD_DELETE_THREADMESSAGELIST;
1041
1042         // Copy Cookie
1043         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1044
1045         // Copy Command Data
1046         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
1047         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_thread_id_t)), &include_protected_msg, sizeof(bool));
1048
1049         // Send Command to Messaging FW
1050         char* pEventData = NULL;
1051         AutoPtr<char> eventBuf(&pEventData);
1052
1053         write((char*)pCmd, cmdSize, &pEventData);
1054
1055         // Get Return Data
1056         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1057
1058         if (pEvent == NULL)
1059                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1060
1061         if (pEvent->eventType != MSG_EVENT_DELETE_THREADMESSAGELIST)
1062         {
1063                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1064         }
1065
1066         if (pEvent->result != MSG_SUCCESS)
1067                 return pEvent->result;
1068
1069         return MSG_SUCCESS;
1070 }
1071
1072
1073 msg_error_t MsgHandle::getQuickPanelData(msg_quickpanel_type_t Type, MSG_MESSAGE_HIDDEN_S *pMsg)
1074 {
1075         // Allocate Memory to Command Data
1076         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_quickpanel_type_t);
1077
1078         char cmdBuf[cmdSize];
1079         bzero(cmdBuf, cmdSize);
1080         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1081
1082         // Set Command Parameters
1083         pCmd->cmdType = MSG_CMD_GET_QUICKPANEL_DATA;
1084
1085         // Copy Cookie
1086         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1087
1088         // Copy Command Data
1089         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &Type, sizeof(msg_quickpanel_type_t));
1090
1091         // Send Command to Messaging FW
1092         char* pEventData = NULL;
1093         AutoPtr<char> eventBuf(&pEventData);
1094
1095         write((char*)pCmd, cmdSize, &pEventData);
1096
1097         // Get Return Data
1098         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1099
1100         if (pEvent == NULL)
1101                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1102
1103         if (pEvent->eventType != MSG_EVENT_GET_QUICKPANEL_DATA)
1104         {
1105                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1106         }
1107
1108         if (pEvent->result != MSG_SUCCESS)
1109                 return pEvent->result;
1110
1111         // Decode Return Data
1112         MSG_MESSAGE_INFO_S msgInfo;
1113
1114         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1115
1116         msgInfo.addressList = NULL;
1117         AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
1118
1119         MsgDecodeMsgInfo((char *)pEvent->data, &msgInfo);
1120
1121         // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_S
1122         convertMsgStruct(&msgInfo, pMsg);
1123
1124         // Delete Temp File
1125         if (msgInfo.bTextSms == false)
1126         {
1127                 // Delete Temp File
1128                 MsgDeleteFile(msgInfo.msgData); //ipc
1129         }
1130
1131         return MSG_SUCCESS;
1132 }
1133
1134
1135 msg_error_t MsgHandle::resetDatabase()
1136 {
1137         // Allocate Memory to Command Data
1138         int cmdSize = sizeof(MSG_CMD_S);
1139
1140         char cmdBuf[cmdSize];
1141         bzero(cmdBuf, cmdSize);
1142         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1143
1144         // Set Command Parameters
1145         pCmd->cmdType = MSG_CMD_RESET_DB;
1146
1147         // Copy Cookie
1148         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1149
1150         // Send Command to Messaging FW
1151         char* pEventData = NULL;
1152         AutoPtr<char> eventBuf(&pEventData);
1153
1154         write((char*)pCmd, cmdSize, &pEventData);
1155
1156         // Get Return Data
1157         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1158
1159         if (pEvent == NULL)
1160                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1161
1162         if (pEvent->eventType != MSG_EVENT_RESET_DB)
1163         {
1164                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1165         }
1166
1167         return pEvent->result;
1168 }
1169
1170
1171 msg_error_t MsgHandle::getMemSize(unsigned int* memsize)
1172 {
1173         // Allocate Memory to Command Data
1174         int cmdSize = sizeof(MSG_CMD_S);
1175
1176         char cmdBuf[cmdSize];
1177         bzero(cmdBuf, cmdSize);
1178         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1179
1180         // Set Command Parameters
1181         pCmd->cmdType = MSG_CMD_GET_MEMSIZE;
1182
1183         // Copy Cookie
1184         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1185
1186         // Send Command to Messaging FW
1187         char* pEventData = NULL;
1188         AutoPtr<char> eventBuf(&pEventData);
1189
1190         write((char*)pCmd, cmdSize, &pEventData);
1191
1192         // Get Return Data
1193         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1194
1195         if (pEvent == NULL)
1196                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1197
1198         if (pEvent->eventType != MSG_EVENT_GET_MEMSIZE)
1199         {
1200                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1201         }
1202
1203         if (pEvent->result != MSG_SUCCESS)
1204                 return pEvent->result;
1205
1206         // Decode Return Data
1207         MsgDecodeMemSize(pEvent->data, memsize);
1208
1209         return MSG_SUCCESS;
1210 }
1211
1212 msg_error_t MsgHandle::backupMessage(msg_message_backup_type_t type, const char *backup_filepath)
1213 {
1214         if (backup_filepath == NULL)
1215                 return MSG_ERR_NULL_POINTER;
1216
1217         //Create an empty file for writing.
1218         //If a file with the same name already exists its content is erased
1219         //and the file is treated as a new empty file.
1220         FILE *pFile = MsgOpenFile(backup_filepath, "w");
1221         if (pFile == NULL) {
1222                 MSG_DEBUG("File Open error");
1223                 return MSG_ERR_STORAGE_ERROR;
1224         }
1225         MsgCloseFile(pFile);
1226
1227         char path[MSG_FILEPATH_LEN_MAX+1] = {0,};
1228         strncpy(path, backup_filepath, MSG_FILEPATH_LEN_MAX);
1229
1230         // Allocate Memory to Command Data
1231         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_backup_type_t) + sizeof(path);
1232
1233         char cmdBuf[cmdSize];
1234         bzero(cmdBuf, cmdSize);
1235         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1236
1237         // Set Command Parameters
1238         pCmd->cmdType = MSG_CMD_BACKUP_MESSAGE;
1239
1240         // Copy Cookie
1241         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1242         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &type, sizeof(msg_message_backup_type_t));
1243         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_backup_type_t)), (char *)path, sizeof(path));
1244
1245         // Send Command to Messaging FW
1246         char* pEventData = NULL;
1247         AutoPtr<char> eventBuf(&pEventData);
1248
1249         write((char*)pCmd, cmdSize, &pEventData);
1250
1251         // Get Return Data
1252         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1253
1254         if (pEvent == NULL)
1255                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1256
1257         if (pEvent->eventType != MSG_EVENT_BACKUP_MESSAGE)
1258         {
1259                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1260         }
1261
1262         if (pEvent->result != MSG_SUCCESS)
1263                 return pEvent->result;
1264
1265         return MSG_SUCCESS;
1266 }
1267
1268 msg_error_t MsgHandle::restoreMessage(const char *backup_filepath)
1269 {
1270         if (backup_filepath == NULL)
1271                 return MSG_ERR_NULL_POINTER;
1272
1273         if (MsgAccessFile(backup_filepath, R_OK) == false) {
1274                 MSG_DEBUG("File access error");
1275                 return MSG_ERR_UNKNOWN;
1276         }
1277
1278         char path[MSG_FILEPATH_LEN_MAX+1] = {0,};
1279         strncpy(path, backup_filepath, MSG_FILEPATH_LEN_MAX);
1280
1281         // Allocate Memory to Command Data
1282         int cmdSize = sizeof(MSG_CMD_S) + sizeof(path);
1283
1284         char cmdBuf[cmdSize];
1285         bzero(cmdBuf, cmdSize);
1286         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1287
1288         // Set Command Parameters
1289         pCmd->cmdType = MSG_CMD_RESTORE_MESSAGE;
1290
1291         // Copy Cookie
1292         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1293         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), (char *)path, sizeof(path));
1294
1295         // Send Command to Messaging FW
1296         char* pEventData = NULL;
1297         AutoPtr<char> eventBuf(&pEventData);
1298
1299         write((char*)pCmd, cmdSize, &pEventData);
1300
1301         // Get Return Data
1302         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1303
1304         if (pEvent == NULL)
1305                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1306
1307         if (pEvent->eventType != MSG_EVENT_RESTORE_MESSAGE)
1308         {
1309                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1310         }
1311
1312         if (pEvent->result != MSG_SUCCESS)
1313                 return pEvent->result;
1314
1315         return MSG_SUCCESS;
1316 }
1317
1318
1319 msg_error_t MsgHandle::searchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList)
1320 {
1321         msg_error_t err =  MSG_SUCCESS;
1322
1323 //      err = MsgStoConnectDB();
1324 //
1325 //      if (err != MSG_SUCCESS)
1326 //      {
1327 //              MSG_DEBUG("MsgStoConnectDB() Error!!");
1328 //              return err;
1329 //      }
1330
1331         err = MsgStoSearchMessage(pSearchString, pThreadViewList);
1332
1333         if (err != MSG_SUCCESS)
1334         {
1335                 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1336                 return err;
1337         }
1338
1339 //      MsgStoDisconnectDB();
1340
1341         return err;
1342 }
1343
1344
1345 msg_error_t MsgHandle::getRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList)
1346 {
1347         msg_error_t err =  MSG_SUCCESS;
1348
1349 //      err = MsgStoConnectDB();
1350 //
1351 //      if (err != MSG_SUCCESS)
1352 //      {
1353 //              MSG_DEBUG("MsgStoConnectDB() Error!!");
1354 //              return err;
1355 //      }
1356
1357         err = MsgStoGetRejectMsgList(pNumber, pRejectMsgList);
1358
1359         if (err != MSG_SUCCESS)
1360         {
1361                 MSG_DEBUG("MsgStoGetRejectMsgList() Error!!");
1362                 return err;
1363         }
1364
1365 //      MsgStoDisconnectDB();
1366
1367         return err;
1368 }
1369
1370
1371 msg_error_t MsgHandle::regStorageChangeCallback(msg_storage_change_cb onStorageChange, void *pUserParam)
1372 {
1373         if (!onStorageChange)
1374                 THROW(MsgException::INVALID_PARAM, "onStorageChange is null");
1375
1376         MsgProxyListener* eventListener = MsgProxyListener::instance();
1377
1378         eventListener->start(this);
1379
1380         int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
1381
1382         if (remoteFd == -1 )
1383                 return MSG_ERR_INVALID_MSGHANDLE;
1384
1385         if (eventListener->regStorageChangeEventCB(this, onStorageChange, pUserParam) == false)
1386                 return MSG_ERR_INVALID_PARAMETER;
1387
1388         // Allocate Memory to Command Data
1389         int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
1390         char cmdBuf[cmdSize];
1391         bzero(cmdBuf, cmdSize);
1392         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
1393
1394         // Set Command Parameters
1395         pCmd->cmdType = MSG_CMD_REG_STORAGE_CHANGE_CB;
1396
1397         // Copy Cookie
1398         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1399
1400         MSG_DEBUG("remote fd %d", remoteFd);
1401
1402         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
1403
1404         MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
1405
1406         // Send Command to Messaging FW
1407         char* pEventData = NULL;
1408         AutoPtr<char> eventBuf(&pEventData);
1409
1410         write((char*)pCmd, cmdSize, &pEventData);
1411
1412         // Get Return Data
1413         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1414
1415         if (pEvent == NULL)
1416                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1417
1418         if (pEvent->eventType != MSG_EVENT_REG_STORAGE_CHANGE_CB)
1419         {
1420                 THROW(MsgException::INVALID_PARAM, "Event Data Error");
1421         }
1422
1423         return pEvent->result;
1424 }
1425
1426 msg_error_t MsgHandle::getReportStatus(msg_message_id_t msg_id, msg_struct_list_s *report_list)
1427 {
1428         // Allocate Memory to Command Data
1429         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1430
1431         char cmdBuf[cmdSize];
1432         bzero(cmdBuf, cmdSize);
1433         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1434
1435         report_list->nCount = 0;
1436         report_list->msg_struct_info = NULL;
1437
1438         // Set Command Parameters
1439         pCmd->cmdType = MSG_CMD_GET_REPORT_STATUS;
1440
1441         // Copy Cookie
1442         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1443
1444         // Copy Command Data
1445         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msg_id, sizeof(msg_message_id_t));
1446
1447         // Send Command to Messaging FW
1448         char* pEventData = NULL;
1449         AutoPtr<char> eventBuf(&pEventData);
1450
1451         write((char*)pCmd, cmdSize, &pEventData);
1452
1453         // Get Return Data
1454         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1455
1456         if (pEvent == NULL)
1457                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1458
1459         if (pEvent->eventType != MSG_EVENT_GET_REPORT_STATUS)
1460         {
1461                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1462         }
1463
1464         if (pEvent->result != MSG_SUCCESS)
1465                 return pEvent->result;
1466
1467         // Decode Return Data
1468         MsgDecodeReportStatus(pEvent->data, report_list);
1469
1470         return MSG_SUCCESS;
1471 }
1472
1473
1474 msg_error_t MsgHandle::getAddressList(const msg_thread_id_t threadId, msg_struct_list_s *pAddrList)
1475 {
1476         msg_error_t err =  MSG_SUCCESS;
1477
1478 //      err = MsgStoConnectDB();
1479 //
1480 //      if (err != MSG_SUCCESS)
1481 //      {
1482 //              MSG_DEBUG("MsgStoConnectDB() Error!!");
1483 //              return err;
1484 //      }
1485
1486         err = MsgStoGetAddressList(threadId, (msg_struct_list_s *)pAddrList);
1487
1488         if (err != MSG_SUCCESS)
1489         {
1490                 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
1491                 return err;
1492         }
1493
1494 //      MsgStoDisconnectDB();
1495
1496         return err;
1497 }
1498
1499
1500 msg_error_t MsgHandle::getThreadIdByAddress(msg_struct_list_s *pAddrList, msg_thread_id_t *pThreadId)
1501 {
1502         // Allocate Memory to Command Data
1503         int cmdSize = sizeof(MSG_CMD_S) + sizeof(pAddrList->nCount) + (sizeof(MSG_ADDRESS_INFO_S)*pAddrList->nCount);
1504
1505         char cmdBuf[cmdSize];
1506         bzero(cmdBuf, cmdSize);
1507         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1508
1509         // Set Command Parameters
1510         pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1511
1512         // Copy Cookie
1513         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1514
1515         // Copy Command Data
1516         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pAddrList->nCount, sizeof(pAddrList->nCount));
1517         int addSize = sizeof(MSG_ADDRESS_INFO_S);
1518         for(int i=0; i<pAddrList->nCount; i++) {
1519                 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));
1520         }
1521
1522         // Send Command to Messaging FW
1523         char* pEventData = NULL;
1524         AutoPtr<char> eventBuf(&pEventData);
1525
1526         write((char*)pCmd, cmdSize, &pEventData);
1527
1528         // Get Return Data
1529         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1530
1531         if (pEvent == NULL)
1532                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1533
1534         if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS)
1535         {
1536                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1537         }
1538
1539         if (pEvent->result != MSG_SUCCESS)
1540                 return pEvent->result;
1541
1542         // Decode Return Data
1543         MsgDecodeThreadId(pEvent->data, pThreadId);
1544
1545         return MSG_SUCCESS;
1546 }
1547
1548
1549 msg_error_t MsgHandle::getThreadIdByAddress(msg_list_handle_t msg_address_list, msg_thread_id_t *pThreadId)
1550 {
1551         int addrCnt = (int)g_list_length((GList *)msg_address_list);
1552
1553         // Allocate Memory to Command Data
1554         int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*addrCnt);
1555
1556         char cmdBuf[cmdSize];
1557         bzero(cmdBuf, cmdSize);
1558         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1559
1560         // Set Command Parameters
1561         pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1562
1563         // Copy Cookie
1564         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1565
1566         // Copy Command Data
1567         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &addrCnt, sizeof(int));
1568         int addSize = sizeof(MSG_ADDRESS_INFO_S);
1569         for(int i=0; i<addrCnt; i++) {
1570                 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));
1571         }
1572
1573         // Send Command to Messaging FW
1574         char* pEventData = NULL;
1575         AutoPtr<char> eventBuf(&pEventData);
1576
1577         write((char*)pCmd, cmdSize, &pEventData);
1578
1579         // Get Return Data
1580         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1581
1582         if (pEvent == NULL)
1583                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1584
1585         if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS)
1586         {
1587                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1588         }
1589
1590         if (pEvent->result != MSG_SUCCESS)
1591                 return pEvent->result;
1592
1593         // Decode Return Data
1594         MsgDecodeThreadId(pEvent->data, pThreadId);
1595
1596         return MSG_SUCCESS;
1597 }
1598
1599
1600 msg_error_t MsgHandle::getThread(msg_thread_id_t threadId, MSG_THREAD_VIEW_S* pThreadInfo)
1601 {
1602         // Allocate Memory to Command Data
1603         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
1604
1605         char cmdBuf[cmdSize];
1606         bzero(cmdBuf, cmdSize);
1607         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1608
1609         // Set Command Parameters
1610         pCmd->cmdType = MSG_CMD_GET_THREAD_INFO;
1611
1612         // Copy Cookie
1613         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1614
1615         // Copy Command Data
1616         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &threadId, sizeof(msg_thread_id_t));
1617
1618         // Send Command to Messaging FW
1619         char* pEventData = NULL;
1620         AutoPtr<char> eventBuf(&pEventData);
1621
1622         write((char*)pCmd, cmdSize, &pEventData);
1623
1624         // Get Return Data
1625         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1626
1627         if (pEvent == NULL)
1628                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1629
1630         if (pEvent->eventType != MSG_EVENT_GET_THREAD_INFO)
1631         {
1632                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1633         }
1634
1635         // Decode Return Data
1636         MsgDecodeThreadInfo(pEvent->data, pThreadInfo);
1637
1638         return MSG_SUCCESS;
1639 }
1640
1641
1642 msg_error_t MsgHandle::getMessageList(const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pMsgList)
1643 {
1644         msg_error_t err =  MSG_SUCCESS;
1645
1646 //      err = MsgStoConnectDB();
1647 //
1648 //      if (err != MSG_SUCCESS) {
1649 //              MSG_DEBUG("MsgStoConnectDB() Error!!");
1650 //              return err;
1651 //      }
1652
1653         err = MsgStoGetMessageList(pListCond, pMsgList);
1654
1655         if (err != MSG_SUCCESS) {
1656                 MSG_DEBUG("MsgStoGetMessageList() Error!!");
1657                 return err;
1658         }
1659
1660 //      MsgStoDisconnectDB();
1661
1662         return err;
1663 }
1664
1665
1666 msg_error_t MsgHandle::getMediaList(const msg_thread_id_t thread_id, msg_list_handle_t *pMediaList)
1667 {
1668         msg_error_t err =  MSG_SUCCESS;
1669
1670         err = MsgStoGetMediaList(thread_id, pMediaList);
1671
1672         if (err != MSG_SUCCESS) {
1673                 MSG_DEBUG("MsgStoGetFmMediaList() Error!!");
1674                 return err;
1675         }
1676
1677         return err;
1678 }
1679
1680
1681 int MsgHandle::addPushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1682 {
1683         // Allocate Memory to Command Data
1684         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1685
1686         char cmdBuf[cmdSize];
1687         bzero(cmdBuf, cmdSize);
1688         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1689
1690         // Set Command Parameters
1691         pCmd->cmdType = MSG_CMD_ADD_PUSH_EVENT;
1692
1693         // Copy Cookie
1694         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1695
1696         // Copy Command Data
1697         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1698
1699         // Send Command to Messaging FW
1700         char* pEventData = NULL;
1701         AutoPtr<char> eventBuf(&pEventData);
1702
1703         write((char*)pCmd, cmdSize, &pEventData);
1704
1705         // Get Return Data
1706         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1707
1708         if (pEvent == NULL)
1709                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1710
1711         if (pEvent->eventType != MSG_EVENT_ADD_PUSH_EVENT)
1712         {
1713                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1714         }
1715
1716         return pEvent->result;
1717 }
1718
1719
1720 int MsgHandle::deletePushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1721 {
1722         // Allocate Memory to Command Data
1723         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1724
1725         char cmdBuf[cmdSize];
1726         bzero(cmdBuf, cmdSize);
1727         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1728
1729         // Set Command Parameters
1730         pCmd->cmdType = MSG_CMD_DELETE_PUSH_EVENT;
1731
1732         // Copy Cookie
1733         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1734
1735         // Copy Command Data
1736         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1737
1738         // Send Command to Messaging FW
1739         char* pEventData = NULL;
1740         AutoPtr<char> eventBuf(&pEventData);
1741
1742         write((char*)pCmd, cmdSize, &pEventData);
1743
1744         // Get Return Data
1745         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1746
1747         if (pEvent == NULL)
1748                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1749
1750         if (pEvent->eventType != MSG_EVENT_DELETE_PUSH_EVENT)
1751         {
1752                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1753         }
1754
1755         return pEvent->result;
1756 }
1757
1758 int MsgHandle::updatePushEvent(MSG_PUSH_EVENT_INFO_S *pSrc, MSG_PUSH_EVENT_INFO_S *pDst)
1759 {
1760         // Allocate Memory to Command Data
1761         int cmdSize = sizeof(MSG_CMD_S) +  2 * sizeof(MSG_PUSH_EVENT_INFO_S);
1762
1763         char cmdBuf[cmdSize];
1764         bzero(cmdBuf, cmdSize);
1765         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1766
1767         // Set Command Parameters
1768         pCmd->cmdType = MSG_CMD_UPDATE_PUSH_EVENT;
1769
1770         // Copy Cookie
1771         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1772
1773         // Copy Command Data
1774         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pSrc, sizeof(MSG_PUSH_EVENT_INFO_S));
1775         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));
1776
1777         // Send Command to Messaging FW
1778         char* pEventData = NULL;
1779         AutoPtr<char> eventBuf(&pEventData);
1780
1781         write((char*)pCmd, cmdSize, &pEventData);
1782
1783         // Get Return Data
1784         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1785
1786         if (pEvent == NULL)
1787                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1788
1789         if (pEvent->eventType != MSG_EVENT_UPDATE_PUSH_EVENT)
1790         {
1791                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1792         }
1793
1794         return pEvent->result;
1795 }
1796
1797 msg_error_t MsgHandle::getVobject(msg_message_id_t MsgId, void** encodedData)
1798 {
1799         // Allocate Memory to Command Data
1800         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1801         char *encode_data = NULL;
1802         char cmdBuf[cmdSize];
1803         bzero(cmdBuf, cmdSize);
1804         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1805
1806         // Set Command Parameters
1807         pCmd->cmdType = MSG_CMD_GET_MSG;
1808
1809         // Copy Cookie
1810         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1811
1812         // Copy Command Data
1813         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
1814
1815         // Send Command to Messaging FW
1816         char* pEventData = NULL;
1817         AutoPtr<char> eventBuf(&pEventData);
1818
1819
1820         write((char*)pCmd, cmdSize, &pEventData);
1821
1822         // Get Return Data
1823         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1824
1825         if (pEvent == NULL)
1826                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1827
1828         if (pEvent->eventType != MSG_EVENT_GET_MSG)
1829         {
1830                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1831         }
1832
1833         if (pEvent->result != MSG_SUCCESS)
1834                 return pEvent->result;
1835
1836         // Decode Return Data
1837         MSG_MESSAGE_INFO_S msgInfo = {0,};
1838         MSG_SENDINGOPT_INFO_S sendOptInfo = {0,};
1839
1840         msgInfo.addressList = NULL;
1841         AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
1842
1843         MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
1844
1845         //Convert MSG_MESSAGE_INFO_S to
1846         encode_data = MsgVMessageEncode(&msgInfo);
1847         if (encode_data) {
1848                 *encodedData = (void*)encode_data;
1849         } else {
1850                 MSG_DEBUG("Error Encode data");
1851                 *encodedData = NULL;
1852         }
1853
1854         // Delete Temp File
1855         if (msgInfo.bTextSms == false)
1856         {
1857                 // Delete Temp File
1858                 MsgDeleteFile(msgInfo.msgData); //ipc
1859         }
1860
1861         return MSG_SUCCESS;
1862 }