Modify flora license version.
[platform/core/messaging/msg-service.git] / include / framework / MsgTransManager.h
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 "MsgIpcSocket.h"
29 #include "MsgCmdTypes.h"
30 #include "MsgInternalTypes.h"
31 #include "MsgTransportTypes.h"
32
33
34
35 /*==================================================================================================
36                                          DEFINITION
37 ==================================================================================================*/
38 typedef std::map<MSG_CMD_TYPE_T, int (*)(const MSG_CMD_S*, char**)> handler_map;
39 typedef std::map<int, MSG_PROXY_INFO_S> sentmsg_map;
40 typedef std::map<int, bool> fd_map;
41 typedef std::list<MSG_CMD_REG_INCOMING_MSG_CB_S> newmsg_list;
42 typedef std::list<MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S>       mmsconf_list;
43 typedef std::list<MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S> pushmsg_list;
44 typedef std::list<MSG_CMD_REG_INCOMING_CB_MSG_CB_S> cbmsg_list;
45 typedef std::list<MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S> syncmlmsg_list;
46 typedef std::list<MSG_CMD_REG_INCOMING_LBS_MSG_CB_S> lbsmsg_list;
47 typedef std::list<MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S> javamms_list;
48 typedef std::list<MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S> syncmlop_list;
49
50
51 /*==================================================================================================
52                                      FUNCTION PROTOTYPES
53 ==================================================================================================*/
54 void MsgContactChangedCallback();
55
56 /*==================================================================================================
57                                      CLASS DEFINITIONS
58 ==================================================================================================*/
59 class MsgTransactionManager
60 {
61 public:
62         static MsgTransactionManager* instance();
63
64         void run();
65         void write(int fd, const char* buf, int len);
66
67         // methods for sent status event
68         void insertSentMsg(int reqId, MSG_PROXY_INFO_S* pChInfo);
69         MSG_PROXY_INFO_S* getProxyInfo(int reqId);
70         void delProxyInfo(int reqId);
71
72         void setSentStatusCB(int listenerFd);
73         void setIncomingMsgCB(MSG_CMD_REG_INCOMING_MSG_CB_S *pCbInfo);
74         void setMMSConfMsgCB(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S *pCbinfo);
75         void setPushMsgCB(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S *pCbinfo);
76         void setCBMsgCB(MSG_CMD_REG_INCOMING_CB_MSG_CB_S *pCbInfo);
77         void setSyncMLMsgCB(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S *pCbinfo);
78         void setLBSMsgCB(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S *pCbinfo);
79         void setJavaMMSList(MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S *pTrId);
80         void setSyncMLMsgOperationCB(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S *pCbinfo);
81         void setStorageChangeCB(int listenerFd);
82
83         javamms_list& getJavaMMSList();
84
85         void broadcastIncomingMsgCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo);
86         void broadcastMMSConfCB(const msg_error_t err, const MSG_MESSAGE_INFO_S *msgInfo, const MMS_RECV_DATA_S *mmsRecvData);
87         void broadcastPushMsgCB(const msg_error_t err, const MSG_PUSH_MESSAGE_DATA_S *pushData);
88         void broadcastCBMsgCB(const msg_error_t err, const MSG_CB_MSG_S *cbMsg);
89         void broadcastSyncMLMsgCB(const msg_error_t err, const MSG_SYNCML_MESSAGE_DATA_S *syncMLData);
90         void broadcastLBSMsgCB(const msg_error_t err, const MSG_LBS_MESSAGE_DATA_S *lbsData);
91         void broadcastSyncMLMsgOperationCB(const msg_error_t err, const int msgId, const int extId);
92         void broadcastStorageChangeCB(const msg_error_t err, const msg_storage_change_type_t storageChangeType, const msg_id_list_s *pMsgIdList);
93
94         void setTMStatus();
95         void getTMStatus();
96
97 private:
98         MsgTransactionManager();
99         ~MsgTransactionManager();
100
101         void handleRequest(int fd);
102         void cleanup(int fd);
103         bool checkPrivilege(MSG_CMD_TYPE_T CmdType, const char *pCookie);
104
105         static MsgTransactionManager* pInstance;
106
107         static MsgIpcServerSocket servSock;
108         bool running;
109
110         handler_map handlerMap;
111
112         sentmsg_map sentMsgMap;                 // req_id, listener_fd, msghandle_addr
113         fd_map statusCBFdMap;           // src_fd, true if registered
114
115         newmsg_list newMsgCBList;       // src_fd, msgType, port if registered
116         mmsconf_list newMMSConfMsgCBList;       // src_fd, msgType, port if registered
117         pushmsg_list newPushMsgCBList;  // src_fd, msgType, port if registered
118         cbmsg_list newCBMsgCBList;      // src_fd, msgType, port if registered
119         syncmlmsg_list newSyncMLMsgCBList;      // src_fd, msgType, port if registered
120         lbsmsg_list newLBSMsgCBList;    // src_fd, msgType, port if registered
121         javamms_list javaMMSList; // trId list to distinguish sent Java MMS msg when sendconf received
122         syncmlop_list operationSyncMLMsgCBList;         // src_fd, msgType, port if registered
123
124         fd_map storageChangeFdMap;      // src_fd, true if registered
125
126         Mutex mx;
127         CndVar cv;
128 };
129
130 #endif //MSG_TRANSACTION_MANAGER_H
131