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