2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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.
18 #include "MsgUtilFile.h"
19 #include "MsgCppTypes.h"
20 #include "MsgException.h"
21 #include "MsgUtilFunction.h"
22 #include "MsgProxyListener.h"
23 #include "MsgHandle.h"
25 #include "MsgStorageHandler.h"
28 /*==================================================================================================
29 IMPLEMENTATION OF MsgHandle - Storage Member Functions
30 ==================================================================================================*/
31 int MsgHandle::addMessage(const MSG_MESSAGE_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
33 MSG_MESSAGE_INFO_S msgInfo = {0};
34 MSG_SENDINGOPT_INFO_S sendOptInfo;
36 // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
37 convertMsgStruct(pMsg, &msgInfo);
39 // Covert MSG_SENDINGOPT_S to MSG_SENDINGOPT_INFO_S
40 convertSendOptStruct(pSendOpt, &sendOptInfo, pMsg->msgType);
42 // Allocate Memory to Command Data
43 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S);
46 bzero(cmdBuf, cmdSize);
47 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
49 // Set Command Parameters
50 pCmd->cmdType = MSG_CMD_ADD_MSG;
53 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
56 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
57 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), &sendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
59 // Send Command to Messaging FW
60 char* pEventData = NULL;
61 AutoPtr<char> eventBuf(&pEventData);
63 write((char*)pCmd, cmdSize, &pEventData);
66 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
68 if (pEvent->eventType != MSG_EVENT_ADD_MSG)
70 THROW(MsgException::INVALID_RESULT, "Event Data Error");
73 if (pEvent->result != MSG_SUCCESS) return pEvent->result;
75 MSG_MESSAGE_ID_T msgId = 0;
78 MsgDecodeMsgId(pEvent->data, &msgId);
84 MSG_ERROR_T MsgHandle::addSyncMLMessage(const MSG_SYNCML_MESSAGE_S *pSyncMLMsg)
86 MSG_MESSAGE_INFO_S msgInfo;
88 // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
89 convertMsgStruct((MSG_MESSAGE_S*)pSyncMLMsg->msg, &msgInfo);
91 // Allocate Memory to Command Data
92 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + sizeof(int) + sizeof(MSG_MESSAGE_INFO_S);
95 bzero(cmdBuf, cmdSize);
96 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
98 // Set Command Parameters
99 pCmd->cmdType = MSG_CMD_ADD_SYNCML_MSG;
102 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
105 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pSyncMLMsg->extId, sizeof(int));
106 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), &pSyncMLMsg->pinCode, sizeof(int));
107 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(int)), &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
109 // Send Command to Messaging FW
110 char* pEventData = NULL;
111 AutoPtr<char> eventBuf(&pEventData);
114 write((char*)pCmd, cmdSize, &pEventData);
117 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
119 if (pEvent->eventType != MSG_EVENT_ADD_SYNCML_MSG)
121 THROW(MsgException::INVALID_RESULT, "Event Data Error");
124 return pEvent->result;
128 MSG_ERROR_T MsgHandle::updateMessage(const MSG_MESSAGE_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
130 MSG_MESSAGE_INFO_S msgInfo;
131 MSG_SENDINGOPT_INFO_S sendOptInfo;
133 // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
134 convertMsgStruct(pMsg, &msgInfo);
137 convertSendOptStruct(pSendOpt, &sendOptInfo, pMsg->msgType);
139 // Allocate Memory to Command Data
140 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S) + sizeof(MSG_SENDINGOPT_INFO_S);
142 char cmdBuf[cmdSize];
143 bzero(cmdBuf, cmdSize);
144 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
146 // Set Command Parameters
147 pCmd->cmdType = MSG_CMD_UPDATE_MSG;
150 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
153 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
154 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), &sendOptInfo, sizeof(MSG_SENDINGOPT_INFO_S));
156 // Send Command to Messaging FW
157 char* pEventData = NULL;
158 AutoPtr<char> eventBuf(&pEventData);
161 write((char*)pCmd, cmdSize, &pEventData);
164 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
166 if (pEvent->eventType != MSG_EVENT_UPDATE_MSG)
168 THROW(MsgException::INVALID_RESULT, "Event Data Error");
171 return pEvent->result;
175 MSG_ERROR_T MsgHandle::updateReadStatus(MSG_MESSAGE_ID_T MsgId, bool bRead)
177 // Allocate Memory to Command Data
178 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_ID_T) + sizeof(bool);
180 char cmdBuf[cmdSize];
181 bzero(cmdBuf, cmdSize);
182 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
184 // Set Command Parameters
185 pCmd->cmdType = MSG_CMD_UPDATE_READ;
188 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
191 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(MSG_MESSAGE_ID_T));
192 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_ID_T)), &bRead, sizeof(bool));
194 // Send Command to Messaging FW
195 char* pEventData = NULL;
196 AutoPtr<char> eventBuf(&pEventData);
199 write((char*)pCmd, cmdSize, &pEventData);
202 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
204 if (pEvent->eventType != MSG_EVENT_UPDATE_READ)
206 THROW(MsgException::INVALID_RESULT, "Event Data Error");
209 return pEvent->result;
213 MSG_ERROR_T MsgHandle::updateProtectedStatus(MSG_MESSAGE_ID_T MsgId, bool bProtected)
215 // Allocate Memory to Command Data
216 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_ID_T) + sizeof(bool);
218 char cmdBuf[cmdSize];
219 bzero(cmdBuf, cmdSize);
220 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
222 // Set Command Parameters
223 pCmd->cmdType = MSG_CMD_UPDATE_PROTECTED;
226 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
229 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(MSG_MESSAGE_ID_T));
230 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_ID_T)), &bProtected, sizeof(bool));
232 // Send Command to Messaging FW
233 char* pEventData = NULL;
234 AutoPtr<char> eventBuf(&pEventData);
237 write((char*)pCmd, cmdSize, &pEventData);
240 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
242 if (pEvent->eventType != MSG_EVENT_UPDATE_PROTECTED)
244 THROW(MsgException::INVALID_RESULT, "Event Data Error");
247 return pEvent->result;
251 MSG_ERROR_T MsgHandle::deleteMessage(MSG_MESSAGE_ID_T MsgId)
253 // Allocate Memory to Command Data
254 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_ID_T);
256 char cmdBuf[cmdSize];
257 bzero(cmdBuf, cmdSize);
258 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
260 // Set Command Parameters
261 pCmd->cmdType = MSG_CMD_DELETE_MSG;
264 memcpy((void*)pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
267 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(MSG_MESSAGE_ID_T));
269 // Send Command to Messaging FW
270 char* pEventData = NULL;
271 AutoPtr<char> eventBuf(&pEventData);
274 write((char*)pCmd, cmdSize, &pEventData);
277 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
279 if (pEvent->eventType != MSG_EVENT_DELETE_MSG)
281 THROW(MsgException::INVALID_RESULT, "Event Data Error");
284 return pEvent->result;
288 MSG_ERROR_T MsgHandle::deleteAllMessagesInFolder(MSG_FOLDER_ID_T FolderId, bool bOnlyDB)
290 // Allocate Memory to Command Data
291 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_ID_T);
293 char cmdBuf[cmdSize];
294 bzero(cmdBuf, cmdSize);
295 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
297 // Set Command Parameters
298 pCmd->cmdType = MSG_CMD_DELALL_MSGINFOLDER;
301 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
304 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(MSG_FOLDER_ID_T));
305 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_FOLDER_ID_T)), &bOnlyDB, sizeof(bool));
307 // Send Command to Messaging FW
308 char* pEventData = NULL;
309 AutoPtr<char> eventBuf(&pEventData);
312 write((char*)pCmd, cmdSize, &pEventData);
315 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
317 if (pEvent->eventType != MSG_EVENT_DELALL_MSGINFOLDER)
319 THROW(MsgException::INVALID_RESULT, "Event Data Error");
322 return pEvent->result;
326 MSG_ERROR_T MsgHandle::moveMessageToFolder(MSG_MESSAGE_ID_T MsgId, MSG_FOLDER_ID_T DestFolderId)
328 // Allocate Memory to Command Data
329 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_ID_T) + sizeof(MSG_FOLDER_ID_T);
331 char cmdBuf[cmdSize];
332 bzero(cmdBuf, cmdSize);
333 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
335 // Set Command Parameters
336 pCmd->cmdType = MSG_CMD_MOVE_MSGTOFOLDER;
339 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
342 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(MSG_MESSAGE_ID_T));
343 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(MSG_MESSAGE_ID_T)+MAX_COOKIE_LEN), &DestFolderId, sizeof(MSG_FOLDER_ID_T));
345 // Send Command to Messaging FW
346 char* pEventData = NULL;
347 AutoPtr<char> eventBuf(&pEventData);
350 write((char*)pCmd, cmdSize, &pEventData);
353 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
355 if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOFOLDER)
357 THROW(MsgException::INVALID_RESULT, "Event Data Error");
360 return pEvent->result;
364 MSG_ERROR_T MsgHandle::moveMessageToStorage(MSG_MESSAGE_ID_T MsgId, MSG_STORAGE_ID_T DestStorageId)
366 // Allocate Memory to Command Data
367 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_ID_T) + sizeof(MSG_STORAGE_ID_T);
369 char cmdBuf[cmdSize];
370 bzero(cmdBuf, cmdSize);
371 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
373 // Set Command Parameters
374 pCmd->cmdType = MSG_CMD_MOVE_MSGTOSTORAGE;
377 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
380 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(MSG_MESSAGE_ID_T));
381 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_ID_T)), &DestStorageId, sizeof(MSG_STORAGE_ID_T));
383 // Send Command to Messaging FW
384 char* pEventData = NULL;
385 AutoPtr<char> eventBuf(&pEventData);
388 write((char*)pCmd, cmdSize, &pEventData);
391 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
393 if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOSTORAGE)
395 THROW(MsgException::INVALID_RESULT, "Event Data Error");
398 return pEvent->result;
402 MSG_ERROR_T MsgHandle::countMessage(MSG_FOLDER_ID_T FolderId, MSG_COUNT_INFO_S *pCountInfo)
404 // Allocate Memory to Command Data
405 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_ID_T);
407 char cmdBuf[cmdSize];
408 bzero(cmdBuf, cmdSize);
409 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
411 // Set Command Parameters
412 pCmd->cmdType = MSG_CMD_COUNT_MSG;
415 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
418 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(MSG_FOLDER_ID_T));
420 // Send Command to Messaging FW
421 char* pEventData = NULL;
422 AutoPtr<char> eventBuf(&pEventData);
425 write((char*)pCmd, cmdSize, &pEventData);
428 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
430 if (pEvent->eventType != MSG_EVENT_COUNT_MSG)
432 THROW(MsgException::INVALID_RESULT, "Event Data Error");
435 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
437 // Decode Return Data
438 MsgDecodeCountInfo(pEvent->data, pCountInfo);
444 MSG_ERROR_T MsgHandle::countMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount)
446 // Allocate Memory to Command Data
447 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_TYPE_S);
449 char cmdBuf[cmdSize];
450 bzero(cmdBuf, cmdSize);
451 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
453 // Set Command Parameters
454 pCmd->cmdType = MSG_CMD_COUNT_BY_MSGTYPE;
457 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
460 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pMsgType, sizeof(MSG_MESSAGE_TYPE_S));
462 // Send Command to Messaging FW
463 char* pEventData = NULL;
464 AutoPtr<char> eventBuf(&pEventData);
466 write((char*)pCmd, cmdSize, &pEventData);
469 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
471 if (pEvent->eventType != MSG_EVENT_COUNT_BY_MSGTYPE)
473 THROW(MsgException::INVALID_RESULT, "Event Data Error");
476 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
478 // Decode Return Data
479 memcpy(pMsgCount, (void*)((char*)pEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(MSG_ERROR_T)), sizeof(int));
485 MSG_ERROR_T MsgHandle::countMsgByContact(const MSG_THREAD_LIST_INDEX_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
487 // Allocate Memory to Command Data
488 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_THREAD_LIST_INDEX_S);
490 char cmdBuf[cmdSize];
491 bzero(cmdBuf, cmdSize);
492 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
494 // Set Command Parameters
495 pCmd->cmdType = MSG_CMD_GET_CONTACT_COUNT;
498 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
501 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pAddrInfo, sizeof(MSG_THREAD_LIST_INDEX_S));
503 // Send Command to Messaging FW
504 char* pEventData = NULL;
505 AutoPtr<char> eventBuf(&pEventData);
507 write((char*)pCmd, cmdSize, &pEventData);
510 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
512 if (pEvent->eventType != MSG_EVENT_GET_CONTACT_COUNT)
514 THROW(MsgException::INVALID_RESULT, "Event Data Error");
517 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
519 // Decode Return Data
520 MsgDecodeContactCount(pEvent->data, pMsgThreadCountList);
526 MSG_ERROR_T MsgHandle::getMessage(MSG_MESSAGE_ID_T MsgId, MSG_MESSAGE_S *pMsg, MSG_SENDINGOPT_S *pSendOpt)
528 // Allocate Memory to Command Data
529 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_ID_T);
531 char cmdBuf[cmdSize];
532 bzero(cmdBuf, cmdSize);
533 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
535 // Set Command Parameters
536 pCmd->cmdType = MSG_CMD_GET_MSG;
539 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
542 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(MSG_MESSAGE_ID_T));
544 // Send Command to Messaging FW
545 char* pEventData = NULL;
546 AutoPtr<char> eventBuf(&pEventData);
549 write((char*)pCmd, cmdSize, &pEventData);
552 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
554 if (pEvent->eventType != MSG_EVENT_GET_MSG)
556 THROW(MsgException::INVALID_RESULT, "Event Data Error");
559 if(pEvent->result != MSG_SUCCESS)
560 return pEvent->result;
562 // Decode Return Data
563 MSG_MESSAGE_INFO_S msgInfo;
564 MSG_SENDINGOPT_INFO_S sendOptInfo;
565 MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
567 // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_S
568 convertMsgStruct(&msgInfo, pMsg);
571 convertSendOptStruct(&sendOptInfo, pSendOpt, pMsg->msgType);
574 if (msgInfo.bTextSms == false)
577 MsgDeleteFile(msgInfo.msgData); //ipc
584 MSG_ERROR_T MsgHandle::getFolderViewList(MSG_FOLDER_ID_T FolderId, const MSG_SORT_RULE_S *pSortRule, MSG_LIST_S *pMsgFolderViewList)
586 MSG_ERROR_T err = MSG_SUCCESS;
588 err = MsgStoConnectDB();
590 if (err != MSG_SUCCESS)
592 MSG_DEBUG("MsgStoConnectDB() Error!!");
596 err = MsgStoGetFolderViewList(FolderId, (MSG_SORT_RULE_S *)pSortRule, pMsgFolderViewList);
598 if (err != MSG_SUCCESS)
600 MSG_DEBUG("MsgStoGetFolderViewList() Error!!");
604 MsgStoDisconnectDB();
610 MSG_ERROR_T MsgHandle::addFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
612 // Allocate Memory to Command Data
613 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
615 char cmdBuf[cmdSize];
616 bzero(cmdBuf, cmdSize);
617 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
619 // Set Command Parameters
620 pCmd->cmdType = MSG_CMD_ADD_FOLDER;
623 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
626 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
628 // Send Command to Messaging FW
629 char* pEventData = NULL;
630 AutoPtr<char> eventBuf(&pEventData);
633 write((char*)pCmd, cmdSize, &pEventData);
636 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
638 if (pEvent->eventType != MSG_EVENT_ADD_FOLDER)
640 THROW(MsgException::INVALID_RESULT, "Event Data Error");
643 return pEvent->result;
647 MSG_ERROR_T MsgHandle::updateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
649 // Allocate Memory to Command Data
650 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
652 char cmdBuf[cmdSize];
653 bzero(cmdBuf, cmdSize);
654 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
656 // Set Command Parameters
657 pCmd->cmdType = MSG_CMD_UPDATE_FOLDER;
660 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
663 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
665 // Send Command to Messaging FW
666 char* pEventData = NULL;
667 AutoPtr<char> eventBuf(&pEventData);
670 write((char*)pCmd, cmdSize, &pEventData);
673 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
675 if (pEvent->eventType != MSG_EVENT_UPDATE_FOLDER)
677 THROW(MsgException::INVALID_RESULT, "Event Data Error");
680 return pEvent->result;;
684 MSG_ERROR_T MsgHandle::deleteFolder(MSG_FOLDER_ID_T FolderId)
686 // Allocate Memory to Command Data
687 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_ID_T);
689 char cmdBuf[cmdSize];
690 bzero(cmdBuf, cmdSize);
691 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
693 // Set Command Parameters
694 pCmd->cmdType = MSG_CMD_DELETE_FOLDER;
697 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
700 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(MSG_FOLDER_ID_T));
702 // Send Command to Messaging FW
703 char* pEventData = NULL;
704 AutoPtr<char> eventBuf(&pEventData);
707 write((char*)pCmd, cmdSize, &pEventData);
710 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
712 if (pEvent->eventType != MSG_EVENT_DELETE_FOLDER)
714 THROW(MsgException::INVALID_RESULT, "Event Data Error");
717 return pEvent->result;
721 MSG_ERROR_T MsgHandle::getFolderList(MSG_FOLDER_LIST_S *pFolderList)
723 // Allocate Memory to Command Data
724 int cmdSize = sizeof(MSG_CMD_S);
726 char cmdBuf[cmdSize];
727 bzero(cmdBuf, cmdSize);
728 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
730 // Set Command Parameters
731 pCmd->cmdType = MSG_CMD_GET_FOLDERLIST;
734 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
736 // Send Command to Messaging FW
737 char* pEventData = NULL;
738 AutoPtr<char> eventBuf(&pEventData);
740 write((char*)pCmd, cmdSize, &pEventData);
743 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
745 if (pEvent->eventType != MSG_EVENT_GET_FOLDERLIST)
747 THROW(MsgException::INVALID_RESULT, "Event Data Error");
750 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
752 // Decode Return Data
753 MsgDecodeFolderList(pEvent->data, pFolderList);
759 MSG_ERROR_T MsgHandle::getThreadViewList(const MSG_SORT_RULE_S *pSortRule, MSG_THREAD_VIEW_LIST_S *pThreadViewList)
761 MSG_ERROR_T err = MSG_SUCCESS;
763 err = MsgStoConnectDB();
765 if (err != MSG_SUCCESS)
767 MSG_DEBUG("MsgStoConnectDB() Error!!");
771 err = MsgStoGetThreadViewList(pSortRule, pThreadViewList);
773 if (err != MSG_SUCCESS)
775 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
779 MsgStoDisconnectDB();
785 MSG_ERROR_T MsgHandle::getConversationViewList(MSG_THREAD_ID_T ThreadId, MSG_LIST_S *pConvViewList)
789 MSG_ERROR_T err = MSG_SUCCESS;
792 err = MsgStoGetConversationViewList(ThreadId, pConvViewList);
793 MsgStoDisconnectDB();
795 if(err != MSG_SUCCESS)
799 // Update Read Status for the Thead ID
800 // Allocate Memory to Command Data
801 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_THREAD_ID_T);
803 char cmdBuf[cmdSize];
804 bzero(cmdBuf, cmdSize);
805 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
807 // Set Command Parameters
808 pCmd->cmdType = MSG_CMD_UPDATE_THREAD_READ;
811 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
814 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(MSG_THREAD_ID_T));
816 // Send Command to Messaging FW
817 char* pEventData = NULL;
818 AutoPtr<char> eventBuf(&pEventData);
820 write((char*)pCmd, cmdSize, &pEventData);
823 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
825 if (pEvent->eventType != MSG_EVENT_UPDATE_THREAD_READ)
827 THROW(MsgException::INVALID_RESULT, "Event Data Error");
836 MSG_ERROR_T MsgHandle::deleteThreadMessageList(MSG_THREAD_ID_T ThreadId)
838 // Allocate Memory to Command Data
839 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_THREAD_LIST_INDEX_S);
841 char cmdBuf[cmdSize];
842 bzero(cmdBuf, cmdSize);
843 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
845 // Set Command Parameters
846 pCmd->cmdType = MSG_CMD_DELETE_THREADMESSAGELIST;
849 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
852 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(MSG_THREAD_ID_T));
854 // Send Command to Messaging FW
855 char* pEventData = NULL;
856 AutoPtr<char> eventBuf(&pEventData);
859 write((char*)pCmd, cmdSize, &pEventData);
862 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
864 if (pEvent->eventType != MSG_EVENT_DELETE_THREADMESSAGELIST)
866 THROW(MsgException::INVALID_RESULT, "Event Data Error");
869 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
875 MSG_ERROR_T MsgHandle::getQuickPanelData(MSG_QUICKPANEL_TYPE_T Type, MSG_MESSAGE_S *pMsg)
877 // Allocate Memory to Command Data
878 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_QUICKPANEL_TYPE_T);
880 char cmdBuf[cmdSize];
881 bzero(cmdBuf, cmdSize);
882 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
884 // Set Command Parameters
885 pCmd->cmdType = MSG_CMD_GET_QUICKPANEL_DATA;
888 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
891 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &Type, sizeof(MSG_QUICKPANEL_TYPE_T));
893 // Send Command to Messaging FW
894 char* pEventData = NULL;
895 AutoPtr<char> eventBuf(&pEventData);
897 write((char*)pCmd, cmdSize, &pEventData);
900 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
902 if (pEvent->eventType != MSG_EVENT_GET_QUICKPANEL_DATA)
904 THROW(MsgException::INVALID_RESULT, "Event Data Error");
907 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
909 // Decode Return Data
910 MSG_MESSAGE_INFO_S msgInfo;
912 memcpy(&msgInfo, (void*)((char*)pEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(MSG_ERROR_T)), sizeof(MSG_MESSAGE_INFO_S));
914 // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_S
915 convertMsgStruct(&msgInfo, pMsg);
918 if (msgInfo.bTextSms == false)
921 MsgDeleteFile(msgInfo.msgData); //ipc
928 MSG_ERROR_T MsgHandle::resetDatabase()
930 // Allocate Memory to Command Data
931 int cmdSize = sizeof(MSG_CMD_S);
933 char cmdBuf[cmdSize];
934 bzero(cmdBuf, cmdSize);
935 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
937 // Set Command Parameters
938 pCmd->cmdType = MSG_CMD_RESET_DB;
941 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
943 // Send Command to Messaging FW
944 char* pEventData = NULL;
945 AutoPtr<char> eventBuf(&pEventData);
947 write((char*)pCmd, cmdSize, &pEventData);
950 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
952 if (pEvent->eventType != MSG_EVENT_RESET_DB)
954 THROW(MsgException::INVALID_RESULT, "Event Data Error");
957 return pEvent->result;
961 MSG_ERROR_T MsgHandle::getMemSize(unsigned int* memsize)
963 // Allocate Memory to Command Data
964 int cmdSize = sizeof(MSG_CMD_S);
966 char cmdBuf[cmdSize];
967 bzero(cmdBuf, cmdSize);
968 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
970 // Set Command Parameters
971 pCmd->cmdType = MSG_CMD_GET_MEMSIZE;
974 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
976 // Send Command to Messaging FW
977 char* pEventData = NULL;
978 AutoPtr<char> eventBuf(&pEventData);
981 write((char*)pCmd, cmdSize, &pEventData);
984 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
986 if (pEvent->eventType != MSG_EVENT_GET_MEMSIZE)
988 THROW(MsgException::INVALID_RESULT, "Event Data Error");
991 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
993 // Decode Return Data
994 MsgDecodeMemSize(pEvent->data, memsize);
1000 MSG_ERROR_T MsgHandle::searchMessage(const char *pSearchString, MSG_THREAD_VIEW_LIST_S *pThreadViewList)
1002 MSG_ERROR_T err = MSG_SUCCESS;
1004 err = MsgStoConnectDB();
1006 if (err != MSG_SUCCESS)
1008 MSG_DEBUG("MsgStoConnectDB() Error!!");
1012 err = MsgStoSearchMessage(pSearchString, pThreadViewList);
1014 if (err != MSG_SUCCESS)
1016 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1020 MsgStoDisconnectDB();
1026 MSG_ERROR_T MsgHandle::searchMessage(const MSG_SEARCH_CONDITION_S *pSearchCon, int offset, int limit, MSG_LIST_S *pMsgList)
1028 MSG_ERROR_T err = MSG_SUCCESS;
1030 err = MsgStoConnectDB();
1032 if (err != MSG_SUCCESS) {
1033 MSG_DEBUG("MsgStoConnectDB() Error!!");
1037 err = MsgStoSearchMessage(pSearchCon, offset, limit, pMsgList);
1039 if (err != MSG_SUCCESS) {
1040 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1044 MsgStoDisconnectDB();
1051 MSG_ERROR_T MsgHandle::getMsgIdList(MSG_REFERENCE_ID_T RefId, MSG_MSGID_LIST_S *pMsgIdList)
1053 MSG_ERROR_T err = MSG_SUCCESS;
1055 err = MsgStoConnectDB();
1057 if (err != MSG_SUCCESS)
1059 MSG_DEBUG("MsgStoConnectDB() Error!!");
1063 err = MsgStoGetMsgIdList(RefId, pMsgIdList);
1065 if (err != MSG_SUCCESS)
1067 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1071 MsgStoDisconnectDB();
1077 MSG_ERROR_T MsgHandle::getRejectMsgList(const char *pNumber, MSG_REJECT_MSG_LIST_S *pRejectMsgList)
1079 MSG_ERROR_T err = MSG_SUCCESS;
1081 err = MsgStoConnectDB();
1083 if (err != MSG_SUCCESS)
1085 MSG_DEBUG("MsgStoConnectDB() Error!!");
1089 err = MsgStoGetRejectMsgList(pNumber, pRejectMsgList);
1091 if (err != MSG_SUCCESS)
1093 MSG_DEBUG("MsgStoGetRejectMsgList() Error!!");
1097 MsgStoDisconnectDB();
1103 MSG_ERROR_T MsgHandle::regStorageChangeCallback(msg_storage_change_cb onStorageChange, void *pUserParam)
1105 if (!onStorageChange)
1106 THROW(MsgException::INVALID_PARAM, "onStorageChange is null");
1108 MsgProxyListener* eventListener = MsgProxyListener::instance();
1110 eventListener->start();
1112 if (eventListener->regStorageChangeEventCB(this, onStorageChange, pUserParam) == false) // callback was already registered, just return SUCCESS
1115 // Allocate Memory to Command Data
1116 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
1117 char cmdBuf[cmdSize];
1118 bzero(cmdBuf, cmdSize);
1119 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
1121 // Set Command Parameters
1122 pCmd->cmdType = MSG_CMD_REG_STORAGE_CHANGE_CB;
1125 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1127 int listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
1129 MSG_DEBUG("remote fd %d", listenerFd);
1131 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &listenerFd, sizeof(listenerFd));
1133 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), listenerFd);
1135 // Send Command to Messaging FW
1136 char* pEventData = NULL;
1137 AutoPtr<char> eventBuf(&pEventData);
1139 write((char*)pCmd, cmdSize, &pEventData);
1142 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1144 if (pEvent->eventType != MSG_EVENT_REG_STORAGE_CHANGE_CB)
1146 THROW(MsgException::INVALID_PARAM, "Event Data Error");
1149 return pEvent->result;
1153 MSG_ERROR_T MsgHandle::getReportStatus(MSG_MESSAGE_ID_T msg_id, MSG_REPORT_STATUS_INFO_S *pReport_status)
1155 // Allocate Memory to Command Data
1156 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_ID_T);
1158 char cmdBuf[cmdSize];
1159 bzero(cmdBuf, cmdSize);
1160 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1162 // Set Command Parameters
1163 pCmd->cmdType = MSG_CMD_GET_REPORT_STATUS;
1166 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1168 // Copy Command Data
1169 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msg_id, sizeof(MSG_MESSAGE_ID_T));
1171 // Send Command to Messaging FW
1172 char* pEventData = NULL;
1173 AutoPtr<char> eventBuf(&pEventData);
1176 write((char*)pCmd, cmdSize, &pEventData);
1179 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1181 if (pEvent->eventType != MSG_EVENT_GET_REPORT_STATUS)
1183 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1186 if(pEvent->result != MSG_SUCCESS) return pEvent->result;
1188 // Decode Return Data
1189 MsgDecodeReportStatus(pEvent->data, pReport_status);