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 typedef std::map<int, bool> fd_map;
46 typedef std::list<MSG_CMD_REG_INCOMING_MSG_CB_S> newmsg_list;
47 typedef std::list<MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S> mmsconf_list;
48 typedef std::list<MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S> pushmsg_list;
49 typedef std::list<MSG_CMD_REG_INCOMING_CB_MSG_CB_S> cbmsg_list;
50 typedef std::list<MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S> syncmlmsg_list;
51 typedef std::list<MSG_CMD_REG_INCOMING_LBS_MSG_CB_S> lbsmsg_list;
52 typedef std::list<MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S> javamms_list;
53 typedef std::list<MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S> syncmlop_list;
56 /*==================================================================================================
58 ==================================================================================================*/
59 class MsgTransactionManager
62 static MsgTransactionManager* instance();
65 void workerEventQueue();
66 void write(int fd, const char* buf, int len);
68 /* methods for sent status event */
69 void insertSentMsg(int reqId, MSG_PROXY_INFO_S* pChInfo);
70 MSG_PROXY_INFO_S* getProxyInfo(int reqId);
71 void delProxyInfo(int reqId);
73 void setSentStatusCB(int listenerFd);
74 void setIncomingMsgCB(MSG_CMD_REG_INCOMING_MSG_CB_S *pCbInfo);
75 void setMMSConfMsgCB(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S *pCbinfo);
76 void setPushMsgCB(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S *pCbinfo);
77 void setCBMsgCB(MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCbInfo);
78 void setSyncMLMsgCB(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S *pCbinfo);
79 void setLBSMsgCB(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S *pCbinfo);
80 void setJavaMMSList(MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S *pTrId);
81 void setSyncMLMsgOperationCB(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S *pCbinfo);
82 void setStorageChangeCB(int listenerFd);
83 void setReportMsgCB(int listenerFd);
85 javamms_list& getJavaMMSList();
87 void broadcastIncomingMsgCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo);
88 void broadcastMMSConfCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo, const MMS_RECV_DATA_S *mmsRecvData);
89 void broadcastPushMsgCB(const msg_error_t err, const MSG_PUSH_MESSAGE_DATA_S *pushData);
90 void broadcastCBMsgCB(const msg_error_t err, const MSG_CB_MSG_S *cbMsg, msg_message_id_t cbMsgId);
91 void broadcastSyncMLMsgCB(const msg_error_t err, const MSG_SYNCML_MESSAGE_DATA_S *syncMLData);
92 void broadcastLBSMsgCB(const msg_error_t err, const MSG_LBS_MESSAGE_DATA_S *lbsData);
93 void broadcastSyncMLMsgOperationCB(const msg_error_t err, const int msgId, const int extId);
94 void broadcastStorageChangeCB(const msg_error_t err, const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList);
95 void broadcastReportMsgCB(const msg_error_t err, const msg_report_type_t reportMsgType, const MSG_MESSAGE_INFO_S *pMsgInfo);
101 MsgTransactionManager();
102 ~MsgTransactionManager();
104 void handleRequest(int fd);
105 void cleanup(int fd);
106 /* bool checkPrivilege(MSG_CMD_TYPE_T CmdType, const char *pCookie); */
107 bool checkPrivilege(int fd, MSG_CMD_TYPE_T CmdType);
109 static MsgTransactionManager* pInstance;
111 static MsgIpcServerSocket servSock;
114 handler_map handlerMap;
115 sentmsg_map sentMsgMap;
116 fd_map statusCBFdMap;
118 newmsg_list newMsgCBList;
119 mmsconf_list newMMSConfMsgCBList;
120 pushmsg_list newPushMsgCBList;
121 cbmsg_list newCBMsgCBList;
122 syncmlmsg_list newSyncMLMsgCBList;
123 lbsmsg_list newLBSMsgCBList;
124 javamms_list javaMMSList;
125 syncmlop_list operationSyncMLMsgCBList;
127 fd_map storageChangeFdMap;
128 fd_map reportMsgCBFdMap;
130 MsgMutex mx; /* mutex for shared resources like callback listeners */
131 MsgMutex mxQ; /* mutex for event queue */
133 MsgSimpleQ<MSG_CMD_S*> eventQueue;
136 enum cynara_client_creds client_method;
137 enum cynara_user_creds user_method;
140 #endif /* MSG_TRANSACTION_MANAGER_H */