2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
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 "MsgVMessage.h"
26 /*==================================================================================================
27 IMPLEMENTATION OF MsgHandle - Storage Member Functions
28 ==================================================================================================*/
29 int MsgHandle::addMessage(MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
31 MSG_MESSAGE_INFO_S msgInfo = {0,};
32 MSG_SENDINGOPT_INFO_S sendOptInfo = {0,};
34 msgInfo.addressList = NULL;
35 AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
37 // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
38 convertMsgStruct(pMsg, &msgInfo);
40 // Covert MSG_SENDINGOPT_S to MSG_SENDINGOPT_INFO_S
41 MSG_MESSAGE_TYPE_S msgType = {0,};
43 msgType.mainType = pMsg->mainType;
44 msgType.subType = pMsg->subType;
45 msgType.classType = pMsg->classType;
47 convertSendOptStruct(pSendOpt, &sendOptInfo, msgType);
49 // Allocate Memory to Command Data
50 char* encodedData = NULL;
51 AutoPtr<char> buf(&encodedData);
52 int dataSize = MsgEncodeMsgInfo(&msgInfo, &sendOptInfo, &encodedData);
54 int cmdSize = sizeof(MSG_CMD_S) + dataSize;
57 bzero(cmdBuf, cmdSize);
58 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
60 // Set Command Parameters
61 pCmd->cmdType = MSG_CMD_ADD_MSG;
64 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
67 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), encodedData, dataSize);
69 // Send Command to Messaging FW
70 char* pEventData = NULL;
71 AutoPtr<char> eventBuf(&pEventData);
73 write((char*)pCmd, cmdSize, &pEventData);
76 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
79 THROW(MsgException::INVALID_RESULT, "Event is NULL");
81 if (pEvent->eventType != MSG_EVENT_ADD_MSG)
83 THROW(MsgException::INVALID_RESULT, "Event Data Error");
86 if (pEvent->result != MSG_SUCCESS)
87 return pEvent->result;
89 msg_message_id_t msgId = 0;
92 MsgDecodeMsgId(pEvent->data, &msgId);
98 msg_error_t MsgHandle::addSyncMLMessage(const MSG_SYNCML_MESSAGE_S *pSyncMLMsg)
100 MSG_MESSAGE_INFO_S msgInfo;
101 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
103 msgInfo.addressList = NULL;
104 AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
106 // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
107 msg_struct_s *msg = (msg_struct_s *)pSyncMLMsg->msg;
108 convertMsgStruct((MSG_MESSAGE_HIDDEN_S *)msg->data, &msgInfo);
110 // Allocate Memory to Command Data
111 char* encodedData = NULL;
112 AutoPtr<char> buf(&encodedData);
113 int dataSize = MsgEncodeMsgInfo(&msgInfo, &encodedData);
115 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + sizeof(int) + dataSize;
117 char cmdBuf[cmdSize];
118 bzero(cmdBuf, cmdSize);
119 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
121 // Set Command Parameters
122 pCmd->cmdType = MSG_CMD_ADD_SYNCML_MSG;
125 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
128 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pSyncMLMsg->extId, sizeof(int));
129 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), &pSyncMLMsg->pinCode, sizeof(int));
130 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(int)), encodedData, dataSize);
132 // Send Command to Messaging FW
133 char* pEventData = NULL;
134 AutoPtr<char> eventBuf(&pEventData);
137 write((char*)pCmd, cmdSize, &pEventData);
140 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
143 THROW(MsgException::INVALID_RESULT, "Event is NULL");
145 if (pEvent->eventType != MSG_EVENT_ADD_SYNCML_MSG)
147 THROW(MsgException::INVALID_RESULT, "Event Data Error");
150 msg_message_id_t msgId = 0;
152 // Decode Return Data
153 MsgDecodeMsgId(pEvent->data, &msgId);
155 ((MSG_MESSAGE_HIDDEN_S *)msg->data)->msgId = msgId;
157 return pEvent->result;
161 msg_error_t MsgHandle::updateMessage(const MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
163 MSG_MESSAGE_INFO_S msgInfo = {0, };
164 MSG_SENDINGOPT_INFO_S sendOptInfo = {0, };
166 msgInfo.addressList = NULL;
167 AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
169 // Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
170 convertMsgStruct(pMsg, &msgInfo);
172 if (pSendOpt != NULL) {
173 MSG_MESSAGE_TYPE_S msgType = {0,};
175 msgType.mainType = pMsg->mainType;
176 msgType.subType = pMsg->subType;
177 msgType.classType = pMsg->classType;
179 convertSendOptStruct(pSendOpt, &sendOptInfo, msgType);
182 // Allocate Memory to Command Data
183 char* encodedData = NULL;
184 AutoPtr<char> buf(&encodedData);
185 int dataSize = MsgEncodeMsgInfo(&msgInfo, &sendOptInfo, &encodedData);
187 int cmdSize = sizeof(MSG_CMD_S) + dataSize;
189 char cmdBuf[cmdSize];
190 bzero(cmdBuf, cmdSize);
191 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
193 // Set Command Parameters
194 pCmd->cmdType = MSG_CMD_UPDATE_MSG;
197 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
200 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), encodedData, dataSize);
202 // Send Command to Messaging FW
203 char* pEventData = NULL;
204 AutoPtr<char> eventBuf(&pEventData);
206 write((char*)pCmd, cmdSize, &pEventData);
209 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
212 THROW(MsgException::INVALID_RESULT, "Event is NULL");
214 if (pEvent->eventType != MSG_EVENT_UPDATE_MSG)
216 THROW(MsgException::INVALID_RESULT, "Event Data Error");
219 return pEvent->result;
223 msg_error_t MsgHandle::updateReadStatus(msg_message_id_t MsgId, bool bRead)
225 // Allocate Memory to Command Data
226 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(bool);
228 char cmdBuf[cmdSize];
229 bzero(cmdBuf, cmdSize);
230 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
232 // Set Command Parameters
233 pCmd->cmdType = MSG_CMD_UPDATE_READ;
236 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
239 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
240 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &bRead, sizeof(bool));
242 // Send Command to Messaging FW
243 char* pEventData = NULL;
244 AutoPtr<char> eventBuf(&pEventData);
246 write((char*)pCmd, cmdSize, &pEventData);
249 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
252 THROW(MsgException::INVALID_RESULT, "Event is NULL");
254 if (pEvent->eventType != MSG_EVENT_UPDATE_READ)
256 THROW(MsgException::INVALID_RESULT, "Event Data Error");
259 return pEvent->result;
263 msg_error_t MsgHandle::setConversationToRead(msg_thread_id_t ThreadId)
265 // Allocate Memory to Command Data
266 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
268 char cmdBuf[cmdSize];
269 bzero(cmdBuf, cmdSize);
270 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
272 // Set Command Parameters
273 pCmd->cmdType = MSG_CMD_UPDATE_THREAD_READ;
276 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
279 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
281 // Send Command to Messaging FW
282 char* pEventData = NULL;
283 AutoPtr<char> eventBuf(&pEventData);
285 write((char*)pCmd, cmdSize, &pEventData);
288 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
291 THROW(MsgException::INVALID_RESULT, "Event is NULL");
293 if (pEvent->eventType != MSG_EVENT_UPDATE_THREAD_READ)
295 THROW(MsgException::INVALID_RESULT, "Event Data Error");
298 return pEvent->result;
302 msg_error_t MsgHandle::updateProtectedStatus(msg_message_id_t MsgId, bool bProtected)
304 // Allocate Memory to Command Data
305 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(bool);
307 char cmdBuf[cmdSize];
308 bzero(cmdBuf, cmdSize);
309 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
311 // Set Command Parameters
312 pCmd->cmdType = MSG_CMD_UPDATE_PROTECTED;
315 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
318 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
319 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &bProtected, sizeof(bool));
321 // Send Command to Messaging FW
322 char* pEventData = NULL;
323 AutoPtr<char> eventBuf(&pEventData);
325 write((char*)pCmd, cmdSize, &pEventData);
328 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
331 THROW(MsgException::INVALID_RESULT, "Event is NULL");
333 if (pEvent->eventType != MSG_EVENT_UPDATE_PROTECTED)
335 THROW(MsgException::INVALID_RESULT, "Event Data Error");
338 return pEvent->result;
342 msg_error_t MsgHandle::deleteMessage(msg_message_id_t MsgId)
344 // Allocate Memory to Command Data
345 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
347 char cmdBuf[cmdSize];
348 bzero(cmdBuf, cmdSize);
349 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
351 // Set Command Parameters
352 pCmd->cmdType = MSG_CMD_DELETE_MSG;
355 memcpy((void*)pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
358 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
360 // Send Command to Messaging FW
361 char* pEventData = NULL;
362 AutoPtr<char> eventBuf(&pEventData);
364 write((char*)pCmd, cmdSize, &pEventData);
367 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
370 THROW(MsgException::INVALID_RESULT, "Event is NULL");
372 if (pEvent->eventType != MSG_EVENT_DELETE_MSG)
374 THROW(MsgException::INVALID_RESULT, "Event Data Error");
377 return pEvent->result;
381 msg_error_t MsgHandle::deleteAllMessagesInFolder(msg_folder_id_t FolderId, bool bOnlyDB)
383 // Allocate Memory to Command Data
384 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
386 char cmdBuf[cmdSize];
387 bzero(cmdBuf, cmdSize);
388 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
390 // Set Command Parameters
391 pCmd->cmdType = MSG_CMD_DELALL_MSGINFOLDER;
394 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
397 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
398 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_folder_id_t)), &bOnlyDB, sizeof(bool));
400 // Send Command to Messaging FW
401 char* pEventData = NULL;
402 AutoPtr<char> eventBuf(&pEventData);
404 write((char*)pCmd, cmdSize, &pEventData);
407 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
410 THROW(MsgException::INVALID_RESULT, "Event is NULL");
412 if (pEvent->eventType != MSG_EVENT_DELALL_MSGINFOLDER)
414 THROW(MsgException::INVALID_RESULT, "Event Data Error");
417 return pEvent->result;
421 msg_error_t MsgHandle::deleteMessagesByList(msg_id_list_s *pMsgIdList)
423 // Allocate Memory to Command Data
424 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + (sizeof(int)*pMsgIdList->nCount);
426 char cmdBuf[cmdSize];
427 bzero(cmdBuf, cmdSize);
428 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
430 // Set Command Parameters
431 pCmd->cmdType = MSG_CMD_DELETE_MESSAGE_BY_LIST;
434 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
437 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &(pMsgIdList->nCount), sizeof(int));
438 for (int i=0; i<pMsgIdList->nCount; i++) {
439 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+(sizeof(int)*i)), &(pMsgIdList->msgIdList[i]), sizeof(int));
442 // Send Command to Messaging FW
443 char* pEventData = NULL;
444 AutoPtr<char> eventBuf(&pEventData);
446 write((char*)pCmd, cmdSize, &pEventData);
449 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
452 THROW(MsgException::INVALID_RESULT, "Event is NULL");
454 if (pEvent->eventType != MSG_EVENT_DELETE_MESSAGE_BY_LIST) {
455 THROW(MsgException::INVALID_RESULT, "Event Data Error");
458 return pEvent->result;
462 msg_error_t MsgHandle::moveMessageToFolder(msg_message_id_t MsgId, msg_folder_id_t DestFolderId)
464 // Allocate Memory to Command Data
465 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(msg_folder_id_t);
467 char cmdBuf[cmdSize];
468 bzero(cmdBuf, cmdSize);
469 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
471 // Set Command Parameters
472 pCmd->cmdType = MSG_CMD_MOVE_MSGTOFOLDER;
475 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
478 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
479 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(msg_message_id_t)+MAX_COOKIE_LEN), &DestFolderId, sizeof(msg_folder_id_t));
481 // Send Command to Messaging FW
482 char* pEventData = NULL;
483 AutoPtr<char> eventBuf(&pEventData);
485 write((char*)pCmd, cmdSize, &pEventData);
488 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
491 THROW(MsgException::INVALID_RESULT, "Event is NULL");
493 if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOFOLDER)
495 THROW(MsgException::INVALID_RESULT, "Event Data Error");
498 return pEvent->result;
502 msg_error_t MsgHandle::moveMessageToStorage(msg_message_id_t MsgId, msg_storage_id_t DestStorageId)
504 // Allocate Memory to Command Data
505 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(msg_storage_id_t);
507 char cmdBuf[cmdSize];
508 bzero(cmdBuf, cmdSize);
509 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
511 // Set Command Parameters
512 pCmd->cmdType = MSG_CMD_MOVE_MSGTOSTORAGE;
515 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
518 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
519 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &DestStorageId, sizeof(msg_storage_id_t));
521 // Send Command to Messaging FW
522 char* pEventData = NULL;
523 AutoPtr<char> eventBuf(&pEventData);
525 write((char*)pCmd, cmdSize, &pEventData);
528 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
531 THROW(MsgException::INVALID_RESULT, "Event is NULL");
533 if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOSTORAGE)
535 THROW(MsgException::INVALID_RESULT, "Event Data Error");
538 return pEvent->result;
542 msg_error_t MsgHandle::countMessage(msg_folder_id_t FolderId, MSG_COUNT_INFO_S *pCountInfo)
544 // Allocate Memory to Command Data
545 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
547 char cmdBuf[cmdSize];
548 bzero(cmdBuf, cmdSize);
549 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
551 // Set Command Parameters
552 pCmd->cmdType = MSG_CMD_COUNT_MSG;
555 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
558 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
560 // Send Command to Messaging FW
561 char* pEventData = NULL;
562 AutoPtr<char> eventBuf(&pEventData);
564 write((char*)pCmd, cmdSize, &pEventData);
567 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
570 THROW(MsgException::INVALID_RESULT, "Event is NULL");
572 if (pEvent->eventType != MSG_EVENT_COUNT_MSG)
574 THROW(MsgException::INVALID_RESULT, "Event Data Error");
577 if (pEvent->result != MSG_SUCCESS)
578 return pEvent->result;
580 // Decode Return Data
581 MsgDecodeCountInfo(pEvent->data, pCountInfo);
587 msg_error_t MsgHandle::countMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount)
589 // Allocate Memory to Command Data
590 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_TYPE_S);
592 char cmdBuf[cmdSize];
593 bzero(cmdBuf, cmdSize);
594 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
596 // Set Command Parameters
597 pCmd->cmdType = MSG_CMD_COUNT_BY_MSGTYPE;
600 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
603 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pMsgType, sizeof(MSG_MESSAGE_TYPE_S));
605 // Send Command to Messaging FW
606 char* pEventData = NULL;
607 AutoPtr<char> eventBuf(&pEventData);
609 write((char*)pCmd, cmdSize, &pEventData);
612 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
615 THROW(MsgException::INVALID_RESULT, "Event is NULL");
617 if (pEvent->eventType != MSG_EVENT_COUNT_BY_MSGTYPE)
619 THROW(MsgException::INVALID_RESULT, "Event Data Error");
622 if (pEvent->result != MSG_SUCCESS)
623 return pEvent->result;
625 // Decode Return Data
626 memcpy(pMsgCount, (void*)((char*)pEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(int));
632 msg_error_t MsgHandle::countMsgByContact(const MSG_THREAD_LIST_INDEX_INFO_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
634 // Allocate Memory to Command Data
635 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_THREAD_LIST_INDEX_S);
637 char cmdBuf[cmdSize];
638 bzero(cmdBuf, cmdSize);
639 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
641 // Set Command Parameters
642 pCmd->cmdType = MSG_CMD_GET_CONTACT_COUNT;
645 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
648 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pAddrInfo, sizeof(msg_contact_id_t));
649 msg_struct_s *pAddr = (msg_struct_s *)pAddrInfo->msgAddrInfo;
651 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN + sizeof(msg_contact_id_t)), pAddr->data, sizeof(MSG_ADDRESS_INFO_S));
652 // Send Command to Messaging FW
653 char* pEventData = NULL;
654 AutoPtr<char> eventBuf(&pEventData);
656 write((char*)pCmd, cmdSize, &pEventData);
659 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
662 THROW(MsgException::INVALID_RESULT, "Event is NULL");
664 if (pEvent->eventType != MSG_EVENT_GET_CONTACT_COUNT)
666 THROW(MsgException::INVALID_RESULT, "Event Data Error");
669 if (pEvent->result != MSG_SUCCESS)
670 return pEvent->result;
672 // Decode Return Data
673 MsgDecodeContactCount(pEvent->data, pMsgThreadCountList);
679 msg_error_t MsgHandle::getMessage(msg_message_id_t MsgId, MSG_MESSAGE_HIDDEN_S *pMsg, MSG_SENDINGOPT_S *pSendOpt)
681 // Allocate Memory to Command Data
682 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
684 char cmdBuf[cmdSize];
685 bzero(cmdBuf, cmdSize);
686 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
688 // Set Command Parameters
689 pCmd->cmdType = MSG_CMD_GET_MSG;
692 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
695 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
697 // Send Command to Messaging FW
698 char* pEventData = NULL;
699 AutoPtr<char> eventBuf(&pEventData);
702 write((char*)pCmd, cmdSize, &pEventData);
705 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
708 THROW(MsgException::INVALID_RESULT, "Event is NULL");
710 if (pEvent->eventType != MSG_EVENT_GET_MSG) {
711 THROW(MsgException::INVALID_RESULT, "Event Data Error");
714 if (pEvent->result != MSG_SUCCESS)
715 return pEvent->result;
717 // Decode Return Data
718 MSG_MESSAGE_INFO_S msgInfo;
719 MSG_SENDINGOPT_INFO_S sendOptInfo;
721 msgInfo.addressList = NULL;
722 AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
724 MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
726 // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_HIDDEN_S
727 convertMsgStruct(&msgInfo, pMsg);
729 if (pSendOpt != NULL) {
730 MSG_MESSAGE_TYPE_S msgType = {0,};
732 msgType.mainType = pMsg->mainType;
733 msgType.subType = pMsg->subType;
734 msgType.classType = pMsg->classType;
736 convertSendOptStruct(&sendOptInfo, pSendOpt, msgType);
740 if (msgInfo.bTextSms == false)
743 MsgDeleteFile(msgInfo.msgData); //ipc
750 msg_error_t MsgHandle::getFolderViewList(msg_folder_id_t FolderId, const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pMsgFolderViewList)
752 msg_error_t err = MSG_SUCCESS;
754 // err = MsgStoConnectDB();
756 // if (err != MSG_SUCCESS)
758 // MSG_DEBUG("MsgStoConnectDB() Error!!");
762 err = MsgStoGetFolderViewList(FolderId, (MSG_SORT_RULE_S *)pSortRule, pMsgFolderViewList);
764 if (err != MSG_SUCCESS)
766 MSG_DEBUG("MsgStoGetFolderViewList() Error!!");
770 // MsgStoDisconnectDB();
776 msg_error_t MsgHandle::addFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
778 // Allocate Memory to Command Data
779 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
781 char cmdBuf[cmdSize];
782 bzero(cmdBuf, cmdSize);
783 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
785 // Set Command Parameters
786 pCmd->cmdType = MSG_CMD_ADD_FOLDER;
789 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
792 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
794 // Send Command to Messaging FW
795 char* pEventData = NULL;
796 AutoPtr<char> eventBuf(&pEventData);
798 write((char*)pCmd, cmdSize, &pEventData);
801 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
804 THROW(MsgException::INVALID_RESULT, "Event is NULL");
806 if (pEvent->eventType != MSG_EVENT_ADD_FOLDER)
808 THROW(MsgException::INVALID_RESULT, "Event Data Error");
811 return pEvent->result;
815 msg_error_t MsgHandle::updateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
817 // Allocate Memory to Command Data
818 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
820 char cmdBuf[cmdSize];
821 bzero(cmdBuf, cmdSize);
822 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
824 // Set Command Parameters
825 pCmd->cmdType = MSG_CMD_UPDATE_FOLDER;
828 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
831 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
833 // Send Command to Messaging FW
834 char* pEventData = NULL;
835 AutoPtr<char> eventBuf(&pEventData);
837 write((char*)pCmd, cmdSize, &pEventData);
840 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
843 THROW(MsgException::INVALID_RESULT, "Event is NULL");
845 if (pEvent->eventType != MSG_EVENT_UPDATE_FOLDER)
847 THROW(MsgException::INVALID_RESULT, "Event Data Error");
850 return pEvent->result;
854 msg_error_t MsgHandle::deleteFolder(msg_folder_id_t FolderId)
856 // Allocate Memory to Command Data
857 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
859 char cmdBuf[cmdSize];
860 bzero(cmdBuf, cmdSize);
861 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
863 // Set Command Parameters
864 pCmd->cmdType = MSG_CMD_DELETE_FOLDER;
867 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
870 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
872 // Send Command to Messaging FW
873 char* pEventData = NULL;
874 AutoPtr<char> eventBuf(&pEventData);
876 write((char*)pCmd, cmdSize, &pEventData);
879 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
882 THROW(MsgException::INVALID_RESULT, "Event is NULL");
884 if (pEvent->eventType != MSG_EVENT_DELETE_FOLDER)
886 THROW(MsgException::INVALID_RESULT, "Event Data Error");
889 return pEvent->result;
893 msg_error_t MsgHandle::getFolderList(msg_struct_list_s *pFolderList)
895 // Allocate Memory to Command Data
896 int cmdSize = sizeof(MSG_CMD_S);
898 char cmdBuf[cmdSize];
899 bzero(cmdBuf, cmdSize);
900 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
902 // Set Command Parameters
903 pCmd->cmdType = MSG_CMD_GET_FOLDERLIST;
906 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
908 // Send Command to Messaging FW
909 char* pEventData = NULL;
910 AutoPtr<char> eventBuf(&pEventData);
912 write((char*)pCmd, cmdSize, &pEventData);
915 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
918 THROW(MsgException::INVALID_RESULT, "Event is NULL");
920 if (pEvent->eventType != MSG_EVENT_GET_FOLDERLIST)
922 THROW(MsgException::INVALID_RESULT, "Event Data Error");
925 if (pEvent->result != MSG_SUCCESS)
926 return pEvent->result;
928 // Decode Return Data
929 MsgDecodeFolderList(pEvent->data, pFolderList);
935 msg_error_t MsgHandle::getThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList)
937 msg_error_t err = MSG_SUCCESS;
939 // err = MsgStoConnectDB();
941 // if (err != MSG_SUCCESS)
943 // MSG_DEBUG("MsgStoConnectDB() Error!!");
947 err = MsgStoGetThreadViewList(pSortRule, pThreadViewList);
949 if (err != MSG_SUCCESS)
951 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
955 // MsgStoDisconnectDB();
958 // Allocate Memory to Command Data
959 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_SORT_RULE_S);
961 char cmdBuf[cmdSize];
962 bzero(cmdBuf, cmdSize);
963 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
965 // Set Command Parameters
966 pCmd->cmdType = MSG_CMD_GET_THREADVIEWLIST;
969 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)), pSortRule, sizeof(MSG_SORT_RULE_S));
971 // Send Command to Messaging FW
972 char* pEventData = NULL;
973 AutoPtr<char> eventBuf(&pEventData);
975 write((char*)pCmd, cmdSize, &pEventData);
978 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
981 THROW(MsgException::INVALID_RESULT, "Event is NULL");
983 if (pEvent->eventType != MSG_EVENT_GET_THREADVIEWLIST)
985 THROW(MsgException::INVALID_RESULT, "Event Data Error");
988 if (pEvent->result != MSG_SUCCESS)
989 return pEvent->result;
991 // Decode Return Data
992 MsgDecodeThreadViewList(pEvent->data, pMsgThreadViewList);
998 msg_error_t MsgHandle::getConversationViewItem(msg_message_id_t MsgId, MSG_CONVERSATION_VIEW_S *pConv)
1002 msg_error_t err = MSG_SUCCESS;
1004 // MsgStoConnectDB();
1005 err = MsgStoGetConversationViewItem(MsgId, pConv);
1006 // MsgStoDisconnectDB();
1011 msg_error_t MsgHandle::getConversationViewList(msg_thread_id_t ThreadId, msg_struct_list_s *pConvViewList)
1015 msg_error_t err = MSG_SUCCESS;
1017 // MsgStoConnectDB();
1018 err = MsgStoGetConversationViewList(ThreadId, pConvViewList);
1019 // MsgStoDisconnectDB();
1021 if (err != MSG_SUCCESS)
1030 msg_error_t MsgHandle::deleteThreadMessageList(msg_thread_id_t ThreadId, bool include_protected_msg)
1032 // Allocate Memory to Command Data
1033 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t) + sizeof(bool);
1035 char cmdBuf[cmdSize];
1036 bzero(cmdBuf, cmdSize);
1037 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1039 // Set Command Parameters
1040 pCmd->cmdType = MSG_CMD_DELETE_THREADMESSAGELIST;
1043 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1045 // Copy Command Data
1046 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
1047 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_thread_id_t)), &include_protected_msg, sizeof(bool));
1049 // Send Command to Messaging FW
1050 char* pEventData = NULL;
1051 AutoPtr<char> eventBuf(&pEventData);
1053 write((char*)pCmd, cmdSize, &pEventData);
1056 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1059 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1061 if (pEvent->eventType != MSG_EVENT_DELETE_THREADMESSAGELIST)
1063 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1066 if (pEvent->result != MSG_SUCCESS)
1067 return pEvent->result;
1073 msg_error_t MsgHandle::getQuickPanelData(msg_quickpanel_type_t Type, MSG_MESSAGE_HIDDEN_S *pMsg)
1075 // Allocate Memory to Command Data
1076 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_quickpanel_type_t);
1078 char cmdBuf[cmdSize];
1079 bzero(cmdBuf, cmdSize);
1080 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1082 // Set Command Parameters
1083 pCmd->cmdType = MSG_CMD_GET_QUICKPANEL_DATA;
1086 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1088 // Copy Command Data
1089 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &Type, sizeof(msg_quickpanel_type_t));
1091 // Send Command to Messaging FW
1092 char* pEventData = NULL;
1093 AutoPtr<char> eventBuf(&pEventData);
1095 write((char*)pCmd, cmdSize, &pEventData);
1098 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1101 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1103 if (pEvent->eventType != MSG_EVENT_GET_QUICKPANEL_DATA)
1105 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1108 if (pEvent->result != MSG_SUCCESS)
1109 return pEvent->result;
1111 // Decode Return Data
1112 MSG_MESSAGE_INFO_S msgInfo;
1114 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1116 msgInfo.addressList = NULL;
1117 AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
1119 MsgDecodeMsgInfo((char *)pEvent->data, &msgInfo);
1121 // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_S
1122 convertMsgStruct(&msgInfo, pMsg);
1125 if (msgInfo.bTextSms == false)
1128 MsgDeleteFile(msgInfo.msgData); //ipc
1135 msg_error_t MsgHandle::resetDatabase()
1137 // Allocate Memory to Command Data
1138 int cmdSize = sizeof(MSG_CMD_S);
1140 char cmdBuf[cmdSize];
1141 bzero(cmdBuf, cmdSize);
1142 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1144 // Set Command Parameters
1145 pCmd->cmdType = MSG_CMD_RESET_DB;
1148 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1150 // Send Command to Messaging FW
1151 char* pEventData = NULL;
1152 AutoPtr<char> eventBuf(&pEventData);
1154 write((char*)pCmd, cmdSize, &pEventData);
1157 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1160 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1162 if (pEvent->eventType != MSG_EVENT_RESET_DB)
1164 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1167 return pEvent->result;
1171 msg_error_t MsgHandle::getMemSize(unsigned int* memsize)
1173 // Allocate Memory to Command Data
1174 int cmdSize = sizeof(MSG_CMD_S);
1176 char cmdBuf[cmdSize];
1177 bzero(cmdBuf, cmdSize);
1178 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1180 // Set Command Parameters
1181 pCmd->cmdType = MSG_CMD_GET_MEMSIZE;
1184 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1186 // Send Command to Messaging FW
1187 char* pEventData = NULL;
1188 AutoPtr<char> eventBuf(&pEventData);
1190 write((char*)pCmd, cmdSize, &pEventData);
1193 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1196 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1198 if (pEvent->eventType != MSG_EVENT_GET_MEMSIZE)
1200 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1203 if (pEvent->result != MSG_SUCCESS)
1204 return pEvent->result;
1206 // Decode Return Data
1207 MsgDecodeMemSize(pEvent->data, memsize);
1212 msg_error_t MsgHandle::backupMessage(msg_message_backup_type_t type, const char *backup_filepath)
1214 if (backup_filepath == NULL)
1215 return MSG_ERR_NULL_POINTER;
1217 //Create an empty file for writing.
1218 //If a file with the same name already exists its content is erased
1219 //and the file is treated as a new empty file.
1220 FILE *pFile = MsgOpenFile(backup_filepath, "w");
1221 if (pFile == NULL) {
1222 MSG_DEBUG("File Open error");
1223 return MSG_ERR_STORAGE_ERROR;
1225 MsgCloseFile(pFile);
1227 char path[MSG_FILEPATH_LEN_MAX+1] = {0,};
1228 strncpy(path, backup_filepath, MSG_FILEPATH_LEN_MAX);
1230 // Allocate Memory to Command Data
1231 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_backup_type_t) + sizeof(path);
1233 char cmdBuf[cmdSize];
1234 bzero(cmdBuf, cmdSize);
1235 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1237 // Set Command Parameters
1238 pCmd->cmdType = MSG_CMD_BACKUP_MESSAGE;
1241 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1242 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &type, sizeof(msg_message_backup_type_t));
1243 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_backup_type_t)), (char *)path, sizeof(path));
1245 // Send Command to Messaging FW
1246 char* pEventData = NULL;
1247 AutoPtr<char> eventBuf(&pEventData);
1249 write((char*)pCmd, cmdSize, &pEventData);
1252 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1255 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1257 if (pEvent->eventType != MSG_EVENT_BACKUP_MESSAGE)
1259 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1262 if (pEvent->result != MSG_SUCCESS)
1263 return pEvent->result;
1268 msg_error_t MsgHandle::restoreMessage(const char *backup_filepath)
1270 if (backup_filepath == NULL)
1271 return MSG_ERR_NULL_POINTER;
1273 if (MsgAccessFile(backup_filepath, R_OK) == false) {
1274 MSG_DEBUG("File access error");
1275 return MSG_ERR_UNKNOWN;
1278 char path[MSG_FILEPATH_LEN_MAX+1] = {0,};
1279 strncpy(path, backup_filepath, MSG_FILEPATH_LEN_MAX);
1281 // Allocate Memory to Command Data
1282 int cmdSize = sizeof(MSG_CMD_S) + sizeof(path);
1284 char cmdBuf[cmdSize];
1285 bzero(cmdBuf, cmdSize);
1286 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1288 // Set Command Parameters
1289 pCmd->cmdType = MSG_CMD_RESTORE_MESSAGE;
1292 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1293 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), (char *)path, sizeof(path));
1295 // Send Command to Messaging FW
1296 char* pEventData = NULL;
1297 AutoPtr<char> eventBuf(&pEventData);
1299 write((char*)pCmd, cmdSize, &pEventData);
1302 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1305 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1307 if (pEvent->eventType != MSG_EVENT_RESTORE_MESSAGE)
1309 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1312 if (pEvent->result != MSG_SUCCESS)
1313 return pEvent->result;
1319 msg_error_t MsgHandle::searchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList)
1321 msg_error_t err = MSG_SUCCESS;
1323 // err = MsgStoConnectDB();
1325 // if (err != MSG_SUCCESS)
1327 // MSG_DEBUG("MsgStoConnectDB() Error!!");
1331 err = MsgStoSearchMessage(pSearchString, pThreadViewList);
1333 if (err != MSG_SUCCESS)
1335 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1339 // MsgStoDisconnectDB();
1345 msg_error_t MsgHandle::getRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList)
1347 msg_error_t err = MSG_SUCCESS;
1349 // err = MsgStoConnectDB();
1351 // if (err != MSG_SUCCESS)
1353 // MSG_DEBUG("MsgStoConnectDB() Error!!");
1357 err = MsgStoGetRejectMsgList(pNumber, pRejectMsgList);
1359 if (err != MSG_SUCCESS)
1361 MSG_DEBUG("MsgStoGetRejectMsgList() Error!!");
1365 // MsgStoDisconnectDB();
1371 msg_error_t MsgHandle::regStorageChangeCallback(msg_storage_change_cb onStorageChange, void *pUserParam)
1373 if (!onStorageChange)
1374 THROW(MsgException::INVALID_PARAM, "onStorageChange is null");
1376 MsgProxyListener* eventListener = MsgProxyListener::instance();
1378 eventListener->start(this);
1380 int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
1382 if (remoteFd == -1 )
1383 return MSG_ERR_INVALID_MSGHANDLE;
1385 if (eventListener->regStorageChangeEventCB(this, onStorageChange, pUserParam) == false)
1386 return MSG_ERR_INVALID_PARAMETER;
1388 // Allocate Memory to Command Data
1389 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
1390 char cmdBuf[cmdSize];
1391 bzero(cmdBuf, cmdSize);
1392 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
1394 // Set Command Parameters
1395 pCmd->cmdType = MSG_CMD_REG_STORAGE_CHANGE_CB;
1398 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1400 MSG_DEBUG("remote fd %d", remoteFd);
1402 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
1404 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
1406 // Send Command to Messaging FW
1407 char* pEventData = NULL;
1408 AutoPtr<char> eventBuf(&pEventData);
1410 write((char*)pCmd, cmdSize, &pEventData);
1413 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1416 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1418 if (pEvent->eventType != MSG_EVENT_REG_STORAGE_CHANGE_CB)
1420 THROW(MsgException::INVALID_PARAM, "Event Data Error");
1423 return pEvent->result;
1426 msg_error_t MsgHandle::getReportStatus(msg_message_id_t msg_id, msg_struct_list_s *report_list)
1428 // Allocate Memory to Command Data
1429 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1431 char cmdBuf[cmdSize];
1432 bzero(cmdBuf, cmdSize);
1433 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1435 report_list->nCount = 0;
1436 report_list->msg_struct_info = NULL;
1438 // Set Command Parameters
1439 pCmd->cmdType = MSG_CMD_GET_REPORT_STATUS;
1442 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1444 // Copy Command Data
1445 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msg_id, sizeof(msg_message_id_t));
1447 // Send Command to Messaging FW
1448 char* pEventData = NULL;
1449 AutoPtr<char> eventBuf(&pEventData);
1451 write((char*)pCmd, cmdSize, &pEventData);
1454 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1457 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1459 if (pEvent->eventType != MSG_EVENT_GET_REPORT_STATUS)
1461 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1464 if (pEvent->result != MSG_SUCCESS)
1465 return pEvent->result;
1467 // Decode Return Data
1468 MsgDecodeReportStatus(pEvent->data, report_list);
1474 msg_error_t MsgHandle::getAddressList(const msg_thread_id_t threadId, msg_struct_list_s *pAddrList)
1476 msg_error_t err = MSG_SUCCESS;
1478 // err = MsgStoConnectDB();
1480 // if (err != MSG_SUCCESS)
1482 // MSG_DEBUG("MsgStoConnectDB() Error!!");
1486 err = MsgStoGetAddressList(threadId, (msg_struct_list_s *)pAddrList);
1488 if (err != MSG_SUCCESS)
1490 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
1494 // MsgStoDisconnectDB();
1500 msg_error_t MsgHandle::getThreadIdByAddress(msg_struct_list_s *pAddrList, msg_thread_id_t *pThreadId)
1502 // Allocate Memory to Command Data
1503 int cmdSize = sizeof(MSG_CMD_S) + sizeof(pAddrList->nCount) + (sizeof(MSG_ADDRESS_INFO_S)*pAddrList->nCount);
1505 char cmdBuf[cmdSize];
1506 bzero(cmdBuf, cmdSize);
1507 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1509 // Set Command Parameters
1510 pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1513 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1515 // Copy Command Data
1516 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pAddrList->nCount, sizeof(pAddrList->nCount));
1517 int addSize = sizeof(MSG_ADDRESS_INFO_S);
1518 for(int i=0; i<pAddrList->nCount; i++) {
1519 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(pAddrList->nCount)+(addSize*i)+MAX_COOKIE_LEN), ((msg_struct_s *)(pAddrList->msg_struct_info[i]))->data, sizeof(MSG_ADDRESS_INFO_S));
1522 // Send Command to Messaging FW
1523 char* pEventData = NULL;
1524 AutoPtr<char> eventBuf(&pEventData);
1526 write((char*)pCmd, cmdSize, &pEventData);
1529 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1532 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1534 if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS)
1536 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1539 if (pEvent->result != MSG_SUCCESS)
1540 return pEvent->result;
1542 // Decode Return Data
1543 MsgDecodeThreadId(pEvent->data, pThreadId);
1549 msg_error_t MsgHandle::getThreadIdByAddress(msg_list_handle_t msg_address_list, msg_thread_id_t *pThreadId)
1551 int addrCnt = (int)g_list_length((GList *)msg_address_list);
1553 // Allocate Memory to Command Data
1554 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*addrCnt);
1556 char cmdBuf[cmdSize];
1557 bzero(cmdBuf, cmdSize);
1558 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1560 // Set Command Parameters
1561 pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1564 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1566 // Copy Command Data
1567 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &addrCnt, sizeof(int));
1568 int addSize = sizeof(MSG_ADDRESS_INFO_S);
1569 for(int i=0; i<addrCnt; i++) {
1570 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(addrCnt)+(addSize*i)+MAX_COOKIE_LEN), ((msg_struct_s *)(g_list_nth_data((GList *)msg_address_list,(guint)i)))->data, sizeof(MSG_ADDRESS_INFO_S));
1573 // Send Command to Messaging FW
1574 char* pEventData = NULL;
1575 AutoPtr<char> eventBuf(&pEventData);
1577 write((char*)pCmd, cmdSize, &pEventData);
1580 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1583 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1585 if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS)
1587 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1590 if (pEvent->result != MSG_SUCCESS)
1591 return pEvent->result;
1593 // Decode Return Data
1594 MsgDecodeThreadId(pEvent->data, pThreadId);
1600 msg_error_t MsgHandle::getThread(msg_thread_id_t threadId, MSG_THREAD_VIEW_S* pThreadInfo)
1602 // Allocate Memory to Command Data
1603 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
1605 char cmdBuf[cmdSize];
1606 bzero(cmdBuf, cmdSize);
1607 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1609 // Set Command Parameters
1610 pCmd->cmdType = MSG_CMD_GET_THREAD_INFO;
1613 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1615 // Copy Command Data
1616 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &threadId, sizeof(msg_thread_id_t));
1618 // Send Command to Messaging FW
1619 char* pEventData = NULL;
1620 AutoPtr<char> eventBuf(&pEventData);
1622 write((char*)pCmd, cmdSize, &pEventData);
1625 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1628 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1630 if (pEvent->eventType != MSG_EVENT_GET_THREAD_INFO)
1632 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1635 // Decode Return Data
1636 MsgDecodeThreadInfo(pEvent->data, pThreadInfo);
1642 msg_error_t MsgHandle::getMessageList(const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pMsgList)
1644 msg_error_t err = MSG_SUCCESS;
1646 // err = MsgStoConnectDB();
1648 // if (err != MSG_SUCCESS) {
1649 // MSG_DEBUG("MsgStoConnectDB() Error!!");
1653 err = MsgStoGetMessageList(pListCond, pMsgList);
1655 if (err != MSG_SUCCESS) {
1656 MSG_DEBUG("MsgStoGetMessageList() Error!!");
1660 // MsgStoDisconnectDB();
1666 msg_error_t MsgHandle::getMediaList(const msg_thread_id_t thread_id, msg_list_handle_t *pMediaList)
1668 msg_error_t err = MSG_SUCCESS;
1670 err = MsgStoGetMediaList(thread_id, pMediaList);
1672 if (err != MSG_SUCCESS) {
1673 MSG_DEBUG("MsgStoGetFmMediaList() Error!!");
1681 int MsgHandle::addPushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1683 // Allocate Memory to Command Data
1684 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1686 char cmdBuf[cmdSize];
1687 bzero(cmdBuf, cmdSize);
1688 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1690 // Set Command Parameters
1691 pCmd->cmdType = MSG_CMD_ADD_PUSH_EVENT;
1694 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1696 // Copy Command Data
1697 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1699 // Send Command to Messaging FW
1700 char* pEventData = NULL;
1701 AutoPtr<char> eventBuf(&pEventData);
1703 write((char*)pCmd, cmdSize, &pEventData);
1706 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1709 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1711 if (pEvent->eventType != MSG_EVENT_ADD_PUSH_EVENT)
1713 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1716 return pEvent->result;
1720 int MsgHandle::deletePushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1722 // Allocate Memory to Command Data
1723 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1725 char cmdBuf[cmdSize];
1726 bzero(cmdBuf, cmdSize);
1727 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1729 // Set Command Parameters
1730 pCmd->cmdType = MSG_CMD_DELETE_PUSH_EVENT;
1733 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1735 // Copy Command Data
1736 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1738 // Send Command to Messaging FW
1739 char* pEventData = NULL;
1740 AutoPtr<char> eventBuf(&pEventData);
1742 write((char*)pCmd, cmdSize, &pEventData);
1745 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1748 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1750 if (pEvent->eventType != MSG_EVENT_DELETE_PUSH_EVENT)
1752 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1755 return pEvent->result;
1758 int MsgHandle::updatePushEvent(MSG_PUSH_EVENT_INFO_S *pSrc, MSG_PUSH_EVENT_INFO_S *pDst)
1760 // Allocate Memory to Command Data
1761 int cmdSize = sizeof(MSG_CMD_S) + 2 * sizeof(MSG_PUSH_EVENT_INFO_S);
1763 char cmdBuf[cmdSize];
1764 bzero(cmdBuf, cmdSize);
1765 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1767 // Set Command Parameters
1768 pCmd->cmdType = MSG_CMD_UPDATE_PUSH_EVENT;
1771 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1773 // Copy Command Data
1774 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pSrc, sizeof(MSG_PUSH_EVENT_INFO_S));
1775 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_PUSH_EVENT_INFO_S)), pDst, sizeof(MSG_PUSH_EVENT_INFO_S));
1777 // Send Command to Messaging FW
1778 char* pEventData = NULL;
1779 AutoPtr<char> eventBuf(&pEventData);
1781 write((char*)pCmd, cmdSize, &pEventData);
1784 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1787 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1789 if (pEvent->eventType != MSG_EVENT_UPDATE_PUSH_EVENT)
1791 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1794 return pEvent->result;
1797 msg_error_t MsgHandle::getVobject(msg_message_id_t MsgId, void** encodedData)
1799 // Allocate Memory to Command Data
1800 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1801 char *encode_data = NULL;
1802 char cmdBuf[cmdSize];
1803 bzero(cmdBuf, cmdSize);
1804 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1806 // Set Command Parameters
1807 pCmd->cmdType = MSG_CMD_GET_MSG;
1810 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1812 // Copy Command Data
1813 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
1815 // Send Command to Messaging FW
1816 char* pEventData = NULL;
1817 AutoPtr<char> eventBuf(&pEventData);
1820 write((char*)pCmd, cmdSize, &pEventData);
1823 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1826 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1828 if (pEvent->eventType != MSG_EVENT_GET_MSG)
1830 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1833 if (pEvent->result != MSG_SUCCESS)
1834 return pEvent->result;
1836 // Decode Return Data
1837 MSG_MESSAGE_INFO_S msgInfo = {0,};
1838 MSG_SENDINGOPT_INFO_S sendOptInfo = {0,};
1840 msgInfo.addressList = NULL;
1841 AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
1843 MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
1845 //Convert MSG_MESSAGE_INFO_S to
1846 encode_data = MsgVMessageEncode(&msgInfo);
1848 *encodedData = (void*)encode_data;
1850 MSG_DEBUG("Error Encode data");
1851 *encodedData = NULL;
1855 if (msgInfo.bTextSms == false)
1858 MsgDeleteFile(msgInfo.msgData); //ipc