Fix issue : fail to make thumbnail
[platform/core/messaging/msg-service.git] / include / proxy / MsgProxyListener.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_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 <set>
30 #include <list>
31 #include <glib.h>
32
33
34 /*==================================================================================================
35                                          VARIABLES
36 ==================================================================================================*/
37 typedef struct {
38         MsgHandle* hAddr;
39         int fd;
40         msg_sent_status_cb pfSentStatusCB;
41         void* userParam;
42 } MSG_SENT_STATUS_CB_ITEM_S;
43
44
45 typedef struct {
46         MsgHandle* hAddr;
47         int fd;
48         msg_sms_incoming_cb pfIncomingCB;
49         int port;
50         void* userParam;
51 } MSG_INCOMING_CB_ITEM_S;
52
53
54 typedef struct {
55         MsgHandle* hAddr;
56         int fd;
57         msg_mms_conf_msg_incoming_cb pfMMSConfIncomingCB;
58         char appId[MAX_MMS_JAVA_APPID_LEN+1];
59         void* userParam;
60 } MSG_MMS_CONF_INCOMING_CB_ITEM_S;
61
62
63 typedef struct {
64         MsgHandle* hAddr;
65         int fd;
66         msg_push_msg_incoming_cb pfPushIncomingCB;
67         char appId[MAX_WAPPUSH_ID_LEN+1];
68         void* userParam;
69 } MSG_PUSH_INCOMING_CB_ITEM_S;
70
71
72 typedef struct {
73         MsgHandle* hAddr;
74         int fd;
75         msg_cb_incoming_cb pfCBIncomingCB;
76         bool bsave;
77         void* userParam;
78 } MSG_CB_INCOMING_CB_ITEM_S;
79
80
81 typedef struct {
82         MsgHandle* hAddr;
83         int fd;
84         msg_syncml_msg_incoming_cb pfSyncMLIncomingCB;
85         void* userParam;
86 } MSG_SYNCML_INCOMING_CB_ITEM_S;
87
88
89 typedef struct {
90         MsgHandle* hAddr;
91         int fd;
92         msg_lbs_msg_incoming_cb pfLBSMsgIncoming;
93         void* userParam;
94 } MSG_LBS_INCOMING_CB_ITEM_S;
95
96
97 typedef struct {
98         MsgHandle* hAddr;
99         int fd;
100         msg_syncml_msg_operation_cb pfSyncMLOperationCB;
101         void* userParam;
102 } MSG_SYNCML_OPERATION_CB_ITEM_S;
103
104
105 typedef struct {
106         MsgHandle* hAddr;
107         int fd;
108         msg_storage_change_cb pfStorageChangeCB;
109         void* userParam;
110 } MSG_STORAGE_CHANGE_CB_ITEM_S;
111
112
113 typedef struct {
114         MsgHandle* hAddr;
115         int fd;
116         msg_report_msg_incoming_cb pfReportMsgIncomingCB;
117         void* userParam;
118 } MSG_REPORT_INCOMING_CB_ITEM_S;
119
120
121 typedef std::list<MSG_SENT_STATUS_CB_ITEM_S> MsgSentStatusCBList;
122 typedef std::list<MSG_INCOMING_CB_ITEM_S> MsgNewMessageCBList;
123 typedef std::list<MSG_MMS_CONF_INCOMING_CB_ITEM_S> MsgNewMMSConfMessageCBList;
124 typedef std::list<MSG_PUSH_INCOMING_CB_ITEM_S> MsgNewPushMessageCBList;
125 typedef std::list<MSG_CB_INCOMING_CB_ITEM_S> MsgNewCBMessageCBList;
126 typedef std::list<MSG_SYNCML_INCOMING_CB_ITEM_S> MsgNewSyncMLMessageCBList;
127 typedef std::list<MSG_LBS_INCOMING_CB_ITEM_S> MsgNewLBSMessageCBList;
128 typedef std::list<MSG_SYNCML_OPERATION_CB_ITEM_S> MsgOperationSyncMLMessageCBList;
129 typedef std::list<MSG_STORAGE_CHANGE_CB_ITEM_S> MsgStorageChangeCBList;
130 typedef std::list<MSG_REPORT_INCOMING_CB_ITEM_S> MsgReportMessageCBList;
131 typedef std::set<MsgHandle*> handle_set;
132
133 /*==================================================================================================
134                                      CLASS DEFINITIONS
135 ==================================================================================================*/
136 class MsgProxyListener
137 {
138 public:
139         static MsgProxyListener* instance();
140
141         void start(MsgHandle* pMsgHandle);
142         void stop();
143
144         bool regSentStatusEventCB(MsgHandle* pMsgHandle, int fd, msg_sent_status_cb pfSentStatus, void *pUserParam);
145         bool regMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_sms_incoming_cb pfNewMessage, int port, void *pUserParam);
146         bool regMMSConfMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_mms_conf_msg_incoming_cb pfNewMMSConfMessage, const char *pAppId, void *pUserParam);
147         bool regPushMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_push_msg_incoming_cb pfNewPushMessage, const char *pAppId, void *pUserParam);
148         bool regCBMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_cb_incoming_cb pfNewCBMessage, bool bSave, void *pUserParam);
149         bool regSyncMLMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_syncml_msg_incoming_cb pfNewSyncMLMessage, void *pUserParam);
150         bool regLBSMessageIncomingEventCB(MsgHandle* pMsgHandle, int fd, msg_lbs_msg_incoming_cb pfNewLBSMsgIncoming, void *pUserParam);
151         bool regSyncMLMessageOperationEventCB(MsgHandle* pMsgHandle, int fd, msg_syncml_msg_operation_cb pfSyncMLMessageOperation, void *pUserParam);
152         bool regStorageChangeEventCB(MsgHandle* pMsgHandle, int fd, msg_storage_change_cb pfStorageChangeOperation, void *pUserParam);
153         bool regReportMsgIncomingCB(MsgHandle* pMsgHandle, int fd, msg_report_msg_incoming_cb pfReportMessage, void *pUserParam);
154
155         void clearListOfClosedHandle(MsgHandle* pMsgHandle);
156         void refreshListOfOpenedHandle(MsgHandle* pMsgHandle);
157
158         void handleEvent(const MSG_EVENT_S* ptr);
159
160         int getRemoteFd();
161         int readFromSocket(char** buf, unsigned int* len);
162         void resetProxyListener();
163         void refreshProxyListener();
164         void clearProxyCBLists();
165         void insertOpenHandleSet(MsgHandle* pMsgHandle);
166         void clearOpenHandleSet();
167 #ifdef CHECK_SENT_STATUS_CALLBACK
168         int getSentStatusCbCnt();
169 #endif
170
171 private:
172         MsgProxyListener();
173         ~MsgProxyListener();
174
175         static MsgProxyListener* pInstance;
176
177         unsigned int running;
178
179         handle_set      openHandleSet;
180
181         MsgIpcClientSocket cliSock;
182
183         MsgMutex mx;
184         MsgCndVar cv;
185
186         MsgSentStatusCBList sentStatusCBList;
187         MsgNewMessageCBList newMessageCBList;
188         MsgNewMMSConfMessageCBList newMMSConfMessageCBList;
189         MsgNewPushMessageCBList newPushMessageCBList;
190         MsgNewCBMessageCBList newCBMessageCBList;
191         MsgNewSyncMLMessageCBList newSyncMLMessageCBList;
192         MsgNewLBSMessageCBList newLBSMessageCBList;
193         MsgOperationSyncMLMessageCBList operationSyncMLMessageCBList;
194         MsgStorageChangeCBList storageChangeCBList;
195         MsgReportMessageCBList reportMessageCBList;
196
197         GIOChannel *channel;
198         guint eventSourceId;
199 };
200
201 #endif /* __MSG_PROXY_LISTENER_H__ */
202