update tizen source
[framework/messaging/msg-service.git] / include / framework / MsgTransManager.h
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31 #ifndef MSG_TRANSACTION_MANAGER_H
32 #define MSG_TRANSACTION_MANAGER_H
33
34
35 /*==================================================================================================
36                                          INCLUDE FILES
37 ==================================================================================================*/
38 #include <list>
39 #include <map>
40
41 #include "MsgMutex.h"
42 #include "MsgIpcSocket.h"
43 #include "MsgCmdTypes.h"
44 #include "MsgInternalTypes.h"
45 #include "MsgTransportTypes.h"
46
47
48
49 /*==================================================================================================
50                                          DEFINITION
51 ==================================================================================================*/
52 typedef std::map<MSG_CMD_TYPE_T, int (*)(const MSG_CMD_S*, char**)> handler_map;
53 typedef std::map<int, MSG_PROXY_INFO_S> sentmsg_map;
54 typedef std::map<int, bool> fd_map;
55 typedef std::list<MSG_CMD_REG_INCOMING_MSG_CB_S> newmsg_list;
56 typedef std::list<MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S>       mmsconf_list;
57 typedef std::list<MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S> syncmlmsg_list;
58 typedef std::list<MSG_CMD_REG_INCOMING_LBS_MSG_CB_S> lbsmsg_list;
59 typedef std::list<MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S> javamms_list;
60 typedef std::list<MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S> syncmlop_list;
61
62
63 /*==================================================================================================
64                                      FUNCTION PROTOTYPES
65 ==================================================================================================*/
66 void MsgContactChangedCallback();
67
68 /*==================================================================================================
69                                      CLASS DEFINITIONS
70 ==================================================================================================*/
71 class MsgTransactionManager
72 {
73 public:
74         static MsgTransactionManager* instance();
75
76         void run();
77         void write(int fd, const char* buf, int len);
78
79         // methods for sent status event
80         void insertSentMsg(int reqId, MSG_PROXY_INFO_S* pChInfo);
81         MSG_PROXY_INFO_S* getProxyInfo(int reqId);
82         void delProxyInfo(int reqId);
83
84         void setSentStatusCB(int listenerFd);
85         void setIncomingMsgCB(MSG_CMD_REG_INCOMING_MSG_CB_S *pCbInfo);
86         void setMMSConfMsgCB(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S *pCbinfo);
87         void setSyncMLMsgCB(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S *pCbinfo);
88         void setLBSMsgCB(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S *pCbinfo);
89         void setJavaMMSList(MSG_CMD_REG_INCOMING_JAVAMMS_TRID_S *pTrId);
90         void setSyncMLMsgOperationCB(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S *pCbinfo);
91         void setStorageChangeCB(int listenerFd);
92
93         javamms_list& getJavaMMSList();
94
95         void broadcastIncomingMsgCB(const MSG_ERROR_T err, const MSG_MESSAGE_INFO_S *msgInfo);
96         void broadcastMMSConfCB(const MSG_ERROR_T err, const MSG_MESSAGE_INFO_S *msgInfo, const MMS_RECV_DATA_S *mmsRecvData);
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_MSGID_LIST_S *pMsgIdList);
101
102         void setTMStatus();
103         void getTMStatus();
104
105 private:
106         MsgTransactionManager();
107         ~MsgTransactionManager();
108
109         void handleRequest(int fd);
110         void cleanup(int fd);
111         bool checkPrivilege(MSG_CMD_TYPE_T CmdType, const char *pCookie);
112
113         static MsgTransactionManager* pInstance;
114
115         static MsgIpcServerSocket servSock;
116         bool running;
117
118         handler_map handlerMap;
119
120         sentmsg_map sentMsgMap;                 // req_id, listener_fd, msghandle_addr
121         fd_map statusCBFdMap;           // src_fd, true if registered
122
123         newmsg_list newMsgCBList;       // src_fd, msgType, port if registered
124         mmsconf_list newMMSConfMsgCBList;       // src_fd, msgType, port if registered
125         syncmlmsg_list newSyncMLMsgCBList;      // src_fd, msgType, port if registered
126         lbsmsg_list newLBSMsgCBList;    // src_fd, msgType, port if registered
127         javamms_list javaMMSList; // trId list to distinguish sent Java MMS msg when sendconf received
128         syncmlop_list operationSyncMLMsgCBList;         // src_fd, msgType, port if registered
129
130         fd_map storageChangeFdMap;      // src_fd, true if registered
131
132         Mutex mx;
133         CndVar cv;
134 };
135
136 #endif //MSG_TRANSACTION_MANAGER_H
137