2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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://floralicense.org
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 "MsgProxyListener.h"
24 #include "MsgHandle.h"
27 #define MAX_ADDRESS_LEN 21 // including '+'
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 msg_struct_s *msg_s = (msg_struct_s *)pReq->msg;
49 MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S*)msg_s->data;
51 if (reqmsg->subType != MSG_SENDREQ_JAVA_MMS) {
52 // In case MMS read report, get address value later.
53 if(reqmsg->subType != MSG_READREPLY_MMS) {
54 if ((reqmsg->addr_list->nCount == 0) || (reqmsg->addr_list->nCount > MAX_TO_ADDRESS_CNT)) {
55 MSG_DEBUG("Recipient address count error [%d]", reqmsg->addr_list->nCount );
56 return MSG_ERR_INVALID_MESSAGE;
60 /* Begin: Setting default values for submit request */
61 // pReq->msg.msgId = 0; // Set Request ID: internal use
62 // pReq->msg.folderId = MSG_OUTBOX_ID; // Set Folder ID
63 if (reqmsg->subType == MSG_RETRIEVE_MMS) {
64 reqmsg->networkStatus = MSG_NETWORK_RETRIEVING;
66 reqmsg->networkStatus = MSG_NETWORK_SENDING;
69 reqmsg->bRead = false;
70 reqmsg->bProtected = false;
71 reqmsg->priority = MSG_MESSAGE_PRIORITY_NORMAL;
72 reqmsg->direction = MSG_DIRECTION_TYPE_MO;
73 reqmsg->storageId = MSG_STORAGE_PHONE;
75 time_t curTime = time(NULL);
78 THROW(MsgException::INVALID_RESULT, "time error : %s", strerror(errno));
80 reqmsg->displayTime = curTime;
81 /* End : Setting default values for submit request */
83 //in case of JAVA MMS msg, parse mms transaction id from pMmsData
84 reqmsg->networkStatus = MSG_NETWORK_SENDING;
85 strncpy(trId, (char*)reqmsg->pMmsData+3,MMS_TR_ID_LEN);
86 MSG_DEBUG("JavaMMS transaction Id:%s ",trId);
89 // Convert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
90 convertMsgStruct(reqmsg, &(reqInfo.msgInfo));
92 /* Check address validation */
93 if (reqInfo.msgInfo.msgType.mainType == MSG_SMS_TYPE) {
94 for(int i=0; i<reqmsg->addr_list->nCount; i++) {
95 if (reqInfo.msgInfo.addressList[i].addressVal[0] == '+' && strlen(reqInfo.msgInfo.addressList[i].addressVal)>MAX_ADDRESS_LEN) {
96 return MSG_ERR_INVALID_PARAMETER;
97 } else if (strlen(reqInfo.msgInfo.addressList[i].addressVal)>(MAX_ADDRESS_LEN-1)) {
98 return MSG_ERR_INVALID_PARAMETER;
103 MSG_MESSAGE_TYPE_S msgType = {0,};
105 msgType.mainType = reqmsg->mainType;
106 msgType.subType = reqmsg->subType;
107 msgType.classType = reqmsg->classType;
109 convertSendOptStruct((const MSG_SENDINGOPT_S *)pReq->sendOpt, &(reqInfo.sendOptInfo), msgType);
113 /* Register proxy info used for receiving sent status */
114 MSG_PROXY_INFO_S chInfo = {0};
116 chInfo.listenerFd = MsgProxyListener::instance()->getRemoteFd();
119 chInfo.handleAddr = (uint64_t) this;
121 chInfo.handleAddr = (unsigned int) this;
124 /* Allocate Memory to Command Data */
125 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_REQUEST_INFO_S) + sizeof(MSG_PROXY_INFO_S);
127 // In case of JAVA MMS msg, add trId
128 if (reqmsg->subType == MSG_SENDREQ_JAVA_MMS)
129 cmdSize += sizeof(trId);
131 char cmdBuf[cmdSize];
132 bzero(cmdBuf, cmdSize);
134 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
136 // Set Command Parameters
137 pCmd->cmdType = MSG_CMD_SUBMIT_REQ;
140 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
143 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &reqInfo, sizeof(MSG_REQUEST_INFO_S));
144 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_REQUEST_INFO_S)), &chInfo, sizeof(MSG_PROXY_INFO_S));
146 // In case of JAVA MMS msg, add trId
147 if (reqmsg->subType == MSG_SENDREQ_JAVA_MMS)
148 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_REQUEST_INFO_S)+sizeof(MSG_PROXY_INFO_S)), &trId, sizeof(trId));
150 // Send Command to Messaging FW
151 char* pEventData = NULL;
152 AutoPtr<char> eventBuf(&pEventData);
154 write((char*)pCmd, cmdSize, &pEventData);
157 MSG_EVENT_S* pEvent = (MSG_EVENT_S*) pEventData;
159 int* pReqId = (int*) pEvent->data;
160 pReq->reqId = *pReqId;
161 MSG_DEBUG("SENT_REQ_ID: %d", pReq->reqId);
163 if (pEvent->eventType != MSG_EVENT_SUBMIT_REQ)
165 THROW(MsgException::INVALID_RESULT, "Event Data Error");
170 return pEvent->result;
174 msg_error_t MsgHandle::cancelReq(msg_request_id_t reqId)
176 // Allocate Memory to Command Data
177 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_request_id_t);
179 char cmdBuf[cmdSize];
180 bzero(cmdBuf, cmdSize);
182 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
184 // Set Command Parameters
185 pCmd->cmdType = MSG_CMD_CANCEL_REQ;
188 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
191 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &reqId, sizeof(msg_request_id_t));
193 // Send Command to Messaging FW
194 char* pEventData = NULL;
195 AutoPtr<char> eventBuf(&pEventData);
198 write((char*)pCmd, cmdSize, &pEventData);
201 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
203 if (pEvent->eventType != MSG_EVENT_CANCEL_REQ)
205 THROW(MsgException::INVALID_RESULT, "Event Data Error");
208 return pEvent->result;
212 msg_error_t MsgHandle::regSentStatusCallback(msg_sent_status_cb onStatusChanged, void *pUserParam)
214 if (!onStatusChanged)
215 THROW(MsgException::INVALID_PARAM, "onStatusChanged is null");
217 MsgProxyListener* eventListener = MsgProxyListener::instance();
219 eventListener->start();
221 if (eventListener->regSentStatusEventCB(this, onStatusChanged, pUserParam) == false) // callback was already registered, just return SUCCESS
224 // Allocate Memory to Command Data
225 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
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_REG_SENT_STATUS_CB;
234 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
236 int listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
238 MSG_DEBUG("remote fd %d", listenerFd);
240 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &listenerFd, sizeof(listenerFd));
242 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), listenerFd);
244 // Send Command to Messaging FW
245 char* pEventData = NULL;
246 AutoPtr<char> eventBuf(&pEventData);
248 write((char*)pCmd, cmdSize, &pEventData);
251 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
253 if (pEvent->eventType != MSG_EVENT_REG_SENT_STATUS_CB)
255 THROW(MsgException::INVALID_PARAM, "Event Data Error");
258 return pEvent->result;
262 msg_error_t MsgHandle::regSmsMessageCallback(msg_sms_incoming_cb onMsgIncoming, unsigned short port, void *pUserParam)
264 if( (!onMsgIncoming) )
265 THROW(MsgException::INVALID_PARAM, "Param %p", onMsgIncoming);
267 MsgProxyListener* eventListener = MsgProxyListener::instance();
269 eventListener->start();
271 if (eventListener->regMessageIncomingEventCB(this, onMsgIncoming, port, pUserParam) == false) // callback was already registered, just return SUCCESS
274 // Allocate Memory to Command Data
275 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
277 char cmdBuf[cmdSize];
278 bzero(cmdBuf, cmdSize);
280 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
282 // Set Command Parameters
283 pCmd->cmdType = MSG_CMD_REG_INCOMING_MSG_CB;
286 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
288 MSG_CMD_REG_INCOMING_MSG_CB_S cmdParam = {0};
290 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
291 cmdParam.msgType = MSG_SMS_TYPE;
292 cmdParam.port = port;
294 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
296 MSG_DEBUG("reg new msg [%s], fd %d, port %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, cmdParam.port);
298 // Send Command to Messaging FW
299 char* pEventData = NULL;
300 AutoPtr<char> eventBuf(&pEventData);
303 write((char*)pCmd, cmdSize, &pEventData);
306 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
308 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_MSG_CB)
310 THROW(MsgException::INVALID_RESULT, "Event Data Error");
313 return pEvent->result;
317 msg_error_t MsgHandle::regMmsConfMessageCallback(msg_mms_conf_msg_incoming_cb onMMSConfMsgIncoming, const char *pAppId, void *pUserParam)
319 if( (!onMMSConfMsgIncoming) )
320 THROW(MsgException::INVALID_PARAM, "Param %p", onMMSConfMsgIncoming);
322 MsgProxyListener* eventListener = MsgProxyListener::instance();
324 eventListener->start();
326 if (eventListener->regMMSConfMessageIncomingEventCB(this, onMMSConfMsgIncoming, pAppId, pUserParam) == false) // callback was already registered, just return SUCCESS
329 // Allocate Memory to Command Data
330 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S);
332 char cmdBuf[cmdSize];
333 bzero(cmdBuf, cmdSize);
335 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
337 // Set Command Parameters
338 pCmd->cmdType = MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB;
341 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
343 MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S cmdParam = {0};
345 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
346 cmdParam.msgType = MSG_MMS_TYPE;
349 strncpy(cmdParam.appId, pAppId, MAX_MMS_JAVA_APPID_LEN);
351 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
353 MSG_DEBUG("reg new msg [%s], fd:%d, appId:%s", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, (pAppId)? cmdParam.appId:"NULL" );
355 // Send Command to Messaging FW
356 char* pEventData = NULL;
357 AutoPtr<char> eventBuf(&pEventData);
360 write((char*)pCmd, cmdSize, &pEventData);
363 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
365 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_MMS_CONF_MSG_CB)
367 THROW(MsgException::INVALID_RESULT, "Event Data Error");
370 return pEvent->result;
374 msg_error_t MsgHandle::regSyncMLMessageCallback(msg_syncml_msg_incoming_cb onSyncMLMsgIncoming, void *pUserParam)
376 if( (!onSyncMLMsgIncoming) )
377 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgIncoming);
379 MsgProxyListener* eventListener = MsgProxyListener::instance();
381 eventListener->start();
383 if (eventListener->regSyncMLMessageIncomingEventCB(this, onSyncMLMsgIncoming, pUserParam) == false) // callback was already registered, just return SUCCESS
386 // Allocate Memory to Command Data
387 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
389 char cmdBuf[cmdSize];
390 bzero(cmdBuf, cmdSize);
392 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
394 // Set Command Parameters
395 pCmd->cmdType = MSG_CMD_REG_INCOMING_SYNCML_MSG_CB;
398 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
400 MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S cmdParam = {0};
402 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
403 cmdParam.msgType = MSG_SMS_TYPE;
405 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
407 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
409 // Send Command to Messaging FW
410 char* pEventData = NULL;
411 AutoPtr<char> eventBuf(&pEventData);
413 write((char*)pCmd, cmdSize, &pEventData);
416 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
418 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_SYNCML_MSG_CB)
420 THROW(MsgException::INVALID_RESULT, "Event Data Error");
423 return pEvent->result;
427 msg_error_t MsgHandle::regLBSMessageCallback(msg_lbs_msg_incoming_cb onLBSMsgIncoming, void *pUserParam)
429 if( (!onLBSMsgIncoming) )
430 THROW(MsgException::INVALID_PARAM, "Param %p", onLBSMsgIncoming);
432 MsgProxyListener* eventListener = MsgProxyListener::instance();
434 eventListener->start();
436 if (eventListener->regLBSMessageIncomingEventCB(this, onLBSMsgIncoming, pUserParam) == false) // callback was already registered, just return SUCCESS
439 // Allocate Memory to Command Data
440 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
441 char cmdBuf[cmdSize];
442 bzero(cmdBuf, cmdSize);
443 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
445 // Set Command Parameters
446 pCmd->cmdType = MSG_CMD_REG_INCOMING_LBS_MSG_CB;
449 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
451 MSG_CMD_REG_INCOMING_LBS_MSG_CB_S cmdParam = {0};
453 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
454 cmdParam.msgType = MSG_SMS_TYPE;
456 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
458 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
460 // Send Command to Messaging FW
461 char* pEventData = NULL;
462 AutoPtr<char> eventBuf(&pEventData);
465 write((char*)pCmd, cmdSize, &pEventData);
468 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
470 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_LBS_MSG_CB)
472 THROW(MsgException::INVALID_RESULT, "Event Data Error");
475 return pEvent->result;
479 msg_error_t MsgHandle::regSyncMLMessageOperationCallback(msg_syncml_msg_operation_cb onSyncMLMsgOperation, void *pUserParam)
481 if( (!onSyncMLMsgOperation) )
482 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgOperation);
484 MsgProxyListener* eventListener = MsgProxyListener::instance();
486 eventListener->start();
488 if (eventListener->regSyncMLMessageOperationEventCB(this, onSyncMLMsgOperation, pUserParam) == false) // callback was already registered, just return SUCCESS
491 // Allocate Memory to Command Data
492 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
494 char cmdBuf[cmdSize];
495 bzero(cmdBuf, cmdSize);
497 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
499 // Set Command Parameters
500 pCmd->cmdType = MSG_CMD_REG_SYNCML_MSG_OPERATION_CB;
503 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
505 MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S cmdParam = {0};
507 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
508 cmdParam.msgType = MSG_SMS_TYPE;
510 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
512 MSG_DEBUG("register syncML msg operation callback [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
514 // Send Command to Messaging FW
515 char* pEventData = NULL;
516 AutoPtr<char> eventBuf(&pEventData);
519 write((char*)pCmd, cmdSize, &pEventData);
522 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
524 if (pEvent->eventType != MSG_EVENT_REG_SYNCML_MSG_OPERATION_CB)
526 THROW(MsgException::INVALID_RESULT, "Event Data Error");
529 return pEvent->result;
532 msg_error_t MsgHandle::regPushMessageCallback(msg_push_msg_incoming_cb onPushMsgIncoming, const char *pAppId, void *pUserParam)
534 if( (!onPushMsgIncoming) )
535 THROW(MsgException::INVALID_PARAM, "Param %p", onPushMsgIncoming);
537 MsgProxyListener* eventListener = MsgProxyListener::instance();
539 eventListener->start();
541 if (eventListener->regPushMessageIncomingEventCB(this, onPushMsgIncoming, pAppId, pUserParam) == false) // callback was already registered, just return SUCCESS
544 // Allocate Memory to Command Data
545 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S);
547 char cmdBuf[cmdSize];
548 bzero(cmdBuf, cmdSize);
550 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
552 // Set Command Parameters
553 pCmd->cmdType = MSG_CMD_REG_INCOMING_PUSH_MSG_CB;
556 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
558 MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S cmdParam = {0};
560 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
561 cmdParam.msgType = MSG_SMS_TYPE;
564 strncpy(cmdParam.appId, pAppId, MAX_WAPPUSH_ID_LEN);
566 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
568 MSG_DEBUG("reg new msg [%s], fd:%d, appId:%s", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, (pAppId)? cmdParam.appId:"NULL" );
570 // Send Command to Messaging FW
571 char* pEventData = NULL;
572 AutoPtr<char> eventBuf(&pEventData);
575 write((char*)pCmd, cmdSize, &pEventData);
578 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
580 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_PUSH_MSG_CB)
582 THROW(MsgException::INVALID_RESULT, "Event Data Error");
585 return pEvent->result;
588 msg_error_t MsgHandle::regCBMessageCallback(msg_cb_incoming_cb onCBIncoming, bool bSave, void *pUserParam)
590 if( (!onCBIncoming) )
591 THROW(MsgException::INVALID_PARAM, "Param %p", onCBIncoming);
593 MsgProxyListener* eventListener = MsgProxyListener::instance();
595 eventListener->start();
597 if (eventListener->regCBMessageIncomingEventCB(this, onCBIncoming, bSave, pUserParam) == false) // callback was already registered, just return SUCCESS
600 // Allocate Memory to Command Data
601 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_CB_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
603 char cmdBuf[cmdSize];
604 bzero(cmdBuf, cmdSize);
606 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
608 // Set Command Parameters
609 pCmd->cmdType = MSG_CMD_REG_INCOMING_CB_MSG_CB;
612 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
614 MSG_CMD_REG_CB_INCOMING_MSG_CB_S cmdParam = {0};
616 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
617 cmdParam.msgType = MSG_SMS_TYPE;
618 cmdParam.bsave = bSave;
620 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
622 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
624 // Send Command to Messaging FW
625 char* pEventData = NULL;
626 AutoPtr<char> eventBuf(&pEventData);
629 write((char*)pCmd, cmdSize, &pEventData);
632 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
634 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_CB_MSG_CB)
636 THROW(MsgException::INVALID_RESULT, "Event Data Error");
639 return pEvent->result;
643 msg_error_t MsgHandle::operateSyncMLMessage(msg_message_id_t msgId)
646 THROW(MsgException::INVALID_PARAM, "Param msgId %d", msgId);
648 // Allocate Memory to Command Data
649 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
651 char cmdBuf[cmdSize];
652 bzero(cmdBuf, cmdSize);
653 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
655 // Set Command Parameters
656 pCmd->cmdType = MSG_CMD_SYNCML_OPERATION;
659 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
662 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgId, sizeof(msg_message_id_t));
664 // Send Command to Messaging FW
665 char* pEventData = NULL;
666 AutoPtr<char> eventBuf(&pEventData);
669 write((char*)pCmd, cmdSize, &pEventData);
672 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
674 if (pEvent->eventType != MSG_EVENT_SYNCML_OPERATION)
676 THROW(MsgException::INVALID_RESULT, "Event Data Error");
679 return pEvent->result;