e63ee010e656fa1882a95fdb2e09341c0ea4ac3a
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_plugininfo.c
1 /*
2  * pkgmgr-info
3  *
4  * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Junghyun Yeon <jungh.yeon@samsung.com>,
7  * Sangyoon Jang <jeremy.jang@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 #define _GNU_SOURCE
24
25 #include <stdlib.h>
26 #include <stdbool.h>
27
28 #include "manager/pkginfo_manager.h"
29 #include "pkgmgrinfo_private.h"
30 #include "pkgmgrinfo_debug.h"
31 #include "pkgmgr-info.h"
32
33 API int pkgmgrinfo_plugininfo_foreach_plugininfo(const char *pkgid,
34                 const char *plugin_type, const char *plugin_name,
35                 pkgmgrinfo_plugin_list_cb plugin_list_cb, void *user_data)
36 {
37         int ret;
38         const char *appid;
39         GList *appid_list = NULL;
40         GList *tmp_list;
41
42         if (!pkgid || !plugin_type || !plugin_name || !plugin_list_cb) {
43                 _LOGE("Invalid parameter");
44                 return PMINFO_R_EINVAL;
45         }
46
47         ret = _plugininfo_get_appids(pkgid, plugin_type, plugin_name,
48                         &appid_list);
49         if (ret != PMINFO_R_OK) {
50                 _LOGE("Fail to get plugininfo");
51                 return ret;
52         }
53
54         for (tmp_list = appid_list; tmp_list != NULL;
55                         tmp_list = tmp_list->next) {
56                 appid = (char *)tmp_list->data;
57                 if (!appid)
58                         continue;
59                 ret = plugin_list_cb(pkgid, appid, plugin_type,
60                                 plugin_name, user_data);
61                 if (ret != 0)
62                         break;
63         }
64
65         g_list_free_full(appid_list, free);
66
67         return ret;
68
69 }