plugin: add apis to add plugin for vendor specific system information 04/52004/1
authortaeyoung <ty317.kim@samsung.com>
Wed, 18 Nov 2015 06:31:28 +0000 (15:31 +0900)
committertaeyoung <ty317.kim@samsung.com>
Wed, 18 Nov 2015 06:31:28 +0000 (15:31 +0900)
- Vendors can add there own system information keys and values
  by making system-info-plugin.so using capi-systsem-info-plugin
  library.

Change-Id: If68dec5f72dfe8d34e2210107472b9f355c61f12
Signed-off-by: taeyoung <ty317.kim@samsung.com>
CMakeLists.txt
capi-system-info-plugin.pc.in [new file with mode: 0755]
include/system_info_intf.h [new file with mode: 0644]
include/system_info_private.h
packaging/capi-system-info.spec
src/system_info.c
src/system_info_external.c [new file with mode: 0644]

index f99151f..606e87b 100644 (file)
@@ -1,6 +1,7 @@
 
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 SET(fw_name "capi-system-info")
+SET(external_plugin "${fw_name}-plugin")
 
 PROJECT(${fw_name})
 
@@ -34,10 +35,12 @@ ADD_DEFINITIONS("-DSERIAL_PATH=\"${SERIAL_PATH}\"")
 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
@@ -51,6 +54,8 @@ INSTALL(
         DIRECTORY ${INC_DIR}/ DESTINATION include/system
         FILES_MATCHING
         PATTERN "*_private.h" EXCLUDE
+        PATTERN "*_doc.h" EXCLUDE
+        PATTERN "*_intf.h" EXCLUDE
         PATTERN "${INC_DIR}/*.h"
         )
 
@@ -67,6 +72,15 @@ CONFIGURE_FILE(
 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)
diff --git a/capi-system-info-plugin.pc.in b/capi-system-info-plugin.pc.in
new file mode 100755 (executable)
index 0000000..bf85a10
--- /dev/null
@@ -0,0 +1,13 @@
+# 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}
+
diff --git a/include/system_info_intf.h b/include/system_info_intf.h
new file mode 100644 (file)
index 0000000..4c67890
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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__ */
index dd897fb..13e3433 100644 (file)
@@ -57,6 +57,8 @@ int system_info_get_value_from_config_xml(char *feature_tag, const char *name_fi
 
 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
index 34e4c6c..6454044 100644 (file)
@@ -77,5 +77,6 @@ cp -f script/make_info_file.sh %{buildroot}/etc/make_info_file.sh
 %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
index b20b9a0..33887d2 100644 (file)
@@ -180,8 +180,12 @@ API int system_info_get_custom_bool(const char *key, bool *value)
 
        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"))
@@ -211,8 +215,12 @@ API int system_info_get_custom_int(const char *key, int *value)
 
        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);
@@ -239,8 +247,12 @@ API int system_info_get_custom_double(const char *key, double *value)
 
        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);
@@ -264,8 +276,12 @@ API int system_info_get_custom_string(const char *key, char **value)
 
        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;
diff --git a/src/system_info_external.c b/src/system_info_external.c
new file mode 100644 (file)
index 0000000..73d68ff
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * 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;
+}