tizen 2.3.1 release
[framework/appfw/pkgmgr-info.git] / include / SLP_pkgmgr_info_PG.h
1 /*
2  * pkgmgr-info
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23
24 /**
25
26  *
27  * @ingroup   SLP_PG
28  * @defgroup   PackageManagerInfoGuide
29
30
31 @par Package Manager Information Library Programming Guide
32
33 <h1 class="pg"> Introduction</h1>
34 <h2 class="pg"> Purpose of this document</h2>
35 The purpose of this document is to describe how applications can use Package Manager Information APIs.\n
36 This document gives only programming guidelines to application developers.
37
38 <h2 class="pg"> Scope</h2>
39 The scope of this document is limited to Samsung platform Package Manager Info API usage.
40
41 <h1 class="pg"> Architecture</h1>
42 <h2 class="pg"> Architecture overview</h2>
43 Package Manager Information Library is responsible for getting/setting manifest file information from/to manifest DB.\n
44
45 The library provides APIs to parse the package's manifest file\n
46 It also provides APIs to insert/update/delete this parsed data from manifest DB.
47
48
49 <h2 class="pg"> Features</h2>
50 Package Manager Info Library has the following features:\n
51
52  - Get /Set Package Information in DB
53         - It provides API to get package manifest data from DB.
54         - It provides API to get package certificate data from DB.
55         - It provides API to set package manifest data in DB.
56         - It provides API to set package certificate data in DB.
57
58 @image html SLP_pkgmgr_info.png "High-Level Architure depicting get/set operation"
59
60  - Filter Package/Application Information
61         - It provides API to filter package information query result.
62         - It provides API to filter application information query result.
63
64  - Manifest Parser
65         - It provides API to parse package manifest file.
66         - It provides API to insert/update/delete manifest data in DB.
67
68 @image html SLP_pkgmgr_parser.png "High-Level Architure depicting manifest parsing"
69
70 <h1 class="pg"> Package Manager API descriptions</h1>
71 <b> SEE API manual </b>
72
73 <h1 class="pg"> Package Manager Features with sample code</h1>
74 <h2 class="pg"> Get /Set Package Information in DB</h2>
75
76 Client application
77 - Get package version from manifest DB
78
79 @code
80 #include <pkgmgr-info.h>
81
82 static int get_pkg_version(const char *pkgid)
83 {
84         int ret = 0;
85         char *version = NULL;
86         pkgmgrinfo_pkginfo_h handle;
87         ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
88         if (ret != PMINFO_R_OK)
89                 return -1;
90         ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
91         if (ret != PMINFO_R_OK) {
92                 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
93                 return -1;
94         }
95         printf("pkg version: %s\n", version);
96         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
97         return 0;
98 }
99 @endcode
100
101 - Get package author root certificate from manifest DB
102
103 @code
104 static int get_cert_info(const char *pkgid)
105 {
106         int ret = 0;
107         pkgmgrinfo_certinfo_h handle;
108         char *auth_cert = NULL;
109         ret = pkgmgrinfo_pkginfo_create_certinfo(&handle);
110         if (ret != PMINFO_R_OK)
111                 return -1;
112         ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle);
113         if (ret != PMINFO_R_OK) {
114                 pkgmgrinfo_pkginfo_destroy_certinfo(handle);
115                 return -1;
116         }
117         ret = pkgmgrinfo_pkginfo_get_cert_value(handle, PMINFO_AUTHOR_ROOT_CERT, &auth_cert);
118         if (ret != PMINFO_R_OK) {
119                 pkgmgrinfo_pkginfo_destroy_certinfo(handle);
120                 return -1;
121         }
122         printf("Author root certificate: %s\n", auth_root);
123         pkgmgrinfo_pkginfo_destroy_certinfo(handle);
124         return 0;
125 }
126 @endcode
127
128 - Set package version in manifest DB
129
130 @code
131 #include <pkgmgr-info.h>
132
133 static int set_pkg_version_in_db(const char *pkgid)
134 {
135         int ret = 0;
136         pkgmgrinfo_pkgdbinfo_h handle;
137         ret = pkgmgrinfo_create_pkgdbinfo(pkgid, &handle);
138         if (ret != PMINFO_R_OK)
139                 return -1;
140         ret = pkgmgrinfo_set_version_to_pkgdbinfo(handle, "0.0.1");
141         if (ret != PMINFO_R_OK) {
142                 pkgmgrinfo_destroy_pkgdbinfo(handle);
143                 return -1;
144         }
145         ret = pkgmgrinfo_save_pkgdbinfo(handle);
146         if (ret != PMINFO_R_OK) {
147                 pkgmgrinfo_destroy_pkgdbinfo(handle);
148                 return -1;
149         }
150         pkgmgrinfo_destroy_pkgdbinfo(handle);
151         return 0;
152 }
153 @endcode
154
155 - Set package author root certificate in manifest DB
156
157 @code
158 static int set_cert_in_db(const char *pkgid)
159 {
160         int ret = 0;
161         pkgmgrinfo_instcertinfo_h handle;
162         ret = pkgmgrinfo_create_certinfo_set_handle(&handle);
163         if (ret != PMINFO_R_OK)
164                 return -1;
165         ret = pkgmgrinfo_set_cert_value(handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
166         if (ret != PMINFO_R_OK) {
167                 pkgmgrinfo_destroy_certinfo_set_handle(handle);
168                 return -1;
169         }
170         ret = pkgmgrinfo_save_pkgdbinfo(pkgid, handle);
171         if (ret != PMINFO_R_OK) {
172                 pkgmgrinfo_destroy_certinfo_set_handle(handle);
173                 return -1;
174         }
175         pkgmgrinfo_destroy_certinfo_set_handle(handle);
176         return 0;
177 }
178 @endcode
179
180
181 <h2 class="pg"> Filter Package/Application Information </h2>
182
183 - Filter number of installed rpm packages out of total number of packages installed.
184
185 @code
186 #include <pkgmgr-info.h>
187 int pkg_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
188 {
189         char *pkgid = NULL;
190         pkgmgrinfo_pkginfo_get_pkgname(handle, &pkgid);
191         printf("pkg id : %s\n", pkgid);
192         return 0;
193 }
194
195 static int get_rpm_pkg_list()
196 {
197         int ret = 0;
198         pkgmgrinfo_pkginfo_filter_h handle;
199         ret = pkgmgrinfo_pkginfo_filter_create(&handle);
200         if (ret != PMINFO_R_OK)
201                 return -1;
202         ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_TYPE, "rpm");
203         if (ret != PMINFO_R_OK) {
204                 pkgmgrinfo_pkginfo_filter_destroy(handle);
205                 return -1;
206         }
207         ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, pkg_list_cb, NULL);
208         if (ret != PMINFO_R_OK) {
209                 pkgmgrinfo_pkginfo_filter_destroy(handle);
210                 return -1;
211         }
212         pkgmgrinfo_pkginfo_filter_destroy(handle);
213         return 0;
214 }
215 @endcode
216
217 - Filter number of installed applications which are of type "capp".
218
219 @code
220 #include <pkgmgr-info.h>
221
222 static int get_capp_count()
223 {
224         int ret = 0;
225         int count = 0;
226         pkgmgrinfo_appinfo_filter_h handle;
227         ret = pkgmgrinfo_appinfo_filter_create(&handle);
228         if (ret != PMINFO_R_OK)
229                 return -1;
230         ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_TYPE, "capp");
231         if (ret != PMINFO_R_OK) {
232                 pkgmgrinfo_appinfo_filter_destroy(handle);
233                 return -1;
234         }
235         ret = pkgmgrinfo_appinfo_filter_count(handle, &count);
236         if (ret != PMINFO_R_OK) {
237                 pkgmgrinfo_appinfo_filter_destroy(handle);
238                 return -1;
239         }
240         printf("No of capp: %d\n", count);
241         pkgmgrinfo_appinfo_filter_destroy(handle);
242         return 0;
243 }
244 @endcode
245
246 <h2 class="pg"> Manifest Parser </h2>
247
248 - Parse the package manifest file and insert the parsed data in manifest DB.
249
250 @code
251 #include <pkgmgr-info.h>
252
253 static int parse_manifest_file_for_installation(const char *manifest)
254 {
255         int ret = 0;
256         ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
257         if (ret)
258                 return -1;
259         return 0;
260 }
261 @endcode
262
263
264 - Parse the package manifest file and update the manifest DB with the parsed data.
265
266 @code
267 #include <pkgmgr-info.h>
268
269 static int parse_manifest_file_for_upgrade(const char *manifest)
270 {
271         int ret = 0;
272         ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
273         if (ret)
274                 return -1;
275         return 0;
276 }
277 @endcode
278
279 - Parse the package manifest file and delete the parsed data from manifest DB.
280
281 @code
282 #include <pkgmgr-info.h>
283
284 static int parse_manifest_file_for_uninstallation(const char *manifest)
285 {
286         int ret = 0;
287         ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
288         if (ret)
289                 return -1;
290         return 0;
291 }
292 @endcode
293
294
295 */
296
297 /**
298 @}
299 */
300
301