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 "MsgProxyContact.h"
26 #include "MsgVMessage.h"
27 /*==================================================================================================
28 IMPLEMENTATION OF MsgHandle - Storage Member Functions
29 ==================================================================================================*/
30 int MsgHandle::addMessage(MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
32 MSG_MESSAGE_INFO_S msgInfo = {0, };
33 MSG_SENDINGOPT_INFO_S sendOptInfo = {0, };
35 msgInfo.addressList = NULL;
36 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
38 /* Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S */
39 convertMsgStruct(pMsg, &msgInfo);
41 /* Covert MSG_SENDINGOPT_S to MSG_SENDINGOPT_INFO_S */
42 MSG_MESSAGE_TYPE_S msgType = {0, };
44 msgType.mainType = pMsg->mainType;
45 msgType.subType = pMsg->subType;
46 msgType.classType = pMsg->classType;
48 convertSendOptStruct(pSendOpt, &sendOptInfo, msgType);
50 /* Allocate Memory to Command Data */
51 char* encodedData = NULL;
52 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
53 int dataSize = MsgEncodeMsgInfo(&msgInfo, &sendOptInfo, &encodedData);
55 int cmdSize = sizeof(MSG_CMD_S) + dataSize;
58 bzero(cmdBuf, cmdSize);
59 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
61 /* Set Command Parameters */
62 pCmd->cmdType = MSG_CMD_ADD_MSG;
65 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
67 /* Copy Command Data */
68 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), encodedData, dataSize);
70 /* Send Command to Messaging FW */
71 char* pEventData = NULL;
72 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
74 write((char*)pCmd, cmdSize, &pEventData);
77 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
80 THROW(MsgException::INVALID_RESULT, "Event is NULL");
82 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;
91 /* Decode Return Data */
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);
127 /* Copy Command Data */
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);
139 /* Get Return Data */
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) {
146 THROW(MsgException::INVALID_RESULT, "Event Data Error");
149 msg_message_id_t msgId = 0;
151 /* Decode Return Data */
152 MsgDecodeMsgId(pEvent->data, &msgId);
154 ((MSG_MESSAGE_HIDDEN_S *)msg->data)->msgId = msgId;
156 return pEvent->result;
160 msg_error_t MsgHandle::updateMessage(const MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
162 MSG_MESSAGE_INFO_S msgInfo = {0, };
163 MSG_SENDINGOPT_INFO_S sendOptInfo = {0, };
165 msgInfo.addressList = NULL;
166 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
168 /* Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S */
169 convertMsgStruct(pMsg, &msgInfo);
171 if (pSendOpt != NULL) {
172 MSG_MESSAGE_TYPE_S msgType = {0, };
174 msgType.mainType = pMsg->mainType;
175 msgType.subType = pMsg->subType;
176 msgType.classType = pMsg->classType;
178 convertSendOptStruct(pSendOpt, &sendOptInfo, msgType);
181 /* Allocate Memory to Command Data */
182 char* encodedData = NULL;
183 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
184 int dataSize = MsgEncodeMsgInfo(&msgInfo, &sendOptInfo, &encodedData);
186 int cmdSize = sizeof(MSG_CMD_S) + dataSize;
188 char cmdBuf[cmdSize];
189 bzero(cmdBuf, cmdSize);
190 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
192 /* Set Command Parameters */
193 pCmd->cmdType = MSG_CMD_UPDATE_MSG;
196 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
198 /* Copy Command Data */
199 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), encodedData, dataSize);
201 /* Send Command to Messaging FW */
202 char* pEventData = NULL;
203 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
205 write((char*)pCmd, cmdSize, &pEventData);
207 /* Get Return Data */
208 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
211 THROW(MsgException::INVALID_RESULT, "Event is NULL");
213 if (pEvent->eventType != MSG_EVENT_UPDATE_MSG) {
214 THROW(MsgException::INVALID_RESULT, "Event Data Error");
217 return pEvent->result;
221 msg_error_t MsgHandle::updateReadStatus(msg_message_id_t MsgId, bool bRead)
223 /* Allocate Memory to Command Data */
224 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(bool);
226 char cmdBuf[cmdSize];
227 bzero(cmdBuf, cmdSize);
228 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
230 /* Set Command Parameters */
231 pCmd->cmdType = MSG_CMD_UPDATE_READ;
234 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
236 /* Copy Command Data */
237 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
238 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &bRead, sizeof(bool));
240 /* Send Command to Messaging FW */
241 char* pEventData = NULL;
242 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
244 write((char*)pCmd, cmdSize, &pEventData);
246 /* Get Return Data */
247 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
250 THROW(MsgException::INVALID_RESULT, "Event is NULL");
252 if (pEvent->eventType != MSG_EVENT_UPDATE_READ) {
253 THROW(MsgException::INVALID_RESULT, "Event Data Error");
256 return pEvent->result;
260 msg_error_t MsgHandle::setConversationToRead(msg_thread_id_t ThreadId)
262 /* Allocate Memory to Command Data */
263 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
265 char cmdBuf[cmdSize];
266 bzero(cmdBuf, cmdSize);
267 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
269 /* Set Command Parameters */
270 pCmd->cmdType = MSG_CMD_UPDATE_THREAD_READ;
273 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
275 /* Copy Command Data */
276 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
278 /* Send Command to Messaging FW */
279 char* pEventData = NULL;
280 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
282 write((char*)pCmd, cmdSize, &pEventData);
284 /* Get Return Data */
285 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
288 THROW(MsgException::INVALID_RESULT, "Event is NULL");
290 if (pEvent->eventType != MSG_EVENT_UPDATE_THREAD_READ) {
291 THROW(MsgException::INVALID_RESULT, "Event Data Error");
294 return pEvent->result;
298 msg_error_t MsgHandle::updateProtectedStatus(msg_message_id_t MsgId, bool bProtected)
300 /* Allocate Memory to Command Data */
301 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(bool);
303 char cmdBuf[cmdSize];
304 bzero(cmdBuf, cmdSize);
305 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
307 /* Set Command Parameters */
308 pCmd->cmdType = MSG_CMD_UPDATE_PROTECTED;
311 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
313 /* Copy Command Data */
314 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
315 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &bProtected, sizeof(bool));
317 /* Send Command to Messaging FW */
318 char* pEventData = NULL;
319 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
321 write((char*)pCmd, cmdSize, &pEventData);
323 /* Get Return Data */
324 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
327 THROW(MsgException::INVALID_RESULT, "Event is NULL");
329 if (pEvent->eventType != MSG_EVENT_UPDATE_PROTECTED) {
330 THROW(MsgException::INVALID_RESULT, "Event Data Error");
333 return pEvent->result;
337 msg_error_t MsgHandle::deleteMessage(msg_message_id_t MsgId)
339 /* Allocate Memory to Command Data */
340 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
342 char cmdBuf[cmdSize];
343 bzero(cmdBuf, cmdSize);
344 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
346 /* Set Command Parameters */
347 pCmd->cmdType = MSG_CMD_DELETE_MSG;
350 memcpy((void*)pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
352 /* Copy Command Data */
353 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
355 /* Send Command to Messaging FW */
356 char* pEventData = NULL;
357 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
359 write((char*)pCmd, cmdSize, &pEventData);
361 /* Get Return Data */
362 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
365 THROW(MsgException::INVALID_RESULT, "Event is NULL");
367 if (pEvent->eventType != MSG_EVENT_DELETE_MSG) {
368 THROW(MsgException::INVALID_RESULT, "Event Data Error");
371 return pEvent->result;
375 msg_error_t MsgHandle::deleteAllMessagesInFolder(msg_folder_id_t FolderId, bool bOnlyDB)
377 /* Allocate Memory to Command Data */
378 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
380 char cmdBuf[cmdSize];
381 bzero(cmdBuf, cmdSize);
382 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
384 /* Set Command Parameters */
385 pCmd->cmdType = MSG_CMD_DELALL_MSGINFOLDER;
388 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
390 /* Copy Command Data */
391 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
392 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_folder_id_t)), &bOnlyDB, sizeof(bool));
394 /* Send Command to Messaging FW */
395 char* pEventData = NULL;
396 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
398 write((char*)pCmd, cmdSize, &pEventData);
400 /* Get Return Data */
401 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
404 THROW(MsgException::INVALID_RESULT, "Event is NULL");
406 if (pEvent->eventType != MSG_EVENT_DELALL_MSGINFOLDER) {
407 THROW(MsgException::INVALID_RESULT, "Event Data Error");
410 return pEvent->result;
414 msg_error_t MsgHandle::deleteMessagesByList(msg_id_list_s *pMsgIdList)
416 /* Allocate Memory to Command Data */
417 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + (sizeof(int)*pMsgIdList->nCount);
419 char cmdBuf[cmdSize];
420 bzero(cmdBuf, cmdSize);
421 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
423 /* Set Command Parameters */
424 pCmd->cmdType = MSG_CMD_DELETE_MESSAGE_BY_LIST;
427 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
429 /* Copy Command Data */
430 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &(pMsgIdList->nCount), sizeof(int));
431 for (int i = 0; i < pMsgIdList->nCount; i++) {
432 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+(sizeof(int)*i)), &(pMsgIdList->msgIdList[i]), sizeof(int));
435 /* Send Command to Messaging FW */
436 char* pEventData = NULL;
437 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
439 write((char*)pCmd, cmdSize, &pEventData);
441 /* Get Return Data */
442 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
445 THROW(MsgException::INVALID_RESULT, "Event is NULL");
447 if (pEvent->eventType != MSG_EVENT_DELETE_MESSAGE_BY_LIST) {
448 THROW(MsgException::INVALID_RESULT, "Event Data Error");
451 return pEvent->result;
455 msg_error_t MsgHandle::moveMessageToFolder(msg_message_id_t MsgId, msg_folder_id_t DestFolderId)
457 /* Allocate Memory to Command Data */
458 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(msg_folder_id_t);
460 char cmdBuf[cmdSize];
461 bzero(cmdBuf, cmdSize);
462 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
464 /* Set Command Parameters */
465 pCmd->cmdType = MSG_CMD_MOVE_MSGTOFOLDER;
468 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
470 /* Copy Command Data */
471 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
472 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(msg_message_id_t)+MAX_COOKIE_LEN), &DestFolderId, sizeof(msg_folder_id_t));
474 /* Send Command to Messaging FW */
475 char* pEventData = NULL;
476 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
478 write((char*)pCmd, cmdSize, &pEventData);
480 /* Get Return Data */
481 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
484 THROW(MsgException::INVALID_RESULT, "Event is NULL");
486 if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOFOLDER) {
487 THROW(MsgException::INVALID_RESULT, "Event Data Error");
490 return pEvent->result;
494 msg_error_t MsgHandle::moveMessageToStorage(msg_message_id_t MsgId, msg_storage_id_t DestStorageId)
496 /* Allocate Memory to Command Data */
497 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(msg_storage_id_t);
499 char cmdBuf[cmdSize];
500 bzero(cmdBuf, cmdSize);
501 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
503 /* Set Command Parameters */
504 pCmd->cmdType = MSG_CMD_MOVE_MSGTOSTORAGE;
507 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
509 /* Copy Command Data */
510 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
511 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &DestStorageId, sizeof(msg_storage_id_t));
513 /* Send Command to Messaging FW */
514 char* pEventData = NULL;
515 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
517 write((char*)pCmd, cmdSize, &pEventData);
519 /* Get Return Data */
520 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
523 THROW(MsgException::INVALID_RESULT, "Event is NULL");
525 if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOSTORAGE) {
526 THROW(MsgException::INVALID_RESULT, "Event Data Error");
529 return pEvent->result;
533 msg_error_t MsgHandle::countMessage(msg_folder_id_t FolderId, MSG_COUNT_INFO_S *pCountInfo)
535 /* Allocate Memory to Command Data */
536 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
538 char cmdBuf[cmdSize];
539 bzero(cmdBuf, cmdSize);
540 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
542 /* Set Command Parameters */
543 pCmd->cmdType = MSG_CMD_COUNT_MSG;
546 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
548 /* Copy Command Data */
549 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
551 /* Send Command to Messaging FW */
552 char* pEventData = NULL;
553 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
555 write((char*)pCmd, cmdSize, &pEventData);
557 /* Get Return Data */
558 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
561 THROW(MsgException::INVALID_RESULT, "Event is NULL");
563 if (pEvent->eventType != MSG_EVENT_COUNT_MSG) {
564 THROW(MsgException::INVALID_RESULT, "Event Data Error");
567 if (pEvent->result != MSG_SUCCESS)
568 return pEvent->result;
570 /* Decode Return Data */
571 MsgDecodeCountInfo(pEvent->data, pCountInfo);
577 msg_error_t MsgHandle::countMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount)
579 /* Allocate Memory to Command Data */
580 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_TYPE_S);
582 char cmdBuf[cmdSize];
583 bzero(cmdBuf, cmdSize);
584 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
586 /* Set Command Parameters */
587 pCmd->cmdType = MSG_CMD_COUNT_BY_MSGTYPE;
590 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
592 /* Copy Command Data */
593 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pMsgType, sizeof(MSG_MESSAGE_TYPE_S));
595 /* Send Command to Messaging FW */
596 char* pEventData = NULL;
597 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
599 write((char*)pCmd, cmdSize, &pEventData);
601 /* Get Return Data */
602 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
605 THROW(MsgException::INVALID_RESULT, "Event is NULL");
607 if (pEvent->eventType != MSG_EVENT_COUNT_BY_MSGTYPE) {
608 THROW(MsgException::INVALID_RESULT, "Event Data Error");
611 if (pEvent->result != MSG_SUCCESS)
612 return pEvent->result;
614 /* Decode Return Data */
615 memcpy(pMsgCount, (void*)((char*)pEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(int));
621 msg_error_t MsgHandle::countMsgByContact(const MSG_THREAD_LIST_INDEX_INFO_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
623 /* Allocate Memory to Command Data */
624 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_THREAD_LIST_INDEX_S);
626 char cmdBuf[cmdSize];
627 bzero(cmdBuf, cmdSize);
628 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
630 /* Set Command Parameters */
631 pCmd->cmdType = MSG_CMD_GET_CONTACT_COUNT;
634 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
636 /* Copy Command Data */
637 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pAddrInfo, sizeof(msg_contact_id_t));
638 msg_struct_s *pAddr = (msg_struct_s *)pAddrInfo->msgAddrInfo;
640 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN + sizeof(msg_contact_id_t)), pAddr->data, sizeof(MSG_ADDRESS_INFO_S));
641 /* Send Command to Messaging FW */
642 char* pEventData = NULL;
643 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
645 write((char*)pCmd, cmdSize, &pEventData);
647 /* Get Return Data */
648 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
651 THROW(MsgException::INVALID_RESULT, "Event is NULL");
653 if (pEvent->eventType != MSG_EVENT_GET_CONTACT_COUNT) {
654 THROW(MsgException::INVALID_RESULT, "Event Data Error");
657 if (pEvent->result != MSG_SUCCESS)
658 return pEvent->result;
660 /* Decode Return Data */
661 MsgDecodeContactCount(pEvent->data, pMsgThreadCountList);
667 msg_error_t MsgHandle::getMessage(msg_message_id_t MsgId, MSG_MESSAGE_HIDDEN_S *pMsg, MSG_SENDINGOPT_S *pSendOpt)
669 /* Allocate Memory to Command Data */
670 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
672 char cmdBuf[cmdSize];
673 bzero(cmdBuf, cmdSize);
674 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
676 /* Set Command Parameters */
677 pCmd->cmdType = MSG_CMD_GET_MSG;
680 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
682 /* Copy Command Data */
683 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
685 /* Send Command to Messaging FW */
686 char* pEventData = NULL;
687 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
690 write((char*)pCmd, cmdSize, &pEventData);
692 /* Get Return Data */
693 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
696 THROW(MsgException::INVALID_RESULT, "Event is NULL");
698 if (pEvent->eventType != MSG_EVENT_GET_MSG) {
699 THROW(MsgException::INVALID_RESULT, "Event Data Error");
702 if (pEvent->result != MSG_SUCCESS)
703 return pEvent->result;
705 /* Decode Return Data */
706 MSG_MESSAGE_INFO_S msgInfo;
707 MSG_SENDINGOPT_INFO_S sendOptInfo;
709 msgInfo.addressList = NULL;
710 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
712 MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
714 /* Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_HIDDEN_S */
715 convertMsgStruct(&msgInfo, pMsg);
717 if (pSendOpt != NULL) {
718 MSG_MESSAGE_TYPE_S msgType = {0, };
720 msgType.mainType = pMsg->mainType;
721 msgType.subType = pMsg->subType;
722 msgType.classType = pMsg->classType;
724 convertSendOptStruct(&sendOptInfo, pSendOpt, msgType);
727 /* Delete Temp File */
728 if (msgInfo.bTextSms == false) {
729 /* Delete Temp File */
730 MsgDeleteFile(msgInfo.msgData); /* ipc */
737 msg_error_t MsgHandle::addFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
739 /* Allocate Memory to Command Data */
740 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
742 char cmdBuf[cmdSize];
743 bzero(cmdBuf, cmdSize);
744 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
746 /* Set Command Parameters */
747 pCmd->cmdType = MSG_CMD_ADD_FOLDER;
750 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
752 /* Copy Command Data */
753 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
755 /* Send Command to Messaging FW */
756 char* pEventData = NULL;
757 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
759 write((char*)pCmd, cmdSize, &pEventData);
761 /* Get Return Data */
762 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
765 THROW(MsgException::INVALID_RESULT, "Event is NULL");
767 if (pEvent->eventType != MSG_EVENT_ADD_FOLDER) {
768 THROW(MsgException::INVALID_RESULT, "Event Data Error");
771 return pEvent->result;
775 msg_error_t MsgHandle::updateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
777 /* Allocate Memory to Command Data */
778 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
780 char cmdBuf[cmdSize];
781 bzero(cmdBuf, cmdSize);
782 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
784 /* Set Command Parameters */
785 pCmd->cmdType = MSG_CMD_UPDATE_FOLDER;
788 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
790 /* Copy Command Data */
791 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
793 /* Send Command to Messaging FW */
794 char* pEventData = NULL;
795 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
797 write((char*)pCmd, cmdSize, &pEventData);
799 /* Get Return Data */
800 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
803 THROW(MsgException::INVALID_RESULT, "Event is NULL");
805 if (pEvent->eventType != MSG_EVENT_UPDATE_FOLDER) {
806 THROW(MsgException::INVALID_RESULT, "Event Data Error");
809 return pEvent->result;
813 msg_error_t MsgHandle::deleteFolder(msg_folder_id_t FolderId)
815 /* Allocate Memory to Command Data */
816 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
818 char cmdBuf[cmdSize];
819 bzero(cmdBuf, cmdSize);
820 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
822 /* Set Command Parameters */
823 pCmd->cmdType = MSG_CMD_DELETE_FOLDER;
826 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
828 /* Copy Command Data */
829 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
831 /* Send Command to Messaging FW */
832 char* pEventData = NULL;
833 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
835 write((char*)pCmd, cmdSize, &pEventData);
837 /* Get Return Data */
838 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
841 THROW(MsgException::INVALID_RESULT, "Event is NULL");
843 if (pEvent->eventType != MSG_EVENT_DELETE_FOLDER) {
844 THROW(MsgException::INVALID_RESULT, "Event Data Error");
847 return pEvent->result;
851 msg_error_t MsgHandle::getFolderList(msg_struct_list_s *pFolderList)
853 /* Allocate Memory to Command Data */
854 int cmdSize = sizeof(MSG_CMD_S);
856 char cmdBuf[cmdSize];
857 bzero(cmdBuf, cmdSize);
858 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
860 /* Set Command Parameters */
861 pCmd->cmdType = MSG_CMD_GET_FOLDERLIST;
864 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
866 /* Send Command to Messaging FW */
867 char* pEventData = NULL;
868 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
870 write((char*)pCmd, cmdSize, &pEventData);
872 /* Get Return Data */
873 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
876 THROW(MsgException::INVALID_RESULT, "Event is NULL");
878 if (pEvent->eventType != MSG_EVENT_GET_FOLDERLIST) {
879 THROW(MsgException::INVALID_RESULT, "Event Data Error");
882 if (pEvent->result != MSG_SUCCESS)
883 return pEvent->result;
885 /* Decode Return Data */
886 MsgDecodeFolderList(pEvent->data, pFolderList);
892 msg_error_t MsgHandle::getThreadViewList(const MSG_SORT_RULE_S *pSortRule, msg_struct_list_s *pThreadViewList)
894 msg_error_t err = MSG_SUCCESS;
896 err = MsgStoConnectDB();
898 if (err != MSG_SUCCESS) {
899 MSG_DEBUG("MsgStoConnectDB() Error!!");
904 err = MsgStoGetThreadViewList(pSortRule, pThreadViewList);
906 if (err != MSG_SUCCESS) {
907 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
911 /* MsgStoDisconnectDB(); */
914 /* Allocate Memory to Command Data */
915 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_SORT_RULE_S);
917 char cmdBuf[cmdSize];
918 bzero(cmdBuf, cmdSize);
919 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
921 /* Set Command Parameters */
922 pCmd->cmdType = MSG_CMD_GET_THREADVIEWLIST;
924 /* Copy Command Data */
925 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)), pSortRule, sizeof(MSG_SORT_RULE_S));
927 /* Send Command to Messaging FW */
928 char* pEventData = NULL;
929 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
931 write((char*)pCmd, cmdSize, &pEventData);
933 /* Get Return Data */
934 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
937 THROW(MsgException::INVALID_RESULT, "Event is NULL");
939 if (pEvent->eventType != MSG_EVENT_GET_THREADVIEWLIST) {
940 THROW(MsgException::INVALID_RESULT, "Event Data Error");
943 if (pEvent->result != MSG_SUCCESS)
944 return pEvent->result;
946 /* Decode Return Data */
947 MsgDecodeThreadViewList(pEvent->data, pMsgThreadViewList);
953 msg_error_t MsgHandle::getConversationViewItem(msg_message_id_t MsgId, MSG_CONVERSATION_VIEW_S *pConv)
957 msg_error_t err = MSG_SUCCESS;
959 /* MsgStoConnectDB(); */
960 err = MsgStoGetConversationViewItem(MsgId, pConv);
961 /* MsgStoDisconnectDB(); */
966 msg_error_t MsgHandle::getConversationViewList(msg_thread_id_t ThreadId, msg_struct_list_s *pConvViewList)
970 msg_error_t err = MSG_SUCCESS;
972 /* MsgStoConnectDB(); */
973 err = MsgStoGetConversationViewList(ThreadId, pConvViewList);
974 /* MsgStoDisconnectDB(); */
976 if (err != MSG_SUCCESS)
985 msg_error_t MsgHandle::deleteThreadMessageList(msg_thread_id_t ThreadId, bool include_protected_msg)
987 /* Allocate Memory to Command Data */
988 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t) + sizeof(bool);
990 char cmdBuf[cmdSize];
991 bzero(cmdBuf, cmdSize);
992 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
994 /* Set Command Parameters */
995 pCmd->cmdType = MSG_CMD_DELETE_THREADMESSAGELIST;
998 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1000 /* Copy Command Data */
1001 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
1002 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_thread_id_t)), &include_protected_msg, sizeof(bool));
1004 /* Send Command to Messaging FW */
1005 char* pEventData = NULL;
1006 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1008 write((char*)pCmd, cmdSize, &pEventData);
1010 /* Get Return Data */
1011 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1014 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1016 if (pEvent->eventType != MSG_EVENT_DELETE_THREADMESSAGELIST) {
1017 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1020 if (pEvent->result != MSG_SUCCESS)
1021 return pEvent->result;
1027 msg_error_t MsgHandle::getQuickPanelData(msg_quickpanel_type_t Type, MSG_MESSAGE_HIDDEN_S *pMsg)
1029 /* Allocate Memory to Command Data */
1030 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_quickpanel_type_t);
1032 char cmdBuf[cmdSize];
1033 bzero(cmdBuf, cmdSize);
1034 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1036 /* Set Command Parameters */
1037 pCmd->cmdType = MSG_CMD_GET_QUICKPANEL_DATA;
1040 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1042 /* Copy Command Data */
1043 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &Type, sizeof(msg_quickpanel_type_t));
1045 /* Send Command to Messaging FW */
1046 char* pEventData = NULL;
1047 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1049 write((char*)pCmd, cmdSize, &pEventData);
1051 /* Get Return Data */
1052 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1055 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1057 if (pEvent->eventType != MSG_EVENT_GET_QUICKPANEL_DATA) {
1058 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1061 if (pEvent->result != MSG_SUCCESS)
1062 return pEvent->result;
1064 /* Decode Return Data */
1065 MSG_MESSAGE_INFO_S msgInfo;
1067 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1069 msgInfo.addressList = NULL;
1070 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1072 MsgDecodeMsgInfo((char *)pEvent->data, &msgInfo);
1074 /* Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_S */
1075 convertMsgStruct(&msgInfo, pMsg);
1077 /* Delete Temp File */
1078 if (msgInfo.bTextSms == false) {
1079 /* Delete Temp File */
1080 MsgDeleteFile(msgInfo.msgData); /* ipc */
1087 msg_error_t MsgHandle::resetDatabase()
1089 /* Allocate Memory to Command Data */
1090 int cmdSize = sizeof(MSG_CMD_S);
1092 char cmdBuf[cmdSize];
1093 bzero(cmdBuf, cmdSize);
1094 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1096 /* Set Command Parameters */
1097 pCmd->cmdType = MSG_CMD_RESET_DB;
1100 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1102 /* Send Command to Messaging FW */
1103 char* pEventData = NULL;
1104 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1106 write((char*)pCmd, cmdSize, &pEventData);
1108 /* Get Return Data */
1109 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1112 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1114 if (pEvent->eventType != MSG_EVENT_RESET_DB) {
1115 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1118 return pEvent->result;
1122 msg_error_t MsgHandle::getMemSize(unsigned int* memsize)
1124 /* Allocate Memory to Command Data */
1125 int cmdSize = sizeof(MSG_CMD_S);
1127 char cmdBuf[cmdSize];
1128 bzero(cmdBuf, cmdSize);
1129 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1131 /* Set Command Parameters */
1132 pCmd->cmdType = MSG_CMD_GET_MEMSIZE;
1135 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1137 /* Send Command to Messaging FW */
1138 char* pEventData = NULL;
1139 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1141 write((char*)pCmd, cmdSize, &pEventData);
1143 /* Get Return Data */
1144 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1147 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1149 if (pEvent->eventType != MSG_EVENT_GET_MEMSIZE) {
1150 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1153 if (pEvent->result != MSG_SUCCESS)
1154 return pEvent->result;
1156 /* Decode Return Data */
1157 MsgDecodeMemSize(pEvent->data, memsize);
1163 msg_error_t MsgHandle::backupMessage(msg_message_backup_type_t type, const char *backup_filepath)
1165 if (backup_filepath == NULL)
1166 return MSG_ERR_NULL_POINTER;
1168 /* Create an empty file for writing. */
1169 /* If a file with the same name already exists its content is erased */
1170 /* and the file is treated as a new empty file. */
1172 FILE *pFile = MsgOpenFile(backup_filepath, "w");
1173 if (pFile == NULL) {
1174 MSG_DEBUG("File Open error");
1175 return MSG_ERR_STORAGE_ERROR;
1177 MsgCloseFile(pFile);
1179 char path[MSG_FILEPATH_LEN_MAX+1] = {0, };
1180 strncpy(path, backup_filepath, MSG_FILEPATH_LEN_MAX);
1182 /* Allocate Memory to Command Data */
1183 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_backup_type_t) + sizeof(path);
1185 char cmdBuf[cmdSize];
1186 bzero(cmdBuf, cmdSize);
1187 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1189 /* Set Command Parameters */
1190 pCmd->cmdType = MSG_CMD_BACKUP_MESSAGE;
1193 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1194 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &type, sizeof(msg_message_backup_type_t));
1195 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_backup_type_t)), (char *)path, sizeof(path));
1197 /* Send Command to Messaging FW */
1198 char* pEventData = NULL;
1199 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1201 write((char*)pCmd, cmdSize, &pEventData);
1203 /* Get Return Data */
1204 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1207 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1209 if (pEvent->eventType != MSG_EVENT_BACKUP_MESSAGE) {
1210 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1213 return pEvent->result;
1217 msg_error_t MsgHandle::restoreMessage(const char *backup_filepath)
1219 if (backup_filepath == NULL)
1220 return MSG_ERR_NULL_POINTER;
1222 if (MsgAccessFile(backup_filepath, R_OK) == false) {
1223 MSG_DEBUG("File access error");
1224 return MSG_ERR_UNKNOWN;
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(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_RESTORE_MESSAGE;
1241 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1242 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), (char *)path, sizeof(path));
1244 /* Send Command to Messaging FW */
1245 char* pEventData = NULL;
1246 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1248 write((char*)pCmd, cmdSize, &pEventData);
1250 /* Get Return Data */
1251 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1254 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1256 if (pEvent->eventType != MSG_EVENT_RESTORE_MESSAGE) {
1257 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1260 return pEvent->result;
1264 msg_error_t MsgHandle::searchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList)
1266 msg_error_t err = MSG_SUCCESS;
1270 MSG_ADDRESS_INFO_S *pAddrInfo = NULL;
1271 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> buf(&pAddrInfo, unique_ptr_deleter);
1273 /* get contact search list */
1274 if (MsgGetContactSearchList(pSearchString, &pAddrInfo, &count) != MSG_SUCCESS) {
1275 MSG_DEBUG("MsgGetContactSearchList fail.");
1280 /* Allocate Memory to Command Data */
1281 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + sizeof(MSG_ADDRESS_INFO_S) * count;
1283 char cmdBuf[cmdSize];
1284 bzero(cmdBuf, cmdSize);
1285 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1287 /* Set Command Parameters */
1288 pCmd->cmdType = MSG_CMD_SET_TEMP_ADDRESS_TABLE;
1291 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1293 /* Copy Command Data */
1294 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &count, sizeof(int));
1295 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), pAddrInfo, sizeof(MSG_ADDRESS_INFO_S) * count);
1297 /* Send Command to Messaging FW */
1298 char* pEventData = NULL;
1299 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1301 write((char*)pCmd, cmdSize, &pEventData);
1303 /* Get Return Data */
1304 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1307 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1309 if (pEvent->eventType != MSG_EVENT_SET_TEMP_ADDRESS_TABLE)
1310 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1312 if (pEvent->result != MSG_SUCCESS)
1316 err = MsgStoSearchMessage(pSearchString, pThreadViewList, count);
1318 if (err != MSG_SUCCESS) {
1319 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1323 /* MsgStoDisconnectDB(); */
1329 msg_error_t MsgHandle::getRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList)
1331 msg_error_t err = MSG_SUCCESS;
1333 err = MsgStoConnectDB();
1335 if (err != MSG_SUCCESS) {
1336 MSG_DEBUG("MsgStoConnectDB() Error!!");
1340 err = MsgStoGetRejectMsgList(pNumber, pRejectMsgList);
1342 if (err != MSG_SUCCESS) {
1343 MSG_DEBUG("MsgStoGetRejectMsgList() Error!!");
1347 /* MsgStoDisconnectDB(); */
1353 msg_error_t MsgHandle::regStorageChangeCallback(msg_storage_change_cb onStorageChange, void *pUserParam)
1355 if (!onStorageChange)
1356 THROW(MsgException::INVALID_PARAM, "onStorageChange is null");
1358 MsgProxyListener* eventListener = MsgProxyListener::instance();
1360 eventListener->start(this);
1362 int remoteFd = eventListener->getRemoteFd(); /* fd that is reserved to the "listener thread" by msgfw daemon */
1364 if (remoteFd == -1 ) {
1365 eventListener->stop();
1366 return MSG_ERR_INVALID_MSGHANDLE;
1369 if (eventListener->regStorageChangeEventCB(this, remoteFd, onStorageChange, pUserParam) == false) {
1370 eventListener->stop();
1371 return MSG_ERR_INVALID_PARAMETER;
1374 /* Allocate Memory to Command Data */
1375 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); /* cmd type, listenerFd */
1376 char cmdBuf[cmdSize];
1377 bzero(cmdBuf, cmdSize);
1378 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
1380 /* Set Command Parameters */
1381 pCmd->cmdType = MSG_CMD_REG_STORAGE_CHANGE_CB;
1384 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1386 MSG_DEBUG("remote fd %d", remoteFd);
1388 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
1390 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
1392 /* Send Command to Messaging FW */
1393 char* pEventData = NULL;
1394 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1396 write((char*)pCmd, cmdSize, &pEventData);
1398 /* Get Return Data */
1399 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1402 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1404 if (pEvent->eventType != MSG_EVENT_REG_STORAGE_CHANGE_CB) {
1405 THROW(MsgException::INVALID_PARAM, "Event Data Error");
1408 return pEvent->result;
1412 msg_error_t MsgHandle::regThreadChangeCallback(msg_thread_change_cb onThreadChange, void *pUserParam)
1414 if (!onThreadChange)
1415 THROW(MsgException::INVALID_PARAM, "onThreadChange is null");
1417 MsgProxyListener* eventListener = MsgProxyListener::instance();
1419 eventListener->start(this);
1421 int remoteFd = eventListener->getRemoteFd(); /* fd that is reserved to the "listener thread" by msgfw daemon */
1423 if (remoteFd == -1 ) {
1424 eventListener->stop();
1425 return MSG_ERR_INVALID_MSGHANDLE;
1428 if (eventListener->regThreadChangeEventCB(this, remoteFd, onThreadChange, pUserParam) == false) {
1429 eventListener->stop();
1430 return MSG_ERR_INVALID_PARAMETER;
1433 /* Allocate Memory to Command Data */
1434 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); /* cmd type, listenerFd */
1435 char cmdBuf[cmdSize];
1436 bzero(cmdBuf, cmdSize);
1437 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
1439 /* Set Command Parameters */
1440 pCmd->cmdType = MSG_CMD_REG_THREAD_CHANGE_CB;
1443 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1445 MSG_DEBUG("remote fd %d", remoteFd);
1447 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
1449 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
1451 /* Send Command to Messaging FW */
1452 char* pEventData = NULL;
1453 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1455 write((char*)pCmd, cmdSize, &pEventData);
1457 /* Get Return Data */
1458 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1461 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1463 if (pEvent->eventType != MSG_EVENT_REG_THREAD_CHANGE_CB) {
1464 THROW(MsgException::INVALID_PARAM, "Event Data Error");
1467 return pEvent->result;
1471 msg_error_t MsgHandle::getReportStatus(msg_message_id_t msg_id, msg_struct_list_s *report_list)
1473 /* Allocate Memory to Command Data */
1474 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1476 char cmdBuf[cmdSize];
1477 bzero(cmdBuf, cmdSize);
1478 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1480 report_list->nCount = 0;
1481 report_list->msg_struct_info = NULL;
1483 /* Set Command Parameters */
1484 pCmd->cmdType = MSG_CMD_GET_REPORT_STATUS;
1487 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1489 /* Copy Command Data */
1490 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msg_id, sizeof(msg_message_id_t));
1492 /* Send Command to Messaging FW */
1493 char* pEventData = NULL;
1494 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1496 write((char*)pCmd, cmdSize, &pEventData);
1498 /* Get Return Data */
1499 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1502 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1504 if (pEvent->eventType != MSG_EVENT_GET_REPORT_STATUS) {
1505 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1508 if (pEvent->result != MSG_SUCCESS)
1509 return pEvent->result;
1511 /* Decode Return Data */
1512 MsgDecodeReportStatus(pEvent->data, report_list);
1518 msg_error_t MsgHandle::getAddressList(const msg_thread_id_t threadId, msg_struct_list_s *pAddrList)
1520 msg_error_t err = MSG_SUCCESS;
1522 err = MsgStoConnectDB();
1524 if (err != MSG_SUCCESS) {
1525 MSG_DEBUG("MsgStoConnectDB() Error!!");
1529 err = MsgStoGetAddressList(threadId, (msg_struct_list_s *)pAddrList);
1531 if (err != MSG_SUCCESS) {
1532 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
1536 /* MsgStoDisconnectDB(); */
1542 msg_error_t MsgHandle::getThreadIdByAddress(msg_struct_list_s *pAddrList, msg_thread_id_t *pThreadId)
1544 /* Allocate Memory to Command Data */
1545 int cmdSize = sizeof(MSG_CMD_S) + sizeof(pAddrList->nCount) + (sizeof(MSG_ADDRESS_INFO_S)*pAddrList->nCount);
1547 char cmdBuf[cmdSize];
1548 bzero(cmdBuf, cmdSize);
1549 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1551 /* Set Command Parameters */
1552 pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1555 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1557 /* Copy Command Data */
1558 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pAddrList->nCount, sizeof(pAddrList->nCount));
1559 int addSize = sizeof(MSG_ADDRESS_INFO_S);
1560 for (int i = 0; i < pAddrList->nCount; i++) {
1561 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));
1564 /* Send Command to Messaging FW */
1565 char* pEventData = NULL;
1566 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1568 write((char*)pCmd, cmdSize, &pEventData);
1570 /* Get Return Data */
1571 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1574 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1576 if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS) {
1577 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1580 if (pEvent->result != MSG_SUCCESS)
1581 return pEvent->result;
1583 /* Decode Return Data */
1584 MsgDecodeThreadId(pEvent->data, pThreadId);
1590 msg_error_t MsgHandle::getThreadIdByAddress(msg_list_handle_t msg_address_list, msg_thread_id_t *pThreadId)
1592 int addrCnt = (int)g_list_length((GList *)msg_address_list);
1594 /* Allocate Memory to Command Data */
1595 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*addrCnt);
1597 char cmdBuf[cmdSize];
1598 bzero(cmdBuf, cmdSize);
1599 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1601 /* Set Command Parameters */
1602 pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1605 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1607 /* Copy Command Data */
1608 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &addrCnt, sizeof(int));
1609 int addSize = sizeof(MSG_ADDRESS_INFO_S);
1610 for (int i = 0; i < addrCnt; i++) {
1611 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));
1614 /* Send Command to Messaging FW */
1615 char* pEventData = NULL;
1616 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1618 write((char*)pCmd, cmdSize, &pEventData);
1620 /* Get Return Data */
1621 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1624 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1626 if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS) {
1627 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1630 if (pEvent->result != MSG_SUCCESS)
1631 return pEvent->result;
1633 /* Decode Return Data */
1634 MsgDecodeThreadId(pEvent->data, pThreadId);
1640 msg_error_t MsgHandle::getThread(msg_thread_id_t threadId, MSG_THREAD_VIEW_S* pThreadInfo)
1642 /* Allocate Memory to Command Data */
1643 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
1645 char cmdBuf[cmdSize];
1646 bzero(cmdBuf, cmdSize);
1647 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1649 /* Set Command Parameters */
1650 pCmd->cmdType = MSG_CMD_GET_THREAD_INFO;
1653 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1655 /* Copy Command Data */
1656 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &threadId, sizeof(msg_thread_id_t));
1658 /* Send Command to Messaging FW */
1659 char* pEventData = NULL;
1660 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1662 write((char*)pCmd, cmdSize, &pEventData);
1664 /* Get Return Data */
1665 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1668 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1670 if (pEvent->eventType != MSG_EVENT_GET_THREAD_INFO) {
1671 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1674 /* Decode Return Data */
1675 MsgDecodeThreadInfo(pEvent->data, pThreadInfo);
1681 msg_error_t MsgHandle::getMessageList(const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pMsgList)
1683 msg_error_t err = MSG_SUCCESS;
1685 err = MsgStoConnectDB();
1687 if (err != MSG_SUCCESS) {
1688 MSG_DEBUG("MsgStoConnectDB() Error!!");
1694 if (pListCond->pAddressVal) {
1695 MSG_ADDRESS_INFO_S *pAddrInfo = NULL;
1696 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> buf(&pAddrInfo, unique_ptr_deleter);
1698 /* get contact search list */
1699 if (MsgGetContactSearchList(pListCond->pAddressVal, &pAddrInfo, &count) != MSG_SUCCESS) {
1700 MSG_DEBUG("MsgGetContactSearchList fail.");
1705 /* Allocate Memory to Command Data */
1706 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + sizeof(MSG_ADDRESS_INFO_S) * count;
1708 char cmdBuf[cmdSize];
1709 bzero(cmdBuf, cmdSize);
1710 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1712 /* Set Command Parameters */
1713 pCmd->cmdType = MSG_CMD_SET_TEMP_ADDRESS_TABLE;
1716 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1718 /* Copy Command Data */
1719 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &count, sizeof(int));
1720 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), pAddrInfo, sizeof(MSG_ADDRESS_INFO_S) * count);
1722 /* Send Command to Messaging FW */
1723 char* pEventData = NULL;
1724 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1726 write((char*)pCmd, cmdSize, &pEventData);
1728 /* Get Return Data */
1729 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1732 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1734 if (pEvent->eventType != MSG_EVENT_SET_TEMP_ADDRESS_TABLE)
1735 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1737 if (pEvent->result != MSG_SUCCESS)
1742 err = MsgStoGetMessageList(pListCond, pMsgList, count);
1744 if (err != MSG_SUCCESS) {
1745 MSG_DEBUG("MsgStoGetMessageList() Error!!");
1749 /* MsgStoDisconnectDB(); */
1755 msg_error_t MsgHandle::getMediaList(const msg_thread_id_t thread_id, msg_list_handle_t *pMediaList)
1757 msg_error_t err = MSG_SUCCESS;
1759 err = MsgStoGetMediaList(thread_id, pMediaList);
1761 if (err != MSG_SUCCESS) {
1762 MSG_DEBUG("MsgStoGetFmMediaList() Error!!");
1770 int MsgHandle::addPushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1772 /* Allocate Memory to Command Data */
1773 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1775 char cmdBuf[cmdSize];
1776 bzero(cmdBuf, cmdSize);
1777 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1779 /* Set Command Parameters */
1780 pCmd->cmdType = MSG_CMD_ADD_PUSH_EVENT;
1783 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1785 /* Copy Command Data */
1786 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1788 /* Send Command to Messaging FW */
1789 char* pEventData = NULL;
1790 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1792 write((char*)pCmd, cmdSize, &pEventData);
1794 /* Get Return Data */
1795 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1798 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1800 if (pEvent->eventType != MSG_EVENT_ADD_PUSH_EVENT) {
1801 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1804 return pEvent->result;
1808 int MsgHandle::deletePushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1810 /* Allocate Memory to Command Data */
1811 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1813 char cmdBuf[cmdSize];
1814 bzero(cmdBuf, cmdSize);
1815 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1817 /* Set Command Parameters */
1818 pCmd->cmdType = MSG_CMD_DELETE_PUSH_EVENT;
1821 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1823 /* Copy Command Data */
1824 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1826 /* Send Command to Messaging FW */
1827 char* pEventData = NULL;
1828 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1830 write((char*)pCmd, cmdSize, &pEventData);
1832 /* Get Return Data */
1833 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1836 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1838 if (pEvent->eventType != MSG_EVENT_DELETE_PUSH_EVENT) {
1839 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1842 return pEvent->result;
1846 int MsgHandle::updatePushEvent(MSG_PUSH_EVENT_INFO_S *pSrc, MSG_PUSH_EVENT_INFO_S *pDst)
1848 /* Allocate Memory to Command Data */
1849 int cmdSize = sizeof(MSG_CMD_S) + 2 * sizeof(MSG_PUSH_EVENT_INFO_S);
1851 char cmdBuf[cmdSize];
1852 bzero(cmdBuf, cmdSize);
1853 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1855 /* Set Command Parameters */
1856 pCmd->cmdType = MSG_CMD_UPDATE_PUSH_EVENT;
1859 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1861 /* Copy Command Data */
1862 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pSrc, sizeof(MSG_PUSH_EVENT_INFO_S));
1863 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));
1865 /* Send Command to Messaging FW */
1866 char* pEventData = NULL;
1867 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1869 write((char*)pCmd, cmdSize, &pEventData);
1871 /* Get Return Data */
1872 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1875 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1877 if (pEvent->eventType != MSG_EVENT_UPDATE_PUSH_EVENT) {
1878 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1881 return pEvent->result;
1885 msg_error_t MsgHandle::getVobject(msg_message_id_t MsgId, void** encodedData)
1887 /* Allocate Memory to Command Data */
1888 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1889 char *encode_data = NULL;
1890 char cmdBuf[cmdSize];
1891 bzero(cmdBuf, cmdSize);
1892 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1894 /* Set Command Parameters */
1895 pCmd->cmdType = MSG_CMD_GET_MSG;
1898 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1900 /* Copy Command Data */
1901 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
1903 /* Send Command to Messaging FW */
1904 char* pEventData = NULL;
1905 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1908 write((char*)pCmd, cmdSize, &pEventData);
1910 /* Get Return Data */
1911 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1914 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1916 if (pEvent->eventType != MSG_EVENT_GET_MSG) {
1917 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1920 if (pEvent->result != MSG_SUCCESS)
1921 return pEvent->result;
1923 /* Decode Return Data */
1924 MSG_MESSAGE_INFO_S msgInfo = {0, };
1925 MSG_SENDINGOPT_INFO_S sendOptInfo = {0, };
1927 msgInfo.addressList = NULL;
1928 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1930 MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
1932 /*Convert MSG_MESSAGE_INFO_S to */
1933 encode_data = MsgVMessageEncode(&msgInfo);
1935 *encodedData = (void*)encode_data;
1937 MSG_DEBUG("Error Encode data");
1938 *encodedData = NULL;
1941 /* Delete Temp File */
1942 if (msgInfo.bTextSms == false) {
1943 /* Delete Temp File */
1944 MsgDeleteFile(msgInfo.msgData); /* ipc */
1951 msg_error_t MsgHandle::dbSelectWithQuery(const char *query, char ***db_res, int *row_count, int *col_count)
1953 msg_error_t err = MSG_SUCCESS;
1955 err = MsgStoDbSelectWithQuery(query, db_res, row_count, col_count);
1957 if (err != MSG_SUCCESS)
1966 void MsgHandle::dbFree(char **db_res)
1968 MsgStoDbFree(db_res);