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 "MsgUtilFile.h"
24 #include "MsgUtilFunction.h"
25 #include "MsgProxyListener.h"
26 #include "MsgHandle.h"
29 /*==================================================================================================
30 IMPLEMENTATION OF MsgHandle - Transport Member Functions
31 ==================================================================================================*/
32 msg_error_t MsgHandle::submitReq(MSG_REQUEST_S* pReq)
37 THROW(MsgException::INVALID_PARAM, "pReq is NULL");
39 #ifdef CHECK_SENT_STATUS_CALLBACK
40 if (MsgProxyListener::instance()->getSentStatusCbCnt() <= 0)
41 THROW(MsgException::SENT_STATUS_ERROR, "Register sent status callback");
44 MSG_REQUEST_INFO_S reqInfo = {0};
45 char trId[MMS_TR_ID_LEN+1] = {0};
47 reqInfo.msgInfo.addressList = NULL;
48 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&reqInfo.msgInfo.addressList, unique_ptr_deleter);
50 msg_struct_s *msg_s = (msg_struct_s *)pReq->msg;
52 MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S*)msg_s->data;
54 if (reqmsg->simIndex <= 0) {
55 MSG_DEBUG("Wrong SIM Index [%d]", reqmsg->simIndex);
56 return MSG_ERR_INVALID_PARAMETER;
59 if (reqmsg->subType != MSG_SENDREQ_JAVA_MMS) {
60 /* In case MMS read report, get address value later. */
61 if (reqmsg->subType != MSG_READREPLY_MMS) {
62 if (reqmsg->addr_list && (reqmsg->addr_list->nCount > 0) && (reqmsg->addr_list->nCount <= MAX_TO_ADDRESS_CNT)) {
63 MSG_DEBUG("Recipient address count [%d]", reqmsg->addr_list->nCount);
64 } else if (g_list_length(reqmsg->addressList) > 0) {
65 MSG_DEBUG("Recipient address count [%d]", g_list_length(reqmsg->addressList) );
67 MSG_DEBUG("Address count is invalid.");
68 return MSG_ERR_INVALID_MESSAGE;
72 /* Begin: Setting default values for submit request */
73 /* Set Request ID: internal use */
74 /* pReq->msg.msgId = 0; */
76 /* pReq->msg.folderId = MSG_OUTBOX_ID; */
77 if (reqmsg->subType == MSG_RETRIEVE_MMS) {
78 reqmsg->networkStatus = MSG_NETWORK_RETRIEVING;
80 reqmsg->networkStatus = MSG_NETWORK_SENDING;
83 reqmsg->bRead = false;
84 /* reqmsg->bProtected = false; */
85 reqmsg->priority = MSG_MESSAGE_PRIORITY_NORMAL;
86 reqmsg->direction = MSG_DIRECTION_TYPE_MO;
87 reqmsg->storageId = MSG_STORAGE_PHONE;
89 time_t curTime = time(NULL);
92 THROW(MsgException::INVALID_RESULT, "time error : %s", g_strerror(errno));
94 reqmsg->displayTime = curTime;
95 /* End : Setting default values for submit request */
97 /* in case of JAVA MMS msg, parse mms transaction id from pMmsData */
98 reqmsg->networkStatus = MSG_NETWORK_SENDING;
99 strncpy(trId, (char*)reqmsg->pMmsData+3, MMS_TR_ID_LEN);
100 MSG_SEC_DEBUG("JavaMMS transaction Id:%s", trId);
103 /* Convert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S */
104 convertMsgStruct(reqmsg, &(reqInfo.msgInfo));
106 MSG_MESSAGE_TYPE_S msgType = {0, };
108 msgType.mainType = reqmsg->mainType;
109 msgType.subType = reqmsg->subType;
110 msgType.classType = reqmsg->classType;
112 msg_struct_s *send_opt_s = (msg_struct_s *)pReq->sendOpt;
113 MSG_SENDINGOPT_S *send_opt = (MSG_SENDINGOPT_S *)send_opt_s->data;
115 convertSendOptStruct((const MSG_SENDINGOPT_S *)send_opt, &(reqInfo.sendOptInfo), msgType);
119 /* Register proxy info used for receiving sent status */
120 MSG_PROXY_INFO_S chInfo = {0};
122 chInfo.listenerFd = MsgProxyListener::instance()->getRemoteFd();
124 chInfo.handleAddr = (unsigned long) this;
126 /* Allocate Memory to Command Data */
127 char* encodedData = NULL;
128 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
129 int dataSize = MsgEncodeMsgInfo(&reqInfo.msgInfo, &reqInfo.sendOptInfo, &encodedData);
131 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_request_id_t) + dataSize + sizeof(MSG_PROXY_INFO_S);
133 /* In case of JAVA MMS msg, add trId */
134 if (reqmsg->subType == MSG_SENDREQ_JAVA_MMS)
135 cmdSize += sizeof(trId);
137 char cmdBuf[cmdSize];
138 bzero(cmdBuf, cmdSize);
140 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
142 /* Set Command Parameters */
143 pCmd->cmdType = MSG_CMD_SUBMIT_REQ;
146 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
148 /* Copy Command Data */
149 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &reqInfo.reqId, sizeof(msg_request_id_t));
150 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)), &chInfo, sizeof(MSG_PROXY_INFO_S));
151 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)+sizeof(MSG_PROXY_INFO_S)), encodedData, dataSize);
153 /* In case of JAVA MMS msg, add trId */
154 if (reqmsg->subType == MSG_SENDREQ_JAVA_MMS)
155 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));
157 /* Send Command to Messaging FW */
158 char* pEventData = NULL;
159 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
161 write((char*)pCmd, cmdSize, &pEventData);
163 /* Delete Temp File */
164 if (reqInfo.msgInfo.bTextSms == false) {
165 MsgDeleteFile(reqInfo.msgInfo.msgData); /* ipc */
168 /* Get Return Data */
169 MSG_EVENT_S* pEvent = (MSG_EVENT_S*) pEventData;
173 memcpy(&ret, (void*)pEvent->data, sizeof(ret));
175 pReq->reqId = ret[0];
176 reqmsg->msgId = (msg_message_id_t)ret[1];
177 reqmsg->threadId = (msg_thread_id_t)ret[2];
178 MSG_DEBUG("SENT_REQ_ID: %d", pReq->reqId);
179 MSG_DEBUG("MSG_ID: %d", reqmsg->msgId);
180 MSG_DEBUG("THREAD_ID: %d", reqmsg->threadId);
182 if (pEvent->eventType != MSG_EVENT_SUBMIT_REQ) {
183 THROW(MsgException::INVALID_RESULT, "Event Data Error:%d", pEvent->eventType);
188 return pEvent->result;
192 msg_error_t MsgHandle::regSentStatusCallback(msg_sent_status_cb onStatusChanged, void *pUserParam)
194 if (!onStatusChanged)
195 THROW(MsgException::INVALID_PARAM, "onStatusChanged is null");
197 MsgProxyListener* eventListener = MsgProxyListener::instance();
199 eventListener->start(this);
201 int remoteFd = eventListener->getRemoteFd(); /* fd that is reserved to the "listener thread" by msgfw daemon */
203 if (remoteFd == -1) {
204 eventListener->stop();
205 return MSG_ERR_INVALID_MSGHANDLE;
208 if (eventListener->regSentStatusEventCB(this, remoteFd, onStatusChanged, pUserParam) == false) {
209 eventListener->stop();
210 return MSG_ERR_INVALID_PARAMETER;
213 /* Allocate Memory to Command Data */
214 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); /* cmd type, listenerFd */
215 char cmdBuf[cmdSize];
216 bzero(cmdBuf, cmdSize);
217 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
219 /* Set Command Parameters */
220 pCmd->cmdType = MSG_CMD_REG_SENT_STATUS_CB;
223 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
225 MSG_DEBUG("remote fd %d", remoteFd);
227 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
229 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
231 /* Send Command to Messaging FW */
232 char* pEventData = NULL;
233 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
235 write((char*)pCmd, cmdSize, &pEventData);
237 /* Get Return Data */
238 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
240 if (pEvent->eventType != MSG_EVENT_REG_SENT_STATUS_CB) {
241 THROW(MsgException::INVALID_PARAM, "Event Data Error");
244 return pEvent->result;
248 msg_error_t MsgHandle::regSmsMessageCallback(msg_sms_incoming_cb onMsgIncoming, unsigned short port, void *pUserParam)
251 THROW(MsgException::INVALID_PARAM, "Param %p", onMsgIncoming);
253 MsgProxyListener* eventListener = MsgProxyListener::instance();
255 eventListener->start(this);
257 int remoteFd = eventListener->getRemoteFd(); /* fd that is reserved to the "listener thread" by msgfw daemon */
259 if (remoteFd == -1) {
260 eventListener->stop();
261 return MSG_ERR_INVALID_MSGHANDLE;
264 if (eventListener->regMessageIncomingEventCB(this, remoteFd, onMsgIncoming, port, pUserParam) == false) {
265 eventListener->stop();
266 return MSG_ERR_INVALID_PARAMETER;
269 /* Allocate Memory to Command Data */
270 /* sizeof(int) + sizeof; */
271 /* cmd type, listener fd */
272 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MSG_CB_S);
274 char cmdBuf[cmdSize];
275 bzero(cmdBuf, cmdSize);
277 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
279 /* Set Command Parameters */
280 pCmd->cmdType = MSG_CMD_REG_INCOMING_MSG_CB;
283 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
285 MSG_CMD_REG_INCOMING_MSG_CB_S cmdParam = {0};
287 cmdParam.listenerFd = remoteFd;
288 cmdParam.msgType = MSG_SMS_TYPE;
289 cmdParam.port = port;
291 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
293 MSG_DEBUG("reg new msg [%s], fd %d, port %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, cmdParam.port);
295 /* Send Command to Messaging FW */
296 char* pEventData = NULL;
297 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
300 write((char*)pCmd, cmdSize, &pEventData);
302 /* Get Return Data */
303 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
305 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_MSG_CB) {
306 THROW(MsgException::INVALID_RESULT, "Event Data Error");
309 return pEvent->result;
313 msg_error_t MsgHandle::regMmsConfMessageCallback(msg_mms_conf_msg_incoming_cb onMMSConfMsgIncoming, const char *pAppId, void *pUserParam)
315 if (!onMMSConfMsgIncoming)
316 THROW(MsgException::INVALID_PARAM, "Param %p", onMMSConfMsgIncoming);
318 MsgProxyListener* eventListener = MsgProxyListener::instance();
320 eventListener->start(this);
322 int remoteFd = eventListener->getRemoteFd(); /* fd that is reserved to the "listener thread" by msgfw daemon */
324 if (remoteFd == -1) {
325 eventListener->stop();
326 return MSG_ERR_INVALID_MSGHANDLE;
329 if (eventListener->regMMSConfMessageIncomingEventCB(this, remoteFd, onMMSConfMsgIncoming, pAppId, pUserParam) == false) {
330 eventListener->stop();
331 return MSG_ERR_INVALID_PARAMETER;
334 /* Allocate Memory to Command Data */
335 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S);
337 char cmdBuf[cmdSize];
338 bzero(cmdBuf, cmdSize);
340 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
342 /* Set Command Parameters */
343 pCmd->cmdType = MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB;
346 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
348 MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S cmdParam = {0};
350 cmdParam.listenerFd = remoteFd;
351 cmdParam.msgType = MSG_MMS_TYPE;
354 strncpy(cmdParam.appId, pAppId, MAX_MMS_JAVA_APPID_LEN);
356 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
358 MSG_DEBUG("reg new msg [%s], fd:%d, appId:%s", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, (pAppId)? cmdParam.appId:"NULL");
360 /* Send Command to Messaging FW */
361 char* pEventData = NULL;
362 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
365 write((char*)pCmd, cmdSize, &pEventData);
367 /* Get Return Data */
368 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
370 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_MMS_CONF_MSG_CB) {
371 THROW(MsgException::INVALID_RESULT, "Event Data Error");
374 return pEvent->result;
378 msg_error_t MsgHandle::regSyncMLMessageCallback(msg_syncml_msg_incoming_cb onSyncMLMsgIncoming, void *pUserParam)
380 if (!onSyncMLMsgIncoming)
381 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgIncoming);
383 MsgProxyListener* eventListener = MsgProxyListener::instance();
385 eventListener->start(this);
387 int remoteFd = eventListener->getRemoteFd(); /* fd that is reserved to the "listener thread" by msgfw daemon */
389 if (remoteFd == -1) {
390 eventListener->stop();
391 return MSG_ERR_INVALID_MSGHANDLE;
394 if (eventListener->regSyncMLMessageIncomingEventCB(this, remoteFd, onSyncMLMsgIncoming, pUserParam) == false) {
395 eventListener->stop();
396 return MSG_ERR_INVALID_PARAMETER;
399 /* Allocate Memory to Command Data */
400 /* sizeof(int) + sizeof; */
401 /* cmd type, listener fd */
402 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S);
404 char cmdBuf[cmdSize];
405 bzero(cmdBuf, cmdSize);
407 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
409 /* Set Command Parameters */
410 pCmd->cmdType = MSG_CMD_REG_INCOMING_SYNCML_MSG_CB;
413 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
415 MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S cmdParam = {0};
417 cmdParam.listenerFd = remoteFd;
418 cmdParam.msgType = MSG_SMS_TYPE;
420 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
422 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
424 /* Send Command to Messaging FW */
425 char* pEventData = NULL;
426 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
428 write((char*)pCmd, cmdSize, &pEventData);
430 /* Get Return Data */
431 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
433 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_SYNCML_MSG_CB) {
434 THROW(MsgException::INVALID_RESULT, "Event Data Error");
437 return pEvent->result;
441 msg_error_t MsgHandle::regLBSMessageCallback(msg_lbs_msg_incoming_cb onLBSMsgIncoming, void *pUserParam)
443 if (!onLBSMsgIncoming)
444 THROW(MsgException::INVALID_PARAM, "Param %p", onLBSMsgIncoming);
446 MsgProxyListener* eventListener = MsgProxyListener::instance();
448 eventListener->start(this);
450 int remoteFd = eventListener->getRemoteFd(); /* fd that is reserved to the "listener thread" by msgfw daemon */
452 if (remoteFd == -1) {
453 eventListener->stop();
454 return MSG_ERR_INVALID_MSGHANDLE;
457 if (eventListener->regLBSMessageIncomingEventCB(this, remoteFd, onLBSMsgIncoming, pUserParam) == false) {
458 eventListener->stop();
459 return MSG_ERR_INVALID_PARAMETER;
462 /* Allocate Memory to Command Data */
463 /* sizeof(int) + sizeof; */
464 /* cmd type, listener fd */
465 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S);
466 char cmdBuf[cmdSize];
467 bzero(cmdBuf, cmdSize);
468 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
470 /* Set Command Parameters */
471 pCmd->cmdType = MSG_CMD_REG_INCOMING_LBS_MSG_CB;
474 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
476 MSG_CMD_REG_INCOMING_LBS_MSG_CB_S cmdParam = {0};
478 cmdParam.listenerFd = remoteFd;
479 cmdParam.msgType = MSG_SMS_TYPE;
481 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
483 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
485 /* Send Command to Messaging FW */
486 char* pEventData = NULL;
487 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
490 write((char*)pCmd, cmdSize, &pEventData);
492 /* Get Return Data */
493 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
495 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_LBS_MSG_CB) {
496 THROW(MsgException::INVALID_RESULT, "Event Data Error");
499 return pEvent->result;
503 msg_error_t MsgHandle::regSyncMLMessageOperationCallback(msg_syncml_msg_operation_cb onSyncMLMsgOperation, void *pUserParam)
505 if (!onSyncMLMsgOperation)
506 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgOperation);
508 MsgProxyListener* eventListener = MsgProxyListener::instance();
510 eventListener->start(this);
512 int remoteFd = eventListener->getRemoteFd(); /* fd that is reserved to the "listener thread" by msgfw daemon */
514 if (remoteFd == -1) {
515 eventListener->stop();
516 return MSG_ERR_INVALID_MSGHANDLE;
519 if (eventListener->regSyncMLMessageOperationEventCB(this, remoteFd, onSyncMLMsgOperation, pUserParam) == false) {
520 eventListener->stop();
521 return MSG_ERR_INVALID_PARAMETER;
524 /* Allocate Memory to Command Data */
525 /* sizeof(int) + sizeof; */
526 /* cmd type, listener fd */
527 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S);
529 char cmdBuf[cmdSize];
530 bzero(cmdBuf, cmdSize);
532 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
534 /* Set Command Parameters */
535 pCmd->cmdType = MSG_CMD_REG_SYNCML_MSG_OPERATION_CB;
538 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
540 MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S cmdParam = {0};
542 cmdParam.listenerFd = remoteFd;
543 cmdParam.msgType = MSG_SMS_TYPE;
545 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
547 MSG_DEBUG("register syncML msg operation callback [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
549 /* Send Command to Messaging FW */
550 char* pEventData = NULL;
551 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
554 write((char*)pCmd, cmdSize, &pEventData);
556 /* Get Return Data */
557 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
559 if (pEvent->eventType != MSG_EVENT_REG_SYNCML_MSG_OPERATION_CB) {
560 THROW(MsgException::INVALID_RESULT, "Event Data Error");
563 return pEvent->result;
567 msg_error_t MsgHandle::regPushMessageCallback(msg_push_msg_incoming_cb onPushMsgIncoming, const char *pAppId, void *pUserParam)
569 if (!onPushMsgIncoming)
570 THROW(MsgException::INVALID_PARAM, "Param %p", onPushMsgIncoming);
572 MsgProxyListener* eventListener = MsgProxyListener::instance();
574 eventListener->start(this);
576 int remoteFd = eventListener->getRemoteFd(); /* fd that is reserved to the "listener thread" by msgfw daemon */
578 if (remoteFd == -1) {
579 eventListener->stop();
580 return MSG_ERR_INVALID_MSGHANDLE;
583 if (eventListener->regPushMessageIncomingEventCB(this, remoteFd, onPushMsgIncoming, pAppId, pUserParam) == false) {
584 eventListener->stop();
585 return MSG_ERR_INVALID_PARAMETER;
588 /* Allocate Memory to Command Data */
589 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S);
591 char cmdBuf[cmdSize];
592 bzero(cmdBuf, cmdSize);
594 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
596 /* Set Command Parameters */
597 pCmd->cmdType = MSG_CMD_REG_INCOMING_PUSH_MSG_CB;
600 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
602 MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S cmdParam = {0};
604 cmdParam.listenerFd = remoteFd;
605 cmdParam.msgType = MSG_SMS_TYPE;
608 strncpy(cmdParam.appId, pAppId, MAX_WAPPUSH_ID_LEN);
610 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
612 MSG_DEBUG("reg new msg [%s], fd:%d, appId:%s", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, (pAppId)? cmdParam.appId:"NULL");
614 /* Send Command to Messaging FW */
615 char* pEventData = NULL;
616 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
619 write((char*)pCmd, cmdSize, &pEventData);
621 /* Get Return Data */
622 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
624 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_PUSH_MSG_CB) {
625 THROW(MsgException::INVALID_RESULT, "Event Data Error");
628 return pEvent->result;
632 msg_error_t MsgHandle::regCBMessageCallback(msg_cb_incoming_cb onCBIncoming, bool bSave, void *pUserParam)
635 THROW(MsgException::INVALID_PARAM, "Param %p", onCBIncoming);
637 MsgProxyListener* eventListener = MsgProxyListener::instance();
639 eventListener->start(this);
641 int remoteFd = eventListener->getRemoteFd(); /* fd that is reserved to the "listener thread" by msgfw daemon */
643 if (remoteFd == -1) {
644 eventListener->stop();
645 return MSG_ERR_INVALID_MSGHANDLE;
648 if (eventListener->regCBMessageIncomingEventCB(this, remoteFd, onCBIncoming, bSave, pUserParam) == false) {
649 eventListener->stop();
650 return MSG_ERR_INVALID_PARAMETER;
653 /* Allocate Memory to Command Data */
654 /* sizeof(int) + sizeof; */
655 /* cmd type, listener fd */
657 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_CB_MSG_CB_S);
659 char cmdBuf[cmdSize];
660 bzero(cmdBuf, cmdSize);
662 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
664 /* Set Command Parameters */
665 pCmd->cmdType = MSG_CMD_REG_INCOMING_CB_MSG_CB;
668 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
670 MSG_CMD_REG_CB_INCOMING_MSG_CB_S cmdParam = {0};
672 cmdParam.listenerFd = remoteFd;
673 cmdParam.msgType = MSG_SMS_TYPE;
674 cmdParam.bsave = bSave;
676 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
678 MSG_DEBUG("reg new msg [%s], fd: %d, bSave: %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, cmdParam.bsave);
680 /* Send Command to Messaging FW */
681 char* pEventData = NULL;
682 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
685 write((char*)pCmd, cmdSize, &pEventData);
687 /* Get Return Data */
688 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
690 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_CB_MSG_CB) {
691 THROW(MsgException::INVALID_RESULT, "Event Data Error");
694 return pEvent->result;
698 msg_error_t MsgHandle::regReportMessageCallback(msg_report_msg_incoming_cb onReportMsgCB, void *pUserParam)
701 THROW(MsgException::INVALID_PARAM, "onReportMsgCB is null");
703 MsgProxyListener* eventListener = MsgProxyListener::instance();
705 eventListener->start(this);
707 int remoteFd = eventListener->getRemoteFd(); /* fd that is reserved to the "listener thread" by msgfw daemon */
709 if (remoteFd == -1) {
710 eventListener->stop();
711 return MSG_ERR_INVALID_MSGHANDLE;
714 if (eventListener->regReportMsgIncomingCB(this, remoteFd, onReportMsgCB, pUserParam) == false) {
715 eventListener->stop();
716 return MSG_ERR_INVALID_PARAMETER;
719 /* Allocate Memory to Command Data */
720 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); /* cmd type, listenerFd */
721 char cmdBuf[cmdSize];
722 bzero(cmdBuf, cmdSize);
723 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
725 /* Set Command Parameters */
726 pCmd->cmdType = MSG_CMD_REG_REPORT_MSG_INCOMING_CB;
729 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
731 MSG_DEBUG("remote fd %d", remoteFd);
733 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
735 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
737 /* Send Command to Messaging FW */
738 char* pEventData = NULL;
739 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
741 write((char*)pCmd, cmdSize, &pEventData);
743 /* Get Return Data */
744 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
746 if (pEvent->eventType != MSG_EVENT_REG_REPORT_MSG_INCOMING_CB) {
747 THROW(MsgException::INVALID_PARAM, "Event Data Error");
750 return pEvent->result;
754 msg_error_t MsgHandle::operateSyncMLMessage(msg_message_id_t msgId)
757 THROW(MsgException::INVALID_PARAM, "Param msgId %d", msgId);
759 /* Allocate Memory to Command Data */
760 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
762 char cmdBuf[cmdSize];
763 bzero(cmdBuf, cmdSize);
764 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
766 /* Set Command Parameters */
767 pCmd->cmdType = MSG_CMD_SYNCML_OPERATION;
770 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
772 /* Copy Command Data */
773 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgId, sizeof(msg_message_id_t));
775 /* Send Command to Messaging FW */
776 char* pEventData = NULL;
777 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
780 write((char*)pCmd, cmdSize, &pEventData);
782 /* Get Return Data */
783 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
785 if (pEvent->eventType != MSG_EVENT_SYNCML_OPERATION) {
786 THROW(MsgException::INVALID_RESULT, "Event Data Error");
789 return pEvent->result;