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