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();
118 chInfo.handleAddr = (unsigned int) this;
120 /* Allocate Memory to Command Data */
121 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_REQUEST_INFO_S) + sizeof(MSG_PROXY_INFO_S);
123 // In case of JAVA MMS msg, add trId
124 if (reqmsg->subType == MSG_SENDREQ_JAVA_MMS)
125 cmdSize += sizeof(trId);
127 char cmdBuf[cmdSize];
128 bzero(cmdBuf, cmdSize);
130 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
132 // Set Command Parameters
133 pCmd->cmdType = MSG_CMD_SUBMIT_REQ;
136 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
139 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &reqInfo, sizeof(MSG_REQUEST_INFO_S));
140 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_REQUEST_INFO_S)), &chInfo, sizeof(MSG_PROXY_INFO_S));
142 // In case of JAVA MMS msg, add trId
143 if (reqmsg->subType == MSG_SENDREQ_JAVA_MMS)
144 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));
146 // Send Command to Messaging FW
147 char* pEventData = NULL;
148 AutoPtr<char> eventBuf(&pEventData);
150 write((char*)pCmd, cmdSize, &pEventData);
153 MSG_EVENT_S* pEvent = (MSG_EVENT_S*) pEventData;
155 int* pReqId = (int*) pEvent->data;
156 pReq->reqId = *pReqId;
157 MSG_DEBUG("SENT_REQ_ID: %d", pReq->reqId);
159 if (pEvent->eventType != MSG_EVENT_SUBMIT_REQ)
161 THROW(MsgException::INVALID_RESULT, "Event Data Error");
166 return pEvent->result;
170 msg_error_t MsgHandle::cancelReq(msg_request_id_t reqId)
172 // Allocate Memory to Command Data
173 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_request_id_t);
175 char cmdBuf[cmdSize];
176 bzero(cmdBuf, cmdSize);
178 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
180 // Set Command Parameters
181 pCmd->cmdType = MSG_CMD_CANCEL_REQ;
184 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
187 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &reqId, sizeof(msg_request_id_t));
189 // Send Command to Messaging FW
190 char* pEventData = NULL;
191 AutoPtr<char> eventBuf(&pEventData);
194 write((char*)pCmd, cmdSize, &pEventData);
197 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
199 if (pEvent->eventType != MSG_EVENT_CANCEL_REQ)
201 THROW(MsgException::INVALID_RESULT, "Event Data Error");
204 return pEvent->result;
208 msg_error_t MsgHandle::regSentStatusCallback(msg_sent_status_cb onStatusChanged, void *pUserParam)
210 if (!onStatusChanged)
211 THROW(MsgException::INVALID_PARAM, "onStatusChanged is null");
213 MsgProxyListener* eventListener = MsgProxyListener::instance();
215 eventListener->start();
217 if (eventListener->regSentStatusEventCB(this, onStatusChanged, pUserParam) == false) // callback was already registered, just return SUCCESS
220 // Allocate Memory to Command Data
221 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
222 char cmdBuf[cmdSize];
223 bzero(cmdBuf, cmdSize);
224 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
226 // Set Command Parameters
227 pCmd->cmdType = MSG_CMD_REG_SENT_STATUS_CB;
230 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
232 int listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
234 MSG_DEBUG("remote fd %d", listenerFd);
236 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &listenerFd, sizeof(listenerFd));
238 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), listenerFd);
240 // Send Command to Messaging FW
241 char* pEventData = NULL;
242 AutoPtr<char> eventBuf(&pEventData);
244 write((char*)pCmd, cmdSize, &pEventData);
247 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
249 if (pEvent->eventType != MSG_EVENT_REG_SENT_STATUS_CB)
251 THROW(MsgException::INVALID_PARAM, "Event Data Error");
254 return pEvent->result;
258 msg_error_t MsgHandle::regSmsMessageCallback(msg_sms_incoming_cb onMsgIncoming, unsigned short port, void *pUserParam)
260 if( (!onMsgIncoming) )
261 THROW(MsgException::INVALID_PARAM, "Param %p", onMsgIncoming);
263 MsgProxyListener* eventListener = MsgProxyListener::instance();
265 eventListener->start();
267 if (eventListener->regMessageIncomingEventCB(this, onMsgIncoming, port, pUserParam) == false) // callback was already registered, just return SUCCESS
270 // Allocate Memory to Command Data
271 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
273 char cmdBuf[cmdSize];
274 bzero(cmdBuf, cmdSize);
276 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
278 // Set Command Parameters
279 pCmd->cmdType = MSG_CMD_REG_INCOMING_MSG_CB;
282 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
284 MSG_CMD_REG_INCOMING_MSG_CB_S cmdParam = {0};
286 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
287 cmdParam.msgType = MSG_SMS_TYPE;
288 cmdParam.port = port;
290 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
292 MSG_DEBUG("reg new msg [%s], fd %d, port %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, cmdParam.port);
294 // Send Command to Messaging FW
295 char* pEventData = NULL;
296 AutoPtr<char> eventBuf(&pEventData);
299 write((char*)pCmd, cmdSize, &pEventData);
302 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
304 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();
322 if (eventListener->regMMSConfMessageIncomingEventCB(this, onMMSConfMsgIncoming, pAppId, pUserParam) == false) // callback was already registered, just return SUCCESS
325 // Allocate Memory to Command Data
326 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S);
328 char cmdBuf[cmdSize];
329 bzero(cmdBuf, cmdSize);
331 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
333 // Set Command Parameters
334 pCmd->cmdType = MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB;
337 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
339 MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S cmdParam = {0};
341 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
342 cmdParam.msgType = MSG_MMS_TYPE;
345 strncpy(cmdParam.appId, pAppId, MAX_MMS_JAVA_APPID_LEN);
347 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
349 MSG_DEBUG("reg new msg [%s], fd:%d, appId:%s", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, (pAppId)? cmdParam.appId:"NULL" );
351 // Send Command to Messaging FW
352 char* pEventData = NULL;
353 AutoPtr<char> eventBuf(&pEventData);
356 write((char*)pCmd, cmdSize, &pEventData);
359 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
361 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_MMS_CONF_MSG_CB)
363 THROW(MsgException::INVALID_RESULT, "Event Data Error");
366 return pEvent->result;
370 msg_error_t MsgHandle::regSyncMLMessageCallback(msg_syncml_msg_incoming_cb onSyncMLMsgIncoming, void *pUserParam)
372 if( (!onSyncMLMsgIncoming) )
373 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgIncoming);
375 MsgProxyListener* eventListener = MsgProxyListener::instance();
377 eventListener->start();
379 if (eventListener->regSyncMLMessageIncomingEventCB(this, onSyncMLMsgIncoming, pUserParam) == false) // callback was already registered, just return SUCCESS
382 // Allocate Memory to Command Data
383 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
385 char cmdBuf[cmdSize];
386 bzero(cmdBuf, cmdSize);
388 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
390 // Set Command Parameters
391 pCmd->cmdType = MSG_CMD_REG_INCOMING_SYNCML_MSG_CB;
394 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
396 MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S cmdParam = {0};
398 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
399 cmdParam.msgType = MSG_SMS_TYPE;
401 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
403 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
405 // Send Command to Messaging FW
406 char* pEventData = NULL;
407 AutoPtr<char> eventBuf(&pEventData);
409 write((char*)pCmd, cmdSize, &pEventData);
412 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
414 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_SYNCML_MSG_CB)
416 THROW(MsgException::INVALID_RESULT, "Event Data Error");
419 return pEvent->result;
423 msg_error_t MsgHandle::regLBSMessageCallback(msg_lbs_msg_incoming_cb onLBSMsgIncoming, void *pUserParam)
425 if( (!onLBSMsgIncoming) )
426 THROW(MsgException::INVALID_PARAM, "Param %p", onLBSMsgIncoming);
428 MsgProxyListener* eventListener = MsgProxyListener::instance();
430 eventListener->start();
432 if (eventListener->regLBSMessageIncomingEventCB(this, onLBSMsgIncoming, pUserParam) == false) // callback was already registered, just return SUCCESS
435 // Allocate Memory to Command Data
436 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
437 char cmdBuf[cmdSize];
438 bzero(cmdBuf, cmdSize);
439 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
441 // Set Command Parameters
442 pCmd->cmdType = MSG_CMD_REG_INCOMING_LBS_MSG_CB;
445 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
447 MSG_CMD_REG_INCOMING_LBS_MSG_CB_S cmdParam = {0};
449 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
450 cmdParam.msgType = MSG_SMS_TYPE;
452 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
454 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
456 // Send Command to Messaging FW
457 char* pEventData = NULL;
458 AutoPtr<char> eventBuf(&pEventData);
461 write((char*)pCmd, cmdSize, &pEventData);
464 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
466 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_LBS_MSG_CB)
468 THROW(MsgException::INVALID_RESULT, "Event Data Error");
471 return pEvent->result;
475 msg_error_t MsgHandle::regSyncMLMessageOperationCallback(msg_syncml_msg_operation_cb onSyncMLMsgOperation, void *pUserParam)
477 if( (!onSyncMLMsgOperation) )
478 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgOperation);
480 MsgProxyListener* eventListener = MsgProxyListener::instance();
482 eventListener->start();
484 if (eventListener->regSyncMLMessageOperationEventCB(this, onSyncMLMsgOperation, pUserParam) == false) // callback was already registered, just return SUCCESS
487 // Allocate Memory to Command Data
488 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
490 char cmdBuf[cmdSize];
491 bzero(cmdBuf, cmdSize);
493 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
495 // Set Command Parameters
496 pCmd->cmdType = MSG_CMD_REG_SYNCML_MSG_OPERATION_CB;
499 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
501 MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S cmdParam = {0};
503 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
504 cmdParam.msgType = MSG_SMS_TYPE;
506 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
508 MSG_DEBUG("register syncML msg operation callback [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
510 // Send Command to Messaging FW
511 char* pEventData = NULL;
512 AutoPtr<char> eventBuf(&pEventData);
515 write((char*)pCmd, cmdSize, &pEventData);
518 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
520 if (pEvent->eventType != MSG_EVENT_REG_SYNCML_MSG_OPERATION_CB)
522 THROW(MsgException::INVALID_RESULT, "Event Data Error");
525 return pEvent->result;
528 msg_error_t MsgHandle::regPushMessageCallback(msg_push_msg_incoming_cb onPushMsgIncoming, const char *pAppId, void *pUserParam)
530 if( (!onPushMsgIncoming) )
531 THROW(MsgException::INVALID_PARAM, "Param %p", onPushMsgIncoming);
533 MsgProxyListener* eventListener = MsgProxyListener::instance();
535 eventListener->start();
537 if (eventListener->regPushMessageIncomingEventCB(this, onPushMsgIncoming, pAppId, pUserParam) == false) // callback was already registered, just return SUCCESS
540 // Allocate Memory to Command Data
541 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S);
543 char cmdBuf[cmdSize];
544 bzero(cmdBuf, cmdSize);
546 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
548 // Set Command Parameters
549 pCmd->cmdType = MSG_CMD_REG_INCOMING_PUSH_MSG_CB;
552 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
554 MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S cmdParam = {0};
556 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
557 cmdParam.msgType = MSG_SMS_TYPE;
560 strncpy(cmdParam.appId, pAppId, MAX_WAPPUSH_ID_LEN);
562 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
564 MSG_DEBUG("reg new msg [%s], fd:%d, appId:%s", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, (pAppId)? cmdParam.appId:"NULL" );
566 // Send Command to Messaging FW
567 char* pEventData = NULL;
568 AutoPtr<char> eventBuf(&pEventData);
571 write((char*)pCmd, cmdSize, &pEventData);
574 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
576 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_PUSH_MSG_CB)
578 THROW(MsgException::INVALID_RESULT, "Event Data Error");
581 return pEvent->result;
584 msg_error_t MsgHandle::regCBMessageCallback(msg_cb_incoming_cb onCBIncoming, bool bSave, void *pUserParam)
586 if( (!onCBIncoming) )
587 THROW(MsgException::INVALID_PARAM, "Param %p", onCBIncoming);
589 MsgProxyListener* eventListener = MsgProxyListener::instance();
591 eventListener->start();
593 if (eventListener->regCBMessageIncomingEventCB(this, onCBIncoming, bSave, pUserParam) == false) // callback was already registered, just return SUCCESS
596 // Allocate Memory to Command Data
597 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_CB_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
599 char cmdBuf[cmdSize];
600 bzero(cmdBuf, cmdSize);
602 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
604 // Set Command Parameters
605 pCmd->cmdType = MSG_CMD_REG_INCOMING_CB_MSG_CB;
608 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
610 MSG_CMD_REG_CB_INCOMING_MSG_CB_S cmdParam = {0};
612 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
613 cmdParam.msgType = MSG_SMS_TYPE;
614 cmdParam.bsave = bSave;
616 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
618 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
620 // Send Command to Messaging FW
621 char* pEventData = NULL;
622 AutoPtr<char> eventBuf(&pEventData);
625 write((char*)pCmd, cmdSize, &pEventData);
628 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
630 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_CB_MSG_CB)
632 THROW(MsgException::INVALID_RESULT, "Event Data Error");
635 return pEvent->result;
639 msg_error_t MsgHandle::operateSyncMLMessage(msg_message_id_t msgId)
642 THROW(MsgException::INVALID_PARAM, "Param msgId %d", msgId);
644 // Allocate Memory to Command Data
645 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
647 char cmdBuf[cmdSize];
648 bzero(cmdBuf, cmdSize);
649 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
651 // Set Command Parameters
652 pCmd->cmdType = MSG_CMD_SYNCML_OPERATION;
655 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
658 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgId, sizeof(msg_message_id_t));
660 // Send Command to Messaging FW
661 char* pEventData = NULL;
662 AutoPtr<char> eventBuf(&pEventData);
665 write((char*)pCmd, cmdSize, &pEventData);
668 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
670 if (pEvent->eventType != MSG_EVENT_SYNCML_OPERATION)
672 THROW(MsgException::INVALID_RESULT, "Event Data Error");
675 return pEvent->result;