merge with master
[platform/framework/native/messaging.git] / src / FMsg_SmsMmsCallbackHandler.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FMsg_SmsMmsCallbackHandler.h
19  * @brief               This is the header file for _SmsMmsCallbackHandler class.
20  *
21  * This header file contains declaration of _SmsMmsCallbackHandler class
22  */
23
24 #ifndef _FMSG_INTERNAL_SMS_MMS_CALLBACK_HANDLER_H_
25 #define _FMSG_INTERNAL_SMS_MMS_CALLBACK_HANDLER_H_
26
27 // includes
28 #include <FBaseObject.h>
29 #include <FBaseColMultiHashMap.h>
30 #include "FMsg_Types.h"
31
32 namespace Tizen { namespace Messaging
33 {
34
35 /**
36 * @class        _SmsMmsCallbackHandler
37 * @brief        This class provides methods to use the SMS/MMS call back Handler service
38 * @since 2.1
39 *
40 * This class provides methods to use the SMS/MMS call back Handler service . @n
41 */
42
43 // forward declaration
44
45 class _SmsMmsCallbackHandler
46         : public Tizen::Base::Object
47 {
48 public:
49         /**
50         * This is the destructor for this class.
51         *
52         * @since 2.1
53         */
54         virtual ~_SmsMmsCallbackHandler(void);
55
56         /**
57         * Initializes the Messaging Hash Map table
58         *
59         * @since                        3.0
60         * @return       An error code
61         * @exception    E_SUCCESS                       The method was successful.
62         * @exception    E_INVALID_ARG                   Input parameter is NULL.
63         * @exception    E_OUT_OF_MEMORY                 Memory error.
64         */
65         result  Construct(void);
66
67         // Operation
68 public:
69         /**
70         * Gets the instance of SmsMmsCallbackHandler class.
71         *
72         * @since 2.1
73         * @return                       instance of SmsMmsCallbackHandler class
74         */
75         static _SmsMmsCallbackHandler* GetInstance(void);
76
77         /**
78         * gets the Message Handle for SMS/MMS operation.
79         *
80         * @since 3.0
81         * @return       An error code
82         * @param[in]    messageHandle                   message Handle
83         * @exception    MSG_SUCCESS                     The method was successful.
84         * @exception    MSG_ERR_NULL_POINTER            Input parameter is NULL.
85         * @exception    MSG_ERR_MEMORY_ERROR            Memory error.
86         */
87         int OpenMessageHandle(msg_handle_t& messageHandle);
88
89         /**
90         * gets the Message Handle for Cbs message operation.
91         *
92         * @since 3.0
93         * @return       An error code
94         * @param[in]    cbsSettingsHandle               cbs message Handle
95         * @exception    MSG_SUCCESS                     The method was successful.
96         * @exception    MSG_ERR_NULL_POINTER            Input parameter is NULL.
97         * @exception    MSG_ERR_MEMORY_ERROR            Memory error.
98         */
99         int OpenCbsSettingsHandle(msg_struct_t& cbsSettingsHandle);
100
101         // Adds a CBS channel with specified parameters.
102         result AddCbsChannel(int from, int to, Tizen::Base::String& name, bool activate);
103
104         // Removes a CBS channel with specified parameters.
105         result RemoveCbsChannel(int from, int to);
106
107         // Searches a CBS channel with specified parameters and returns index of channel found. 
108         result SearchCbsChannel(int from, int to, int& index);
109
110         // Updates a CBS channel with specified parameters.
111         result UpdateCbsChannel(int from, int to, Tizen::Base::String name, bool activate);
112
113         // Gets a CBS channel data with specified index.
114         result GetCbsChannel(int index, int& from, int& to, Tizen::Base::String& name, bool& activate);
115
116         // Gets a CBS channel count.
117         result GetCbsChannelsCount(int& count);
118
119         /**
120         * loads the Cbs channels list.
121         *
122         * @since 3.0
123         * @return       An error code
124         * @exception    E_SUCCESS                       The method was successful.
125         * @exception    E_INVALID_ARG                   Input parameter is NULL.
126         * @exception    E_OUT_OF_MEMORY                 Memory error.
127         */
128         result LoadCbsSettings();
129
130         /**
131         * saves the Cbs channels list.
132         *
133         * @since 3.0
134         * @return       An error code
135         * @exception    E_SUCCESS                       The method was successful.
136         * @exception    E_INVALID_ARG                   Input parameter is NULL.
137         * @exception    E_OUT_OF_MEMORY                 Memory error.
138         */
139         result SaveCbsSettings();
140
141         /**
142         * closes the CBS Message Handle.
143         *
144         * @since 3.0
145         * @return       An error code
146         * @exception    MSG_SUCCESS                     The method was successful.
147         * @exception    MSG_ERR_NULL_POINTER            Input parameter is NULL.
148         * @exception    MSG_ERR_MEMORY_ERROR            Memory error.
149         */
150         int CloseCbsSettingsHandle(void);
151
152         /**
153         * closes the Message Handle for SMS/MMS operation.
154         *
155         * @since 3.0
156         * @return       An error code
157         * @exception    MSG_SUCCESS                     The method was successful.
158         * @exception    MSG_ERR_NULL_POINTER            Input parameter is NULL.
159         * @exception    MSG_ERR_MEMORY_ERROR            Memory error.
160         */
161         int CloseMessageHandle(void);
162
163         /**
164         * Registers the Message call back for SMS/MMS operation.
165         *
166         * @since                        3.0
167         * @return       An error code
168         * @exception    MSG_SUCCESS                     The method was successful.
169         * @exception    MSG_ERR_NULL_POINTER            Input parameter is NULL.
170         * @exception    MSG_ERR_MEMORY_ERROR            Memory error.
171         */
172         int RegisterMessageCallback(void);
173
174         /**
175         * Adds the message requestId/Message Type/Message Event to Message Hash Map table
176         *
177         * @since                        3.0
178         * @return       An error code
179         * @param[in]    reqId                           SMS/MMS message requestId
180         * @param[in]    msgType                         message type
181         * @param[in]    pEvent                          message Event
182         * @exception    E_SUCCESS                       The method was successful.
183         * @exception    E_INVALID_ARG                   Input parameter is NULL.
184         * @exception    E_OUT_OF_MEMORY                 Memory error.
185         */
186         result AddToMessageMap(int reqId, _MessageType msgType, Tizen::Base::Object* pEvent);
187
188         /**
189         * Gets the Message Type and Message Event based on the message requestId. Also removes the Hashmap elements for the requestId
190         *
191         * @since                        3.0
192         * @return       An error code
193         * @param[in]    reqId                           SMS/MMS message requestId
194         * @param[in]    msgType                         message type
195         * @param[in]    pEvent                          message Event
196         * @exception    E_SUCCESS                       The method was successful.
197         * @exception    E_INVALID_ARG                   Input parameter is NULL.
198         * @exception    E_OUT_OF_MEMORY                 Memory error.
199         */
200         result GetAndRemoveFromMessageMap(int reqId, _MessageType& msgType, Tizen::Base::Object** pEvent);
201
202         // for SMS and MMS sent status
203         static void SentMessageStatusCallback(msg_handle_t hMsgHandle, msg_struct_t msgStatus, void* pUserParam);
204
205         // for incoming SMS
206         static void IncomingSmsMessageCallback(msg_handle_t hMsgHandle, msg_struct_t newMsg, void* pUserParam);
207
208         /**
209         * Sets the __incomingSmsCallbackRegistered flag.
210         *
211         * @since                        3.0
212         * @param[in]    incomingSmsCallbackRegistered      SMS registered flag
213         */
214         void SetInComingSmsCallback(bool incomingSmsCallbackRegistered);
215
216         /**
217         * Sets the Cbs And Etws UserEvent.
218         *
219         * @since                        3.0
220         * @param[in]    msgType     message type
221         * @param[in]    pEvent      message Event
222         */
223         void SetCbsAndEtwsUserEvent(_MessageType msgType, Tizen::Base::Object* pEvent);
224
225         // for incoming CBS/Etws
226         static void IncomingCbsMessageCallback(msg_handle_t hMsgHandle, msg_struct_t newMsg, void* pUserParam);
227
228         // for incoming Wap push
229         static void IncomingWapPushMessageCallback(msg_handle_t hMsgHandle, const char* pHeader, const char* pBody, int bodyLength, void* pUserParam);
230
231         //get cb message language type
232         static Tizen::Base::String GetCbsLanguageType(byte codingScheme);
233
234         // Life cycle
235 private:
236         /**
237         *       This is the default constructor for this class.
238         *
239         * @since 2.1
240         */
241         _SmsMmsCallbackHandler(void);
242
243         result ConvertException(int err) const;
244
245 private:
246         static _SmsMmsCallbackHandler* __pMessageCallbackHandler;
247         msg_handle_t __msgHandle;
248         msg_struct_t __cbsSettingsHandle;
249         msg_struct_list_s* __pCbsChannelList;
250         Tizen::Base::Collection::ArrayList* __pTempCbsChannelList;
251         bool   __callbackRegistered;
252         bool   __incomingSmsCallbackRegistered;
253         Tizen::Base::Collection::MultiHashMap __messageMap;
254         Tizen::Base::Runtime::Mutex  __msgMutex;
255         Tizen::Base::Object* __pCbsUserEvent;
256         Tizen::Base::Object* __pEtwsUserEvent;
257 }; // _SmsMmsCallbackHandler
258
259 } } // Tizen::Messaging
260
261 #endif // _FMSG_INTERNAL_SMS_MMS_CALLBACK_HANDLER_H_