2933099413dd2f8955bb34ae0b8f4287c21d37d6
[platform/core/messaging/msg-service.git] / include / framework / MsgTransManager.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15 */
16
17 #ifndef MSG_TRANSACTION_MANAGER_H
18 #define MSG_TRANSACTION_MANAGER_H
19
20
21 /*==================================================================================================
22                                          INCLUDE FILES
23 ==================================================================================================*/
24 #include <list>
25 #include <map>
26
27 #include "MsgMutex.h"
28 #include "MsgQueue.h"
29 #include "MsgIpcSocket.h"
30 #include "MsgCmdTypes.h"
31 #include "MsgInternalTypes.h"
32 #include "MsgTransportTypes.h"
33
34 #include <cynara-client.h>
35 #include <cynara-creds-socket.h>
36 #include <cynara-session.h>
37 #include <cynara-creds-commons.h>
38
39
40 /*==================================================================================================
41                                          DEFINITION
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;
54
55
56 /*==================================================================================================
57                                      CLASS DEFINITIONS
58 ==================================================================================================*/
59 class MsgTransactionManager
60 {
61 public:
62         static MsgTransactionManager* instance();
63
64         void run();
65       void workerEventQueue();
66         void write(int fd, const char* buf, int len);
67
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);
72
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);
84
85         javamms_list& getJavaMMSList();
86
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);
96
97         bool initCynara();
98         void finishCynara();
99
100 private:
101         MsgTransactionManager();
102         ~MsgTransactionManager();
103
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);
108
109         static MsgTransactionManager* pInstance;
110
111         static MsgIpcServerSocket servSock;
112         bool running;
113
114         handler_map handlerMap;
115         sentmsg_map sentMsgMap;
116         fd_map statusCBFdMap;
117
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;
126
127         fd_map storageChangeFdMap;
128         fd_map reportMsgCBFdMap;
129
130         Mutex mx; /* mutex for shared resources like callback listeners */
131         Mutex mxQ; /* mutex for event queue */
132         CndVar cv;
133         MsgSimpleQ<MSG_CMD_S*> eventQueue;
134
135         cynara *p_cynara;
136         enum cynara_client_creds client_method;
137         enum cynara_user_creds user_method;
138 };
139
140 #endif /* MSG_TRANSACTION_MANAGER_H */
141