ad38464f48400cfc3a14c2621a0e15e5d23a7e94
[platform/core/appfw/librua.git] / include / rua.h
1 /*
2  * Copyright (c) 2000 - 2016 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  * @file        rua.h
19  * @brief       RUA API declaration header file.
20  * @author      Jinwoo Nam (jwoo.nam@samsung.com)
21  * @version     0.1
22  * @history     0.1: RUA API Declarations, structure declaration
23  */
24
25 #ifndef __RUA_H__
26 #define __RUA_H__
27
28 #include <sqlite3.h>
29 #include <bundle.h>
30 #include <time.h>
31 #include <unistd.h>
32 #include <sys/types.h>
33
34 #include <dlog.h>
35
36 #ifdef LOG_TAG
37 #undef LOG_TAG
38 #endif
39
40 #define LOG_TAG "RUA"
41
42 #ifndef API
43 #define API __attribute__ ((visibility("default")))
44 #endif
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 /**
51  * @defgroup RUA rua
52  * @{
53  */
54
55 /**
56  * @}
57  */
58
59 /**
60  * @addtogroup RUA
61  * @{
62  */
63
64 /**
65  * @struct rua_rec
66  * @brief RUA record info structure
67  */
68 struct rua_rec {
69         int id;                 /**< primary key */
70         char *pkg_name;         /**< package name */
71         char *app_path;         /**< application path */
72         char *arg;              /**< application launching argument */
73         time_t launch_time;     /**< application launching time */
74         char *instance_id;      /**< Instance ID */
75         char *instance_name;    /**< Instance Name */
76         char *icon;             /**< Icon path */
77         char *uri;              /**< URI */
78 };
79
80 /**
81  * @brief Called when the history is updated.
82  * @param[in] table db table pointer
83  * @param[in] nrows the number of record
84  * @param[in] ncols the number of field
85  * @param[in] user_data  The user data passed from rua_register_update_cb()
86  */
87 typedef void (*rua_history_update_cb) (
88                 char **table,
89                 int nrows,
90                 int ncols,
91                 void *user_data);
92
93 /**
94  * @brief       Add history
95  * @param[in]   pkg_name package name to delete history
96  * @return      0 on success, otherwise a nagative error value
97  * @retval      0 on successful
98  * @retval      -1 on failed
99  */
100 API int rua_add_history_for_uid(char *pkg_name, char *app_path, char *arg, uid_t uid);
101
102 /**
103  * @brief       Delete history with pkg_name
104  * @param[in]   pkg_name package name to delete history
105  * @return      0 on success, otherwise a nagative error value
106  * @retval      0 on successful
107  * @retval      -1 on failed
108  */
109 API int rua_delete_history_with_pkgname(char *pkg_name);
110 API int rua_delete_history_with_pkgname_for_uid(char *pkg_name, uid_t uid);
111
112 /**
113  * @brief       Delete history with app_path
114  * @param[in]   app_path package name to delete history
115  * @return      0 on success, otherwise a nagative error value
116  * @retval      0 on successful
117  * @retval      -1 on failed
118  */
119 API int rua_delete_history_with_apppath(char *app_path);
120 API int rua_delete_history_with_apppath_for_uid(char *app_path, uid_t uid);
121
122 /**
123  * @brief       Clear history
124  * @return      0 on success, otherwise a nagative error value
125  * @retval      0 on successful
126  * @retval      -1 on failed
127  */
128 API int rua_clear_history(void);
129 API int rua_clear_history_for_uid(uid_t uid);
130
131 /**
132  * @brief       Load recently used application history db.
133  * @param[out]  table db table pointer
134  * @param[out]  nrows the number of record
135  * @param[out]  ncols the number of field
136  * @return      0 on success, otherwise a nagative error value
137  * @retval      0 on successful
138  * @retval      -1 on failed
139  */
140 API int rua_history_load_db(char ***table, int *nrows, int *ncols);
141 API int rua_history_load_db_for_uid(char ***table, int *nrows, int *ncols, uid_t uid);
142
143 /**
144  * @brief       Unload recently used application history db.
145  * @param[in]   table db table pointer to unload
146  * @return      0 on success, otherwise a nagative error value
147  * @retval      0 on successful
148  * @retval      -1 on failed
149  */
150 API int rua_history_unload_db(char ***table);
151
152 /**
153  * @brief       Load recently used application record.
154  * @param[out]  rec record to load
155  * @param[in]   table db table pointer
156  * @param[in]   nrows the number of record
157  * @param[in]   ncols the number of field
158  * @param[in]   row record index to load
159  * @return      0 on success, otherwise a nagative error value
160  * @retval      0 on successful
161  * @retval      -1 on failed
162  */
163 API int rua_history_get_rec(struct rua_rec *rec, char **table,
164                                 int nrows, int ncols, int row);
165
166 /**
167  * @brief       Check some package is latest or not with package name
168  * @param[in]   pkg_name package name
169  * @return      0 on success, otherwise a nagative error value
170  * @retval      0 if given pkg_name is lastest application
171  * @retval      -1 if not lastest applicaton or on failed
172  */
173 API int rua_is_latest_app(const char *pkg_name);
174 API int rua_is_latest_app_for_uid(const char *pkg_name, uid_t uid);
175
176 /**
177  * @brief       Delete rua history with instance id
178  * @param[in]   app_id The application ID
179  * @param[in]   instance_id The instance ID
180  * @return      0 on success, otherwise a negative error value
181  */
182 API int rua_delete_history_with_instance_id(const char *app_id,
183                 const char *instance_id);
184
185 /**
186  * @brief       Registers a callback function to be invoked when the history is updated
187  * @param[in]   callback The callback function to be registered
188  * @param[in]   user_data The user data passed to rua_register_update_cb()
189  * @param[out]  callback_id Added callback id
190  * @return      0 on success, otherwise a nagative error value
191  * @retval      0 if on successful
192  * @retval      -1 if it is already registered or on failed
193  */
194 API int rua_register_update_cb(rua_history_update_cb callback,
195                 void *user_data, int *callback_id);
196 API int rua_register_update_cb_for_uid(rua_history_update_cb callback,
197                 void *user_data, int *callback_id, uid_t uid);
198
199 /**
200  * @brief       Unregisters a callback function
201  * @param[in]   callback_id Target callback id
202  * @return      0 on success, otherwise a nagative error value
203  * @retval      0 if on successful
204  * @retval      -1 if the callback was not registered or on failed
205  */
206 API int rua_unregister_update_cb(int callback_id);
207 API int rua_unregister_update_cb_for_uid(int callback_id, uid_t uid);
208
209 /**
210  * @brief       Initialize rua
211  * @return      0 on success, otherwise a nagative error value
212  * @retval      0 on successful
213  * @retval      -1 on failed
214  */
215 API int rua_init(void);
216
217 /**
218  * @brief       Finalize rua
219  * @return      0 on success, otherwise a nagative error value
220  * @retval      0 on successful
221  * @retval      -1 on failed
222  */
223 API int rua_fini(void);
224
225 #ifdef __cplusplus
226 }
227 #endif
228 #endif                          /*__RUA_H__*/