CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
SET(fw_name "capi-system-info")
+SET(external_plugin "${fw_name}-plugin")
PROJECT(${fw_name})
ADD_DEFINITIONS("-DTIZEN_ID_PATH=\"${TIZEN_ID_PATH}\"")
ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}\"")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib")
+
aux_source_directory(src SOURCES)
ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
-TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS} "-ldl")
SET_TARGET_PROPERTIES(${fw_name}
PROPERTIES
DIRECTORY ${INC_DIR}/ DESTINATION include/system
FILES_MATCHING
PATTERN "*_private.h" EXCLUDE
+ PATTERN "*_doc.h" EXCLUDE
+ PATTERN "*_intf.h" EXCLUDE
PATTERN "${INC_DIR}/*.h"
)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/packaging/tizenid.service DESTINATION lib/systemd/system)
+SET(PLUGIN_PC_NAME ${external_plugin})
+CONFIGURE_FILE(
+ ${PLUGIN_PC_NAME}.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${PLUGIN_PC_NAME}.pc
+ @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PLUGIN_PC_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/system_info_intf.h DESTINATION include/plugin)
+
ADD_SUBDIRECTORY(src/tizenid)
IF(UNIX)
--- /dev/null
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=@LIB_INSTALL_DIR@
+includedir=/usr/include/plugin
+
+Name: @PLUGIN_PC_NAME@
+Description: capi-system-info plugin library
+Version: @VERSION@
+Requires:
+Cflags: -I${includedir}
+
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __TIZEN_SYSTEM_SYSTEM_INFO_INTF_H__
+#define __TIZEN_SYSTEM_SYSTEM_INFO_INTF_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdio.h>
+
+#define TAG_CUSTOM "custom"
+
+#define TYPE_BOOL "bool"
+#define TYPE_INT "int"
+#define TYPE_DBL "double"
+#define TYPE_STR "string"
+
+typedef struct {
+ int (*get_value_external)(const char *tag,
+ const char *key, const char *type,
+ char *buf, unsigned int len);
+} system_info_external_plugin_interface;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_SYSTEM_SYSTEM_INFO_PRIVATE_H__ */
int system_info_get_file(const char *key, void **value);
+int external_get_value(const char *tag, const char *key, const char *type, char **value);
+
#ifdef __cplusplus
}
#endif
%manifest %{name}.manifest
%{_includedir}/system/system_info.h
%{_includedir}/system/system_info_type.h
+%{_includedir}/plugin/system_info_intf.h
%{_libdir}/pkgconfig/*.pc
%{_libdir}/libcapi-system-info.so
ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, BOOL_TYPE, &string);
if (ret) {
- _E("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
- return ret;
+ _I("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
+ ret = external_get_value(CUSTOM_TAG, key, BOOL_TYPE, &string);
+ if (ret) {
+ _E("Cannot find key (%s) in the plugin (%d)", key, ret);
+ return ret;
+ }
}
if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, INT_TYPE, &string);
if (ret) {
- _E("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
- return ret;
+ _I("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
+ ret = external_get_value(CUSTOM_TAG, key, INT_TYPE, &string);
+ if (ret) {
+ _E("Cannot find key (%s) in the plugin (%d)", key, ret);
+ return ret;
+ }
}
*ret_val = atoi(string);
ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, DBL_TYPE, &string);
if (ret) {
- _E("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
- return ret;
+ _I("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
+ ret = external_get_value(CUSTOM_TAG, key, DBL_TYPE, &string);
+ if (ret) {
+ _E("Cannot find key (%s) in the plugin (%d)", key, ret);
+ return ret;
+ }
}
*ret_val = atof(string);
ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, STR_TYPE, &string);
if (ret) {
- _E("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
- return ret;
+ _I("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
+ ret = external_get_value(CUSTOM_TAG, key, STR_TYPE, &string);
+ if (ret) {
+ _E("Cannot find key (%s) in the plugin (%d)", key, ret);
+ return ret;
+ }
}
*value = string;
--- /dev/null
+/*
+ * system-info
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "system_info_private.h"
+#include "system_info_type.h"
+#include "system_info_intf.h"
+#include <string.h>
+#include <unistd.h>
+#include <dlfcn.h>
+
+#define BUF_MAX 256
+
+#define EXTERNAL_SYSTEM_INFO "/usr/lib/libsystem-info-external-plugin.so"
+
+int external_get_value(const char *tag, const char *key,
+ const char *type, char **val)
+{
+ void *handle = NULL;
+ int ret;
+ char buf[BUF_MAX];
+ const system_info_external_plugin_interface *plugin;
+ const system_info_external_plugin_interface *(*system_info_get_external_plugin_interface)(void);
+
+
+ if (access(EXTERNAL_SYSTEM_INFO, F_OK) != 0) {
+ _E("No external system info library");
+ return SYSTEM_INFO_ERROR_IO_ERROR;
+ }
+
+ handle = dlopen(EXTERNAL_SYSTEM_INFO, RTLD_NOW);
+ if (!handle) {
+ _E("dlopen(%s) failed(%s)", EXTERNAL_SYSTEM_INFO, dlerror());
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
+ goto out;
+ }
+
+ system_info_get_external_plugin_interface = dlsym(handle, "system_info_get_external_plugin_interface");
+ if (!system_info_get_external_plugin_interface) {
+ _E("dlsym failed(%s)", dlerror());
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
+ goto out;
+ }
+
+ plugin = system_info_get_external_plugin_interface();
+ if (!plugin) {
+ _E("Failed to get plugin");
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
+ goto out;
+ }
+
+ if (plugin->get_value_external == NULL) {
+ _E("Invalid plugin function");
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
+ goto out;
+ }
+
+ ret = plugin->get_value_external(tag, key, type, buf, sizeof(buf));
+ if (ret < 0) {
+ _E("Failed to get value from plugin (ret:%d)", ret);
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
+ goto out;
+ }
+
+ *val = strdup(buf);
+ if (*val == NULL) {
+ _E("strdup() failed");
+ ret = SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ ret = SYSTEM_INFO_ERROR_NONE;
+
+out:
+ if (handle)
+ dlclose(handle);
+
+ return ret;
+}