4 * Copyright (c) 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.
20 #include "system_info_private.h"
21 #include "system_info_type.h"
22 #include "system_info_intf.h"
29 #define EXTERNAL_SYSTEM_INFO "/usr/lib/libsystem-info-external-plugin.so"
33 int external_get_value(const char *tag, const char *key,
34 const char *type, char **val)
39 const system_info_external_plugin_interface *plugin;
40 const system_info_external_plugin_interface *(*system_info_get_external_plugin_interface)(void);
43 if (access(EXTERNAL_SYSTEM_INFO, F_OK) != 0) {
44 _E("No external system info library");
45 return SYSTEM_INFO_ERROR_IO_ERROR;
48 handle = dlopen(EXTERNAL_SYSTEM_INFO, RTLD_NOW);
50 _E("dlopen(%s) failed(%s)", EXTERNAL_SYSTEM_INFO, dlerror());
51 ret = SYSTEM_INFO_ERROR_IO_ERROR;
55 system_info_get_external_plugin_interface = dlsym(handle, "system_info_get_external_plugin_interface");
56 if (!system_info_get_external_plugin_interface) {
57 _E("dlsym failed(%s)", dlerror());
58 ret = SYSTEM_INFO_ERROR_IO_ERROR;
62 plugin = system_info_get_external_plugin_interface();
64 _E("Failed to get plugin");
65 ret = SYSTEM_INFO_ERROR_IO_ERROR;
69 if (plugin->get_value_external == NULL) {
70 _E("Invalid plugin function");
71 ret = SYSTEM_INFO_ERROR_IO_ERROR;
75 ret = plugin->get_value_external(tag, key, type, buf, sizeof(buf));
77 _E("Failed to get value from plugin (ret:%d)", ret);
78 ret = SYSTEM_INFO_ERROR_IO_ERROR;
84 _E("strdup() failed");
85 ret = SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
89 ret = SYSTEM_INFO_ERROR_NONE;
98 int external_get_type(const char *tag, const char *key, char **type)
103 const system_info_external_plugin_interface *plugin;
104 const system_info_external_plugin_interface *(*system_info_get_external_plugin_interface)(void);
107 if (access(EXTERNAL_SYSTEM_INFO, F_OK) != 0) {
108 _E("No external system info library");
109 return SYSTEM_INFO_ERROR_IO_ERROR;
112 handle = dlopen(EXTERNAL_SYSTEM_INFO, RTLD_NOW);
114 _E("dlopen(%s) failed(%s)", EXTERNAL_SYSTEM_INFO, dlerror());
115 ret = SYSTEM_INFO_ERROR_IO_ERROR;
119 system_info_get_external_plugin_interface = dlsym(handle, "system_info_get_external_plugin_interface");
120 if (!system_info_get_external_plugin_interface) {
121 _E("dlsym failed(%s)", dlerror());
122 ret = SYSTEM_INFO_ERROR_IO_ERROR;
126 plugin = system_info_get_external_plugin_interface();
128 _E("Failed to get plugin");
129 ret = SYSTEM_INFO_ERROR_IO_ERROR;
133 if (plugin->get_type_external == NULL) {
134 _E("Invalid plugin function");
135 ret = SYSTEM_INFO_ERROR_IO_ERROR;
139 ret = plugin->get_type_external(tag, key, buf, sizeof(buf));
141 _E("Failed to get value from plugin (ret:%d)", ret);
142 ret = SYSTEM_INFO_ERROR_IO_ERROR;
148 _E("strdup() failed");
149 ret = SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
153 ret = SYSTEM_INFO_ERROR_NONE;