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