Modify error code for badge API
[platform/core/appfw/badge.git] / include / badge_internal.h
1 /*
2  * Copyright (c) 2000 - 2017 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 #ifndef __BADGE_INTERNAL_DEF_H__
19 #define __BADGE_INTERNAL_DEF_H__
20
21 #include <stdbool.h>
22 #include <stdarg.h>
23 #include <glib.h>
24 #include <sys/types.h>
25
26 #include "badge_error.h"
27 #include "badge.h"
28
29 #ifndef EXPORT_API
30 #define EXPORT_API __attribute__ ((visibility("default")))
31 #endif
32
33 #ifndef DEPRECATED
34 #define DEPRECATED __attribute__((deprecated))
35 #endif
36
37 #define BADGE_ERROR (badge_error_quark())
38 GQuark badge_error_quark(void);
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif /* __cplusplus */
43
44 typedef struct _badge_h badge_h;
45
46 typedef struct badge_info {
47         char *pkg;
48         unsigned int badge_count;
49 } badge_info_s;
50
51 /**
52  * @internal
53  * @brief This function checks whether badge service is ready
54  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
55  * @privlevel public
56  * @privilege %http://tizen.org/privilege/notification
57  * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
58  * @return 1 if badge service is ready, other value if badge service isn't ready
59  * @retval BADGE_ERROR_NONE Success
60  * @retval BADGE_ERROR_SERVICE_NOT_READY Service is not ready
61  * @retval BADGE_ERROR_NOT_SUPPORTED Not supported
62  */
63 int badge_is_service_ready(void);
64
65 /**
66  * @internal
67  * @brief This function adds deferred task. the registered task will be executed when badge service become ready
68  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
69  * @privlevel public
70  * @privilege %http://tizen.org/privilege/notification
71  * @param[in] badge_add_deferred_task The callback function
72  * @param[in] user_data The user data to be passed to the callback function
73  * @return #BADGE_ERROR_NONE if success, other value if failure
74  * @retval BADGE_ERROR_NONE Success
75  * @retval BADGE_ERROR_PERMISSION_DENIED The application does not have the privilege to call this method
76  * @retval BADGE_ERROR_OUT_OF_MEMORY Out of memory
77  * @retval BADGE_ERROR_NOT_SUPPORTED Not supported
78  * @see #badge_error_e
79  * @see badge_is_service_ready()
80  */
81 int badge_add_deferred_task(
82                 void (*badge_add_deferred_task)(void *data), void *user_data);
83
84 /**
85  * @internal
86  * @brief This function removes deferred task.
87  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
88  * @privlevel public
89  * @privilege %http://tizen.org/privilege/notification
90  * @param[in] badge_add_deferred_task The callback function
91  * @return #BADGE_ERROR_NONE if success, other value if failure
92  * @retval BADGE_ERROR_NONE Success
93  * @retval BADGE_ERROR_INVALID_PARAMETER Invalid parameter
94  * @retval BADGE_ERROR_PERMISSION_DENIED The application does not have the privilege to call this method
95  * @retval BADGE_ERROR_NOT_SUPPORTED Not supported
96  * @see #badge_error_e
97  * @see badge_is_service_ready()
98  */
99 int badge_del_deferred_task(
100                 void (*badge_add_deferred_task)(void *data));
101
102 /**
103  * @internal
104  * @brief Tests if the badge for the designated application exists or not.
105  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
106  * @privlevel public
107  * @privilege %http://tizen.org/privilege/notification
108  * @param[in] app_id The name of the designated application
109  * @param[out] existing The bool value of badge existence status
110  * @return #BADGE_ERROR_NONE if success, other value if failure
111  * @retval BADGE_ERROR_NONE Success
112  * @retval BADGE_ERROR_INVALID_PARAMETER Invalid parameter
113  * @retval BADGE_ERROR_PERMISSION_DENIED The application does not have the privilege to call this method
114  * @retval BADGE_ERROR_FROM_DB Error from DB
115  * @retval BADGE_ERROR_OUT_OF_MEMORY Out of memory
116  * @retval BADGE_ERROR_NOT_EXIST Not exist
117  * @retval BADGE_ERROR_SERVICE_NOT_READY Service is not ready
118  * @retval BADGE_ERROR_NOT_SUPPORTED Not supported
119  * @see #badge_error_e
120  * @see badge_new()
121  * @see badge_remove()
122  * @par Sample code:
123  * @code
124 #include <badge.h>
125 ...
126 {
127         int err = BADGE_ERROR_NONE;
128         bool exist;
129
130         err = badge_is_existing(app_id, &exist);
131         if (err != BADGE_ERROR_NONE) {
132                 return;
133         }
134
135 }
136  * @endcode
137  */
138 int badge_is_existing(const char *app_id, bool *existing);
139
140 char *_badge_get_pkgname_by_pid(void);
141
142 int _badge_is_existing(const char *pkgname, bool *existing, uid_t uid);
143
144 int _badge_get_list(GList **badge_list, uid_t uid);
145
146 int _badge_insert(badge_h *badge, uid_t uid);
147
148 int _badge_remove(const char *caller, const char *pkgname, uid_t uid, pid_t pid);
149
150 int _badge_remove_by_pkgname(const char *pkgname, uid_t uid);
151
152 int _badge_set_count(const char *caller, const char *pkgname,
153                         unsigned int count, uid_t uid, pid_t pid);
154
155 int _badge_get_count(const char *pkgname, unsigned int *count, uid_t uid);
156
157 int _badge_set_display(const char *pkgname, unsigned int is_display, uid_t uid);
158
159 int _badge_get_display(const char *pkgname, unsigned int *is_display, uid_t uid);
160
161 int _badge_free(badge_h *badge);
162
163 badge_h *_badge_new(const char *pkgname, const char *writable_pkgs,
164                 int *err);
165
166 char *_badge_pkgs_new(int *err, const char *pkg1, ...);
167
168 void badge_changed_cb_call(unsigned int action, const char *pkgname,
169                         unsigned int count, uid_t uid);
170
171 /**
172  * @internal
173  * @brief Creates a badge for the designated package.
174  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
175  * @privlevel public
176  * @privilege %http://tizen.org/privilege/notification
177  * @details Creates new badge to display.
178  * @param[in] pkgname The name of the designated package
179  * @param[in] writable_pkg The name of package which is authorized to change the badge
180  * @return #BADGE_ERROR_NONE if success, other value if failure
181  * @retval BADGE_ERROR_NOT_SUPPORTED Not supported
182  * @see #badge_error_e
183  * @par Sample code:
184  * @code
185 #include <badge.h>
186 ...
187 {
188         int err = BADGE_ERROR_NONE;
189
190         err = badge_create("org.tizen.sms", "org.tizen.sms2");
191         if (err != BADGE_ERROR_NONE) {
192                 return;
193         }
194
195 }
196  * @endcode
197  */
198 int badge_create(const char *pkgname, const char *writable_pkg);
199
200 int badge_create_for_uid(const char *pkgname, const char *writable_pkg, uid_t uid);
201
202 int badge_new_for_uid(const char *writable_app_id, uid_t uid);
203
204 int badge_add_for_uid(const char *badge_app_id, uid_t uid);
205
206 int badge_remove_for_uid(const char *app_id, uid_t uid);
207
208 int badge_is_existing_for_uid(const char *app_id, bool *existing, uid_t uid);
209
210 int badge_foreach_for_uid(badge_foreach_cb callback, void *user_data, uid_t uid);
211
212 int badge_set_count_for_uid(const char *app_id, unsigned int count, uid_t uid);
213
214 int badge_get_count_for_uid(const char *app_id, unsigned int *count, uid_t uid);
215
216 int badge_set_display_for_uid(const char *app_id, unsigned int is_display, uid_t uid);
217
218 int badge_get_display_for_uid(const char *app_id, unsigned int *is_display, uid_t uid);
219
220 int badge_register_changed_cb_for_uid(badge_change_cb callback, void *data, uid_t uid);
221
222 int badge_unregister_changed_cb_for_uid(badge_change_cb callback, uid_t uid);
223
224
225 #ifdef __cplusplus
226 }
227 #endif /* __cplusplus */
228
229 #endif /* __BADGE_INTERNAL_DEF_H__ */
230