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.
17 #ifndef MSG_TRANSACTION_MANAGER_H
18 #define MSG_TRANSACTION_MANAGER_H
21 /*==================================================================================================
23 ==================================================================================================*/
29 #include "MsgIpcSocket.h"
30 #include "MsgCmdTypes.h"
31 #include "MsgInternalTypes.h"
32 #include "MsgTransportTypes.h"
34 #include <cynara-client.h>
35 #include <cynara-creds-socket.h>
36 #include <cynara-session.h>
37 #include <cynara-creds-commons.h>
40 /*==================================================================================================
42 ==================================================================================================*/
43 typedef std::map<MSG_CMD_TYPE_T, int (*)(const MSG_CMD_S*, char**)> handler_map;
44 typedef std::map<int, MSG_PROXY_INFO_S> sentmsg_map;
45 #ifdef MSG_PENDING_PUSH_MESSAGE
46 typedef std::list<MSG_PUSH_MESSAGE_DATA_S> pushpending_list;
48 typedef std::map<int, bool> fd_map;
49 typedef std::list<MSG_CMD_REG_INCOMING_MSG_CB_S> newmsg_list;
50 typedef std::list<MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S> mmsconf_list;
51 typedef std::list<MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S> pushmsg_list;
52 typedef std::list<MSG_CMD_REG_INCOMING_CB_MSG_CB_S> cbmsg_list;
53 typedef std::list<MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S> syncmlmsg_list;
54 typedef std::list<MSG_CMD_REG_INCOMING_LBS_MSG_CB_S> lbsmsg_list;
55 typedef std::list<MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S> javamms_list;
56 typedef std::list<MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S> syncmlop_list;
59 /*==================================================================================================
61 ==================================================================================================*/
62 class MsgTransactionManager
65 static MsgTransactionManager* instance();
68 void workerEventQueue();
69 void write(int fd, const char* buf, int len);
71 // methods for sent status event
72 void insertSentMsg(int reqId, MSG_PROXY_INFO_S* pChInfo);
73 MSG_PROXY_INFO_S* getProxyInfo(int reqId);
74 void delProxyInfo(int reqId);
76 void setSentStatusCB(int listenerFd);
77 void setIncomingMsgCB(MSG_CMD_REG_INCOMING_MSG_CB_S *pCbInfo);
78 void setMMSConfMsgCB(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S *pCbinfo);
79 void setPushMsgCB(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S *pCbinfo);
80 void setCBMsgCB(MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCbInfo);
81 void setSyncMLMsgCB(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S *pCbinfo);
82 void setLBSMsgCB(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S *pCbinfo);
83 void setJavaMMSList(MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S *pTrId);
84 void setSyncMLMsgOperationCB(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S *pCbinfo);
85 void setStorageChangeCB(int listenerFd);
86 void setReportMsgCB(int listenerFd);
87 #ifdef MSG_PENDING_PUSH_MESSAGE
88 void sendPendingPushMsg(void);
91 javamms_list& getJavaMMSList();
93 void broadcastIncomingMsgCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo);
94 void broadcastMMSConfCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo, const MMS_RECV_DATA_S *mmsRecvData);
95 void broadcastPushMsgCB(const msg_error_t err, const MSG_PUSH_MESSAGE_DATA_S *pushData);
96 void broadcastCBMsgCB(const msg_error_t err, const MSG_CB_MSG_S *cbMsg);
97 void broadcastSyncMLMsgCB(const msg_error_t err, const MSG_SYNCML_MESSAGE_DATA_S *syncMLData);
98 void broadcastLBSMsgCB(const msg_error_t err, const MSG_LBS_MESSAGE_DATA_S *lbsData);
99 void broadcastSyncMLMsgOperationCB(const msg_error_t err, const int msgId, const int extId);
100 void broadcastStorageChangeCB(const msg_error_t err, const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList);
101 void broadcastReportMsgCB(const msg_error_t err, const msg_report_type_t reportMsgType, const MSG_MESSAGE_INFO_S *pMsgInfo);
109 MsgTransactionManager();
110 ~MsgTransactionManager();
112 void handleRequest(int fd);
113 void cleanup(int fd);
114 // bool checkPrivilege(MSG_CMD_TYPE_T CmdType, const char *pCookie);
115 bool checkPrivilege(int fd, MSG_CMD_TYPE_T CmdType);
117 static MsgTransactionManager* pInstance;
119 static MsgIpcServerSocket servSock;
122 handler_map handlerMap;
123 #ifdef MSG_PENDING_PUSH_MESSAGE
124 pushpending_list pushMsgList;
126 sentmsg_map sentMsgMap; // req_id, listener_fd, msghandle_addr
127 fd_map statusCBFdMap; // src_fd, true if registered
129 newmsg_list newMsgCBList; // src_fd, msgType, port if registered
130 mmsconf_list newMMSConfMsgCBList; // src_fd, msgType, port if registered
131 pushmsg_list newPushMsgCBList; // src_fd, msgType, port if registered
132 cbmsg_list newCBMsgCBList; // src_fd, msgType, port if registered
133 syncmlmsg_list newSyncMLMsgCBList; // src_fd, msgType, port if registered
134 lbsmsg_list newLBSMsgCBList; // src_fd, msgType, port if registered
135 javamms_list javaMMSList; // trId list to distinguish sent Java MMS msg when sendconf received
136 syncmlop_list operationSyncMLMsgCBList; // src_fd, msgType, port if registered
138 fd_map storageChangeFdMap; // src_fd, true if registered
139 fd_map reportMsgCBFdMap; // src_fd, true if registered
143 MsgSimpleQ<MSG_CMD_S*> eventQueue;
146 enum cynara_client_creds client_method;
147 enum cynara_user_creds user_method;
150 #endif //MSG_TRANSACTION_MANAGER_H