Clean up repository
[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 };
64
65 /**
66  * @brief Called when the history is updated.
67  * @param[in] table db table pointer
68  * @param[in] nrows the number of record
69  * @param[in] ncols the number of field
70  * @param[in] user_data  The user data passed from rua_register_update_cb()
71  */
72 typedef void (*rua_history_update_cb) (
73                 char **table,
74                 int nrows,
75                 int ncols,
76                 void *user_data);
77
78 /**
79  * @brief       Add history
80  * @param[in]   pkg_name package name to delete history
81  * @return      0 on success, otherwise a nagative error value
82  * @retval      0 on successful
83  * @retval      -1 on failed
84  */
85 int rua_add_history_for_uid(char *pkg_name, char *app_path, char *arg, uid_t uid);
86
87 /**
88  * @brief       Delete history with pkg_name
89  * @param[in]   pkg_name package name to delete history
90  * @return      0 on success, otherwise a nagative error value
91  * @retval      0 on successful
92  * @retval      -1 on failed
93  */
94 int rua_delete_history_with_pkgname(char *pkg_name);
95 int rua_delete_history_with_pkgname_for_uid(char *pkg_name, uid_t uid);
96
97 /**
98  * @brief       Delete history with app_path
99  * @param[in]   app_path package name to delete history
100  * @return      0 on success, otherwise a nagative error value
101  * @retval      0 on successful
102  * @retval      -1 on failed
103  */
104 int rua_delete_history_with_apppath(char *app_path);
105 int rua_delete_history_with_apppath_for_uid(char *app_path, uid_t uid);
106
107 /**
108  * @brief       Clear history
109  * @return      0 on success, otherwise a nagative error value
110  * @retval      0 on successful
111  * @retval      -1 on failed
112  */
113 int rua_clear_history(void);
114 int rua_clear_history_for_uid(uid_t uid);
115
116 /**
117  * @brief       Load recently used application history db.
118  * @param[out]  table db table pointer
119  * @param[out]  nrows the number of record
120  * @param[out]  ncols the number of field
121  * @return      0 on success, otherwise a nagative error value
122  * @retval      0 on successful
123  * @retval      -1 on failed
124  */
125 int rua_history_load_db(char ***table, int *nrows, int *ncols);
126 int rua_history_load_db_for_uid(char ***table, int *nrows, int *ncols, uid_t uid);
127
128 /**
129  * @brief       Unload recently used application history db.
130  * @param[in]   table db table pointer to unload
131  * @return      0 on success, otherwise a nagative error value
132  * @retval      0 on successful
133  * @retval      -1 on failed
134  */
135 int rua_history_unload_db(char ***table);
136
137 /**
138  * @brief       Load recently used application record.
139  * @param[out]  rec record to load
140  * @param[in]   table db table pointer
141  * @param[in]   nrows the number of record
142  * @param[in]   ncols the number of field
143  * @param[in]   row record index to load
144  * @return      0 on success, otherwise a nagative error value
145  * @retval      0 on successful
146  * @retval      -1 on failed
147  */
148 int rua_history_get_rec(struct rua_rec *rec, char **table,
149                                 int nrows, int ncols, int row);
150
151 /**
152  * @brief       Check some package is latest or not with package name
153  * @param[in]   pkg_name package name
154  * @return      0 on success, otherwise a nagative error value
155  * @retval      0 if given pkg_name is lastest application
156  * @retval      -1 if not lastest applicaton or on failed
157  */
158 int rua_is_latest_app(const char *pkg_name);
159 int rua_is_latest_app_for_uid(const char *pkg_name, uid_t uid);
160
161 /**
162  * @brief       Delete rua history with instance id
163  * @param[in]   app_id The application ID
164  * @param[in]   instance_id The instance ID
165  * @return      0 on success, otherwise a negative error value
166  */
167 int rua_delete_history_with_instance_id(const char *app_id,
168                 const char *instance_id);
169
170 /**
171  * @brief       Registers a callback function to be invoked when the history is updated
172  * @param[in]   callback The callback function to be registered
173  * @param[in]   user_data The user data passed to rua_register_update_cb()
174  * @param[out]  callback_id Added callback id
175  * @return      0 on success, otherwise a nagative error value
176  * @retval      0 if on successful
177  * @retval      -1 if it is already registered or on failed
178  */
179 int rua_register_update_cb(rua_history_update_cb callback,
180                 void *user_data, int *callback_id);
181 int rua_register_update_cb_for_uid(rua_history_update_cb callback,
182                 void *user_data, int *callback_id, uid_t uid);
183
184 /**
185  * @brief       Unregisters a callback function
186  * @param[in]   callback_id Target callback id
187  * @return      0 on success, otherwise a nagative error value
188  * @retval      0 if on successful
189  * @retval      -1 if the callback was not registered or on failed
190  */
191 int rua_unregister_update_cb(int callback_id);
192 int rua_unregister_update_cb_for_uid(int callback_id, uid_t uid);
193
194 /**
195  * @brief       Initialize rua
196  * @return      0 on success, otherwise a nagative error value
197  * @retval      0 on successful
198  * @retval      -1 on failed
199  */
200 int rua_init(void);
201
202 /**
203  * @brief       Finalize rua
204  * @return      0 on success, otherwise a nagative error value
205  * @retval      0 on successful
206  * @retval      -1 on failed
207  */
208 int rua_fini(void);
209
210 #ifdef __cplusplus
211 }
212 #endif
213 #endif                          /*__RUA_H__*/