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 setThreadChangeCB(int listenerFd);
84 void setReportMsgCB(int listenerFd);
86 javamms_list &getJavaMMSList();
88 void broadcastIncomingMsgCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo);
89 void broadcastMMSConfCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo, const MMS_RECV_DATA_S *mmsRecvData);
90 void broadcastPushMsgCB(const msg_error_t err, const MSG_PUSH_MESSAGE_DATA_S *pushData);
91 void broadcastCBMsgCB(const msg_error_t err, const MSG_CB_MSG_S *cbMsg, msg_message_id_t cbMsgId);
92 void broadcastSyncMLMsgCB(const msg_error_t err, const MSG_SYNCML_MESSAGE_DATA_S *syncMLData);
93 void broadcastLBSMsgCB(const msg_error_t err, const MSG_LBS_MESSAGE_DATA_S *lbsData);
94 void broadcastSyncMLMsgOperationCB(const msg_error_t err, const int msgId, const int extId);
95 void broadcastStorageChangeCB(const msg_error_t err, const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList);
96 void broadcastThreadChangeCB(const msg_error_t err, const msg_storage_change_type_t storageChangeType, const msg_thread_id_t threadId);
97 void broadcastReportMsgCB(const msg_error_t err, const msg_report_type_t reportMsgType, const MSG_MESSAGE_INFO_S *pMsgInfo);
103 MsgTransactionManager();
104 ~MsgTransactionManager();
106 void handleRequest(int fd);
107 void cleanup(int fd);
108 /* bool checkPrivilege(MSG_CMD_TYPE_T CmdType, const char *pCookie); */
109 bool checkPrivilege(int fd, MSG_CMD_TYPE_T CmdType);
111 static MsgTransactionManager* pInstance;
113 static MsgIpcServerSocket servSock;
116 handler_map handlerMap;
117 sentmsg_map sentMsgMap;
118 fd_map statusCBFdMap;
120 newmsg_list newMsgCBList;
121 mmsconf_list newMMSConfMsgCBList;
122 pushmsg_list newPushMsgCBList;
123 cbmsg_list newCBMsgCBList;
124 syncmlmsg_list newSyncMLMsgCBList;
125 lbsmsg_list newLBSMsgCBList;
126 javamms_list javaMMSList;
127 syncmlop_list operationSyncMLMsgCBList;
129 fd_map storageChangeFdMap;
130 fd_map threadChangeFdMap;
131 fd_map reportMsgCBFdMap;
133 MsgMutex mx; /* mutex for shared resources like callback listeners */
134 MsgMutex mxQ; /* mutex for event queue */
136 MsgSimpleQ<MSG_CMD_S*> eventQueue;
139 enum cynara_client_creds client_method;
140 enum cynara_user_creds user_method;
143 #endif /* MSG_TRANSACTION_MANAGER_H */