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 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
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 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
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::addFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
752 // Allocate Memory to Command Data
753 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
755 char cmdBuf[cmdSize];
756 bzero(cmdBuf, cmdSize);
757 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
759 // Set Command Parameters
760 pCmd->cmdType = MSG_CMD_ADD_FOLDER;
763 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
766 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
768 // Send Command to Messaging FW
769 char* pEventData = NULL;
770 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
772 write((char*)pCmd, cmdSize, &pEventData);
775 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
778 THROW(MsgException::INVALID_RESULT, "Event is NULL");
780 if (pEvent->eventType != MSG_EVENT_ADD_FOLDER)
782 THROW(MsgException::INVALID_RESULT, "Event Data Error");
785 return pEvent->result;
789 msg_error_t MsgHandle::updateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
791 // Allocate Memory to Command Data
792 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
794 char cmdBuf[cmdSize];
795 bzero(cmdBuf, cmdSize);
796 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
798 // Set Command Parameters
799 pCmd->cmdType = MSG_CMD_UPDATE_FOLDER;
802 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
805 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
807 // Send Command to Messaging FW
808 char* pEventData = NULL;
809 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
811 write((char*)pCmd, cmdSize, &pEventData);
814 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
817 THROW(MsgException::INVALID_RESULT, "Event is NULL");
819 if (pEvent->eventType != MSG_EVENT_UPDATE_FOLDER)
821 THROW(MsgException::INVALID_RESULT, "Event Data Error");
824 return pEvent->result;
828 msg_error_t MsgHandle::deleteFolder(msg_folder_id_t FolderId)
830 // Allocate Memory to Command Data
831 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
833 char cmdBuf[cmdSize];
834 bzero(cmdBuf, cmdSize);
835 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
837 // Set Command Parameters
838 pCmd->cmdType = MSG_CMD_DELETE_FOLDER;
841 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
844 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
846 // Send Command to Messaging FW
847 char* pEventData = NULL;
848 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
850 write((char*)pCmd, cmdSize, &pEventData);
853 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
856 THROW(MsgException::INVALID_RESULT, "Event is NULL");
858 if (pEvent->eventType != MSG_EVENT_DELETE_FOLDER)
860 THROW(MsgException::INVALID_RESULT, "Event Data Error");
863 return pEvent->result;
867 msg_error_t MsgHandle::getFolderList(msg_struct_list_s *pFolderList)
869 // Allocate Memory to Command Data
870 int cmdSize = sizeof(MSG_CMD_S);
872 char cmdBuf[cmdSize];
873 bzero(cmdBuf, cmdSize);
874 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
876 // Set Command Parameters
877 pCmd->cmdType = MSG_CMD_GET_FOLDERLIST;
880 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
882 // Send Command to Messaging FW
883 char* pEventData = NULL;
884 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
886 write((char*)pCmd, cmdSize, &pEventData);
889 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
892 THROW(MsgException::INVALID_RESULT, "Event is NULL");
894 if (pEvent->eventType != MSG_EVENT_GET_FOLDERLIST)
896 THROW(MsgException::INVALID_RESULT, "Event Data Error");
899 if (pEvent->result != MSG_SUCCESS)
900 return pEvent->result;
902 // Decode Return Data
903 MsgDecodeFolderList(pEvent->data, pFolderList);
909 msg_error_t MsgHandle::getThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList)
911 msg_error_t err = MSG_SUCCESS;
913 // err = MsgStoConnectDB();
915 // if (err != MSG_SUCCESS)
917 // MSG_DEBUG("MsgStoConnectDB() Error!!");
921 err = MsgStoGetThreadViewList(pSortRule, pThreadViewList);
923 if (err != MSG_SUCCESS)
925 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
929 // MsgStoDisconnectDB();
932 // Allocate Memory to Command Data
933 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_SORT_RULE_S);
935 char cmdBuf[cmdSize];
936 bzero(cmdBuf, cmdSize);
937 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
939 // Set Command Parameters
940 pCmd->cmdType = MSG_CMD_GET_THREADVIEWLIST;
943 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)), pSortRule, sizeof(MSG_SORT_RULE_S));
945 // Send Command to Messaging FW
946 char* pEventData = NULL;
947 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
949 write((char*)pCmd, cmdSize, &pEventData);
952 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
955 THROW(MsgException::INVALID_RESULT, "Event is NULL");
957 if (pEvent->eventType != MSG_EVENT_GET_THREADVIEWLIST)
959 THROW(MsgException::INVALID_RESULT, "Event Data Error");
962 if (pEvent->result != MSG_SUCCESS)
963 return pEvent->result;
965 // Decode Return Data
966 MsgDecodeThreadViewList(pEvent->data, pMsgThreadViewList);
972 msg_error_t MsgHandle::getConversationViewItem(msg_message_id_t MsgId, MSG_CONVERSATION_VIEW_S *pConv)
976 msg_error_t err = MSG_SUCCESS;
978 // MsgStoConnectDB();
979 err = MsgStoGetConversationViewItem(MsgId, pConv);
980 // MsgStoDisconnectDB();
985 msg_error_t MsgHandle::getConversationViewList(msg_thread_id_t ThreadId, msg_struct_list_s *pConvViewList)
989 msg_error_t err = MSG_SUCCESS;
991 // MsgStoConnectDB();
992 err = MsgStoGetConversationViewList(ThreadId, pConvViewList);
993 // MsgStoDisconnectDB();
995 if (err != MSG_SUCCESS)
1004 msg_error_t MsgHandle::deleteThreadMessageList(msg_thread_id_t ThreadId, bool include_protected_msg)
1006 // Allocate Memory to Command Data
1007 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t) + sizeof(bool);
1009 char cmdBuf[cmdSize];
1010 bzero(cmdBuf, cmdSize);
1011 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1013 // Set Command Parameters
1014 pCmd->cmdType = MSG_CMD_DELETE_THREADMESSAGELIST;
1017 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1019 // Copy Command Data
1020 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
1021 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_thread_id_t)), &include_protected_msg, sizeof(bool));
1023 // Send Command to Messaging FW
1024 char* pEventData = NULL;
1025 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1027 write((char*)pCmd, cmdSize, &pEventData);
1030 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1033 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1035 if (pEvent->eventType != MSG_EVENT_DELETE_THREADMESSAGELIST)
1037 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1040 if (pEvent->result != MSG_SUCCESS)
1041 return pEvent->result;
1047 msg_error_t MsgHandle::getQuickPanelData(msg_quickpanel_type_t Type, MSG_MESSAGE_HIDDEN_S *pMsg)
1049 // Allocate Memory to Command Data
1050 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_quickpanel_type_t);
1052 char cmdBuf[cmdSize];
1053 bzero(cmdBuf, cmdSize);
1054 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1056 // Set Command Parameters
1057 pCmd->cmdType = MSG_CMD_GET_QUICKPANEL_DATA;
1060 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1062 // Copy Command Data
1063 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &Type, sizeof(msg_quickpanel_type_t));
1065 // Send Command to Messaging FW
1066 char* pEventData = NULL;
1067 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1069 write((char*)pCmd, cmdSize, &pEventData);
1072 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1075 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1077 if (pEvent->eventType != MSG_EVENT_GET_QUICKPANEL_DATA)
1079 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1082 if (pEvent->result != MSG_SUCCESS)
1083 return pEvent->result;
1085 // Decode Return Data
1086 MSG_MESSAGE_INFO_S msgInfo;
1088 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1090 msgInfo.addressList = NULL;
1091 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1093 MsgDecodeMsgInfo((char *)pEvent->data, &msgInfo);
1095 // Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_S
1096 convertMsgStruct(&msgInfo, pMsg);
1099 if (msgInfo.bTextSms == false)
1102 MsgDeleteFile(msgInfo.msgData); //ipc
1109 msg_error_t MsgHandle::resetDatabase()
1111 // Allocate Memory to Command Data
1112 int cmdSize = sizeof(MSG_CMD_S);
1114 char cmdBuf[cmdSize];
1115 bzero(cmdBuf, cmdSize);
1116 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1118 // Set Command Parameters
1119 pCmd->cmdType = MSG_CMD_RESET_DB;
1122 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1124 // Send Command to Messaging FW
1125 char* pEventData = NULL;
1126 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1128 write((char*)pCmd, cmdSize, &pEventData);
1131 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1134 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1136 if (pEvent->eventType != MSG_EVENT_RESET_DB)
1138 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1141 return pEvent->result;
1145 msg_error_t MsgHandle::getMemSize(unsigned int* memsize)
1147 // Allocate Memory to Command Data
1148 int cmdSize = sizeof(MSG_CMD_S);
1150 char cmdBuf[cmdSize];
1151 bzero(cmdBuf, cmdSize);
1152 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1154 // Set Command Parameters
1155 pCmd->cmdType = MSG_CMD_GET_MEMSIZE;
1158 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1160 // Send Command to Messaging FW
1161 char* pEventData = NULL;
1162 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1164 write((char*)pCmd, cmdSize, &pEventData);
1167 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1170 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1172 if (pEvent->eventType != MSG_EVENT_GET_MEMSIZE)
1174 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1177 if (pEvent->result != MSG_SUCCESS)
1178 return pEvent->result;
1180 // Decode Return Data
1181 MsgDecodeMemSize(pEvent->data, memsize);
1186 msg_error_t MsgHandle::backupMessage(msg_message_backup_type_t type, const char *backup_filepath)
1188 if (backup_filepath == NULL)
1189 return MSG_ERR_NULL_POINTER;
1191 //Create an empty file for writing.
1192 //If a file with the same name already exists its content is erased
1193 //and the file is treated as a new empty file.
1195 FILE *pFile = MsgOpenFile(backup_filepath, "w");
1196 if (pFile == NULL) {
1197 MSG_DEBUG("File Open error");
1198 return MSG_ERR_STORAGE_ERROR;
1200 MsgCloseFile(pFile);
1202 char path[MSG_FILEPATH_LEN_MAX+1] = {0,};
1203 strncpy(path, backup_filepath, MSG_FILEPATH_LEN_MAX);
1205 // Allocate Memory to Command Data
1206 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_backup_type_t) + sizeof(path);
1208 char cmdBuf[cmdSize];
1209 bzero(cmdBuf, cmdSize);
1210 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1212 // Set Command Parameters
1213 pCmd->cmdType = MSG_CMD_BACKUP_MESSAGE;
1216 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1217 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &type, sizeof(msg_message_backup_type_t));
1218 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_backup_type_t)), (char *)path, sizeof(path));
1220 // Send Command to Messaging FW
1221 char* pEventData = NULL;
1222 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1224 write((char*)pCmd, cmdSize, &pEventData);
1227 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1230 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1232 if (pEvent->eventType != MSG_EVENT_BACKUP_MESSAGE)
1234 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1237 return pEvent->result;
1240 msg_error_t MsgHandle::restoreMessage(const char *backup_filepath)
1242 if (backup_filepath == NULL)
1243 return MSG_ERR_NULL_POINTER;
1245 if (MsgAccessFile(backup_filepath, R_OK) == false) {
1246 MSG_DEBUG("File access error");
1247 return MSG_ERR_UNKNOWN;
1250 char path[MSG_FILEPATH_LEN_MAX+1] = {0,};
1251 strncpy(path, backup_filepath, MSG_FILEPATH_LEN_MAX);
1253 // Allocate Memory to Command Data
1254 int cmdSize = sizeof(MSG_CMD_S) + sizeof(path);
1256 char cmdBuf[cmdSize];
1257 bzero(cmdBuf, cmdSize);
1258 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1260 // Set Command Parameters
1261 pCmd->cmdType = MSG_CMD_RESTORE_MESSAGE;
1264 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1265 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), (char *)path, sizeof(path));
1267 // Send Command to Messaging FW
1268 char* pEventData = NULL;
1269 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1271 write((char*)pCmd, cmdSize, &pEventData);
1274 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1277 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1279 if (pEvent->eventType != MSG_EVENT_RESTORE_MESSAGE)
1281 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1284 return pEvent->result;
1288 msg_error_t MsgHandle::searchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList)
1290 msg_error_t err = MSG_SUCCESS;
1292 // err = MsgStoConnectDB();
1294 // if (err != MSG_SUCCESS)
1296 // MSG_DEBUG("MsgStoConnectDB() Error!!");
1300 err = MsgStoSearchMessage(pSearchString, pThreadViewList);
1302 if (err != MSG_SUCCESS)
1304 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1308 // MsgStoDisconnectDB();
1314 msg_error_t MsgHandle::getRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList)
1316 msg_error_t err = MSG_SUCCESS;
1318 // err = MsgStoConnectDB();
1320 // if (err != MSG_SUCCESS)
1322 // MSG_DEBUG("MsgStoConnectDB() Error!!");
1326 err = MsgStoGetRejectMsgList(pNumber, pRejectMsgList);
1328 if (err != MSG_SUCCESS)
1330 MSG_DEBUG("MsgStoGetRejectMsgList() Error!!");
1334 // MsgStoDisconnectDB();
1340 msg_error_t MsgHandle::regStorageChangeCallback(msg_storage_change_cb onStorageChange, void *pUserParam)
1342 if (!onStorageChange)
1343 THROW(MsgException::INVALID_PARAM, "onStorageChange is null");
1345 MsgProxyListener* eventListener = MsgProxyListener::instance();
1347 eventListener->start(this);
1349 int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
1351 if (remoteFd == -1 )
1352 return MSG_ERR_INVALID_MSGHANDLE;
1354 if (eventListener->regStorageChangeEventCB(this, onStorageChange, pUserParam) == false)
1355 return MSG_ERR_INVALID_PARAMETER;
1357 // Allocate Memory to Command Data
1358 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
1359 char cmdBuf[cmdSize];
1360 bzero(cmdBuf, cmdSize);
1361 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
1363 // Set Command Parameters
1364 pCmd->cmdType = MSG_CMD_REG_STORAGE_CHANGE_CB;
1367 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1369 MSG_DEBUG("remote fd %d", remoteFd);
1371 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
1373 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
1375 // Send Command to Messaging FW
1376 char* pEventData = NULL;
1377 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1379 write((char*)pCmd, cmdSize, &pEventData);
1382 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1385 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1387 if (pEvent->eventType != MSG_EVENT_REG_STORAGE_CHANGE_CB)
1389 THROW(MsgException::INVALID_PARAM, "Event Data Error");
1392 return pEvent->result;
1395 msg_error_t MsgHandle::getReportStatus(msg_message_id_t msg_id, msg_struct_list_s *report_list)
1397 // Allocate Memory to Command Data
1398 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1400 char cmdBuf[cmdSize];
1401 bzero(cmdBuf, cmdSize);
1402 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1404 report_list->nCount = 0;
1405 report_list->msg_struct_info = NULL;
1407 // Set Command Parameters
1408 pCmd->cmdType = MSG_CMD_GET_REPORT_STATUS;
1411 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1413 // Copy Command Data
1414 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msg_id, sizeof(msg_message_id_t));
1416 // Send Command to Messaging FW
1417 char* pEventData = NULL;
1418 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1420 write((char*)pCmd, cmdSize, &pEventData);
1423 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1426 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1428 if (pEvent->eventType != MSG_EVENT_GET_REPORT_STATUS)
1430 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1433 if (pEvent->result != MSG_SUCCESS)
1434 return pEvent->result;
1436 // Decode Return Data
1437 MsgDecodeReportStatus(pEvent->data, report_list);
1443 msg_error_t MsgHandle::getAddressList(const msg_thread_id_t threadId, msg_struct_list_s *pAddrList)
1445 msg_error_t err = MSG_SUCCESS;
1447 // err = MsgStoConnectDB();
1449 // if (err != MSG_SUCCESS)
1451 // MSG_DEBUG("MsgStoConnectDB() Error!!");
1455 err = MsgStoGetAddressList(threadId, (msg_struct_list_s *)pAddrList);
1457 if (err != MSG_SUCCESS)
1459 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
1463 // MsgStoDisconnectDB();
1469 msg_error_t MsgHandle::getThreadIdByAddress(msg_struct_list_s *pAddrList, msg_thread_id_t *pThreadId)
1471 // Allocate Memory to Command Data
1472 int cmdSize = sizeof(MSG_CMD_S) + sizeof(pAddrList->nCount) + (sizeof(MSG_ADDRESS_INFO_S)*pAddrList->nCount);
1474 char cmdBuf[cmdSize];
1475 bzero(cmdBuf, cmdSize);
1476 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1478 // Set Command Parameters
1479 pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1482 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1484 // Copy Command Data
1485 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pAddrList->nCount, sizeof(pAddrList->nCount));
1486 int addSize = sizeof(MSG_ADDRESS_INFO_S);
1487 for(int i=0; i<pAddrList->nCount; i++) {
1488 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));
1491 // Send Command to Messaging FW
1492 char* pEventData = NULL;
1493 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1495 write((char*)pCmd, cmdSize, &pEventData);
1498 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1501 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1503 if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS)
1505 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1508 if (pEvent->result != MSG_SUCCESS)
1509 return pEvent->result;
1511 // Decode Return Data
1512 MsgDecodeThreadId(pEvent->data, pThreadId);
1518 msg_error_t MsgHandle::getThreadIdByAddress(msg_list_handle_t msg_address_list, msg_thread_id_t *pThreadId)
1520 int addrCnt = (int)g_list_length((GList *)msg_address_list);
1522 // Allocate Memory to Command Data
1523 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*addrCnt);
1525 char cmdBuf[cmdSize];
1526 bzero(cmdBuf, cmdSize);
1527 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1529 // Set Command Parameters
1530 pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1533 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1535 // Copy Command Data
1536 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &addrCnt, sizeof(int));
1537 int addSize = sizeof(MSG_ADDRESS_INFO_S);
1538 for(int i=0; i<addrCnt; i++) {
1539 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));
1542 // Send Command to Messaging FW
1543 char* pEventData = NULL;
1544 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1546 write((char*)pCmd, cmdSize, &pEventData);
1549 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1552 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1554 if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS)
1556 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1559 if (pEvent->result != MSG_SUCCESS)
1560 return pEvent->result;
1562 // Decode Return Data
1563 MsgDecodeThreadId(pEvent->data, pThreadId);
1569 msg_error_t MsgHandle::getThread(msg_thread_id_t threadId, MSG_THREAD_VIEW_S* pThreadInfo)
1571 // Allocate Memory to Command Data
1572 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
1574 char cmdBuf[cmdSize];
1575 bzero(cmdBuf, cmdSize);
1576 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1578 // Set Command Parameters
1579 pCmd->cmdType = MSG_CMD_GET_THREAD_INFO;
1582 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1584 // Copy Command Data
1585 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &threadId, sizeof(msg_thread_id_t));
1587 // Send Command to Messaging FW
1588 char* pEventData = NULL;
1589 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1591 write((char*)pCmd, cmdSize, &pEventData);
1594 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1597 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1599 if (pEvent->eventType != MSG_EVENT_GET_THREAD_INFO)
1601 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1604 // Decode Return Data
1605 MsgDecodeThreadInfo(pEvent->data, pThreadInfo);
1611 msg_error_t MsgHandle::getMessageList(const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pMsgList)
1613 msg_error_t err = MSG_SUCCESS;
1615 // err = MsgStoConnectDB();
1617 // if (err != MSG_SUCCESS) {
1618 // MSG_DEBUG("MsgStoConnectDB() Error!!");
1622 err = MsgStoGetMessageList(pListCond, pMsgList);
1624 if (err != MSG_SUCCESS) {
1625 MSG_DEBUG("MsgStoGetMessageList() Error!!");
1629 // MsgStoDisconnectDB();
1635 msg_error_t MsgHandle::getMediaList(const msg_thread_id_t thread_id, msg_list_handle_t *pMediaList)
1637 msg_error_t err = MSG_SUCCESS;
1639 err = MsgStoGetMediaList(thread_id, pMediaList);
1641 if (err != MSG_SUCCESS) {
1642 MSG_DEBUG("MsgStoGetFmMediaList() Error!!");
1650 int MsgHandle::addPushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1652 // Allocate Memory to Command Data
1653 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1655 char cmdBuf[cmdSize];
1656 bzero(cmdBuf, cmdSize);
1657 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1659 // Set Command Parameters
1660 pCmd->cmdType = MSG_CMD_ADD_PUSH_EVENT;
1663 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1665 // Copy Command Data
1666 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1668 // Send Command to Messaging FW
1669 char* pEventData = NULL;
1670 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1672 write((char*)pCmd, cmdSize, &pEventData);
1675 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1678 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1680 if (pEvent->eventType != MSG_EVENT_ADD_PUSH_EVENT)
1682 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1685 return pEvent->result;
1689 int MsgHandle::deletePushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1691 // Allocate Memory to Command Data
1692 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1694 char cmdBuf[cmdSize];
1695 bzero(cmdBuf, cmdSize);
1696 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1698 // Set Command Parameters
1699 pCmd->cmdType = MSG_CMD_DELETE_PUSH_EVENT;
1702 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1704 // Copy Command Data
1705 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1707 // Send Command to Messaging FW
1708 char* pEventData = NULL;
1709 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1711 write((char*)pCmd, cmdSize, &pEventData);
1714 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1717 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1719 if (pEvent->eventType != MSG_EVENT_DELETE_PUSH_EVENT)
1721 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1724 return pEvent->result;
1727 int MsgHandle::updatePushEvent(MSG_PUSH_EVENT_INFO_S *pSrc, MSG_PUSH_EVENT_INFO_S *pDst)
1729 // Allocate Memory to Command Data
1730 int cmdSize = sizeof(MSG_CMD_S) + 2 * sizeof(MSG_PUSH_EVENT_INFO_S);
1732 char cmdBuf[cmdSize];
1733 bzero(cmdBuf, cmdSize);
1734 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1736 // Set Command Parameters
1737 pCmd->cmdType = MSG_CMD_UPDATE_PUSH_EVENT;
1740 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1742 // Copy Command Data
1743 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pSrc, sizeof(MSG_PUSH_EVENT_INFO_S));
1744 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));
1746 // Send Command to Messaging FW
1747 char* pEventData = NULL;
1748 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1750 write((char*)pCmd, cmdSize, &pEventData);
1753 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1756 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1758 if (pEvent->eventType != MSG_EVENT_UPDATE_PUSH_EVENT)
1760 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1763 return pEvent->result;
1766 msg_error_t MsgHandle::getVobject(msg_message_id_t MsgId, void** encodedData)
1768 // Allocate Memory to Command Data
1769 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1770 char *encode_data = NULL;
1771 char cmdBuf[cmdSize];
1772 bzero(cmdBuf, cmdSize);
1773 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1775 // Set Command Parameters
1776 pCmd->cmdType = MSG_CMD_GET_MSG;
1779 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1781 // Copy Command Data
1782 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
1784 // Send Command to Messaging FW
1785 char* pEventData = NULL;
1786 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1789 write((char*)pCmd, cmdSize, &pEventData);
1792 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1795 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1797 if (pEvent->eventType != MSG_EVENT_GET_MSG)
1799 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1802 if (pEvent->result != MSG_SUCCESS)
1803 return pEvent->result;
1805 // Decode Return Data
1806 MSG_MESSAGE_INFO_S msgInfo = {0,};
1807 MSG_SENDINGOPT_INFO_S sendOptInfo = {0,};
1809 msgInfo.addressList = NULL;
1810 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1812 MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
1814 //Convert MSG_MESSAGE_INFO_S to
1815 encode_data = MsgVMessageEncode(&msgInfo);
1817 *encodedData = (void*)encode_data;
1819 MSG_DEBUG("Error Encode data");
1820 *encodedData = NULL;
1824 if (msgInfo.bTextSms == false)
1827 MsgDeleteFile(msgInfo.msgData); //ipc