4 * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
25 #include <package_manager.h>
28 #include "sal_observer.h"
30 //******************************************************************************
31 //* Global variables and defines
32 //******************************************************************************
33 #define SAL_PLUGIN_METADATA_KEY_ADAPTOR "service-adaptor"
35 //******************************************************************************
37 //******************************************************************************
39 //******************************************************************************
40 //* Private interface definition
41 //******************************************************************************
44 * @brief callback of app info
48 static bool _sal_app_meta_cb(const char *key, const char *value, void *user_data)
52 char **app_meta = (char **) user_data;
54 if ((NULL != key) && (NULL != value))
56 if (0 == strncmp(SAL_PLUGIN_METADATA_KEY_ADAPTOR, key, strlen(SAL_PLUGIN_METADATA_KEY_ADAPTOR)))
58 app_meta[0] = strdup(value);
59 SAL_INFO("SAL_PLUGIN_METADATA_KEY_ADAPTOR: %s", value);
67 * @brief callback of app info
71 static bool _sal_app_info_cb(package_info_app_component_type_e comp_type, const char *app_id, void *user_data)
75 app_info_h app_info = NULL;
76 int ret = PACKAGE_MANAGER_ERROR_NONE;
77 char *pkg_path = (char *) user_data;
78 char **app_meta = (char **) g_malloc0(sizeof(char *) * 1);
82 app_info_create(app_id, &app_info);
83 ret = app_info_foreach_metadata(app_info, _sal_app_meta_cb, (void *) app_meta);
84 RETVM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, false, "app_info_foreach_metadata() Fail(%d)", ret);
86 app_info_destroy(app_info);
88 // TODO: using app_meta
96 * @brief callback of package manager
100 static void _sal_package_event_cb(const char *type,
102 package_manager_event_type_e event_type,
103 package_manager_event_state_e event_state,
105 package_manager_error_e error,
110 if ((PACKAGE_MANAGER_EVENT_TYPE_INSTALL == event_type)
111 && (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state))
113 int ret = PACKAGE_MANAGER_ERROR_NONE;
114 package_info_h p_info = NULL;
116 ret = package_manager_get_package_info(package, &p_info);
117 RETM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, "package_manager_get_package_info() Fail(%d)", ret);
120 ret = package_info_get_root_path(p_info, &path);
121 RETM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, "package_info_get_root_path() Fail(%d)", ret);
123 ret = package_info_foreach_app_from_package(p_info, PACKAGE_INFO_ALLAPP, _sal_app_info_cb, path);
124 RETM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, "package_info_foreach_app_from_package() Fail(%d)", ret);
126 ret = package_info_destroy(p_info);
127 RETM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, "package_info_destroy() Fail(%d)", ret);
135 //******************************************************************************
136 //* Public interface definition
137 //******************************************************************************
140 * @brief start observer using package manager
144 service_adaptor_error_e sal_observer_start()
147 package_manager_h package = NULL;
149 package_manager_create(&package);
151 ret = package_manager_set_event_cb(package, _sal_package_event_cb, NULL);
152 RETVM_IF(PACKAGE_MANAGER_ERROR_NONE != ret, SERVICE_ADAPTOR_ERROR_SYSTEM, "package_manager_set_event_cb() Fail(%d)", ret);
154 return SERVICE_ADAPTOR_ERROR_NONE;