4 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include "MsgUtilFile.h"
22 #include "MsgCppTypes.h"
23 #include "MsgException.h"
24 #include "MsgUtilFunction.h"
25 #include "MsgProxyListener.h"
26 #include "MsgHandle.h"
28 #include "MsgStorageHandler.h"
30 #include "MsgVMessage.h"
31 /*==================================================================================================
32 IMPLEMENTATION OF MsgHandle - Storage Member Functions
33 ==================================================================================================*/
34 int MsgHandle::addMessage(MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
36 MSG_MESSAGE_INFO_S msgInfo = {0,};
37 MSG_SENDINGOPT_INFO_S sendOptInfo = {0,};
39 // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
40 convertMsgStruct(pMsg, &msgInfo);
42 // Covert MSG_SENDINGOPT_S to MSG_SENDINGOPT_INFO_S
43 MSG_MESSAGE_TYPE_S msgType = {0,};
45 msgType.mainType = pMsg->mainType;
46 msgType.subType = pMsg->subType;
47 msgType.classType = pMsg->classType;
49 convertSendOptStruct(pSendOpt, &sendOptInfo, msgType);
51 // Allocate Memory to Command Data
52 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S);
55 bzero(cmdBuf, cmdSize);
56 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
58 // Set Command Parameters
59 pCmd->cmdType = MSG_CMD_ADD_MSG;
62 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
65 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
66 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), &sendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
68 // Send Command to Messaging FW
69 char* pEventData = NULL;
70 AutoPtr<char> eventBuf(&pEventData);
72 write((char*)pCmd, cmdSize, &pEventData);
75 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
77 if (pEvent->eventType != MSG_EVENT_ADD_MSG)
79 THROW(MsgException::INVALID_RESULT, "Event Data Error");
82 if (pEvent->result != MSG_SUCCESS) return pEvent->result;
84 msg_message_id_t msgId = 0;
87 MsgDecodeMsgId(pEvent->data, &msgId);
93 msg_error_t MsgHandle::addSyncMLMessage(const MSG_SYNCML_MESSAGE_S *pSyncMLMsg)
95 MSG_MESSAGE_INFO_S msgInfo = {0, };
97 // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
98 msg_struct_s *msg = (msg_struct_s *)pSyncMLMsg->msg;
99 convertMsgStruct((MSG_MESSAGE_HIDDEN_S *)msg->data, &msgInfo);
101 // Allocate Memory to Command Data
102 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + sizeof(int) + sizeof(MSG_MESSAGE_INFO_S);
104 char cmdBuf[cmdSize];
105 bzero(cmdBuf, cmdSize);
106 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
108 // Set Command Parameters
109 pCmd->cmdType = MSG_CMD_ADD_SYNCML_MSG;
112 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
115 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pSyncMLMsg->extId, sizeof(int));
116 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), &pSyncMLMsg->pinCode, sizeof(int));
117 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(int)), &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
119 // Send Command to Messaging FW
120 char* pEventData = NULL;
121 AutoPtr<char> eventBuf(&pEventData);
124 write((char*)pCmd, cmdSize, &pEventData);
127 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
129 if (pEvent->eventType != MSG_EVENT_ADD_SYNCML_MSG)
131 THROW(MsgException::INVALID_RESULT, "Event Data Error");
134 return pEvent->result;
138 msg_error_t MsgHandle::updateMessage(const MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
140 MSG_MESSAGE_INFO_S msgInfo = {0, };
141 MSG_SENDINGOPT_INFO_S sendOptInfo = {0, };
143 // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
144 convertMsgStruct(pMsg, &msgInfo);
146 if(pSendOpt != NULL) {
147 MSG_MESSAGE_TYPE_S msgType = {0,};
149 msgType.mainType = pMsg->mainType;
150 msgType.subType = pMsg->subType;
151 msgType.classType = pMsg->classType;
153 convertSendOptStruct(pSendOpt, &sendOptInfo, msgType);
156 // Allocate Memory to Command Data
157 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S);
159 char cmdBuf[cmdSize];
160 bzero(cmdBuf, cmdSize);
161 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
163 // Set Command Parameters
164 pCmd->cmdType = MSG_CMD_UPDATE_MSG;
167 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
170 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
171 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), &sendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
173 // Send Command to Messaging FW
174 char* pEventData = NULL;
175 AutoPtr<char> eventBuf(&pEventData);
178 write((char*)pCmd, cmdSize, &pEventData);
181 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
183 if (pEvent->eventType != MSG_EVENT_UPDATE_MSG)
185 THROW(MsgException::INVALID_RESULT, "Event Data Error");
188 return pEvent->result;
192 msg_error_t MsgHandle::updateReadStatus(msg_message_id_t MsgId, bool bRead)
194 // Allocate Memory to Command Data
195 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(bool);
197 char cmdBuf[cmdSize];
198 bzero(cmdBuf, cmdSize);
199 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
201 // Set Command Parameters
202 pCmd->cmdType = MSG_CMD_UPDATE_READ;
205 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
208 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
209 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &bRead, sizeof(bool));
211 // Send Command to Messaging FW
212 char* pEventData = NULL;
213 AutoPtr<char> eventBuf(&pEventData);
216 write((char*)pCmd, cmdSize, &pEventData);
219 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
221 if (pEvent->eventType != MSG_EVENT_UPDATE_READ)
223 THROW(MsgException::INVALID_RESULT, "Event Data Error");
226 return pEvent->result;
230 msg_error_t MsgHandle::updateProtectedStatus(msg_message_id_t MsgId, bool bProtected)
232 // Allocate Memory to Command Data
233 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(bool);
235 char cmdBuf[cmdSize];
236 bzero(cmdBuf, cmdSize);
237 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
239 // Set Command Parameters
240 pCmd->cmdType = MSG_CMD_UPDATE_PROTECTED;
243 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
246 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
247 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &bProtected, sizeof(bool));
249 // Send Command to Messaging FW
250 char* pEventData = NULL;
251 AutoPtr<char> eventBuf(&pEventData);
254 write((char*)pCmd, cmdSize, &pEventData);
257 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
259 if (pEvent->eventType != MSG_EVENT_UPDATE_PROTECTED)
261 THROW(MsgException::INVALID_RESULT, "Event Data Error");
264 return pEvent->result;
268 msg_error_t MsgHandle::deleteMessage(msg_message_id_t MsgId)
270 // Allocate Memory to Command Data
271 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
273 char cmdBuf[cmdSize];
274 bzero(cmdBuf, cmdSize);
275 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
277 // Set Command Parameters
278 pCmd->cmdType = MSG_CMD_DELETE_MSG;
281 memcpy((void*)pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
284 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
286 // Send Command to Messaging FW
287 char* pEventData = NULL;
288 AutoPtr<char> eventBuf(&pEventData);
291 write((char*)pCmd, cmdSize, &pEventData);
294 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
296 if (pEvent->eventType != MSG_EVENT_DELETE_MSG)
298 THROW(MsgException::INVALID_RESULT, "Event Data Error");
301 return pEvent->result;
305 msg_error_t MsgHandle::deleteAllMessagesInFolder(msg_folder_id_t FolderId, bool bOnlyDB)
307 // Allocate Memory to Command Data
308 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
310 char cmdBuf[cmdSize];
311 bzero(cmdBuf, cmdSize);
312 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
314 // Set Command Parameters
315 pCmd->cmdType = MSG_CMD_DELALL_MSGINFOLDER;
318 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
321 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
322 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_folder_id_t)), &bOnlyDB, sizeof(bool));
324 // Send Command to Messaging FW
325 char* pEventData = NULL;
326 AutoPtr<char> eventBuf(&pEventData);
329 write((char*)pCmd, cmdSize, &pEventData);
332 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
334 if (pEvent->eventType != MSG_EVENT_DELALL_MSGINFOLDER)
336 THROW(MsgException::INVALID_RESULT, "Event Data Error");
339 return pEvent->result;
343 msg_error_t MsgHandle::deleteMessagesByList(msg_id_list_s *pMsgIdList)
345 // Allocate Memory to Command Data
346 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + (sizeof(int)*pMsgIdList->nCount);
348 char cmdBuf[cmdSize];
349 bzero(cmdBuf, cmdSize);
350 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
352 // Set Command Parameters
353 pCmd->cmdType = MSG_CMD_DELETE_MESSAGE_BY_LIST;
356 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
359 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &(pMsgIdList->nCount), sizeof(int));
360 for (int i=0; i<pMsgIdList->nCount; i++) {
361 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+(sizeof(int)*i)), &(pMsgIdList->msgIdList[i]), sizeof(int));
364 // Send Command to Messaging FW
365 char* pEventData = NULL;
366 AutoPtr<char> eventBuf(&pEventData);
369 write((char*)pCmd, cmdSize, &pEventData);
372 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
374 if (pEvent->eventType != MSG_EVENT_DELETE_MESSAGE_BY_LIST) {
375 THROW(MsgException::INVALID_RESULT, "Event Data Error");
378 return pEvent->result;
382 msg_error_t MsgHandle::moveMessageToFolder(msg_message_id_t MsgId, msg_folder_id_t DestFolderId)
384 // Allocate Memory to Command Data
385 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(msg_folder_id_t);
387 char cmdBuf[cmdSize];
388 bzero(cmdBuf, cmdSize);
389 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
391 // Set Command Parameters
392 pCmd->cmdType = MSG_CMD_MOVE_MSGTOFOLDER;
395 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
398 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
399 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(msg_message_id_t)+MAX_COOKIE_LEN), &DestFolderId, sizeof(msg_folder_id_t));
401 // Send Command to Messaging FW
402 char* pEventData = NULL;
403 AutoPtr<char> eventBuf(&pEventData);
406 write((char*)pCmd, cmdSize, &pEventData);
409 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
411 if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOFOLDER)
413 THROW(MsgException::INVALID_RESULT, "Event Data Error");
416 return pEvent->result;
420 msg_error_t MsgHandle::moveMessageToStorage(msg_message_id_t MsgId, msg_storage_id_t DestStorageId)
422 // Allocate Memory to Command Data
423 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(msg_storage_id_t);
425 char cmdBuf[cmdSize];
426 bzero(cmdBuf, cmdSize);
427 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
429 // Set Command Parameters
430 pCmd->cmdType = MSG_CMD_MOVE_MSGTOSTORAGE;
433 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
436 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
437 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &DestStorageId, sizeof(msg_storage_id_t));
439 // Send Command to Messaging FW
440 char* pEventData = NULL;
441 AutoPtr<char> eventBuf(&pEventData);
444 write((char*)pCmd, cmdSize, &pEventData);
447 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
449 if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOSTORAGE)
451 THROW(MsgException::INVALID_RESULT, "Event Data Error");
454 return pEvent->result;
458 msg_error_t MsgHandle::countMessage(msg_folder_id_t FolderId, MSG_COUNT_INFO_S *pCountInfo)
460 // Allocate Memory to Command Data
461 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
463 char cmdBuf[cmdSize];
464 bzero(cmdBuf, cmdSize);
465 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
467 // Set Command Parameters
468 pCmd->cmdType = MSG_CMD_COUNT_MSG;
471 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
474 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
476 // Send Command to Messaging FW
477 char* pEventData = NULL;
478 AutoPtr<char> eventBuf(&pEventData);
481 write((char*)pCmd, cmdSize, &pEventData);
484 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
486 if (pEvent->eventType != MSG_EVENT_COUNT_MSG)
488 THROW(MsgException::INVALID_RESULT, "Event Data Error");
491 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
493 // Decode Return Data
494 MsgDecodeCountInfo(pEvent->data, pCountInfo);
500 msg_error_t MsgHandle::countMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount)
502 // Allocate Memory to Command Data
503 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_TYPE_S);
505 char cmdBuf[cmdSize];
506 bzero(cmdBuf, cmdSize);
507 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
509 // Set Command Parameters
510 pCmd->cmdType = MSG_CMD_COUNT_BY_MSGTYPE;
513 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
516 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pMsgType, sizeof(MSG_MESSAGE_TYPE_S));
518 // Send Command to Messaging FW
519 char* pEventData = NULL;
520 AutoPtr<char> eventBuf(&pEventData);
522 write((char*)pCmd, cmdSize, &pEventData);
525 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
527 if (pEvent->eventType != MSG_EVENT_COUNT_BY_MSGTYPE)
529 THROW(MsgException::INVALID_RESULT, "Event Data Error");
532 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
534 // Decode Return Data
535 memcpy(pMsgCount, (void*)((char*)pEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(int));
541 msg_error_t MsgHandle::countMsgByContact(const MSG_THREAD_LIST_INDEX_INFO_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
543 // Allocate Memory to Command Data
544 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_THREAD_LIST_INDEX_S);
546 char cmdBuf[cmdSize];
547 bzero(cmdBuf, cmdSize);
548 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
550 // Set Command Parameters
551 pCmd->cmdType = MSG_CMD_GET_CONTACT_COUNT;
554 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
557 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pAddrInfo, sizeof(msg_contact_id_t));
558 msg_struct_s *pAddr = (msg_struct_s *)pAddrInfo->msgAddrInfo;
560 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN + sizeof(msg_contact_id_t)), pAddr->data, sizeof(MSG_ADDRESS_INFO_S));
561 // Send Command to Messaging FW
562 char* pEventData = NULL;
563 AutoPtr<char> eventBuf(&pEventData);
565 write((char*)pCmd, cmdSize, &pEventData);
568 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
570 if (pEvent->eventType != MSG_EVENT_GET_CONTACT_COUNT)
572 THROW(MsgException::INVALID_RESULT, "Event Data Error");
575 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
577 // Decode Return Data
578 MsgDecodeContactCount(pEvent->data, pMsgThreadCountList);
584 msg_error_t MsgHandle::getMessage(msg_message_id_t MsgId, MSG_MESSAGE_HIDDEN_S *pMsg, MSG_SENDINGOPT_S *pSendOpt)
586 // Allocate Memory to Command Data
587 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
589 char cmdBuf[cmdSize];
590 bzero(cmdBuf, cmdSize);
591 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
593 // Set Command Parameters
594 pCmd->cmdType = MSG_CMD_GET_MSG;
597 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
600 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
602 // Send Command to Messaging FW
603 char* pEventData = NULL;
604 AutoPtr<char> eventBuf(&pEventData);
607 write((char*)pCmd, cmdSize, &pEventData);
610 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
612 if (pEvent->eventType != MSG_EVENT_GET_MSG)
614 THROW(MsgException::INVALID_RESULT, "Event Data Error");
617 if(pEvent->result != MSG_SUCCESS)
618 return pEvent->result;
620 // Decode Return Data
621 MSG_MESSAGE_INFO_S msgInfo;
622 MSG_SENDINGOPT_INFO_S sendOptInfo;
623 MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
625 // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_HIDDEN_S
626 convertMsgStruct(&msgInfo, pMsg);
628 if(pSendOpt != NULL) {
629 MSG_MESSAGE_TYPE_S msgType = {0,};
631 msgType.mainType = pMsg->mainType;
632 msgType.subType = pMsg->subType;
633 msgType.classType = pMsg->classType;
635 convertSendOptStruct(&sendOptInfo, pSendOpt, msgType);
639 if (msgInfo.bTextSms == false)
642 MsgDeleteFile(msgInfo.msgData); //ipc
649 msg_error_t MsgHandle::getFolderViewList(msg_folder_id_t FolderId, const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pMsgFolderViewList)
651 msg_error_t err = MSG_SUCCESS;
653 err = MsgStoConnectDB();
655 if (err != MSG_SUCCESS)
657 MSG_DEBUG("MsgStoConnectDB() Error!!");
661 err = MsgStoGetFolderViewList(FolderId, (MSG_SORT_RULE_S *)pSortRule, pMsgFolderViewList);
663 if (err != MSG_SUCCESS)
665 MSG_DEBUG("MsgStoGetFolderViewList() Error!!");
669 MsgStoDisconnectDB();
675 msg_error_t MsgHandle::addFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
677 // Allocate Memory to Command Data
678 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
680 char cmdBuf[cmdSize];
681 bzero(cmdBuf, cmdSize);
682 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
684 // Set Command Parameters
685 pCmd->cmdType = MSG_CMD_ADD_FOLDER;
688 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
691 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
693 // Send Command to Messaging FW
694 char* pEventData = NULL;
695 AutoPtr<char> eventBuf(&pEventData);
698 write((char*)pCmd, cmdSize, &pEventData);
701 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
703 if (pEvent->eventType != MSG_EVENT_ADD_FOLDER)
705 THROW(MsgException::INVALID_RESULT, "Event Data Error");
708 return pEvent->result;
712 msg_error_t MsgHandle::updateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
714 // Allocate Memory to Command Data
715 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
717 char cmdBuf[cmdSize];
718 bzero(cmdBuf, cmdSize);
719 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
721 // Set Command Parameters
722 pCmd->cmdType = MSG_CMD_UPDATE_FOLDER;
725 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
728 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
730 // Send Command to Messaging FW
731 char* pEventData = NULL;
732 AutoPtr<char> eventBuf(&pEventData);
735 write((char*)pCmd, cmdSize, &pEventData);
738 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
740 if (pEvent->eventType != MSG_EVENT_UPDATE_FOLDER)
742 THROW(MsgException::INVALID_RESULT, "Event Data Error");
745 return pEvent->result;;
749 msg_error_t MsgHandle::deleteFolder(msg_folder_id_t FolderId)
751 // Allocate Memory to Command Data
752 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
754 char cmdBuf[cmdSize];
755 bzero(cmdBuf, cmdSize);
756 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
758 // Set Command Parameters
759 pCmd->cmdType = MSG_CMD_DELETE_FOLDER;
762 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
765 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
767 // Send Command to Messaging FW
768 char* pEventData = NULL;
769 AutoPtr<char> eventBuf(&pEventData);
772 write((char*)pCmd, cmdSize, &pEventData);
775 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
777 if (pEvent->eventType != MSG_EVENT_DELETE_FOLDER)
779 THROW(MsgException::INVALID_RESULT, "Event Data Error");
782 return pEvent->result;
786 msg_error_t MsgHandle::getFolderList(msg_struct_list_s *pFolderList)
788 // Allocate Memory to Command Data
789 int cmdSize = sizeof(MSG_CMD_S);
791 char cmdBuf[cmdSize];
792 bzero(cmdBuf, cmdSize);
793 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
795 // Set Command Parameters
796 pCmd->cmdType = MSG_CMD_GET_FOLDERLIST;
799 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
801 // Send Command to Messaging FW
802 char* pEventData = NULL;
803 AutoPtr<char> eventBuf(&pEventData);
805 write((char*)pCmd, cmdSize, &pEventData);
808 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
810 if (pEvent->eventType != MSG_EVENT_GET_FOLDERLIST)
812 THROW(MsgException::INVALID_RESULT, "Event Data Error");
815 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
817 // Decode Return Data
818 MsgDecodeFolderList(pEvent->data, pFolderList);
824 msg_error_t MsgHandle::getThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList)
826 msg_error_t err = MSG_SUCCESS;
828 err = MsgStoConnectDB();
830 if (err != MSG_SUCCESS)
832 MSG_DEBUG("MsgStoConnectDB() Error!!");
836 err = MsgStoGetThreadViewList(pSortRule, pThreadViewList);
838 if (err != MSG_SUCCESS)
840 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
844 MsgStoDisconnectDB();
849 msg_error_t MsgHandle::getConversationViewItem(msg_message_id_t MsgId, MSG_CONVERSATION_VIEW_S *pConv)
853 msg_error_t err = MSG_SUCCESS;
856 err = MsgStoGetConversationViewItem(MsgId, pConv);
857 MsgStoDisconnectDB();
862 msg_error_t MsgHandle::getConversationViewList(msg_thread_id_t ThreadId, msg_struct_list_s *pConvViewList)
866 msg_error_t err = MSG_SUCCESS;
869 err = MsgStoGetConversationViewList(ThreadId, pConvViewList);
870 MsgStoDisconnectDB();
872 if(err != MSG_SUCCESS)
876 // Update Read Status for the Thead ID
878 // Allocate Memory to Command Data
879 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
881 char cmdBuf[cmdSize];
882 bzero(cmdBuf, cmdSize);
883 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
885 // Set Command Parameters
886 pCmd->cmdType = MSG_CMD_UPDATE_THREAD_READ;
889 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
892 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
894 // Send Command to Messaging FW
895 char* pEventData = NULL;
896 AutoPtr<char> eventBuf(&pEventData);
898 write((char*)pCmd, cmdSize, &pEventData);
901 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
903 if (pEvent->eventType != MSG_EVENT_UPDATE_THREAD_READ)
905 THROW(MsgException::INVALID_RESULT, "Event Data Error");
915 msg_error_t MsgHandle::deleteThreadMessageList(msg_thread_id_t ThreadId, bool include_protected_msg)
917 // Allocate Memory to Command Data
918 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t) + sizeof(bool);
920 char cmdBuf[cmdSize];
921 bzero(cmdBuf, cmdSize);
922 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
924 // Set Command Parameters
925 pCmd->cmdType = MSG_CMD_DELETE_THREADMESSAGELIST;
928 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
931 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
932 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_thread_id_t)), &include_protected_msg, sizeof(bool));
934 // Send Command to Messaging FW
935 char* pEventData = NULL;
936 AutoPtr<char> eventBuf(&pEventData);
939 write((char*)pCmd, cmdSize, &pEventData);
942 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
944 if (pEvent->eventType != MSG_EVENT_DELETE_THREADMESSAGELIST)
946 THROW(MsgException::INVALID_RESULT, "Event Data Error");
949 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
955 msg_error_t MsgHandle::getQuickPanelData(msg_quickpanel_type_t Type, MSG_MESSAGE_HIDDEN_S *pMsg)
957 // Allocate Memory to Command Data
958 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_quickpanel_type_t);
960 char cmdBuf[cmdSize];
961 bzero(cmdBuf, cmdSize);
962 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
964 // Set Command Parameters
965 pCmd->cmdType = MSG_CMD_GET_QUICKPANEL_DATA;
968 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
971 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &Type, sizeof(msg_quickpanel_type_t));
973 // Send Command to Messaging FW
974 char* pEventData = NULL;
975 AutoPtr<char> eventBuf(&pEventData);
977 write((char*)pCmd, cmdSize, &pEventData);
980 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
982 if (pEvent->eventType != MSG_EVENT_GET_QUICKPANEL_DATA)
984 THROW(MsgException::INVALID_RESULT, "Event Data Error");
987 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
989 // Decode Return Data
990 MSG_MESSAGE_INFO_S msgInfo;
992 memcpy(&msgInfo, (void*)((char*)pEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(MSG_MESSAGE_INFO_S));
994 // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_S
995 convertMsgStruct(&msgInfo, pMsg);
998 if (msgInfo.bTextSms == false)
1001 MsgDeleteFile(msgInfo.msgData); //ipc
1008 msg_error_t MsgHandle::resetDatabase()
1010 // Allocate Memory to Command Data
1011 int cmdSize = sizeof(MSG_CMD_S);
1013 char cmdBuf[cmdSize];
1014 bzero(cmdBuf, cmdSize);
1015 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1017 // Set Command Parameters
1018 pCmd->cmdType = MSG_CMD_RESET_DB;
1021 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1023 // Send Command to Messaging FW
1024 char* pEventData = NULL;
1025 AutoPtr<char> eventBuf(&pEventData);
1027 write((char*)pCmd, cmdSize, &pEventData);
1030 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1032 if (pEvent->eventType != MSG_EVENT_RESET_DB)
1034 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1037 return pEvent->result;
1041 msg_error_t MsgHandle::getMemSize(unsigned int* memsize)
1043 // Allocate Memory to Command Data
1044 int cmdSize = sizeof(MSG_CMD_S);
1046 char cmdBuf[cmdSize];
1047 bzero(cmdBuf, cmdSize);
1048 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1050 // Set Command Parameters
1051 pCmd->cmdType = MSG_CMD_GET_MEMSIZE;
1054 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1056 // Send Command to Messaging FW
1057 char* pEventData = NULL;
1058 AutoPtr<char> eventBuf(&pEventData);
1061 write((char*)pCmd, cmdSize, &pEventData);
1064 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1066 if (pEvent->eventType != MSG_EVENT_GET_MEMSIZE)
1068 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1071 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
1073 // Decode Return Data
1074 MsgDecodeMemSize(pEvent->data, memsize);
1079 msg_error_t MsgHandle::backupMessage(msg_message_backup_type_t type, const char *backup_filepath)
1081 if (backup_filepath == NULL)
1082 return MSG_ERR_NULL_POINTER;
1084 //Create an empty file for writing.
1085 //If a file with the same name already exists its content is erased
1086 //and the file is treated as a new empty file.
1087 FILE *pFile = MsgOpenFile(backup_filepath, "w");
1088 if (pFile == NULL) {
1089 MSG_DEBUG("File Open error");
1090 return MSG_ERR_STORAGE_ERROR;
1092 MsgCloseFile(pFile);
1094 char path[MSG_FILEPATH_LEN_MAX+1] = {0,};
1095 strncpy(path, backup_filepath, MSG_FILEPATH_LEN_MAX);
1097 // Allocate Memory to Command Data
1098 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_backup_type_t) + sizeof(path);
1100 char cmdBuf[cmdSize];
1101 bzero(cmdBuf, cmdSize);
1102 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1104 // Set Command Parameters
1105 pCmd->cmdType = MSG_CMD_BACKUP_MESSAGE;
1108 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1109 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &type, sizeof(msg_message_backup_type_t));
1110 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_backup_type_t)), (char *)path, sizeof(path));
1112 // Send Command to Messaging FW
1113 char* pEventData = NULL;
1114 AutoPtr<char> eventBuf(&pEventData);
1116 write((char*)pCmd, cmdSize, &pEventData);
1119 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1121 if (pEvent->eventType != MSG_EVENT_BACKUP_MESSAGE)
1123 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1126 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
1131 msg_error_t MsgHandle::restoreMessage(const char *backup_filepath)
1133 if (backup_filepath == NULL)
1134 return MSG_ERR_NULL_POINTER;
1136 if (MsgAccessFile(backup_filepath, R_OK) == false) {
1137 MSG_DEBUG("File access error");
1138 return MSG_ERR_UNKNOWN;
1141 char path[MSG_FILEPATH_LEN_MAX+1] = {0,};
1142 strncpy(path, backup_filepath, MSG_FILEPATH_LEN_MAX);
1144 // Allocate Memory to Command Data
1145 int cmdSize = sizeof(MSG_CMD_S) + sizeof(path);
1147 char cmdBuf[cmdSize];
1148 bzero(cmdBuf, cmdSize);
1149 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1151 // Set Command Parameters
1152 pCmd->cmdType = MSG_CMD_RESTORE_MESSAGE;
1155 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1156 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), (char *)path, sizeof(path));
1158 // Send Command to Messaging FW
1159 char* pEventData = NULL;
1160 AutoPtr<char> eventBuf(&pEventData);
1163 write((char*)pCmd, cmdSize, &pEventData);
1166 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1168 if (pEvent->eventType != MSG_EVENT_RESTORE_MESSAGE)
1170 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1173 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
1179 msg_error_t MsgHandle::searchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList)
1181 msg_error_t err = MSG_SUCCESS;
1183 err = MsgStoConnectDB();
1185 if (err != MSG_SUCCESS)
1187 MSG_DEBUG("MsgStoConnectDB() Error!!");
1191 err = MsgStoSearchMessage(pSearchString, pThreadViewList);
1193 if (err != MSG_SUCCESS)
1195 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1199 MsgStoDisconnectDB();
1205 msg_error_t MsgHandle::searchMessage(const MSG_SEARCH_CONDITION_S *pSearchCon, int offset, int limit, msg_struct_list_s *pMsgList)
1207 msg_error_t err = MSG_SUCCESS;
1209 err = MsgStoConnectDB();
1211 if (err != MSG_SUCCESS) {
1212 MSG_DEBUG("MsgStoConnectDB() Error!!");
1216 err = MsgStoSearchMessage(pSearchCon, offset, limit, pMsgList);
1218 if (err != MSG_SUCCESS) {
1219 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1223 MsgStoDisconnectDB();
1229 msg_error_t MsgHandle::getRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList)
1231 msg_error_t err = MSG_SUCCESS;
1233 err = MsgStoConnectDB();
1235 if (err != MSG_SUCCESS)
1237 MSG_DEBUG("MsgStoConnectDB() Error!!");
1241 err = MsgStoGetRejectMsgList(pNumber, pRejectMsgList);
1243 if (err != MSG_SUCCESS)
1245 MSG_DEBUG("MsgStoGetRejectMsgList() Error!!");
1249 MsgStoDisconnectDB();
1255 msg_error_t MsgHandle::regStorageChangeCallback(msg_storage_change_cb onStorageChange, void *pUserParam)
1257 if (!onStorageChange)
1258 THROW(MsgException::INVALID_PARAM, "onStorageChange is null");
1260 MsgProxyListener* eventListener = MsgProxyListener::instance();
1262 eventListener->start();
1264 int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
1267 return MSG_ERR_TRANSPORT_ERROR;
1269 if (eventListener->regStorageChangeEventCB(this, onStorageChange, pUserParam) == false) // callback was already registered, just return SUCCESS
1272 // Allocate Memory to Command Data
1273 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
1274 char cmdBuf[cmdSize];
1275 bzero(cmdBuf, cmdSize);
1276 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
1278 // Set Command Parameters
1279 pCmd->cmdType = MSG_CMD_REG_STORAGE_CHANGE_CB;
1282 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1284 int listenerFd = clientFd;
1286 MSG_DEBUG("remote fd %d", listenerFd);
1288 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &listenerFd, sizeof(listenerFd));
1290 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), listenerFd);
1292 // Send Command to Messaging FW
1293 char* pEventData = NULL;
1294 AutoPtr<char> eventBuf(&pEventData);
1296 write((char*)pCmd, cmdSize, &pEventData);
1299 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1301 if (pEvent->eventType != MSG_EVENT_REG_STORAGE_CHANGE_CB)
1303 THROW(MsgException::INVALID_PARAM, "Event Data Error");
1306 return pEvent->result;
1309 msg_error_t MsgHandle::getReportStatus(msg_message_id_t msg_id, msg_struct_list_s *report_list)
1311 // Allocate Memory to Command Data
1312 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1314 char cmdBuf[cmdSize];
1315 bzero(cmdBuf, cmdSize);
1316 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1318 // Set Command Parameters
1319 pCmd->cmdType = MSG_CMD_GET_REPORT_STATUS;
1322 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1324 // Copy Command Data
1325 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msg_id, sizeof(msg_message_id_t));
1327 // Send Command to Messaging FW
1328 char* pEventData = NULL;
1329 AutoPtr<char> eventBuf(&pEventData);
1332 write((char*)pCmd, cmdSize, &pEventData);
1335 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1337 if (pEvent->eventType != MSG_EVENT_GET_REPORT_STATUS)
1339 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1342 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
1344 // Decode Return Data
1345 MsgDecodeReportStatus(pEvent->data, report_list);
1351 msg_error_t MsgHandle::getAddressList(const msg_thread_id_t threadId, msg_struct_list_s *pAddrList)
1353 msg_error_t err = MSG_SUCCESS;
1355 err = MsgStoConnectDB();
1357 if (err != MSG_SUCCESS)
1359 MSG_DEBUG("MsgStoConnectDB() Error!!");
1363 err = MsgStoGetAddressList(threadId, (msg_struct_list_s *)pAddrList);
1365 if (err != MSG_SUCCESS)
1367 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
1371 MsgStoDisconnectDB();
1377 msg_error_t MsgHandle::getThreadIdByAddress(msg_struct_list_s *pAddrList, msg_thread_id_t *pThreadId)
1379 // Allocate Memory to Command Data
1380 int cmdSize = sizeof(MSG_CMD_S) + sizeof(pAddrList->nCount) + (sizeof(MSG_ADDRESS_INFO_S)*pAddrList->nCount);
1382 char cmdBuf[cmdSize];
1383 bzero(cmdBuf, cmdSize);
1384 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1386 // Set Command Parameters
1387 pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1390 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1392 // Copy Command Data
1393 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pAddrList->nCount, sizeof(pAddrList->nCount));
1394 int addSize = sizeof(MSG_ADDRESS_INFO_S);
1395 for(int i=0; i<pAddrList->nCount; i++) {
1396 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));
1399 // Send Command to Messaging FW
1400 char* pEventData = NULL;
1401 AutoPtr<char> eventBuf(&pEventData);
1404 write((char*)pCmd, cmdSize, &pEventData);
1407 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1409 if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS)
1411 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1414 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
1416 // Decode Return Data
1417 MsgDecodeThreadId(pEvent->data, pThreadId);
1423 msg_error_t MsgHandle::getThread(msg_thread_id_t threadId, MSG_THREAD_VIEW_S* pThreadInfo)
1425 // Allocate Memory to Command Data
1426 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
1428 char cmdBuf[cmdSize];
1429 bzero(cmdBuf, cmdSize);
1430 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1432 // Set Command Parameters
1433 pCmd->cmdType = MSG_CMD_GET_THREAD_INFO;
1436 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1438 // Copy Command Data
1439 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &threadId, sizeof(msg_thread_id_t));
1441 // Send Command to Messaging FW
1442 char* pEventData = NULL;
1443 AutoPtr<char> eventBuf(&pEventData);
1445 write((char*)pCmd, cmdSize, &pEventData);
1448 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1450 if (pEvent->eventType != MSG_EVENT_GET_THREAD_INFO)
1452 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1455 // Decode Return Data
1456 MsgDecodeThreadInfo(pEvent->data, pThreadInfo);
1462 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)
1464 msg_error_t err = MSG_SUCCESS;
1466 err = MsgStoConnectDB();
1468 if (err != MSG_SUCCESS) {
1469 MSG_DEBUG("MsgStoConnectDB() Error!!");
1473 err = MsgStoGetMessageList(folderId, threadId, msgType, storageId, pMsgList);
1475 if (err != MSG_SUCCESS) {
1476 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1480 MsgStoDisconnectDB();
1486 int MsgHandle::addPushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1488 // Allocate Memory to Command Data
1489 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1491 char cmdBuf[cmdSize];
1492 bzero(cmdBuf, cmdSize);
1493 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1495 // Set Command Parameters
1496 pCmd->cmdType = MSG_CMD_ADD_PUSH_EVENT;
1499 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1501 // Copy Command Data
1502 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1504 // Send Command to Messaging FW
1505 char* pEventData = NULL;
1506 AutoPtr<char> eventBuf(&pEventData);
1508 write((char*)pCmd, cmdSize, &pEventData);
1511 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1513 if (pEvent->eventType != MSG_EVENT_ADD_PUSH_EVENT)
1515 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1518 return pEvent->result;
1522 int MsgHandle::deletePushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1524 // Allocate Memory to Command Data
1525 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1527 char cmdBuf[cmdSize];
1528 bzero(cmdBuf, cmdSize);
1529 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1531 // Set Command Parameters
1532 pCmd->cmdType = MSG_CMD_DELETE_PUSH_EVENT;
1535 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1537 // Copy Command Data
1538 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1540 // Send Command to Messaging FW
1541 char* pEventData = NULL;
1542 AutoPtr<char> eventBuf(&pEventData);
1544 write((char*)pCmd, cmdSize, &pEventData);
1547 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1549 if (pEvent->eventType != MSG_EVENT_DELETE_PUSH_EVENT)
1551 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1554 return pEvent->result;
1557 int MsgHandle::updatePushEvent(MSG_PUSH_EVENT_INFO_S *pSrc, MSG_PUSH_EVENT_INFO_S *pDst)
1559 // Allocate Memory to Command Data
1560 int cmdSize = sizeof(MSG_CMD_S) + 2 * sizeof(MSG_PUSH_EVENT_INFO_S);
1562 char cmdBuf[cmdSize];
1563 bzero(cmdBuf, cmdSize);
1564 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1566 // Set Command Parameters
1567 pCmd->cmdType = MSG_CMD_UPDATE_PUSH_EVENT;
1570 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1572 // Copy Command Data
1573 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pSrc, sizeof(MSG_PUSH_EVENT_INFO_S));
1574 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));
1576 // Send Command to Messaging FW
1577 char* pEventData = NULL;
1578 AutoPtr<char> eventBuf(&pEventData);
1580 write((char*)pCmd, cmdSize, &pEventData);
1583 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1585 if (pEvent->eventType != MSG_EVENT_UPDATE_PUSH_EVENT)
1587 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1590 return pEvent->result;
1593 msg_error_t MsgHandle::getVobject(msg_message_id_t MsgId, void** encodedData)
1595 // Allocate Memory to Command Data
1596 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1597 char *encode_data = NULL;
1598 char cmdBuf[cmdSize];
1599 bzero(cmdBuf, cmdSize);
1600 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1602 // Set Command Parameters
1603 pCmd->cmdType = MSG_CMD_GET_MSG;
1606 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1608 // Copy Command Data
1609 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
1611 // Send Command to Messaging FW
1612 char* pEventData = NULL;
1613 AutoPtr<char> eventBuf(&pEventData);
1616 write((char*)pCmd, cmdSize, &pEventData);
1619 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1621 if (pEvent->eventType != MSG_EVENT_GET_MSG)
1623 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1626 if(pEvent->result != MSG_SUCCESS)
1627 return pEvent->result;
1629 // Decode Return Data
1630 MSG_MESSAGE_INFO_S msgInfo = {0,};
1631 MSG_SENDINGOPT_INFO_S sendOptInfo = {0,};
1633 MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
1635 //Convert MSG_MESSAGE_INFO_S to
1636 encode_data = MsgVMessageEncode(&msgInfo);
1638 *encodedData = (void*)encode_data;
1640 MSG_DEBUG("Error Encode data");
1641 *encodedData = NULL;
1645 if (msgInfo.bTextSms == false)
1648 MsgDeleteFile(msgInfo.msgData); //ipc