RSA sync with private
[platform/core/messaging/msg-service.git] / include / proxy / MsgProxyListener.h
1 /*
2 * Copyright 2012  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.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.tizenopensource.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_PROXY_LISTENER_H__
18 #define __MSG_PROXY_LISTENER_H__
19
20
21 /*==================================================================================================
22                                          INCLUDE FILES
23 ==================================================================================================*/
24 #include "MsgIpcSocket.h"
25 #include "MsgTypes.h"
26 #include "MsgMutex.h"
27 #include "MsgHandle.h"
28
29 #include <map>
30 #include <list>
31 #include <glib.h>
32
33
34 /*==================================================================================================
35                                          VARIABLES
36 ==================================================================================================*/
37 typedef struct
38 {
39         MsgHandle* hAddr;
40         msg_sent_status_cb pfSentStatusCB;
41         void* userParam;
42 } MSG_SENT_STATUS_CB_ITEM_S;
43
44 typedef struct
45 {
46         MsgHandle* hAddr;
47         msg_sms_incoming_cb pfIncomingCB;
48         int port;
49         void* userParam;
50 } MSG_INCOMING_CB_ITEM_S;
51
52 typedef struct
53 {
54         MsgHandle* hAddr;
55         msg_mms_conf_msg_incoming_cb pfMMSConfIncomingCB;
56         char appId[MAX_MMS_JAVA_APPID_LEN+1];
57         void* userParam;
58 } MSG_MMS_CONF_INCOMING_CB_ITEM_S;
59
60 typedef struct
61 {
62         MsgHandle* hAddr;
63         msg_push_msg_incoming_cb pfPushIncomingCB;
64         char appId[MAX_WAPPUSH_ID_LEN+1];
65         void* userParam;
66 } MSG_PUSH_INCOMING_CB_ITEM_S;
67
68 typedef struct
69 {
70         MsgHandle* hAddr;
71         msg_cb_incoming_cb pfCBIncomingCB;
72         bool bsave;
73         void* userParam;
74 } MSG_CB_INCOMING_CB_ITEM_S;
75
76 typedef struct
77 {
78         MsgHandle* hAddr;
79         msg_syncml_msg_incoming_cb pfSyncMLIncomingCB;
80         void* userParam;
81 } MSG_SYNCML_INCOMING_CB_ITEM_S;
82
83 typedef struct
84 {
85         MsgHandle* hAddr;
86         msg_lbs_msg_incoming_cb pfLBSMsgIncoming;
87         void* userParam;
88 } MSG_LBS_INCOMING_CB_ITEM_S;
89
90 typedef struct
91 {
92         MsgHandle* hAddr;
93         msg_syncml_msg_operation_cb pfSyncMLOperationCB;
94         void* userParam;
95 } MSG_SYNCML_OPERATION_CB_ITEM_S;
96
97 typedef struct
98 {
99         MsgHandle* hAddr;
100         msg_storage_change_cb pfStorageChangeCB;
101         void* userParam;
102 } MSG_STORAGE_CHANGE_CB_ITEM_S;
103
104
105 typedef std::list<MSG_SENT_STATUS_CB_ITEM_S> MsgSentStatusCBList;
106 typedef std::list<MSG_INCOMING_CB_ITEM_S> MsgNewMessageCBList;
107 typedef std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S> MsgNewMMSConfMessageCBList;
108 typedef std::list<MSG_PUSH_INCOMING_CB_ITEM_S> MsgNewPushMessageCBList;
109 typedef std::list<MSG_CB_INCOMING_CB_ITEM_S> MsgNewCBMessageCBList;
110 typedef std::list<MSG_SYNCML_INCOMING_CB_ITEM_S> MsgNewSyncMLMessageCBList;
111 typedef std::list<MSG_LBS_INCOMING_CB_ITEM_S> MsgNewLBSMessageCBList;
112 typedef std::list<MSG_SYNCML_OPERATION_CB_ITEM_S> MsgOperationSyncMLMessageCBList;
113 typedef std::list<MSG_STORAGE_CHANGE_CB_ITEM_S> MsgStorageChangeCBList;
114
115
116 /*==================================================================================================
117                                      CLASS DEFINITIONS
118 ==================================================================================================*/
119 class MsgProxyListener
120 {
121 public:
122         static MsgProxyListener* instance();
123
124         void start();
125         void stop();
126
127         bool regSentStatusEventCB(MsgHandle* pMsgHandle, msg_sent_status_cb pfSentStatus, void *pUserParam);
128         bool regMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_sms_incoming_cb pfNewMessage, int port, void *pUserParam);
129         bool regMMSConfMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_mms_conf_msg_incoming_cb pfNewMMSConfMessage, const char *pAppId, void *pUserParam);
130         bool regPushMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_push_msg_incoming_cb pfNewPushMessage, const char *pAppId, void *pUserParam);
131         bool regCBMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_cb_incoming_cb pfNewCBMessage, bool bSave, void *pUserParam);
132         bool regSyncMLMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_syncml_msg_incoming_cb pfNewSyncMLMessage, void *pUserParam);
133         bool regLBSMessageIncomingEventCB(MsgHandle* pMsgHandle, msg_lbs_msg_incoming_cb pfNewLBSMsgIncoming, void *pUserParam);
134         bool regSyncMLMessageOperationEventCB(MsgHandle* pMsgHandle, msg_syncml_msg_operation_cb pfSyncMLMessageOperation, void *pUserParam);
135         bool regStorageChangeEventCB(MsgHandle* pMsgHandle, msg_storage_change_cb pfStorageChangeOperation, void *pUserParam);
136
137         void clearListOfClosedHandle(MsgHandle* pMsgHandle);
138
139         void handleEvent(const MSG_EVENT_S* ptr);
140
141         int getRemoteFd();
142         int readFromSocket(char** buf, unsigned int* len);
143 #ifdef CHECK_SENT_STATUS_CALLBACK
144         int getSentStatusCbCnt();
145 #endif
146
147 private:
148         MsgProxyListener();
149         ~MsgProxyListener();
150
151         static MsgProxyListener* pInstance;
152
153         unsigned int running;
154
155         MsgIpcClientSocket cliSock;
156
157         Mutex mx;
158         CndVar cv;
159
160         MsgSentStatusCBList sentStatusCBList;
161         MsgNewMessageCBList newMessageCBList;
162         MsgNewMMSConfMessageCBList newMMSConfMessageCBList;
163         MsgNewPushMessageCBList newPushMessageCBList;
164         MsgNewCBMessageCBList newCBMessageCBList;
165         MsgNewSyncMLMessageCBList newSyncMLMessageCBList;
166         MsgNewLBSMessageCBList newLBSMessageCBList;
167         MsgOperationSyncMLMessageCBList operationSyncMLMessageCBList;
168         MsgStorageChangeCBList storageChangeCBList;
169
170         GIOChannel *channel;
171         guint eventSourceId;
172 };
173
174 #endif // __MSG_PROXY_LISTENER_H__
175