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.
21 #include "MsgCppTypes.h"
22 #include "MsgException.h"
23 #include "MsgUtilFunction.h"
24 #include "MsgProxyListener.h"
25 #include "MsgHandle.h"
28 /*==================================================================================================
29 IMPLEMENTATION OF MsgHandle - Transport Member Functions
30 ==================================================================================================*/
31 msg_error_t MsgHandle::submitReq(MSG_REQUEST_S* pReq)
36 THROW(MsgException::INVALID_PARAM, "pReq is NULL");
38 #ifdef CHECK_SENT_STATUS_CALLBACK
39 if (MsgProxyListener::instance()->getSentStatusCbCnt() <= 0)
40 THROW(MsgException::SENT_STATUS_ERROR,"Register sent status callback");
43 MSG_REQUEST_INFO_S reqInfo = {0};
44 char trId[MMS_TR_ID_LEN+1] = {0};
46 reqInfo.msgInfo.addressList = NULL;
47 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&reqInfo.msgInfo.addressList, unique_ptr_deleter);
49 msg_struct_s *msg_s = (msg_struct_s *)pReq->msg;
51 MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S*)msg_s->data;
53 if (reqmsg->simIndex <= 0) {
54 MSG_DEBUG("Wrong SIM Index [%d]", reqmsg->simIndex);
55 return MSG_ERR_INVALID_PARAMETER;
58 if (reqmsg->subType != MSG_SENDREQ_JAVA_MMS) {
59 // In case MMS read report, get address value later.
60 if(reqmsg->subType != MSG_READREPLY_MMS) {
61 if (reqmsg->addr_list && (reqmsg->addr_list->nCount > 0) && (reqmsg->addr_list->nCount <= MAX_TO_ADDRESS_CNT)) {
62 MSG_DEBUG("Recipient address count [%d]", reqmsg->addr_list->nCount );
63 } else if (g_list_length(reqmsg->addressList) > 0) {
64 MSG_DEBUG("Recipient address count [%d]", g_list_length(reqmsg->addressList) );
66 MSG_DEBUG("Address count is invalid.");
67 return MSG_ERR_INVALID_MESSAGE;
71 /* Begin: Setting default values for submit request */
72 // pReq->msg.msgId = 0; // Set Request ID: internal use
73 // pReq->msg.folderId = MSG_OUTBOX_ID; // Set Folder ID
74 if (reqmsg->subType == MSG_RETRIEVE_MMS) {
75 reqmsg->networkStatus = MSG_NETWORK_RETRIEVING;
77 reqmsg->networkStatus = MSG_NETWORK_SENDING;
80 reqmsg->bRead = false;
81 //reqmsg->bProtected = false;
82 reqmsg->priority = MSG_MESSAGE_PRIORITY_NORMAL;
83 reqmsg->direction = MSG_DIRECTION_TYPE_MO;
84 reqmsg->storageId = MSG_STORAGE_PHONE;
86 time_t curTime = time(NULL);
89 THROW(MsgException::INVALID_RESULT, "time error : %s", g_strerror(errno));
91 reqmsg->displayTime = curTime;
92 /* End : Setting default values for submit request */
94 //in case of JAVA MMS msg, parse mms transaction id from pMmsData
95 reqmsg->networkStatus = MSG_NETWORK_SENDING;
96 strncpy(trId, (char*)reqmsg->pMmsData+3,MMS_TR_ID_LEN);
97 MSG_SEC_DEBUG("JavaMMS transaction Id:%s ",trId);
100 // Convert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
101 convertMsgStruct(reqmsg, &(reqInfo.msgInfo));
103 MSG_MESSAGE_TYPE_S msgType = {0,};
105 msgType.mainType = reqmsg->mainType;
106 msgType.subType = reqmsg->subType;
107 msgType.classType = reqmsg->classType;
109 msg_struct_s *send_opt_s = (msg_struct_s *)pReq->sendOpt;
110 MSG_SENDINGOPT_S *send_opt = (MSG_SENDINGOPT_S *)send_opt_s->data;
112 convertSendOptStruct((const MSG_SENDINGOPT_S *)send_opt, &(reqInfo.sendOptInfo), msgType);
116 /* Register proxy info used for receiving sent status */
117 MSG_PROXY_INFO_S chInfo = {0};
119 chInfo.listenerFd = MsgProxyListener::instance()->getRemoteFd();
121 chInfo.handleAddr = (unsigned long) this;
123 /* Allocate Memory to Command Data */
124 char* encodedData = NULL;
125 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
126 int dataSize = MsgEncodeMsgInfo(&reqInfo.msgInfo, &reqInfo.sendOptInfo, &encodedData);
128 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_request_id_t) + dataSize + sizeof(MSG_PROXY_INFO_S);
130 // In case of JAVA MMS msg, add trId
131 if (reqmsg->subType == MSG_SENDREQ_JAVA_MMS)
132 cmdSize += sizeof(trId);
134 char cmdBuf[cmdSize];
135 bzero(cmdBuf, cmdSize);
137 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
139 // Set Command Parameters
140 pCmd->cmdType = MSG_CMD_SUBMIT_REQ;
143 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
146 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &reqInfo.reqId, sizeof(msg_request_id_t));
147 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)), &chInfo, sizeof(MSG_PROXY_INFO_S));
148 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)+sizeof(MSG_PROXY_INFO_S)), encodedData, dataSize);
150 // In case of JAVA MMS msg, add trId
151 if (reqmsg->subType == MSG_SENDREQ_JAVA_MMS)
152 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)+sizeof(MSG_PROXY_INFO_S)+dataSize), &trId, sizeof(trId));
154 // Send Command to Messaging FW
155 char* pEventData = NULL;
156 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
158 write((char*)pCmd, cmdSize, &pEventData);
161 MSG_EVENT_S* pEvent = (MSG_EVENT_S*) pEventData;
163 int* pReqId = (int*) pEvent->data;
164 pReq->reqId = *pReqId;
165 MSG_DEBUG("SENT_REQ_ID: %d", pReq->reqId);
167 if (pEvent->eventType != MSG_EVENT_SUBMIT_REQ)
169 THROW(MsgException::INVALID_RESULT, "Event Data Error:%d", pEvent->eventType);
174 return pEvent->result;
178 msg_error_t MsgHandle::regSentStatusCallback(msg_sent_status_cb onStatusChanged, void *pUserParam)
180 if (!onStatusChanged)
181 THROW(MsgException::INVALID_PARAM, "onStatusChanged is null");
183 MsgProxyListener* eventListener = MsgProxyListener::instance();
185 eventListener->start(this);
187 int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
190 return MSG_ERR_INVALID_MSGHANDLE;
192 if (eventListener->regSentStatusEventCB(this, onStatusChanged, pUserParam) == false)
193 return MSG_ERR_INVALID_PARAMETER;
195 // Allocate Memory to Command Data
196 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
197 char cmdBuf[cmdSize];
198 bzero(cmdBuf, cmdSize);
199 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
201 // Set Command Parameters
202 pCmd->cmdType = MSG_CMD_REG_SENT_STATUS_CB;
205 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
207 MSG_DEBUG("remote fd %d", remoteFd);
209 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
211 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
213 // Send Command to Messaging FW
214 char* pEventData = NULL;
215 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
217 write((char*)pCmd, cmdSize, &pEventData);
220 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
222 if (pEvent->eventType != MSG_EVENT_REG_SENT_STATUS_CB)
224 THROW(MsgException::INVALID_PARAM, "Event Data Error");
227 return pEvent->result;
231 msg_error_t MsgHandle::regSmsMessageCallback(msg_sms_incoming_cb onMsgIncoming, unsigned short port, void *pUserParam)
233 if( (!onMsgIncoming) )
234 THROW(MsgException::INVALID_PARAM, "Param %p", onMsgIncoming);
236 MsgProxyListener* eventListener = MsgProxyListener::instance();
238 eventListener->start(this);
240 int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
243 return MSG_ERR_INVALID_MSGHANDLE;
245 if (eventListener->regMessageIncomingEventCB(this, onMsgIncoming, port, pUserParam) == false)
246 return MSG_ERR_INVALID_PARAMETER;
248 // Allocate Memory to Command Data
249 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
251 char cmdBuf[cmdSize];
252 bzero(cmdBuf, cmdSize);
254 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
256 // Set Command Parameters
257 pCmd->cmdType = MSG_CMD_REG_INCOMING_MSG_CB;
260 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
262 MSG_CMD_REG_INCOMING_MSG_CB_S cmdParam = {0};
264 cmdParam.listenerFd = remoteFd;
265 cmdParam.msgType = MSG_SMS_TYPE;
266 cmdParam.port = port;
268 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
270 MSG_DEBUG("reg new msg [%s], fd %d, port %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, cmdParam.port);
272 // Send Command to Messaging FW
273 char* pEventData = NULL;
274 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
277 write((char*)pCmd, cmdSize, &pEventData);
280 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
282 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_MSG_CB)
284 THROW(MsgException::INVALID_RESULT, "Event Data Error");
287 return pEvent->result;
291 msg_error_t MsgHandle::regMmsConfMessageCallback(msg_mms_conf_msg_incoming_cb onMMSConfMsgIncoming, const char *pAppId, void *pUserParam)
293 if( (!onMMSConfMsgIncoming) )
294 THROW(MsgException::INVALID_PARAM, "Param %p", onMMSConfMsgIncoming);
296 MsgProxyListener* eventListener = MsgProxyListener::instance();
298 eventListener->start(this);
300 int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
303 return MSG_ERR_INVALID_MSGHANDLE;
305 if (eventListener->regMMSConfMessageIncomingEventCB(this, onMMSConfMsgIncoming, pAppId, pUserParam) == false)
306 return MSG_ERR_INVALID_PARAMETER;
308 // Allocate Memory to Command Data
309 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S);
311 char cmdBuf[cmdSize];
312 bzero(cmdBuf, cmdSize);
314 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
316 // Set Command Parameters
317 pCmd->cmdType = MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB;
320 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
322 MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S cmdParam = {0};
324 cmdParam.listenerFd = remoteFd;
325 cmdParam.msgType = MSG_MMS_TYPE;
328 strncpy(cmdParam.appId, pAppId, MAX_MMS_JAVA_APPID_LEN);
330 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
332 MSG_DEBUG("reg new msg [%s], fd:%d, appId:%s", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, (pAppId)? cmdParam.appId:"NULL" );
334 // Send Command to Messaging FW
335 char* pEventData = NULL;
336 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
339 write((char*)pCmd, cmdSize, &pEventData);
342 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
344 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_MMS_CONF_MSG_CB)
346 THROW(MsgException::INVALID_RESULT, "Event Data Error");
349 return pEvent->result;
353 msg_error_t MsgHandle::regSyncMLMessageCallback(msg_syncml_msg_incoming_cb onSyncMLMsgIncoming, void *pUserParam)
355 if( (!onSyncMLMsgIncoming) )
356 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgIncoming);
358 MsgProxyListener* eventListener = MsgProxyListener::instance();
360 eventListener->start(this);
362 int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
365 return MSG_ERR_INVALID_MSGHANDLE;
367 if (eventListener->regSyncMLMessageIncomingEventCB(this, onSyncMLMsgIncoming, pUserParam) == false)
368 return MSG_ERR_INVALID_PARAMETER;
370 // Allocate Memory to Command Data
371 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
373 char cmdBuf[cmdSize];
374 bzero(cmdBuf, cmdSize);
376 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
378 // Set Command Parameters
379 pCmd->cmdType = MSG_CMD_REG_INCOMING_SYNCML_MSG_CB;
382 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
384 MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S cmdParam = {0};
386 cmdParam.listenerFd = remoteFd;
387 cmdParam.msgType = MSG_SMS_TYPE;
389 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
391 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
393 // Send Command to Messaging FW
394 char* pEventData = NULL;
395 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
397 write((char*)pCmd, cmdSize, &pEventData);
400 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
402 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_SYNCML_MSG_CB)
404 THROW(MsgException::INVALID_RESULT, "Event Data Error");
407 return pEvent->result;
411 msg_error_t MsgHandle::regLBSMessageCallback(msg_lbs_msg_incoming_cb onLBSMsgIncoming, void *pUserParam)
413 if( (!onLBSMsgIncoming) )
414 THROW(MsgException::INVALID_PARAM, "Param %p", onLBSMsgIncoming);
416 MsgProxyListener* eventListener = MsgProxyListener::instance();
418 eventListener->start(this);
420 int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
423 return MSG_ERR_INVALID_MSGHANDLE;
425 if (eventListener->regLBSMessageIncomingEventCB(this, onLBSMsgIncoming, pUserParam) == false)
426 return MSG_ERR_INVALID_PARAMETER;
428 // Allocate Memory to Command Data
429 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
430 char cmdBuf[cmdSize];
431 bzero(cmdBuf, cmdSize);
432 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
434 // Set Command Parameters
435 pCmd->cmdType = MSG_CMD_REG_INCOMING_LBS_MSG_CB;
438 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
440 MSG_CMD_REG_INCOMING_LBS_MSG_CB_S cmdParam = {0};
442 cmdParam.listenerFd = remoteFd;
443 cmdParam.msgType = MSG_SMS_TYPE;
445 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
447 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
449 // Send Command to Messaging FW
450 char* pEventData = NULL;
451 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
454 write((char*)pCmd, cmdSize, &pEventData);
457 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
459 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_LBS_MSG_CB)
461 THROW(MsgException::INVALID_RESULT, "Event Data Error");
464 return pEvent->result;
468 msg_error_t MsgHandle::regSyncMLMessageOperationCallback(msg_syncml_msg_operation_cb onSyncMLMsgOperation, void *pUserParam)
470 if( (!onSyncMLMsgOperation) )
471 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgOperation);
473 MsgProxyListener* eventListener = MsgProxyListener::instance();
475 eventListener->start(this);
477 int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
480 return MSG_ERR_INVALID_MSGHANDLE;
482 if (eventListener->regSyncMLMessageOperationEventCB(this, onSyncMLMsgOperation, pUserParam) == false)
483 return MSG_ERR_INVALID_PARAMETER;
485 // Allocate Memory to Command Data
486 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
488 char cmdBuf[cmdSize];
489 bzero(cmdBuf, cmdSize);
491 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
493 // Set Command Parameters
494 pCmd->cmdType = MSG_CMD_REG_SYNCML_MSG_OPERATION_CB;
497 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
499 MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S cmdParam = {0};
501 cmdParam.listenerFd = remoteFd;
502 cmdParam.msgType = MSG_SMS_TYPE;
504 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
506 MSG_DEBUG("register syncML msg operation callback [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
508 // Send Command to Messaging FW
509 char* pEventData = NULL;
510 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
513 write((char*)pCmd, cmdSize, &pEventData);
516 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
518 if (pEvent->eventType != MSG_EVENT_REG_SYNCML_MSG_OPERATION_CB)
520 THROW(MsgException::INVALID_RESULT, "Event Data Error");
523 return pEvent->result;
526 msg_error_t MsgHandle::regPushMessageCallback(msg_push_msg_incoming_cb onPushMsgIncoming, const char *pAppId, void *pUserParam)
528 if( (!onPushMsgIncoming) )
529 THROW(MsgException::INVALID_PARAM, "Param %p", onPushMsgIncoming);
531 MsgProxyListener* eventListener = MsgProxyListener::instance();
533 eventListener->start(this);
535 int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
538 return MSG_ERR_INVALID_MSGHANDLE;
540 if (eventListener->regPushMessageIncomingEventCB(this, onPushMsgIncoming, pAppId, pUserParam) == false)
541 return MSG_ERR_INVALID_PARAMETER;
543 // Allocate Memory to Command Data
544 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S);
546 char cmdBuf[cmdSize];
547 bzero(cmdBuf, cmdSize);
549 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
551 // Set Command Parameters
552 pCmd->cmdType = MSG_CMD_REG_INCOMING_PUSH_MSG_CB;
555 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
557 MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S cmdParam = {0};
559 cmdParam.listenerFd = remoteFd;
560 cmdParam.msgType = MSG_SMS_TYPE;
563 strncpy(cmdParam.appId, pAppId, MAX_WAPPUSH_ID_LEN);
565 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
567 MSG_DEBUG("reg new msg [%s], fd:%d, appId:%s", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, (pAppId)? cmdParam.appId:"NULL" );
569 // Send Command to Messaging FW
570 char* pEventData = NULL;
571 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
574 write((char*)pCmd, cmdSize, &pEventData);
577 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
579 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_PUSH_MSG_CB)
581 THROW(MsgException::INVALID_RESULT, "Event Data Error");
584 return pEvent->result;
587 msg_error_t MsgHandle::regCBMessageCallback(msg_cb_incoming_cb onCBIncoming, bool bSave, void *pUserParam)
589 if( (!onCBIncoming) )
590 THROW(MsgException::INVALID_PARAM, "Param %p", onCBIncoming);
592 MsgProxyListener* eventListener = MsgProxyListener::instance();
594 eventListener->start(this);
596 int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
599 return MSG_ERR_INVALID_MSGHANDLE;
601 if (eventListener->regCBMessageIncomingEventCB(this, onCBIncoming, bSave, pUserParam) == false)
604 // Allocate Memory to Command Data
605 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_CB_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
607 char cmdBuf[cmdSize];
608 bzero(cmdBuf, cmdSize);
610 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
612 // Set Command Parameters
613 pCmd->cmdType = MSG_CMD_REG_INCOMING_CB_MSG_CB;
616 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
618 MSG_CMD_REG_CB_INCOMING_MSG_CB_S cmdParam = {0};
620 cmdParam.listenerFd = remoteFd;
621 cmdParam.msgType = MSG_SMS_TYPE;
622 cmdParam.bsave = bSave;
624 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
626 MSG_DEBUG("reg new msg [%s], fd: %d, bSave: %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, cmdParam.bsave);
628 // Send Command to Messaging FW
629 char* pEventData = NULL;
630 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
633 write((char*)pCmd, cmdSize, &pEventData);
636 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
638 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_CB_MSG_CB)
640 THROW(MsgException::INVALID_RESULT, "Event Data Error");
643 return pEvent->result;
647 msg_error_t MsgHandle::regReportMessageCallback(msg_report_msg_incoming_cb onReportMsgCB, void *pUserParam)
650 THROW(MsgException::INVALID_PARAM, "onReportMsgCB is null");
652 MsgProxyListener* eventListener = MsgProxyListener::instance();
654 eventListener->start(this);
656 int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
659 return MSG_ERR_INVALID_MSGHANDLE;
661 if (eventListener->regReportMsgIncomingCB(this, onReportMsgCB, pUserParam) == false)
662 return MSG_ERR_INVALID_PARAMETER;
664 // Allocate Memory to Command Data
665 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
666 char cmdBuf[cmdSize];
667 bzero(cmdBuf, cmdSize);
668 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
670 // Set Command Parameters
671 pCmd->cmdType = MSG_CMD_REG_REPORT_MSG_INCOMING_CB;
674 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
676 MSG_DEBUG("remote fd %d", remoteFd);
678 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
680 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
682 // Send Command to Messaging FW
683 char* pEventData = NULL;
684 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
686 write((char*)pCmd, cmdSize, &pEventData);
689 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
691 if (pEvent->eventType != MSG_EVENT_REG_REPORT_MSG_INCOMING_CB)
693 THROW(MsgException::INVALID_PARAM, "Event Data Error");
696 return pEvent->result;
700 msg_error_t MsgHandle::operateSyncMLMessage(msg_message_id_t msgId)
703 THROW(MsgException::INVALID_PARAM, "Param msgId %d", msgId);
705 // Allocate Memory to Command Data
706 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
708 char cmdBuf[cmdSize];
709 bzero(cmdBuf, cmdSize);
710 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
712 // Set Command Parameters
713 pCmd->cmdType = MSG_CMD_SYNCML_OPERATION;
716 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
719 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgId, sizeof(msg_message_id_t));
721 // Send Command to Messaging FW
722 char* pEventData = NULL;
723 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
726 write((char*)pCmd, cmdSize, &pEventData);
729 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
731 if (pEvent->eventType != MSG_EVENT_SYNCML_OPERATION)
733 THROW(MsgException::INVALID_RESULT, "Event Data Error");
736 return pEvent->result;