[PushService] Update daemon & library to 2.4 version
[platform/core/appfw/sppc.git] / include / pushlog.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 /*
18  * pushlog.h
19  *
20  *  Created on: Dec 17, 2012
21  *      Author: sampath
22  */
23
24 #ifndef PUSHLOG_H_
25 #define PUSHLOG_H_
26
27
28 #include <errno.h>
29 #include <app.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /**
36  * @brief Enumerations of error codes for push log service
37  */
38
39 typedef enum
40 {
41         PUSHLOG_ERROR_NONE = 1000,
42
43         // Server reply error code. This should be synchronized with local_msg.h
44         PUSHLOG_ERROR_SUCCESS=1000,
45         PUSHLOG_ERROR_SUCCESS_AND_NO_UPDATE=1010,       //this is not neccessary in client side. this rc will be replaced to 1000
46         PUSHLOG_ERROR_WRONG_REQUEST_FORMAT=2001,
47         PUSHLOG_ERROR_BLOCKED_DEVICE_TOKEN=2002,
48         PUSHLOG_ERROR_TOO_LONG_REQUEST_MSG=2003,
49         PUSHLOG_ERROR_EXCEEDED_DAILY_QUOTA=2004,
50         PUSHLOG_ERROR_FAIL_TO_AUTHENTICATE = 3001,
51
52         PUSHLOG_ERROR_WRONG_APP_ID = 4010,
53         PUSHLOG_ERROR_EMPTY_SERVICE = 4013,
54         PUSHLOG_ERROR_EMPTY_MESSAGES = 4014,
55
56         PUSHLOG_ERROR_NETWORK_NOT_AVAILABLE = -2,
57         PUSHLOG_ERROR_INVALID_REQUEST = -200,
58         PUSHLOG_ERROR_LOG_SIZE_OVER = -202,
59         PUSHLOG_ERROR_INVALID_LOG_STATUS = -204,
60         PUSHLOG_ERROR_ALREADY_REQUESTED = -205,
61         PUSHLOG_ERROR_LOGGING_FAIL = -206,
62         PUSHLOG_ERROR_REQUEST_TURN_OVER = -207,
63         PUSHLOG_ERROR_LOG_NOT_ACTIVATION = -208,
64
65         PUSHLOG_ERROR_INVALID_PARAMETER = -1000,
66         PUSHLOG_ERROR_OUT_OF_MEMORY,
67         PUSHLOG_ERROR_OPERATION_FAILED,
68         PUSHLOG_ERROR_CONNECT_FAIL,
69         PUSHLOG_ERROR_INTERNAL_SERVER_ERROR=8002,
70         PUSHLOG_ERROR_PANIC=9999
71 } pushlog_error_e;
72
73
74 /**
75  * @brief Enumerations of registration state
76  */
77 typedef enum {
78         PUSHLOG_STATE_CONNECTED,   /**< Connected to SPPCD */
79         PUSHLOG_STATE_DISCONNECTED, /**< Disconnected from SPPCD */
80         PUSHLOG_STATE_READY,
81         PUSHLOG_STATE_ERROR,       /**< Error */
82 } pushlog_state_e;
83
84
85 /**
86  * @brief Push log service handle
87  */
88 typedef struct pushlog_connection_s *pushlog_connection_h;
89
90
91 /**
92  * @brief Push log data handle
93  */
94 typedef void *pushlog_data;
95
96 /**
97  * @brief Notification callback for logging service status
98  * @param[in] log_req_type status of logging service
99  * @param[in] result error code if any.
100  * PUSHLOG_ERROR_NONE indicates success.
101  * @param[in] user_data User data set with pushlog_connect()
102  * @see pushlog_connect()
103  */
104 typedef void (*pushlog_state_cb)(
105                 pushlog_state_e state, pushlog_error_e err,
106                 void *user_data);
107
108 /**
109  * @brief Notification callback invoked for pushlog_send_data() api response
110  * @param[in] log_id log id set while sending the data
111  * @param[in] result  error code if any.
112  * PUSHLOG_ERROR_NONE indicates success.
113  * @param[in] user_data User data set with pushlog_connect()
114  * @see pushlog_connect()
115  */
116 typedef void (*pushlog_send_cb)(
117                 const char *log_id, pushlog_error_e err,
118                 void *user_data);
119
120 /**
121  * @brief Connects to the push log service and sets callback functions
122  * @remarks The status of connection between an application and the push log service,
123  * is indicated with the callback push_log_status_cb.
124  * Connection should be freed with @ref pushlog_disconnect() by you.
125  * @param[in] status_cb connection status callback
126  * @param[in] send_cb callback to receive pushlog_send_data() response
127  * @param[in] user_data User data to pass to <I>state_cb</I> and <I>notify_cb</I>
128  * @param[in] service A @ref Service handle to launch an application by
129  * an posted UI notification
130  * @param[out] log_h  Handle of a connection to the push log service
131  * @return PUSHLOG_ERROR_NONE on success, otherwise a indicated by push_log_error_e.
132  * @see push_disconnect()
133  */
134 pushlog_error_e pushlog_connect(const char *service_name,
135                 pushlog_state_cb status_cb,
136                 pushlog_send_cb send_cb,
137                 void *cb_data, app_control_h service,
138                 pushlog_connection_h *log_h);
139
140 /**
141  * @brief Disconnect push log service
142  * @remarks If there is a connection between an application and the push service,
143  * the notify callback passes the notification upon its arrival.
144  * Otherwise, the push service posts a UI notification to alert users.
145  * Connection should be freed with @ref push_disconnect() by you.
146  * @param[in] log_h  Handle of a connection to the push log service
147  * @return PUSHLOG_ERROR_NONE on success, otherwise a indicated by push_log_error_e.
148  * @see pushlog_connect()
149  */
150 pushlog_error_e pushlog_disconnect(pushlog_connection_h log_h);
151
152 /**
153  * @brief Send log data to server
154  * @remarks
155  * @param[in] log_h  Handle of a connection to the push log service
156  * @param[in] log_prefix Data setting for prefix of log.
157  * @param[in] log_id log id
158  * @param[in] data_h Data to be sent
159  * @return PUSHLOG_ERROR_NONE on success, otherwise a indicated by push_log_error_e.
160  */
161 pushlog_error_e pushlog_send(pushlog_connection_h log_h,
162                 const char *log_prefix,
163                 const char *log_id, pushlog_data data_h);
164
165
166 /**
167  * @brief Get push log service's configurations
168  * @remarks
169  * @param[in] log_h Handle of a connection to the push log service
170  * @param[in] item_size
171  * @param[out] unlimited_sending
172  * @return PUSHLOG_ERROR_NONE on success, otherwise a indicated by push_log_error_e.
173  */
174 pushlog_error_e pushlog_get_config(pushlog_connection_h log_h,
175                 int *item_size, bool *unlimited_sending);
176
177 /**
178  * @brief
179  * @remarks
180  * @param[in] log_h Handle of a connection to the push log service
181  * @param[in] state
182  * @return PUSHLOG_ERROR_NONE on success, otherwise a indicated by push_log_error_e.
183  */
184 pushlog_error_e pushlog_get_state(pushlog_connection_h log_h,
185                                 pushlog_state_e *state);
186
187 /**
188  * @brief
189  * @remarks
190  * @param[in] data
191  * @return PUSHLOG_ERROR_NONE on success, otherwise a indicated by push_log_error_e.
192  */
193 pushlog_error_e pushlog_create_data(pushlog_data *data);
194
195 /**
196  * @brief
197  * @remarks
198  * @param[in] data
199  * @param[in] value
200  * @param[in] len
201  * @return PUSHLOG_ERROR_NONE on success, otherwise a indicated by push_log_error_e.
202  */
203 pushlog_error_e pushlog_add_data(pushlog_data data, char *value, int len);
204
205 /**
206  * @brief
207  * @remarks
208  * @param[in] data
209  * @return PUSHLOG_ERROR_NONE on success, otherwise a indicated by push_log_error_e.
210  */
211 pushlog_error_e pushlog_free_data(pushlog_data data);
212
213
214 #ifdef __cplusplus
215 }
216 #endif
217
218 #endif /* PUSHLOG_H_ */