merge with master
[platform/framework/native/messaging.git] / src / FMsg_SmsManagerImpl.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_SmsManagerImpl.h
19  * @brief       This is the header file for the _SmsManagerImpl class.
20  *
21  * This header file contains the declarations of the _SmsManagerImpl class.
22  */
23
24 #ifndef _FMSG_INTERNAL_SMS_MANAGER_IMPL_H_
25 #define _FMSG_INTERNAL_SMS_MANAGER_IMPL_H_
26
27 #include "FMsg_Types.h"
28
29 namespace Tizen { namespace Messaging
30 {
31
32 /**
33 * @class        _SmsManagerImpl
34 * @brief        This class provides methods to use the SMS messaging service.
35 * @since        1.0
36 *
37 * This class provides methods to use the SMS messaging service. @n
38 */
39
40 // forward declaration
41 class _SmsEvent;
42 class SmsManager;
43
44 class _SmsManagerImpl
45         : public Tizen::Base::Object
46 {
47         // Life cycle
48 public:
49         /**
50         *       This is the default constructor for this class.
51         */
52         _SmsManagerImpl(void);
53
54         /**
55         *       This is the destructor for this class.
56         */
57         virtual ~_SmsManagerImpl(void);
58
59 private:
60         _SmsManagerImpl(const _SmsManagerImpl& value);
61         _SmsManagerImpl& operator =(const _SmsManagerImpl& rhs);
62
63
64         // Operation
65 public:
66         /**
67         * Initializes this instance of _SmsManagerImpl with the specified listener.
68         *
69         * @return               An error code
70         * @param[in]    listener                        The listener to receive a send result asynchronously
71         * @exception    E_SUCCESS                       The method was successful.
72         */
73         result Construct(const ISmsListener& listener);
74
75         /**
76         * Adds the event listener for receiving SMS messages.
77         *
78         * @return               An error code
79         * @param[in]    port                                    A port number
80         * @param[in]    eventListener                   The listener to receive SMS messages
81         * @exception    E_SUCCESS                               The method was successful.
82         * @exception    E_OBJ_ALREADY_EXIST             The port number was already registered.
83         * @exception    E_FAILURE                               The port number was already used in other applications.
84         * @exception    E_INVALID_ARG                   The value of the specified @c port is invalid. @n
85         *                                       The port number should range from 1 to 9999 (1 <= port <= 9999).
86         * @see                  ISmsEventListener, RemoveSmsEventListener()
87         */
88         result AddSmsEventListener(int port, ISmsEventListener& eventListener);
89
90         /**
91         * Removes the event listener for receiving SMS messages.
92         *
93         * @return               An error code
94         * @param[in]    port                                    A port number
95         * @param[in]    eventListener                   The listener to receive SMS messages
96         * @exception    E_SUCCESS                               The method was successful.
97         * @exception    E_OBJ_NOT_FOUND                 The listener was not found.
98         * @exception    E_SYSTEM                                A system error occurred.
99         * @exception    E_INVALID_ARG                   The value of the specified @c port is invalid. @n
100         *                                       The port number should range from 1 to 9999 (1 <= port <= 9999).
101         * @see                  ISmsEventListener, AddSmsEventListener()
102         */
103         result RemoveSmsEventListener(int port, ISmsEventListener& eventListener);
104
105         /**
106         * Adds the event listener for receiving SMS messages.
107         *
108         * @return               An error code
109         * @param[in]    eventListener                   The listener to receive SMS messages
110         * @exception    E_SUCCESS                               The method was successful.
111         * @exception    E_OUT_OF_MEMORY                 Insufficient memory.
112         * @see                  ISmsMessageEventListener, RemoveSmsMessageEventListener()
113         */
114         result AddSmsMessageEventListener(const ISmsMessageEventListener& eventListener);
115
116         /**
117         * Removes the event listener for receiving SMS messages.
118         *
119         * @return               An error code
120         * @param[in]    eventListener                   The listener to receive SMS messages
121         * @exception    E_SUCCESS                               The method was successful.
122         * @exception    E_OBJ_NOT_FOUND                 The listener was not found.
123         * @exception    E_SYSTEM                                A system error occurred.
124         * @see                  ISmsMessageEventListener, AddSmsMessageEventListener()
125         */
126         result RemoveSmsMessageEventListener(const ISmsMessageEventListener& eventListener);
127
128         /**
129         * Sends the SMS message.
130         *
131         * @return               An error code
132         * @param[in]    message                                 The message to be sent
133         * @param[in]    recipientList                   The list of recipients
134         * @param[in]    saveToSentBox                   Set to @c true to save the message in the Sentbox, @n
135         *                                                                               else @c false
136         * @exception    E_SUCCESS                               The method was successful.
137         * @exception    E_ON_INITIALIZING               The mailbox is not completely loaded yet.
138         * @exception    E_STORAGE_FULL                  The storage is full.
139         * @exception    E_DEVICE_UNAVAILABLE    The device is unavailable.
140         * @exception    E_NETWORK_UNAVAILABLE   The network is unavailable.
141         * @exception    E_INVALID_ADDRESS               The address is invalid.
142         * @exception    E_FDN_MODE                              The FDN mode has been activated.
143         * @exception    E_INVALID_ARG                   The number of recipients is @c 0.
144         * @exception    E_MAX_EXCEEDED                  The number of recipients crossed the limit (Maximum 10).
145         * @see                  ISmsListener::OnSmsMessageSent()
146         */
147         result Send(const SmsMessage& message, const RecipientList& recipientList, bool saveToSentBox);
148
149         /**
150         * Gets the total number of SMS messages in the specified message box.
151         *
152         * @return               The total number of SMS messages in the specified message box
153         * @param[in]    type                            The type of message box
154         * @exception    E_SUCCESS                       The method was successful.
155         * @exception    E_INVALID_ARG           The value of specified @c type is invalid.
156         * @exception    E_SYSTEM                        A system error occurred.
157         * @remarks              In case of an error, this method returns the negative value (-1).
158         * @remarks              The specific error code can be accessed using the GetLastResult() method.
159         */
160         int GetTotalMessageCount(SmsMessageBoxType type) const;
161
162         /**
163         * Searches the SMS messages by keyword and|or sender address in the Inbox.
164         *
165         * @return               The list of the SmsMessage class instances
166         * @param[in]    pKeyword                        A part of the body text as a keyword (partial match) @n
167         *                                                                       In case of @c null or an empty string, this method searches all SMS messages in the Inbox regardless of the keyword.
168         * @param[in]    pSenderAddress          A telephone number as a sender address (exact match) @n
169         *                                                                       In case of @c null or an empty string, this method searches all SMS messages in the Inbox regardless of the sender address.
170         * @param[in]    startIndex                      The start index (base 0)
171         * @param[in]    count                           The count of SMS messages to search
172         * @param[out]   totalResultCount        The total count of the searched result
173         * @exception    E_SUCCESS                       The method was successful.
174         * @exception    E_INVALID_ARG           Either of the following of the conditions has occurred: @n
175         *                                   -- The specified @c pKeyword string length is less than @c 2 or greater than @c 30. @n
176         *                                   -- The specified @c pSenderAddress string length is less than @c 3 or greater than @c 41. @n
177         *                                   -- The specified @c startIndex value is less than @c o. @n
178         *                                   -- The specified @c count value is less than @c 0 or greater than @c 20.
179         * @exception    E_SYSTEM                        A system error occurred.
180         * @remarks              The specific error code can be accessed using the GetLastResult() method. @n
181         * @remarks              The search with the specified keywords searches using only the first 50 characters of the body text.
182         * @remarks              The SMS messages in the searched result contain only 160 bytes for the body text. @n
183         *               To check whether there is additional text, use the SmsMessage::HasMoreText() method. @n
184         *               To get the full body text, use GetFullText() with its message ID.
185         * @see                  SmsMessage, GetFullText()
186         */
187         Tizen::Base::Collection::IList* SearchInboxN(const Tizen::Base::String* pKeyword, const Tizen::Base::String* pSenderAddress, int startIndex, int count, int& totalResultCount) const;
188
189         /**
190         * Searches the SMS messages by keyword in the specified message box.
191         *
192         * @return               The list of the SmsMessage class instances
193         * @param[in]    type                            The type of message box
194         * @param[in]    pKeyword                        A part of the body text as a keyword (partial match) @n
195         *                                                                       In case of @c null or an empty string, this method searches all SMS messages in the specified message box.
196         * @param[in]    startIndex                      The start index (base 0)
197         * @param[in]    count                           The count of SMS messages to search
198         * @param[out]   totalResultCount        The total count of the searched result
199         * @exception    E_SUCCESS                       The method was successful.
200         * @exception    E_INVALID_ARG           Either of the following conditions has occurred: @n
201         *                                   -- The value of specified @c type is invalid. @n
202         *                                   -- The specified @c pKeyword string length is less than @c 2 or greater than @c 30. @n
203         *                                   -- The specified @c startIndex value is less than @c 0. @n
204         *                                   -- The specified @c count value is less than @c 0 or greater than @c 20.
205         * @exception    E_SYSTEM                        A system error occurred.
206         * @remarks              The specific error code can be accessed using the GetLastResult() method. @n
207         * @remarks              The search with the specified keywords searches using only the first 50 characters of the body text.
208         * @remarks              The SMS messages in the searched result contain only 160 bytes for the body text. @n
209         *               To check whether there is additional text, use the SmsMessage::HasMoreText() method. @n
210         *               To get the full body text, use the GetFullText() method with its message ID.
211         * @see                  SmsMessage, GetFullText()
212         */
213         Tizen::Base::Collection::IList* SearchMessageBoxN(SmsMessageBoxType type, const Tizen::Base::String* pKeyword, int startIndex, int count, int& totalResultCount) const;
214
215         /**
216         * Gets the full text of the SMS message in the message box using the message ID.
217         *
218         * @return               The full text of the specified SMS message
219         * @param[in]    messageId                       The unique ID of the message
220         * @exception    E_SUCCESS                       The method was successful.
221         * @exception    E_INVALID_ARG           The value of the specified @c messageId is invalid, or @c messageId should be greater than or equal to @c 0.
222         * @exception    E_OBJ_NOT_FOUND         The SMS message with the specified @c messageId was not found.
223         * @exception    E_SYSTEM                        A system error occurred.
224         * @remarks              The specific error code can be accessed using the GetLastResult() method.
225         * @remarks              In case of an error, this method returns an empty string.
226         * @see                  SmsMessage::HasMoreText()
227         */
228         Tizen::Base::String GetFullText(int messageId) const;
229
230         /**
231         * Sets the event listener for receiving CB messages.
232         *
233         * @return               An error code
234         * @param[in]    pListener                       The listener to receive CB messages
235         * @exception    E_SUCCESS                       The method is successful.
236         * @exception    E_SYSTEM                        A system error has occurred.
237         * @see                  ICbsMessageEventListener
238         */
239         result SetCbsMessageEventListener(ICbsMessageEventListener* pListener);
240
241         /**
242         * Sets the event listener for receiving ETWS primary notification.
243         *
244         * @return               An error code
245         * @param[in]    pListener                       The listener to receive ETWS primary notification
246         * @exception    E_SUCCESS                       The method is successful.
247         * @exception    E_SYSTEM                        A system error has occurred.
248         * @see                  IEtwsPrimaryNotificationEventListener
249         */
250         result SetEtwsPrimaryNotificationEventListener(IEtwsPrimaryNotificationEventListener* pListener);
251
252         /**
253         * Enables or disables the save option for CBS message to the CbsBox
254         *
255         * @return               An error code
256         * @param[in]    enable                          Set to @c true to save the message in the CbsBox, @n
257         *                                                                       else @c false
258         * @exception    E_SUCCESS                       The method is successful.
259         * @exception    E_SYSTEM                        A system error has occurred.
260         */
261         result SetSavingToCbsBoxEnabled(bool enable);
262
263         /**
264         * Checks whether the CB service is enabled.
265         *
266         * @return               @c true if the CB service is enabled, @n
267         *                               else @c false
268         * @see                  SetCbsEnabled()
269         */
270         bool IsCbsEnabled(void) const;
271
272         /**
273         * Enables or disables the CB service.
274         *
275         * @return               An error code
276         * @param[in]    enable                                  Set to @c true to enable the CB service, @n
277         *                                                                               else @c false
278         * @exception    E_SUCCESS               The method is successful.
279         * @exception    E_SYSTEM                A system error has occurred.
280         * @see                  IsCbsEnabled()
281         */
282         result SetCbsEnabled(bool enable);
283
284         /**
285         * Adds a CBS channel with specified parameters.
286         *
287         * @return               An error code
288         * @param[in]    from                                    The starting index of the message ID of the channel.
289         * @param[in]    to                                              The last index of the message ID of the channel.
290         * @param[in]    name                                    The name of the channel. (can be an empty string)
291         * @param[in]    activate                                Set to @c true to activate the channel, @n
292         *                                                                               else @c false.
293         * @exception    E_SUCCESS                               The method is successful.
294         * @exception    E_INVALID_ARG                   The specified @c to parameter is smaller than @c from. @n
295         *                                                                               The specified @c to or @c from parameter is a negative value. @n
296         *                                                                               The specified @c to parameter exceeds the limit (0xFFFF). @n
297         *                                                                               The range (@c to - @c from) exceeds the limit (0xFFFF).
298         *                                                                               The specified @c name string length is greater than @c 32. @n
299         * @exception    E_ALREADY_SET                   The channel range (@c from ~ @c to) is already set.
300         * @exception    E_ILLEGAL_ACCESS                The application does not have the permission to add the CBS channel.
301         * @exception    E_SYSTEM                                A system error has occurred.
302         * @see                  RemoveCbsChannel()
303         */
304         result AddCbsChannel(int from, int to, Tizen::Base::String& name, bool activate = true);
305
306         /**
307         * Removes a CBS channel.
308         *
309         * @return               An error code
310         * @param[in]    from                                    The starting index of the message ID of the channel.
311         * @param[in]    to                                              The last index of the message ID of the channel.
312         * @exception    E_SUCCESS                               The method is successful.
313         * @exception    E_INVALID_ARG                   The specified @c to parameter is smaller than @c from. @n
314         *                                                                               The specified @c to or @c from parameter is a negative value. @n
315         *                                                                               The specified @c to parameter exceeds the limit (0xFFFF). @n
316         *                                                                               The range (@c to - @c from) exceeds the limit (0xFFFF).
317         * @exception    E_OBJ_NOT_FOUND                 The channel range (@c from ~ @c to) is not found.
318         * @exception    E_ILLEGAL_ACCESS                The application does not have the permission to remove the CBS channel.
319         * @exception    E_SYSTEM                                A system error has occurred.
320         * @see                  AddCbsChannel()
321         */
322         result RemoveCbsChannel(int from, int to);
323
324         /**
325         * Gets a CBS channel with specified range.
326         *
327         * @return               A pointer to the CBS channel with specific range.
328         * @param[in]    from                                    The starting index of the message ID of the channel.
329         * @param[in]    to                                              The last index of the message ID of the channel.
330         * @exception    E_SUCCESS                               The method is successful.
331         * @exception    E_INVALID_ARG                   The specified @c to parameter is smaller than @c from. @n
332         *                                                                               The specified @c to or @c from parameter is a negative value. @n
333         *                                                                               The specified @c to parameter exceeds the limit (0xFFFF). @n
334         *                                                                               The range (@c to - @c from) exceeds the limit (0xFFFF).
335         * @exception    E_SYSTEM                                A system error has occurred.
336         * @remarks              The specific error code can be accessed using the GetLastResult() method.
337         * @see                  AddCbsChannel(), RemoveCbsChannel()
338         */
339         CbsChannel* GetCbsChannelN(int from, int to) const;
340
341         /**
342         * Gets the CBS channel list.
343         *
344         * @return               A pointer to the list of CBS channel
345         * @exception    E_SUCCESS                               The method is successful.
346         * @exception    E_SYSTEM                                A system error has occurred.
347         * @remarks              The specific error code can be accessed using the GetLastResult() method.
348         * @see                  AddCbsChannel(), RemoveCbsChannel(), CbsChannel
349         */
350         Tizen::Base::Collection::IList* GetCbsChannelListN(void);
351
352 public:
353     /**
354      * Gets the Impl instance.
355      *
356      * @return          The pointer to _SmsManagerImpl
357      * @param[in]       smsManager              An instance of SmsManager
358      */
359         static _SmsManagerImpl* GetInstance(SmsManager& smsManager);
360
361     /**
362      * Gets the Impl instance.
363      *
364      * @return          The pointer to _SmsManagerImpl
365      * @param[in]       smsManager              An instance of SmsManager
366      */
367         static const _SmsManagerImpl* GetInstance(const SmsManager& smsManager);
368
369         // utility
370 private:
371         result ConvertException(int err) const;
372
373 private:
374         bool __isConstructed;
375         bool __isCbsSaveEnabled;
376         std::unique_ptr<_SmsEvent> __pSmsEvent;
377         _SmsEvent* __pSmsReceiveEvent;
378         _SmsEvent* __pCbsReceiveEvent;
379         _SmsEvent* __pEtwsReceiveEvent;
380         Tizen::Base::Collection::ArrayList* __pSmsTriggerEventList;
381         msg_handle_t __msgHandle;
382         msg_struct_t __cbsSettingsHandle;
383         ICbsMessageEventListener* __pCbsListener;
384         IEtwsPrimaryNotificationEventListener* __pEtwsListener;
385 }; // _SmsManagerImpl
386 } } // Tizen::Messaging
387
388 #endif // _FMSG_INTERNAL_SMS_MANAGER_IMPL_H_