d9c7235f72876b12769ab475617961c39480df3a
[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 };
75
76 /**
77  * @brief       Add history
78  * @param[in]   pkg_name package name to delete history
79  * @return      0 on success, otherwise a nagative error value
80  * @retval      0 on successful
81  * @retval      -1 on failed
82  */
83 API int rua_add_history_for_uid(char *pkg_name, char *app_path, char *arg, uid_t uid);
84
85 /**
86  * @brief       Delete history with pkg_name
87  * @param[in]   pkg_name package name to delete history
88  * @return      0 on success, otherwise a nagative error value
89  * @retval      0 on successful
90  * @retval      -1 on failed
91  */
92 API int rua_delete_history_with_pkgname(char *pkg_name);
93 API int rua_delete_history_with_pkgname_for_uid(char *pkg_name, uid_t uid);
94
95 /**
96  * @brief       Delete history with app_path
97  * @param[in]   app_path package name to delete history
98  * @return      0 on success, otherwise a nagative error value
99  * @retval      0 on successful
100  * @retval      -1 on failed
101  */
102 API int rua_delete_history_with_apppath(char *app_path);
103 API int rua_delete_history_with_apppath_for_uid(char *app_path, uid_t uid);
104
105 /**
106  * @brief       Clear history
107  * @return      0 on success, otherwise a nagative error value
108  * @retval      0 on successful
109  * @retval      -1 on failed
110  */
111 API int rua_clear_history(void);
112 API int rua_clear_history_for_uid(uid_t uid);
113
114 /**
115  * @brief       Load recently used application history db.
116  * @param[out]  table db table pointer
117  * @param[out]  nrows the number of record
118  * @param[out]  ncols the number of field
119  * @return      0 on success, otherwise a nagative error value
120  * @retval      0 on successful
121  * @retval      -1 on failed
122  */
123 API int rua_history_load_db(char ***table, int *nrows, int *ncols);
124 API int rua_history_load_db_for_uid(char ***table, int *nrows, int *ncols, uid_t uid);
125
126 /**
127  * @brief       Unload recently used application history db.
128  * @param[in]   table db table pointer to unload
129  * @return      0 on success, otherwise a nagative error value
130  * @retval      0 on successful
131  * @retval      -1 on failed
132  */
133 API int rua_history_unload_db(char ***table);
134
135 /**
136  * @brief       Load recently used application record.
137  * @param[out]  rec record to load
138  * @param[in]   table db table pointer
139  * @param[in]   nrows the number of record
140  * @param[in]   ncols the number of field
141  * @param[in]   row record index to load
142  * @return      0 on success, otherwise a nagative error value
143  * @retval      0 on successful
144  * @retval      -1 on failed
145  */
146 API int rua_history_get_rec(struct rua_rec *rec, char **table,
147                                 int nrows, int ncols, int row);
148
149 /**
150  * @brief       Check some package is latest or not with package name
151  * @param[in]   pkg_name package name
152  * @return      0 on success, otherwise a nagative error value
153  * @retval      0 if given pkg_name is lastest application
154  * @retval      -1 if not lastest applicaton or on failed
155  */
156 API int rua_is_latest_app(const char *pkg_name);
157 API int rua_is_latest_app_for_uid(const char *pkg_name, uid_t uid);
158
159 /**
160  * @brief       Initialize rua
161  * @return      0 on success, otherwise a nagative error value
162  * @retval      0 on successful
163  * @retval      -1 on failed
164  */
165 API int rua_init(void);
166
167 /**
168  * @brief       Finalize rua
169  * @return      0 on success, otherwise a nagative error value
170  * @retval      0 on successful
171  * @retval      -1 on failed
172  */
173 API int rua_fini(void);
174
175 #ifdef __cplusplus
176 }
177 #endif
178 #endif                          /*__RUA_H__*/