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 int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
224 return MSG_ERR_TRANSPORT_ERROR;
226 if (eventListener->regSentStatusEventCB(this, onStatusChanged, pUserParam) == false) // callback was already registered, just return SUCCESS
229 // Allocate Memory to Command Data
230 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
231 char cmdBuf[cmdSize];
232 bzero(cmdBuf, cmdSize);
233 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
235 // Set Command Parameters
236 pCmd->cmdType = MSG_CMD_REG_SENT_STATUS_CB;
239 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
241 int listenerFd = clientFd;
243 MSG_DEBUG("remote fd %d", listenerFd);
245 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &listenerFd, sizeof(listenerFd));
247 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), listenerFd);
249 // Send Command to Messaging FW
250 char* pEventData = NULL;
251 AutoPtr<char> eventBuf(&pEventData);
253 write((char*)pCmd, cmdSize, &pEventData);
256 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
258 if (pEvent->eventType != MSG_EVENT_REG_SENT_STATUS_CB)
260 THROW(MsgException::INVALID_PARAM, "Event Data Error");
263 return pEvent->result;
267 msg_error_t MsgHandle::regSmsMessageCallback(msg_sms_incoming_cb onMsgIncoming, unsigned short port, void *pUserParam)
269 if( (!onMsgIncoming) )
270 THROW(MsgException::INVALID_PARAM, "Param %p", onMsgIncoming);
272 MsgProxyListener* eventListener = MsgProxyListener::instance();
274 eventListener->start();
276 int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
279 return MSG_ERR_TRANSPORT_ERROR;
281 if (eventListener->regMessageIncomingEventCB(this, onMsgIncoming, port, pUserParam) == false) // callback was already registered, just return SUCCESS
284 // Allocate Memory to Command Data
285 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
287 char cmdBuf[cmdSize];
288 bzero(cmdBuf, cmdSize);
290 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
292 // Set Command Parameters
293 pCmd->cmdType = MSG_CMD_REG_INCOMING_MSG_CB;
296 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
298 MSG_CMD_REG_INCOMING_MSG_CB_S cmdParam = {0};
300 cmdParam.listenerFd = clientFd;
301 cmdParam.msgType = MSG_SMS_TYPE;
302 cmdParam.port = port;
304 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
306 MSG_DEBUG("reg new msg [%s], fd %d, port %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, cmdParam.port);
308 // Send Command to Messaging FW
309 char* pEventData = NULL;
310 AutoPtr<char> eventBuf(&pEventData);
313 write((char*)pCmd, cmdSize, &pEventData);
316 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
318 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_MSG_CB)
320 THROW(MsgException::INVALID_RESULT, "Event Data Error");
323 return pEvent->result;
327 msg_error_t MsgHandle::regMmsConfMessageCallback(msg_mms_conf_msg_incoming_cb onMMSConfMsgIncoming, const char *pAppId, void *pUserParam)
329 if( (!onMMSConfMsgIncoming) )
330 THROW(MsgException::INVALID_PARAM, "Param %p", onMMSConfMsgIncoming);
332 MsgProxyListener* eventListener = MsgProxyListener::instance();
334 eventListener->start();
336 int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
339 return MSG_ERR_TRANSPORT_ERROR;
341 if (eventListener->regMMSConfMessageIncomingEventCB(this, onMMSConfMsgIncoming, pAppId, pUserParam) == false) // callback was already registered, just return SUCCESS
344 // Allocate Memory to Command Data
345 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S);
347 char cmdBuf[cmdSize];
348 bzero(cmdBuf, cmdSize);
350 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
352 // Set Command Parameters
353 pCmd->cmdType = MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB;
356 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
358 MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S cmdParam = {0};
360 cmdParam.listenerFd = clientFd;
361 cmdParam.msgType = MSG_MMS_TYPE;
364 strncpy(cmdParam.appId, pAppId, MAX_MMS_JAVA_APPID_LEN);
366 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
368 MSG_DEBUG("reg new msg [%s], fd:%d, appId:%s", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, (pAppId)? cmdParam.appId:"NULL" );
370 // Send Command to Messaging FW
371 char* pEventData = NULL;
372 AutoPtr<char> eventBuf(&pEventData);
375 write((char*)pCmd, cmdSize, &pEventData);
378 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
380 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_MMS_CONF_MSG_CB)
382 THROW(MsgException::INVALID_RESULT, "Event Data Error");
385 return pEvent->result;
389 msg_error_t MsgHandle::regSyncMLMessageCallback(msg_syncml_msg_incoming_cb onSyncMLMsgIncoming, void *pUserParam)
391 if( (!onSyncMLMsgIncoming) )
392 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgIncoming);
394 MsgProxyListener* eventListener = MsgProxyListener::instance();
396 eventListener->start();
398 int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
401 return MSG_ERR_TRANSPORT_ERROR;
403 if (eventListener->regSyncMLMessageIncomingEventCB(this, onSyncMLMsgIncoming, pUserParam) == false) // callback was already registered, just return SUCCESS
406 // Allocate Memory to Command Data
407 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
409 char cmdBuf[cmdSize];
410 bzero(cmdBuf, cmdSize);
412 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
414 // Set Command Parameters
415 pCmd->cmdType = MSG_CMD_REG_INCOMING_SYNCML_MSG_CB;
418 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
420 MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S cmdParam = {0};
422 cmdParam.listenerFd = clientFd;
423 cmdParam.msgType = MSG_SMS_TYPE;
425 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
427 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
429 // Send Command to Messaging FW
430 char* pEventData = NULL;
431 AutoPtr<char> eventBuf(&pEventData);
433 write((char*)pCmd, cmdSize, &pEventData);
436 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
438 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_SYNCML_MSG_CB)
440 THROW(MsgException::INVALID_RESULT, "Event Data Error");
443 return pEvent->result;
447 msg_error_t MsgHandle::regLBSMessageCallback(msg_lbs_msg_incoming_cb onLBSMsgIncoming, void *pUserParam)
449 if( (!onLBSMsgIncoming) )
450 THROW(MsgException::INVALID_PARAM, "Param %p", onLBSMsgIncoming);
452 MsgProxyListener* eventListener = MsgProxyListener::instance();
454 eventListener->start();
456 int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
459 return MSG_ERR_TRANSPORT_ERROR;
461 if (eventListener->regLBSMessageIncomingEventCB(this, onLBSMsgIncoming, pUserParam) == false) // callback was already registered, just return SUCCESS
464 // Allocate Memory to Command Data
465 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
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 = clientFd;
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 AutoPtr<char> eventBuf(&pEventData);
490 write((char*)pCmd, cmdSize, &pEventData);
493 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
495 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_LBS_MSG_CB)
497 THROW(MsgException::INVALID_RESULT, "Event Data Error");
500 return pEvent->result;
504 msg_error_t MsgHandle::regSyncMLMessageOperationCallback(msg_syncml_msg_operation_cb onSyncMLMsgOperation, void *pUserParam)
506 if( (!onSyncMLMsgOperation) )
507 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgOperation);
509 MsgProxyListener* eventListener = MsgProxyListener::instance();
511 eventListener->start();
513 int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
516 return MSG_ERR_TRANSPORT_ERROR;
518 if (eventListener->regSyncMLMessageOperationEventCB(this, onSyncMLMsgOperation, pUserParam) == false) // callback was already registered, just return SUCCESS
521 // Allocate Memory to Command Data
522 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
524 char cmdBuf[cmdSize];
525 bzero(cmdBuf, cmdSize);
527 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
529 // Set Command Parameters
530 pCmd->cmdType = MSG_CMD_REG_SYNCML_MSG_OPERATION_CB;
533 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
535 MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S cmdParam = {0};
537 cmdParam.listenerFd = clientFd;
538 cmdParam.msgType = MSG_SMS_TYPE;
540 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
542 MSG_DEBUG("register syncML msg operation callback [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
544 // Send Command to Messaging FW
545 char* pEventData = NULL;
546 AutoPtr<char> eventBuf(&pEventData);
549 write((char*)pCmd, cmdSize, &pEventData);
552 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
554 if (pEvent->eventType != MSG_EVENT_REG_SYNCML_MSG_OPERATION_CB)
556 THROW(MsgException::INVALID_RESULT, "Event Data Error");
559 return pEvent->result;
562 msg_error_t MsgHandle::regPushMessageCallback(msg_push_msg_incoming_cb onPushMsgIncoming, const char *pAppId, void *pUserParam)
564 if( (!onPushMsgIncoming) )
565 THROW(MsgException::INVALID_PARAM, "Param %p", onPushMsgIncoming);
567 MsgProxyListener* eventListener = MsgProxyListener::instance();
569 eventListener->start();
571 int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
574 return MSG_ERR_TRANSPORT_ERROR;
576 if (eventListener->regPushMessageIncomingEventCB(this, onPushMsgIncoming, pAppId, pUserParam) == false) // callback was already registered, just return SUCCESS
579 // Allocate Memory to Command Data
580 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S);
582 char cmdBuf[cmdSize];
583 bzero(cmdBuf, cmdSize);
585 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
587 // Set Command Parameters
588 pCmd->cmdType = MSG_CMD_REG_INCOMING_PUSH_MSG_CB;
591 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
593 MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S cmdParam = {0};
595 cmdParam.listenerFd = clientFd;
596 cmdParam.msgType = MSG_SMS_TYPE;
599 strncpy(cmdParam.appId, pAppId, MAX_WAPPUSH_ID_LEN);
601 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
603 MSG_DEBUG("reg new msg [%s], fd:%d, appId:%s", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, (pAppId)? cmdParam.appId:"NULL" );
605 // Send Command to Messaging FW
606 char* pEventData = NULL;
607 AutoPtr<char> eventBuf(&pEventData);
610 write((char*)pCmd, cmdSize, &pEventData);
613 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
615 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_PUSH_MSG_CB)
617 THROW(MsgException::INVALID_RESULT, "Event Data Error");
620 return pEvent->result;
623 msg_error_t MsgHandle::regCBMessageCallback(msg_cb_incoming_cb onCBIncoming, bool bSave, void *pUserParam)
625 if( (!onCBIncoming) )
626 THROW(MsgException::INVALID_PARAM, "Param %p", onCBIncoming);
628 MsgProxyListener* eventListener = MsgProxyListener::instance();
630 eventListener->start();
632 int clientFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
635 return MSG_ERR_TRANSPORT_ERROR;
637 if (eventListener->regCBMessageIncomingEventCB(this, onCBIncoming, bSave, pUserParam) == false) // callback was already registered, just return SUCCESS
640 // Allocate Memory to Command Data
641 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_CB_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
643 char cmdBuf[cmdSize];
644 bzero(cmdBuf, cmdSize);
646 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
648 // Set Command Parameters
649 pCmd->cmdType = MSG_CMD_REG_INCOMING_CB_MSG_CB;
652 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
654 MSG_CMD_REG_CB_INCOMING_MSG_CB_S cmdParam = {0};
656 cmdParam.listenerFd = clientFd; // fd that is reserved to the "listener thread" by msgfw daemon
657 cmdParam.msgType = MSG_SMS_TYPE;
658 cmdParam.bsave = bSave;
660 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
662 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
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_REG_INCOMING_CB_MSG_CB)
676 THROW(MsgException::INVALID_RESULT, "Event Data Error");
679 return pEvent->result;
683 msg_error_t MsgHandle::operateSyncMLMessage(msg_message_id_t msgId)
686 THROW(MsgException::INVALID_PARAM, "Param msgId %d", msgId);
688 // Allocate Memory to Command Data
689 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
691 char cmdBuf[cmdSize];
692 bzero(cmdBuf, cmdSize);
693 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
695 // Set Command Parameters
696 pCmd->cmdType = MSG_CMD_SYNCML_OPERATION;
699 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
702 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgId, sizeof(msg_message_id_t));
704 // Send Command to Messaging FW
705 char* pEventData = NULL;
706 AutoPtr<char> eventBuf(&pEventData);
709 write((char*)pCmd, cmdSize, &pEventData);
712 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
714 if (pEvent->eventType != MSG_EVENT_SYNCML_OPERATION)
716 THROW(MsgException::INVALID_RESULT, "Event Data Error");
719 return pEvent->result;