fixed condition for proper comparing spp_app_id
[platform/core/appfw/sppc.git] / include / push.h
1 /*
2  * Copyright (c) 2000 - 2012 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 __PUSH_LIB_H__
18 #define __PUSH_LIB_H__
19
20 #include <app.h>
21 #include <tizen_error.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /**
28  * @file push.h
29  */
30
31 /**
32  * @internal
33  * @addtogroup CAPI_MESSAGING_PUSH_MODULE
34  * @{
35  */
36
37 /**
38  * @brief Enumeration of error codes for push API.
39  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
40  */
41 typedef enum {
42         PUSH_ERROR_NONE = TIZEN_ERROR_NONE,   /**< Successful */
43         PUSH_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,   /**< Out of memory */
44         PUSH_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,   /**< Invalid parameter */
45         PUSH_ERROR_NOT_CONNECTED = TIZEN_ERROR_CONNECTION,  /**< Not connected */
46         PUSH_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA,  /**< No data available */
47         PUSH_ERROR_OPERATION_FAILED = TIZEN_ERROR_UNKNOWN, /**< Internal operation failed */
48         PUSH_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< No privilege to access the push service */
49         PUSH_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Push not supported */
50 } push_error_e;
51
52 /**
53  * @brief Enumeration of registration states.
54  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
55  */
56 typedef enum {
57         PUSH_STATE_REGISTERED,   /**< Registered */
58         PUSH_STATE_UNREGISTERED, /**< Unregistered */
59         PUSH_STATE_PROVISIONING_IPCHANGE, /**< To change the provisioning server IP */
60         PUSH_STATE_PING_CHANGE,       /**< Ping interval is changing */
61         PUSH_STATE_ERROR,       /**< Error */
62 } push_state_e;
63
64 /**
65  * @brief Enumeration of result.
66  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
67  */
68 typedef enum {
69         PUSH_RESULT_SUCCESS,  /**< Successful */
70         PUSH_RESULT_TIMEOUT,  /**< Request timed out */
71         PUSH_RESULT_SERVER_ERROR,  /**< Push server error */
72         PUSH_RESULT_SYSTEM_ERROR,  /**< System error */
73 } push_result_e;
74
75 /**
76  * @brief Connection to the push service handle.
77  */
78 typedef struct push_connection_s *push_connection_h;
79
80 /**
81  * @brief Notification delivered from the push server handle.
82  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
83  */
84 typedef struct push_notification_s *push_notification_h;
85
86 /**
87  * @brief Called when the registration state is refreshed.
88  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
89  * @remarks This callback will be invoked when the registration state is refreshed. \n
90  *          If the registration or deregistration has succeeded, then this state callback must be called. \n
91  *          In addition, the state can be changed if the push server deregisters the application.
92  * @param[in] state The registration state
93  * @param[in] err  The error message
94  * @param[in] user_data The user data passed to this callback
95  * @see push_connect()
96  */
97 typedef void (*push_state_cb)(
98                 push_state_e state, const char *err, void *user_data);
99
100 /**
101  * @brief Called to handle a notification.
102  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
103  * @param[in] notification A handle of the notification containing its payload \n
104  *                         The handle is available inside this callback only.
105  * @param[in] user_data The user data passed to this callback
106  * @see push_connect()
107  * @see push_get_notification_data()
108  */
109 typedef void (*push_notify_cb)(
110                 push_notification_h noti, void *user_data);
111
112 /**
113  * @brief Called with the result of a registration/deregistration.
114  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
115  * @param[in] result The registration/deregistration result
116  * @param[in] msg The result message from the push server,
117  *                otherwise @c NULL
118  * @param[in] user_data The user data passed to this callback
119  * @see push_register()
120  * @see push_deregister()
121  */
122 typedef void (*push_result_cb)(push_result_e result, const char *msg, void *user_data);
123
124 /**
125  * @brief Connects to the push service and sets callback functions.
126  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
127  * @privlevel public
128  * @privilege %http://tizen.org/privilege/push
129  * @remarks If there is a connection between an application and the push service,
130  *          the notify callback passes the notification upon its arrival.\n
131  *          Otherwise, the push service posts a UI notification to alert users.\n
132  *          The connection should be freed using push_disconnect().
133  * @param[in] app_id The application ID
134  * @param[in] state_cb The state callback function
135  * @param[in] notify_cb The notify callback function
136  * @param[in] user_data The user data to pass to @a state_cb and @a notify_cb
137  * @param[out] connection The connection handle to the push service
138  * @return @c 0 on success,
139  *         otherwise a negative error value
140  * @retval #PUSH_ERROR_NONE Successful
141  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
142  * @retval #PUSH_ERROR_OUT_OF_MEMORY Out of memory
143  * @retval #PUSH_ERROR_NOT_CONNECTED Connection to the daemon failed
144  * @retval #PUSH_ERROR_PERMISSION_DENIED No push privilege
145  * @pre There is no connection for the @a app_id to the push service.
146  * @post The state callback will be called to let you know the current
147  *       registration state immediately.
148  * @see push_disconnect()
149  */
150 int push_connect(const char *push_app_id, push_state_cb state_callback,
151                 push_notify_cb notify_callback, void *user_data,
152                 push_connection_h *connection);
153
154 /**
155  * @brief Closes the connection and releases all its resources.
156  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
157  * @privlevel public
158  * @remarks If you call this function in the push callback functions,
159  *          it may cause your application to crash.
160  * @param[in] connection A connection to the push service handle
161  * @see push_connect()
162  */
163 void push_disconnect(push_connection_h connection);
164
165 /**
166  * @brief Registers an application to the push server.
167  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
168  * @privlevel public
169  * @param[in] connection The connection handle to the push service
170  * @param[in] app_control An @ref CAPI_APP_CONTROL_MODULE handle to launch an application by\n
171  * an posted UI notification
172  * @param[in] result_callback  Result callback function
173  * @param[in] user_data  The user data to pass to @a result_cb
174  * @return @c 0 on success,
175  *         otherwise a negative error value
176  * @retval #PUSH_ERROR_NONE Successful
177  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
178  * @retval #PUSH_ERROR_OUT_OF_MEMORY Out of memory
179  * @retval #PUSH_ERROR_NOT_CONNECTED No connection to the push service
180  * @retval #PUSH_ERROR_OPERATION_FAILED Operation failed
181  * @pre The application should be connected to the push service.
182  * @post For successful result, the state callback should be invoked.
183  * @see push_deregister()
184  */
185 int push_register(push_connection_h connection, app_control_h app_control,
186                 push_result_cb result_callback, void *user_data);
187
188 /**
189  * @brief Deregisters an application from the Push server.
190  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
191  * @privlevel public
192  * @param[in] connection The connection handle to the push service
193  * @param[in] result_callback Result callback function
194  * @param[in] user_data The user data to pass to @a result_cb
195  * @return @c 0 on success,
196  *         otherwise a negative error value
197  * @retval #PUSH_ERROR_NONE Successful
198  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
199  * @retval #PUSH_ERROR_OUT_OF_MEMORY Out of memory
200  * @retval #PUSH_ERROR_NOT_CONNECTED No connection to the push service
201  * @retval #PUSH_ERROR_OPERATION_FAILED Operation failed
202  * @pre The application should be connected to the push service.
203  * @post As a result, the state callback will be invoked.
204  * @see push_register()
205  */
206 int push_deregister(push_connection_h connection, push_result_cb result_callback,
207                 void *user_data);
208
209 /**
210  * @brief Registers an daemon dbus call information.
211  * @since_tizen @if TV 2.4 @endif
212  * @privlevel platform
213  * @param[in] connection The connection handle to the push service
214  * @param[in] result_callback  Result callback function
215  * @param[in] dbus_bus_name  The string of dbus bus name to be called
216  * @param[in] dbus_object_path  The string of dbus object path name to be called
217  * @param[in] dbus_interface_name  The string of dbus interface name to be called
218  * @param[in] dbus_method_name  The string of dbus method name to be called
219  * @param[in] user_data  The user data to pass to @a result_cb
220  * @return @c 0 on success,
221  *         otherwise a negative error value
222  * @retval #PUSH_ERROR_NONE Successful
223  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
224  * @retval #PUSH_ERROR_OUT_OF_MEMORY Out of memory
225  * @retval #PUSH_ERROR_NOT_CONNECTED No connection to the push service
226  * @retval #PUSH_ERROR_OPERATION_FAILED Operation failed
227  * @pre The application should be registered to the push service.
228  * @post For successful result, you must clear dbus call infomaion with push_deregister_dbus_call_info
229  *         before deregister your daemon service.
230  * @see push_deregister() and push_register_dbus_call_info
231  */
232 int push_register_dbus_call_info(struct push_connection_s *conn, push_result_cb cb,
233                 const char *dbus_bus_name, const char *dbus_object_path, const char *dbus_interface_name,
234                 const char *dbus_method_name, void *user_data);
235
236 /**
237  * @brief Deregisters an daemon dbus call information.
238  * @since_tizen @if TV 2.4 @endif
239  * @privlevel platform
240  * @param[in] connection The connection handle to the push service
241  * @param[in] result_callback  Result callback function
242  * @param[in] user_data  The user data to pass to @a result_cb
243  * @return @c 0 on success,
244  *         otherwise a negative error value
245  * @retval #PUSH_ERROR_NONE Successful
246  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
247  * @retval #PUSH_ERROR_OUT_OF_MEMORY Out of memory
248  * @retval #PUSH_ERROR_NOT_CONNECTED No connection to the push service
249  * @retval #PUSH_ERROR_OPERATION_FAILED Operation failed
250  * @pre The application should be connected to the push service, and dbus call info was registerd.
251  * @post For successful result, no more push dbus call activated.
252  * @see push_register() and push_register_dbus_call_info
253  */
254 int push_deregister_dbus_call_info(struct push_connection_s *conn, push_result_cb cb, void *user_data);
255
256 /**
257  * @brief Gets the payload data in the notification.
258  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
259  * @privlevel public
260  * @remarks You must release @a data using free().
261  * @param[in] notification The notification handle
262  * @param[out] data The notification data\n
263  *                  Set @c NULL if error but #PUSH_ERROR_INVALID_PARAMETER
264  * @return @c 0 on success,
265  *         otherwise a negative error value
266  * @retval #PUSH_ERROR_NONE Successful
267  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
268  * @retval #PUSH_ERROR_OUT_OF_MEMORY Out of memory
269  * @retval #PUSH_ERROR_NO_DATA No data available
270  * @see push_notify_cb()
271  * @see push_request_unread_notification()
272  */
273 int push_get_notification_data(push_notification_h notification, char **data);
274
275 /**
276  * @brief Gets the message in the notification.
277  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
278  * @privlevel public
279  * @remarks You must release @a msg using free().
280  * @param[in] notification The notification handle
281  * @param[out] msg The notification message\n
282  *                  Set @c NULL if error but #PUSH_ERROR_INVALID_PARAMETER
283  * @return @c 0 on success,
284  *         otherwise a negative error value
285  * @retval #PUSH_ERROR_NONE Successful
286  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
287  * @retval #PUSH_ERROR_OUT_OF_MEMORY Out of memory
288  * @retval #PUSH_ERROR_NO_DATA No data available
289  * @see push_notify_cb()
290  * @see push_request_unread_notification()
291  */
292 int push_get_notification_message(push_notification_h notification,
293                 char **msg);
294
295 /**
296  * @brief Gets the received time of the notification.
297  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
298  * @privlevel public
299  * @param[in] notification The notification handle
300  * @param[out] timestamp The timestamp information that the application server
301  *                                              optinally added to this notification when sending it.
302  *                                              Typically, it is the number of milliseconds from a given
303  *                                              standard time in the server.
304  * @return @c 0 on success,
305  *         otherwise a negative error value
306  * @retval #PUSH_ERROR_NONE Successful
307  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
308  * @retval #PUSH_ERROR_NO_DATA No data available
309  *
310  * @see push_notify_cb()
311  * @see push_request_unread_notification()
312  */
313 int push_get_notification_time(push_notification_h notification, long long int *timestamp);
314
315 /**
316  * @brief Gets the sender of the notification.
317  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
318  * @privlevel public
319  * @remarks You must release @a sender using free().
320  * @param[in] notification The notification handle
321  * @param[out] sender The sender\n
322  *                  Set @c NULL if error but #PUSH_ERROR_INVALID_PARAMETER
323  * @return @c 0 on success,
324  *         otherwise a negative error value
325  * @retval #PUSH_ERROR_NONE Successful
326  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
327  * @retval #PUSH_ERROR_OUT_OF_MEMORY Out of memory
328  * @retval #PUSH_ERROR_NO_DATA No data available
329  * @see push_notify_cb()
330  * @see push_request_unread_notification()
331  */
332 int push_get_notification_sender(push_notification_h notification,
333                 char **sender);
334
335 /**
336  * @brief Gets the session ID of the notification.
337  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
338  * @privlevel public
339  * @remarks You must release @a session_info using free().
340  * @param[in] notification The notification handle
341  * @param[out] session_info The session ID\n
342  *                  Set @c NULL if error but #PUSH_ERROR_INVALID_PARAMETER
343  * @return @c 0 on success,
344  *         otherwise a negative error value
345  * @retval #PUSH_ERROR_NONE Successful
346  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
347  * @retval #PUSH_ERROR_OUT_OF_MEMORY Out of memory
348  * @retval #PUSH_ERROR_NO_DATA No data available
349  * @see push_notify_cb()
350  * @see push_request_unread_notification()
351  */
352 int push_get_notification_session_info(push_notification_h notification,
353                 char **session_info);
354
355
356 /**
357  * @brief Gets the request ID assigned by the sender.
358  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
359  * @privlevel public
360  * @remarks You must release @a request_id using free().
361  * @param[in] notification The notification handle
362  * @param[out] request_id The request ID\n
363  *                  Set @c NULL if error but #PUSH_ERROR_INVALID_PARAMETER
364  * @return @c 0 on success,
365  *         otherwise a negative error value
366  * @retval #PUSH_ERROR_NONE Successful
367  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
368  * @retval #PUSH_ERROR_OUT_OF_MEMORY Out of memory
369  * @retval #PUSH_ERROR_NO_DATA No data available
370  * @see push_notify_cb()
371  * @see push_request_unread_notification()
372  */
373 int push_get_notification_request_id(push_notification_h notification,
374                 char **request_id);
375
376 /**
377  * @brief Gets the value in the type field of the notification
378  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
379  * @privlevel public
380  * @param[in] notification The notification handle
381  * @param[out] type The type value assigned by the sender
382  * @return @c 0 on success,
383  *         otherwise a negative error value
384  * @retval #PUSH_ERROR_NONE Successful
385  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
386  * @retval #PUSH_ERROR_NO_DATA No data available
387  * @see push_notify_cb()
388  * @see push_request_unread_notification()
389  */
390 int push_get_notification_type(push_notification_h notification, int *type);
391
392 /**
393  * @brief Gets an unread notification message from the push server.
394  *
395  * @details If an application receives an unread message with this method, the message is removed from the system.\n
396  *          This method can be called repeatedly until it returns #PUSH_ERROR_NO_DATA.\n
397  *          However, this method does NOT guarantee order and reliability of notification messages.\n
398  *          Some notification messages can be dropped when the system message queue is full.
399  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
400  * @privlevel public
401  * @remarks This method will be deprecated.
402  * @remarks You must release @a noti using push_free_notification().
403  *                      push_request_unread_notification() is preferred to this API.
404  * @param[in] connection The connection handle to the push service
405  * @param[out] noti The notification handle
406  * @return @c 0 on success,
407  *         otherwise a negative error value
408  * @retval #PUSH_ERROR_NONE Successful
409  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
410  * @retval #PUSH_ERROR_OUT_OF_MEMORY Out of memory
411  * @retval #PUSH_ERROR_NO_DATA No data available
412  *
413  * @see push_get_notification_message()
414  * @see push_get_notification_time()
415  * @see push_get_notification_data()
416  */
417 int push_get_unread_notification(push_connection_h connection,
418                 push_notification_h *noti);
419
420 /**
421  * @brief Requests unread notification messages to the push server.
422  * @details When the app wants to receive messages that arrived before it launced, this  \n
423  *          method should be called. Upon receiving ths request, the daemon sends messages\n
424  *          stored in its DB to the app. The notify_callback() method assigned in push_connect()\n
425  *          will be called when these messages arrive. No need to call this method multiple\n
426  *          times to receive multiple messages. This method does NOT guarantee order and\n
427  *          reliability of notification messages.
428  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
429  * @privlevel public
430  * @remark This method is preferred to push_get_unread_notification().
431  * @param[in] connection The connection handle to the push service
432  * @return @c 0 on success,
433  *         otherwise a negative error value
434  * @retval #PUSH_ERROR_NONE Successful
435  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
436  * @retval #PUSH_ERROR_NOT_CONNECTED Not connected to the daemon
437  * @retval #PUSH_ERROR_OPERATION_FAILED Error when sending the request
438  *
439  * @see push_get_unread_notification()
440  * @see push_connect()
441  */
442 int push_request_unread_notification(push_connection_h connection);
443
444 /**
445  * @brief Retrieves the notification with the notification token
446  * @details When the push service forcibly launches the application to\n
447                         deliver a notification, a unique token for the notification\n
448                         is generated and delivered to the application as a bundle.\n
449                         Using this API with this token, the application can get\n
450                         the notification.
451  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
452  * @privlevel public
453  * @privilege %http://tizen.org/privilege/push
454  * @remark This function must be called in the app control callback function.\n
455  *                 You must release the notification using push_free_notification().
456  * @param[in] noti_token The notification token received from the bundle
457  * @param[out] noti     The handle for the notification that launched this app
458  * @return @c 0 on success,
459  *         otherwise a negative error value
460  * @retval #PUSH_SERVICE_ERROR_NONE Successful
461  * @retval #PUSH_SERVICE_ERROR_INVALID_PARAMETER Invalid parameter
462  * @retval #PUSH_SERVICE_ERROR_NO_DATA  No notification for this token
463  * @retval #PUSH_SERVICE_ERROR_OPERATION_FAILED Operation fail
464  * @retval #PUSH_SERVICE_ERROR_OUT_OF_MEMORY Out of memory
465  * @retval #PUSH_SERVICE_ERROR_NOT_CONNECTED Connection to the daemon failed
466  * @retval #PUSH_SERVICE_ERROR_PERMISSION_DENIED No push privilege
467  * @see push_free_notification()
468  * @see app_control_get_operation()
469  */
470 int push_get_notification_using_token(const char *noti_token, push_notification_h *noti);
471
472
473 /**
474  * @brief Gets the registration ID in the @a #PUSH_STATE_REGISTERED state.
475  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
476  * @privlevel public
477  * @remarks You must release @a reg_id using free().
478  * @param[in] connection The connection handle to the push service
479  * @param[out] reg_id The registration ID
480  *                    Set @c NULL if error but #PUSH_ERROR_INVALID_PARAMETER
481  * @return @c 0 on success,
482  *         otherwise a negative error value
483  * @retval #PUSH_ERROR_NONE Successful
484  * @retval #PUSH_ERROR_INVALID_PARAMETER Invalid parameter
485  * @retval #PUSH_ERROR_OUT_OF_MEMORY Out of memory
486  * @retval #PUSH_ERROR_NO_DATA No registration ID available
487  */
488 int push_get_registration_id(push_connection_h connection, char **reg_id);
489
490
491 /**
492  * @brief Frees the notification handle.
493  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
494  * @privlevel public
495  * @privilege %http://tizen.org/privilege/push
496  * @param[in] noti The notification handle
497  */
498 void push_free_notification(push_notification_h noti);
499
500 /**
501  * @}
502  */
503
504 #ifdef __cplusplus
505 }
506 #endif
507
508 #endif /* __PUSH_LIB_H__ */