2.0_beta
[platform/core/messaging/msg-service.git] / proxy / MsgHandleStorage.cpp
1 /*
2 * Copyright 2012  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *    http://www.tizenopensource.org/license
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "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 "MsgStorageHandler.h"
26
27
28 /*==================================================================================================
29                                      IMPLEMENTATION OF MsgHandle - Storage Member Functions
30 ==================================================================================================*/
31 int MsgHandle::addMessage(MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
32 {
33         MSG_MESSAGE_INFO_S msgInfo = {0};
34         MSG_SENDINGOPT_INFO_S sendOptInfo;
35
36         // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
37         convertMsgStruct(pMsg, &msgInfo);
38
39         // Covert MSG_SENDINGOPT_S to MSG_SENDINGOPT_INFO_S
40         MSG_MESSAGE_TYPE_S msgType = {0,};
41
42         msgType.mainType = pMsg->mainType;
43         msgType.subType = pMsg->subType;
44         msgType.classType = pMsg->classType;
45
46         convertSendOptStruct(pSendOpt, &sendOptInfo, msgType);
47
48         // Allocate Memory to Command Data
49         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S);
50
51         char cmdBuf[cmdSize];
52         bzero(cmdBuf, cmdSize);
53         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
54
55         // Set Command Parameters
56         pCmd->cmdType = MSG_CMD_ADD_MSG;
57
58         // Copy Cookie
59         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
60
61         // Copy Command Data
62         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
63         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), &sendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
64
65         // Send Command to Messaging FW
66         char* pEventData = NULL;
67         AutoPtr<char> eventBuf(&pEventData);
68
69         write((char*)pCmd, cmdSize, &pEventData);
70
71         // Get Return Data
72         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
73
74         if (pEvent->eventType != MSG_EVENT_ADD_MSG)
75         {
76                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
77         }
78
79         if (pEvent->result != MSG_SUCCESS) return pEvent->result;
80
81         msg_message_id_t msgId = 0;
82
83         // Decode Return Data
84         MsgDecodeMsgId(pEvent->data, &msgId);
85
86         return (int)msgId;
87 }
88
89
90 msg_error_t MsgHandle::addSyncMLMessage(const MSG_SYNCML_MESSAGE_S *pSyncMLMsg)
91 {
92         MSG_MESSAGE_INFO_S msgInfo;
93
94         // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
95         msg_struct_s *msg = (msg_struct_s *)pSyncMLMsg->msg;
96         convertMsgStruct((MSG_MESSAGE_HIDDEN_S *)msg->data, &msgInfo);
97
98         // Allocate Memory to Command Data
99         int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + sizeof(int) + sizeof(MSG_MESSAGE_INFO_S);
100
101         char cmdBuf[cmdSize];
102         bzero(cmdBuf, cmdSize);
103         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
104
105         // Set Command Parameters
106         pCmd->cmdType = MSG_CMD_ADD_SYNCML_MSG;
107
108         // Copy Cookie
109         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
110
111         // Copy Command Data
112         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pSyncMLMsg->extId, sizeof(int));
113         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), &pSyncMLMsg->pinCode, sizeof(int));
114         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(int)), &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
115
116         // Send Command to Messaging FW
117         char* pEventData = NULL;
118         AutoPtr<char> eventBuf(&pEventData);
119
120
121         write((char*)pCmd, cmdSize, &pEventData);
122
123         // Get Return Data
124         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
125
126         if (pEvent->eventType != MSG_EVENT_ADD_SYNCML_MSG)
127         {
128                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
129         }
130
131         return pEvent->result;
132 }
133
134
135 msg_error_t MsgHandle::updateMessage(const MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
136 {
137         MSG_MESSAGE_INFO_S msgInfo;
138         MSG_SENDINGOPT_INFO_S sendOptInfo;
139
140         // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
141         convertMsgStruct(pMsg, &msgInfo);
142
143         if(pSendOpt != NULL) {
144                 MSG_MESSAGE_TYPE_S msgType = {0,};
145
146                 msgType.mainType = pMsg->mainType;
147                 msgType.subType = pMsg->subType;
148                 msgType.classType = pMsg->classType;
149
150                 convertSendOptStruct(pSendOpt, &sendOptInfo, msgType);
151         }
152
153         // Allocate Memory to Command Data
154         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S);
155
156         char cmdBuf[cmdSize];
157         bzero(cmdBuf, cmdSize);
158         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
159
160         // Set Command Parameters
161         pCmd->cmdType = MSG_CMD_UPDATE_MSG;
162
163         // Copy Cookie
164         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
165
166         // Copy Command Data
167         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
168         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), &sendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
169
170         // Send Command to Messaging FW
171         char* pEventData = NULL;
172         AutoPtr<char> eventBuf(&pEventData);
173
174
175         write((char*)pCmd, cmdSize, &pEventData);
176
177         // Get Return Data
178         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
179
180         if (pEvent->eventType != MSG_EVENT_UPDATE_MSG)
181         {
182                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
183         }
184
185         return pEvent->result;
186 }
187
188
189 msg_error_t MsgHandle::updateReadStatus(msg_message_id_t MsgId, bool bRead)
190 {
191         // Allocate Memory to Command Data
192         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(bool);
193
194         char cmdBuf[cmdSize];
195         bzero(cmdBuf, cmdSize);
196         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
197
198         // Set Command Parameters
199         pCmd->cmdType = MSG_CMD_UPDATE_READ;
200
201         // Copy Cookie
202         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
203
204         // Copy Command Data
205         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
206         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &bRead, sizeof(bool));
207
208         // Send Command to Messaging FW
209         char* pEventData = NULL;
210         AutoPtr<char> eventBuf(&pEventData);
211
212
213         write((char*)pCmd, cmdSize, &pEventData);
214
215         // Get Return Data
216         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
217
218         if (pEvent->eventType != MSG_EVENT_UPDATE_READ)
219         {
220                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
221         }
222
223         return pEvent->result;
224 }
225
226
227 msg_error_t MsgHandle::updateProtectedStatus(msg_message_id_t MsgId, bool bProtected)
228 {
229         // Allocate Memory to Command Data
230         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(bool);
231
232         char cmdBuf[cmdSize];
233         bzero(cmdBuf, cmdSize);
234         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
235
236         // Set Command Parameters
237         pCmd->cmdType = MSG_CMD_UPDATE_PROTECTED;
238
239         // Copy Cookie
240         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
241
242         // Copy Command Data
243         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
244         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &bProtected, sizeof(bool));
245
246         // Send Command to Messaging FW
247         char* pEventData = NULL;
248         AutoPtr<char> eventBuf(&pEventData);
249
250
251         write((char*)pCmd, cmdSize, &pEventData);
252
253         // Get Return Data
254         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
255
256         if (pEvent->eventType != MSG_EVENT_UPDATE_PROTECTED)
257         {
258                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
259         }
260
261         return pEvent->result;
262 }
263
264
265 msg_error_t MsgHandle::deleteMessage(msg_message_id_t MsgId)
266 {
267         // Allocate Memory to Command Data
268         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
269
270         char cmdBuf[cmdSize];
271         bzero(cmdBuf, cmdSize);
272         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
273
274         // Set Command Parameters
275         pCmd->cmdType = MSG_CMD_DELETE_MSG;
276
277         // Copy Cookie
278         memcpy((void*)pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
279
280         // Copy Command Data
281         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
282
283         // Send Command to Messaging FW
284         char* pEventData = NULL;
285         AutoPtr<char> eventBuf(&pEventData);
286
287
288         write((char*)pCmd, cmdSize, &pEventData);
289
290         // Get Return Data
291         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
292
293         if (pEvent->eventType != MSG_EVENT_DELETE_MSG)
294         {
295                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
296         }
297
298         return pEvent->result;
299 }
300
301
302 msg_error_t MsgHandle::deleteAllMessagesInFolder(msg_folder_id_t FolderId, bool bOnlyDB)
303 {
304         // Allocate Memory to Command Data
305         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
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_DELALL_MSGINFOLDER;
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), &FolderId, sizeof(msg_folder_id_t));
319         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_folder_id_t)), &bOnlyDB, sizeof(bool));
320
321         // Send Command to Messaging FW
322         char* pEventData = NULL;
323         AutoPtr<char> eventBuf(&pEventData);
324
325
326         write((char*)pCmd, cmdSize, &pEventData);
327
328         // Get Return Data
329         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
330
331         if (pEvent->eventType != MSG_EVENT_DELALL_MSGINFOLDER)
332         {
333                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
334         }
335
336         return pEvent->result;
337 }
338
339
340 msg_error_t MsgHandle::moveMessageToFolder(msg_message_id_t MsgId, msg_folder_id_t DestFolderId)
341 {
342         // Allocate Memory to Command Data
343         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(msg_folder_id_t);
344
345         char cmdBuf[cmdSize];
346         bzero(cmdBuf, cmdSize);
347         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
348
349         // Set Command Parameters
350         pCmd->cmdType = MSG_CMD_MOVE_MSGTOFOLDER;
351
352         // Copy Cookie
353         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
354
355         // Copy Command Data
356         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
357         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(msg_message_id_t)+MAX_COOKIE_LEN), &DestFolderId, sizeof(msg_folder_id_t));
358
359         // Send Command to Messaging FW
360         char* pEventData = NULL;
361         AutoPtr<char> eventBuf(&pEventData);
362
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->eventType != MSG_EVENT_MOVE_MSGTOFOLDER)
370         {
371                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
372         }
373
374         return pEvent->result;
375 }
376
377
378 msg_error_t MsgHandle::moveMessageToStorage(msg_message_id_t MsgId, msg_storage_id_t DestStorageId)
379 {
380         // Allocate Memory to Command Data
381         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(msg_storage_id_t);
382
383         char cmdBuf[cmdSize];
384         bzero(cmdBuf, cmdSize);
385         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
386
387         // Set Command Parameters
388         pCmd->cmdType = MSG_CMD_MOVE_MSGTOSTORAGE;
389
390         // Copy Cookie
391         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
392
393         // Copy Command Data
394         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
395         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &DestStorageId, sizeof(msg_storage_id_t));
396
397         // Send Command to Messaging FW
398         char* pEventData = NULL;
399         AutoPtr<char> eventBuf(&pEventData);
400
401
402         write((char*)pCmd, cmdSize, &pEventData);
403
404         // Get Return Data
405         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
406
407         if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOSTORAGE)
408         {
409                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
410         }
411
412         return pEvent->result;
413 }
414
415
416 msg_error_t MsgHandle::countMessage(msg_folder_id_t FolderId, MSG_COUNT_INFO_S *pCountInfo)
417 {
418         // Allocate Memory to Command Data
419         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
420
421         char cmdBuf[cmdSize];
422         bzero(cmdBuf, cmdSize);
423         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
424
425         // Set Command Parameters
426         pCmd->cmdType = MSG_CMD_COUNT_MSG;
427
428         // Copy Cookie
429         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
430
431         // Copy Command Data
432         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
433
434         // Send Command to Messaging FW
435         char* pEventData = NULL;
436         AutoPtr<char> eventBuf(&pEventData);
437
438
439         write((char*)pCmd, cmdSize, &pEventData);
440
441         // Get Return Data
442         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
443
444         if (pEvent->eventType != MSG_EVENT_COUNT_MSG)
445         {
446                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
447         }
448
449         if(pEvent->result != MSG_SUCCESS) return pEvent->result;
450
451         // Decode Return Data
452         MsgDecodeCountInfo(pEvent->data, pCountInfo);
453
454         return MSG_SUCCESS;
455 }
456
457
458 msg_error_t MsgHandle::countMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount)
459 {
460         // Allocate Memory to Command Data
461         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_TYPE_S);
462
463         char cmdBuf[cmdSize];
464         bzero(cmdBuf, cmdSize);
465         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
466
467         // Set Command Parameters
468         pCmd->cmdType = MSG_CMD_COUNT_BY_MSGTYPE;
469
470         // Copy Cookie
471         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
472
473         // Copy Command Data
474         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pMsgType, sizeof(MSG_MESSAGE_TYPE_S));
475
476         // Send Command to Messaging FW
477         char* pEventData = NULL;
478         AutoPtr<char> eventBuf(&pEventData);
479
480         write((char*)pCmd, cmdSize, &pEventData);
481
482         // Get Return Data
483         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
484
485         if (pEvent->eventType != MSG_EVENT_COUNT_BY_MSGTYPE)
486         {
487                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
488         }
489
490         if(pEvent->result != MSG_SUCCESS) return pEvent->result;
491
492         // Decode Return Data
493         memcpy(pMsgCount, (void*)((char*)pEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(int));
494
495         return MSG_SUCCESS;
496 }
497
498
499 msg_error_t MsgHandle::countMsgByContact(const MSG_THREAD_LIST_INDEX_INFO_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
500 {
501         // Allocate Memory to Command Data
502         int cmdSize = sizeof(MSG_CMD_S) +  sizeof(MSG_THREAD_LIST_INDEX_S);
503
504         char cmdBuf[cmdSize];
505         bzero(cmdBuf, cmdSize);
506         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
507
508         // Set Command Parameters
509         pCmd->cmdType = MSG_CMD_GET_CONTACT_COUNT;
510
511         // Copy Cookie
512         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
513
514         // Copy Command Data
515         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pAddrInfo, sizeof(msg_contact_id_t));
516         msg_struct_s *pAddr = (msg_struct_s *)pAddrInfo->msgAddrInfo;
517
518         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN + sizeof(msg_contact_id_t)), pAddr->data, sizeof(MSG_ADDRESS_INFO_S));
519         // Send Command to Messaging FW
520         char* pEventData = NULL;
521         AutoPtr<char> eventBuf(&pEventData);
522
523         write((char*)pCmd, cmdSize, &pEventData);
524
525         // Get Return Data
526         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
527
528         if (pEvent->eventType != MSG_EVENT_GET_CONTACT_COUNT)
529         {
530                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
531         }
532
533         if(pEvent->result != MSG_SUCCESS) return pEvent->result;
534
535         // Decode Return Data
536         MsgDecodeContactCount(pEvent->data, pMsgThreadCountList);
537
538         return MSG_SUCCESS;
539 }
540
541
542 msg_error_t MsgHandle::getMessage(msg_message_id_t MsgId, MSG_MESSAGE_HIDDEN_S *pMsg, MSG_SENDINGOPT_S *pSendOpt)
543 {
544         // Allocate Memory to Command Data
545         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_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_GET_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), &MsgId, sizeof(msg_message_id_t));
559
560         // Send Command to Messaging FW
561         char* pEventData = NULL;
562         AutoPtr<char> eventBuf(&pEventData);
563
564
565         write((char*)pCmd, cmdSize, &pEventData);
566
567         // Get Return Data
568         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
569
570         if (pEvent->eventType != MSG_EVENT_GET_MSG)
571         {
572                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
573         }
574
575         if(pEvent->result != MSG_SUCCESS)
576                 return pEvent->result;
577
578         // Decode Return Data
579         MSG_MESSAGE_INFO_S msgInfo;
580         MSG_SENDINGOPT_INFO_S sendOptInfo;
581         MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
582
583         // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_HIDDEN_S
584         convertMsgStruct(&msgInfo, pMsg);
585
586         if(pSendOpt != NULL) {
587                 MSG_MESSAGE_TYPE_S msgType = {0,};
588
589                 msgType.mainType = pMsg->mainType;
590                 msgType.subType = pMsg->subType;
591                 msgType.classType = pMsg->classType;
592
593                 convertSendOptStruct(&sendOptInfo, pSendOpt, msgType);
594         }
595
596         // Delete Temp File
597         if (msgInfo.bTextSms == false)
598         {
599                 // Delete Temp File
600                 MsgDeleteFile(msgInfo.msgData); //ipc
601         }
602
603         return MSG_SUCCESS;
604 }
605
606
607 msg_error_t MsgHandle::getFolderViewList(msg_folder_id_t FolderId, const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pMsgFolderViewList)
608 {
609         msg_error_t err = MSG_SUCCESS;
610
611         err = MsgStoConnectDB();
612
613         if (err != MSG_SUCCESS)
614         {
615                 MSG_DEBUG("MsgStoConnectDB() Error!!");
616                 return err;
617         }
618
619         err = MsgStoGetFolderViewList(FolderId, (MSG_SORT_RULE_S *)pSortRule, pMsgFolderViewList);
620
621         if (err != MSG_SUCCESS)
622         {
623                 MSG_DEBUG("MsgStoGetFolderViewList() Error!!");
624                 return err;
625         }
626
627         MsgStoDisconnectDB();
628
629         return err;
630 }
631
632
633 msg_error_t MsgHandle::addFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
634 {
635         // Allocate Memory to Command Data
636         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
637
638         char cmdBuf[cmdSize];
639         bzero(cmdBuf, cmdSize);
640         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
641
642         // Set Command Parameters
643         pCmd->cmdType = MSG_CMD_ADD_FOLDER;
644
645         // Copy Cookie
646         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
647
648         // Copy Command Data
649         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
650
651         // Send Command to Messaging FW
652         char* pEventData = NULL;
653         AutoPtr<char> eventBuf(&pEventData);
654
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->eventType != MSG_EVENT_ADD_FOLDER)
662         {
663                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
664         }
665
666         return pEvent->result;
667 }
668
669
670 msg_error_t MsgHandle::updateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
671 {
672         // Allocate Memory to Command Data
673         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
674
675         char cmdBuf[cmdSize];
676         bzero(cmdBuf, cmdSize);
677         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
678
679         // Set Command Parameters
680         pCmd->cmdType = MSG_CMD_UPDATE_FOLDER;
681
682         // Copy Cookie
683         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
684
685         // Copy Command Data
686         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
687
688         // Send Command to Messaging FW
689         char* pEventData = NULL;
690         AutoPtr<char> eventBuf(&pEventData);
691
692
693         write((char*)pCmd, cmdSize, &pEventData);
694
695         // Get Return Data
696         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
697
698         if (pEvent->eventType != MSG_EVENT_UPDATE_FOLDER)
699         {
700                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
701         }
702
703         return pEvent->result;;
704 }
705
706
707 msg_error_t MsgHandle::deleteFolder(msg_folder_id_t FolderId)
708 {
709         // Allocate Memory to Command Data
710         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
711
712         char cmdBuf[cmdSize];
713         bzero(cmdBuf, cmdSize);
714         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
715
716         // Set Command Parameters
717         pCmd->cmdType = MSG_CMD_DELETE_FOLDER;
718
719         // Copy Cookie
720         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
721
722         // Copy Command Data
723         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
724
725         // Send Command to Messaging FW
726         char* pEventData = NULL;
727         AutoPtr<char> eventBuf(&pEventData);
728
729
730         write((char*)pCmd, cmdSize, &pEventData);
731
732         // Get Return Data
733         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
734
735         if (pEvent->eventType != MSG_EVENT_DELETE_FOLDER)
736         {
737                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
738         }
739
740         return pEvent->result;
741 }
742
743
744 msg_error_t MsgHandle::getFolderList(msg_struct_list_s *pFolderList)
745 {
746         // Allocate Memory to Command Data
747         int cmdSize = sizeof(MSG_CMD_S);
748
749         char cmdBuf[cmdSize];
750         bzero(cmdBuf, cmdSize);
751         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
752
753         // Set Command Parameters
754         pCmd->cmdType = MSG_CMD_GET_FOLDERLIST;
755
756         // Copy Cookie
757         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
758
759         // Send Command to Messaging FW
760         char* pEventData = NULL;
761         AutoPtr<char> eventBuf(&pEventData);
762
763         write((char*)pCmd, cmdSize, &pEventData);
764
765         // Get Return Data
766         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
767
768         if (pEvent->eventType != MSG_EVENT_GET_FOLDERLIST)
769         {
770                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
771         }
772
773         if(pEvent->result != MSG_SUCCESS) return pEvent->result;
774
775         // Decode Return Data
776         MsgDecodeFolderList(pEvent->data, pFolderList);
777
778         return MSG_SUCCESS;
779 }
780
781
782 msg_error_t MsgHandle::getThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList)
783 {
784         msg_error_t err =  MSG_SUCCESS;
785
786         err = MsgStoConnectDB();
787
788         if (err != MSG_SUCCESS)
789         {
790                 MSG_DEBUG("MsgStoConnectDB() Error!!");
791                 return err;
792         }
793
794         err = MsgStoGetThreadViewList(pSortRule, pThreadViewList);
795
796         if (err != MSG_SUCCESS)
797         {
798                 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
799                 return err;
800         }
801
802         MsgStoDisconnectDB();
803
804         return err;
805 }
806
807
808 msg_error_t MsgHandle::getConversationViewList(msg_thread_id_t ThreadId, msg_struct_list_s *pConvViewList)
809 {
810         MSG_BEGIN();
811
812         msg_error_t err =  MSG_SUCCESS;
813
814         MsgStoConnectDB();
815         err = MsgStoGetConversationViewList(ThreadId, pConvViewList);
816         MsgStoDisconnectDB();
817
818         if(err != MSG_SUCCESS)
819                 return err;
820
821
822 // Update Read Status for the Thead ID
823 #if 1
824         // Allocate Memory to Command Data
825         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
826
827         char cmdBuf[cmdSize];
828         bzero(cmdBuf, cmdSize);
829         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
830
831         // Set Command Parameters
832         pCmd->cmdType = MSG_CMD_UPDATE_THREAD_READ;
833
834         // Copy Cookie
835         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
836
837         // Copy Command Data
838         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
839
840         // Send Command to Messaging FW
841         char* pEventData = NULL;
842         AutoPtr<char> eventBuf(&pEventData);
843
844         write((char*)pCmd, cmdSize, &pEventData);
845
846         // Get Return Data
847         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
848
849         if (pEvent->eventType != MSG_EVENT_UPDATE_THREAD_READ)
850         {
851                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
852         }
853 #endif
854
855         MSG_END();
856
857         return err;
858 }
859
860
861 msg_error_t MsgHandle::deleteThreadMessageList(msg_thread_id_t ThreadId)
862 {
863         // Allocate Memory to Command Data
864         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_THREAD_LIST_INDEX_S);
865
866         char cmdBuf[cmdSize];
867         bzero(cmdBuf, cmdSize);
868         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
869
870         // Set Command Parameters
871         pCmd->cmdType = MSG_CMD_DELETE_THREADMESSAGELIST;
872
873         // Copy Cookie
874         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
875
876         // Copy Command Data
877         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
878
879         // Send Command to Messaging FW
880         char* pEventData = NULL;
881         AutoPtr<char> eventBuf(&pEventData);
882
883
884         write((char*)pCmd, cmdSize, &pEventData);
885
886         // Get Return Data
887         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
888
889         if (pEvent->eventType != MSG_EVENT_DELETE_THREADMESSAGELIST)
890         {
891                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
892         }
893
894         if(pEvent->result != MSG_SUCCESS) return pEvent->result;
895
896         return MSG_SUCCESS;
897 }
898
899
900 msg_error_t MsgHandle::getQuickPanelData(msg_quickpanel_type_t Type, MSG_MESSAGE_HIDDEN_S *pMsg)
901 {
902         // Allocate Memory to Command Data
903         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_quickpanel_type_t);
904
905         char cmdBuf[cmdSize];
906         bzero(cmdBuf, cmdSize);
907         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
908
909         // Set Command Parameters
910         pCmd->cmdType = MSG_CMD_GET_QUICKPANEL_DATA;
911
912         // Copy Cookie
913         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
914
915         // Copy Command Data
916         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &Type, sizeof(msg_quickpanel_type_t));
917
918         // Send Command to Messaging FW
919         char* pEventData = NULL;
920         AutoPtr<char> eventBuf(&pEventData);
921
922         write((char*)pCmd, cmdSize, &pEventData);
923
924         // Get Return Data
925         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
926
927         if (pEvent->eventType != MSG_EVENT_GET_QUICKPANEL_DATA)
928         {
929                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
930         }
931
932         if(pEvent->result != MSG_SUCCESS) return pEvent->result;
933
934         // Decode Return Data
935         MSG_MESSAGE_INFO_S msgInfo;
936
937         memcpy(&msgInfo, (void*)((char*)pEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(MSG_MESSAGE_INFO_S));
938
939         // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_S
940         convertMsgStruct(&msgInfo, pMsg);
941
942         // Delete Temp File
943         if (msgInfo.bTextSms == false)
944         {
945                 // Delete Temp File
946                 MsgDeleteFile(msgInfo.msgData); //ipc
947         }
948
949         return MSG_SUCCESS;
950 }
951
952
953 msg_error_t MsgHandle::resetDatabase()
954 {
955         // Allocate Memory to Command Data
956         int cmdSize = sizeof(MSG_CMD_S);
957
958         char cmdBuf[cmdSize];
959         bzero(cmdBuf, cmdSize);
960         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
961
962         // Set Command Parameters
963         pCmd->cmdType = MSG_CMD_RESET_DB;
964
965         // Copy Cookie
966         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
967
968         // Send Command to Messaging FW
969         char* pEventData = NULL;
970         AutoPtr<char> eventBuf(&pEventData);
971
972         write((char*)pCmd, cmdSize, &pEventData);
973
974         // Get Return Data
975         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
976
977         if (pEvent->eventType != MSG_EVENT_RESET_DB)
978         {
979                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
980         }
981
982         return pEvent->result;
983 }
984
985
986 msg_error_t MsgHandle::getMemSize(unsigned int* memsize)
987 {
988         // Allocate Memory to Command Data
989         int cmdSize = sizeof(MSG_CMD_S);
990
991         char cmdBuf[cmdSize];
992         bzero(cmdBuf, cmdSize);
993         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
994
995         // Set Command Parameters
996         pCmd->cmdType = MSG_CMD_GET_MEMSIZE;
997
998         // Copy Cookie
999         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1000
1001         // Send Command to Messaging FW
1002         char* pEventData = NULL;
1003         AutoPtr<char> eventBuf(&pEventData);
1004
1005
1006         write((char*)pCmd, cmdSize, &pEventData);
1007
1008         // Get Return Data
1009         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1010
1011         if (pEvent->eventType != MSG_EVENT_GET_MEMSIZE)
1012         {
1013                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1014         }
1015
1016         if(pEvent->result != MSG_SUCCESS) return pEvent->result;
1017
1018         // Decode Return Data
1019         MsgDecodeMemSize(pEvent->data, memsize);
1020
1021         return MSG_SUCCESS;
1022 }
1023
1024
1025 msg_error_t MsgHandle::backupMessage()
1026 {
1027         // Allocate Memory to Command Data
1028         int cmdSize = sizeof(MSG_CMD_S);
1029
1030         char cmdBuf[cmdSize];
1031         bzero(cmdBuf, cmdSize);
1032         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1033
1034         // Set Command Parameters
1035         pCmd->cmdType = MSG_CMD_BACKUP_MESSAGE;
1036
1037         // Copy Cookie
1038         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1039
1040         // Send Command to Messaging FW
1041         char* pEventData = NULL;
1042         AutoPtr<char> eventBuf(&pEventData);
1043
1044
1045         write((char*)pCmd, cmdSize, &pEventData);
1046
1047         // Get Return Data
1048         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1049
1050         if (pEvent->eventType != MSG_EVENT_BACKUP_MESSAGE)
1051         {
1052                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1053         }
1054
1055         if(pEvent->result != MSG_SUCCESS) return pEvent->result;
1056
1057         return MSG_SUCCESS;
1058 }
1059
1060
1061 msg_error_t MsgHandle::restoreMessage()
1062 {
1063         // Allocate Memory to Command Data
1064         int cmdSize = sizeof(MSG_CMD_S);
1065
1066         char cmdBuf[cmdSize];
1067         bzero(cmdBuf, cmdSize);
1068         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1069
1070         // Set Command Parameters
1071         pCmd->cmdType = MSG_CMD_RESTORE_MESSAGE;
1072
1073         // Copy Cookie
1074         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1075
1076         // Send Command to Messaging FW
1077         char* pEventData = NULL;
1078         AutoPtr<char> eventBuf(&pEventData);
1079
1080
1081         write((char*)pCmd, cmdSize, &pEventData);
1082
1083         // Get Return Data
1084         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1085
1086         if (pEvent->eventType != MSG_EVENT_RESTORE_MESSAGE)
1087         {
1088                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1089         }
1090
1091         if(pEvent->result != MSG_SUCCESS) return pEvent->result;
1092
1093         return MSG_SUCCESS;
1094 }
1095
1096
1097 msg_error_t MsgHandle::searchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList)
1098 {
1099         msg_error_t err =  MSG_SUCCESS;
1100
1101         err = MsgStoConnectDB();
1102
1103         if (err != MSG_SUCCESS)
1104         {
1105                 MSG_DEBUG("MsgStoConnectDB() Error!!");
1106                 return err;
1107         }
1108
1109         err = MsgStoSearchMessage(pSearchString, pThreadViewList);
1110
1111         if (err != MSG_SUCCESS)
1112         {
1113                 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1114                 return err;
1115         }
1116
1117         MsgStoDisconnectDB();
1118
1119         return err;
1120 }
1121
1122
1123 msg_error_t MsgHandle::searchMessage(const MSG_SEARCH_CONDITION_S *pSearchCon, int offset, int limit, msg_struct_list_s *pMsgList)
1124 {
1125         msg_error_t err =  MSG_SUCCESS;
1126
1127         err = MsgStoConnectDB();
1128
1129         if (err != MSG_SUCCESS) {
1130                 MSG_DEBUG("MsgStoConnectDB() Error!!");
1131                 return err;
1132         }
1133
1134         err = MsgStoSearchMessage(pSearchCon, offset, limit, pMsgList);
1135
1136         if (err != MSG_SUCCESS) {
1137                 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1138                 return err;
1139         }
1140
1141         MsgStoDisconnectDB();
1142
1143         return err;
1144 }
1145
1146
1147 msg_error_t MsgHandle::getRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList)
1148 {
1149         msg_error_t err =  MSG_SUCCESS;
1150
1151         err = MsgStoConnectDB();
1152
1153         if (err != MSG_SUCCESS)
1154         {
1155                 MSG_DEBUG("MsgStoConnectDB() Error!!");
1156                 return err;
1157         }
1158
1159         err = MsgStoGetRejectMsgList(pNumber, pRejectMsgList);
1160
1161         if (err != MSG_SUCCESS)
1162         {
1163                 MSG_DEBUG("MsgStoGetRejectMsgList() Error!!");
1164                 return err;
1165         }
1166
1167         MsgStoDisconnectDB();
1168
1169         return err;
1170 }
1171
1172
1173 msg_error_t MsgHandle::regStorageChangeCallback(msg_storage_change_cb onStorageChange, void *pUserParam)
1174 {
1175         if (!onStorageChange)
1176                 THROW(MsgException::INVALID_PARAM, "onStorageChange is null");
1177
1178         MsgProxyListener* eventListener = MsgProxyListener::instance();
1179
1180         eventListener->start();
1181
1182         if (eventListener->regStorageChangeEventCB(this, onStorageChange, pUserParam) == false) // callback was already registered, just return SUCCESS
1183                 return MSG_SUCCESS;
1184
1185         // Allocate Memory to Command Data
1186         int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
1187         char cmdBuf[cmdSize];
1188         bzero(cmdBuf, cmdSize);
1189         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
1190
1191         // Set Command Parameters
1192         pCmd->cmdType = MSG_CMD_REG_STORAGE_CHANGE_CB;
1193
1194         // Copy Cookie
1195         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1196
1197         int listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
1198
1199         MSG_DEBUG("remote fd %d", listenerFd);
1200
1201         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &listenerFd, sizeof(listenerFd));
1202
1203         MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), listenerFd);
1204
1205         // Send Command to Messaging FW
1206         char* pEventData = NULL;
1207         AutoPtr<char> eventBuf(&pEventData);
1208
1209         write((char*)pCmd, cmdSize, &pEventData);
1210
1211         // Get Return Data
1212         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1213
1214         if (pEvent->eventType != MSG_EVENT_REG_STORAGE_CHANGE_CB)
1215         {
1216                 THROW(MsgException::INVALID_PARAM, "Event Data Error");
1217         }
1218
1219         return pEvent->result;
1220 }
1221
1222
1223 msg_error_t MsgHandle::getReportStatus(msg_message_id_t msg_id, MSG_REPORT_STATUS_INFO_S *pReport_status)
1224 {
1225         // Allocate Memory to Command Data
1226         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1227
1228         char cmdBuf[cmdSize];
1229         bzero(cmdBuf, cmdSize);
1230         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1231
1232         // Set Command Parameters
1233         pCmd->cmdType = MSG_CMD_GET_REPORT_STATUS;
1234
1235         // Copy Cookie
1236         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1237
1238         // Copy Command Data
1239         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msg_id, sizeof(msg_message_id_t));
1240
1241         // Send Command to Messaging FW
1242         char* pEventData = NULL;
1243         AutoPtr<char> eventBuf(&pEventData);
1244
1245
1246         write((char*)pCmd, cmdSize, &pEventData);
1247
1248         // Get Return Data
1249         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1250
1251         if (pEvent->eventType != MSG_EVENT_GET_REPORT_STATUS)
1252         {
1253                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1254         }
1255
1256         if(pEvent->result != MSG_SUCCESS) return pEvent->result;
1257
1258         // Decode Return Data
1259         MsgDecodeReportStatus(pEvent->data, pReport_status);
1260
1261         return MSG_SUCCESS;
1262 }
1263
1264
1265 msg_error_t MsgHandle::getAddressList(const msg_thread_id_t threadId, msg_struct_list_s *pAddrList)
1266 {
1267         msg_error_t err =  MSG_SUCCESS;
1268
1269         err = MsgStoConnectDB();
1270
1271         if (err != MSG_SUCCESS)
1272         {
1273                 MSG_DEBUG("MsgStoConnectDB() Error!!");
1274                 return err;
1275         }
1276
1277         err = MsgStoGetAddressList(threadId, (msg_struct_list_s *)pAddrList);
1278
1279         if (err != MSG_SUCCESS)
1280         {
1281                 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
1282                 return err;
1283         }
1284
1285         MsgStoDisconnectDB();
1286
1287         return err;
1288 }
1289
1290
1291 msg_error_t MsgHandle::getThreadIdByAddress(msg_struct_list_s *pAddrList, msg_thread_id_t *pThreadId)
1292 {
1293         // Allocate Memory to Command Data
1294         int cmdSize = sizeof(MSG_CMD_S) + sizeof(pAddrList->nCount) + (sizeof(MSG_ADDRESS_INFO_S)*pAddrList->nCount);
1295
1296         char cmdBuf[cmdSize];
1297         bzero(cmdBuf, cmdSize);
1298         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1299
1300         // Set Command Parameters
1301         pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1302
1303         // Copy Cookie
1304         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1305
1306         // Copy Command Data
1307         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pAddrList->nCount, sizeof(pAddrList->nCount));
1308         int addSize = sizeof(MSG_ADDRESS_INFO_S);
1309         for(int i=0; i<pAddrList->nCount; i++) {
1310                 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));
1311         }
1312
1313         // Send Command to Messaging FW
1314         char* pEventData = NULL;
1315         AutoPtr<char> eventBuf(&pEventData);
1316
1317
1318         write((char*)pCmd, cmdSize, &pEventData);
1319
1320         // Get Return Data
1321         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1322
1323         if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS)
1324         {
1325                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1326         }
1327
1328         if(pEvent->result != MSG_SUCCESS) return pEvent->result;
1329
1330         // Decode Return Data
1331         MsgDecodeThreadId(pEvent->data, pThreadId);
1332
1333         return MSG_SUCCESS;
1334 }
1335
1336
1337 msg_error_t MsgHandle::getThread(msg_thread_id_t threadId, MSG_THREAD_VIEW_S* pThreadInfo)
1338 {
1339         // Allocate Memory to Command Data
1340         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
1341
1342         char cmdBuf[cmdSize];
1343         bzero(cmdBuf, cmdSize);
1344         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1345
1346         // Set Command Parameters
1347         pCmd->cmdType = MSG_CMD_GET_THREAD_INFO;
1348
1349         // Copy Cookie
1350         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1351
1352         // Copy Command Data
1353         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &threadId, sizeof(msg_thread_id_t));
1354
1355         // Send Command to Messaging FW
1356         char* pEventData = NULL;
1357         AutoPtr<char> eventBuf(&pEventData);
1358
1359         write((char*)pCmd, cmdSize, &pEventData);
1360
1361         // Get Return Data
1362         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1363
1364         if (pEvent->eventType != MSG_EVENT_GET_THREAD_INFO)
1365         {
1366                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1367         }
1368
1369         // Decode Return Data
1370         MsgDecodeThreadInfo(pEvent->data, pThreadInfo);
1371
1372         return MSG_SUCCESS;
1373 }
1374
1375
1376 msg_error_t MsgHandle::getMessageList(msg_folder_id_t folderId, msg_thread_id_t threadId, msg_message_type_t msgType, msg_storage_id_t storageId, msg_struct_list_s *pMsgList)
1377 {
1378         msg_error_t err =  MSG_SUCCESS;
1379
1380         err = MsgStoConnectDB();
1381
1382         if (err != MSG_SUCCESS) {
1383                 MSG_DEBUG("MsgStoConnectDB() Error!!");
1384                 return err;
1385         }
1386
1387         err = MsgStoGetMessageList(folderId, threadId, msgType, storageId, pMsgList);
1388
1389         if (err != MSG_SUCCESS) {
1390                 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1391                 return err;
1392         }
1393
1394         MsgStoDisconnectDB();
1395
1396         return err;
1397 }