add build support for appinfo lib
authorYoung Ik Cho <youngik.cho@samsung.com>
Tue, 6 Aug 2013 12:45:47 +0000 (21:45 +0900)
committerYoung Ik Cho <youngik.cho@samsung.com>
Thu, 8 Aug 2013 01:27:55 +0000 (10:27 +0900)
Change-Id: I0feca6c6da4b682f99f8c749dca7507eee53d44a
Signed-off-by: Young Ik Cho <youngik.cho@samsung.com>
appinfo/CMakeLists.txt
appinfo/appinfo.c
appinfo/appinfo.h [moved from include/appinfo.h with 92% similarity]
appinfo/appinfo.pc.in [new file with mode: 0644]
packaging/osp-env-config.spec [changed mode: 0755->0644]

index e9ee8a8..7435457 100644 (file)
@@ -1,20 +1,25 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 
-SET(this_target osp-appinfo)
+SET(this_target appinfo)
 
-SET(VERSION 0.1.1)
 SET(VERSION_MAJOR 0)
+SET(VERSION "${VERSION_MAJOR}.1.0")
 
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
-INCLUDE_DIRECTORIES(
-       /usr/include/dlog
+#INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED
+       dlog
 )
 
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+
 SET (${this_target}_SOURCE_FILES
        ${CMAKE_CURRENT_SOURCE_DIR}/appinfo.c
-       )
-
-#CONFIGURE_FILE(appinfo.pc.in appinfo.pc @ONLY)
+)
 
 ADD_LIBRARY(${this_target} SHARED ${${this_target}_SOURCE_FILES})
 
@@ -23,10 +28,19 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
 SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
 SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined -Wl,--as-needed")
 
-TARGET_LINK_LIBRARIES(${this_target} "-ldlog")
+TARGET_LINK_LIBRARIES(${this_target} ${pkgs_LDFLAGS})
+
+SET(PC_NAME ${this_target})
+SET(PC_REQUIRED ${pc_requires})
+SET(PC_LDFLAGS -l${this_target})
 
-INSTALL(TARGETS ${this_target} DESTINATION ${LIB_INSTALL_DIR}
+CONFIGURE_FILE(appinfo.pc.in appinfo.pc @ONLY)
+
+INSTALL(TARGETS ${this_target} DESTINATION ${LIB_INSTALL_DIR}/osp
                                PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
                GROUP_EXECUTE GROUP_READ
                WORLD_EXECUTE WORLD_READ)
 
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/appinfo.h DESTINATION include/osp)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/appinfo.pc DESTINATION lib/pkgconfig)
+
index 7ef3de5..5ea76c2 100644 (file)
@@ -43,8 +43,8 @@ static app_info_version_e _current_api_ver = APP_INFO_VERSION_2_2;
 static int _compat_mode = 0;
 static int _app_info_init = 0;
 
-static int _argc;
-static char** _argv;
+static int _argc = 0;
+static char** _argv = NULL;
 
 #define MAX_OSP_PKGID 10
 #define MAX_APPID 256
@@ -55,50 +55,6 @@ static const char* _pkgid = NULL;
 static const char* _appid = NULL;
 static const char* _execname = NULL;
 
-static app_info_version_e __get_api_version_from_str(const char * ver_str)
-{
-
-       if(ver_str == NULL)
-               return APP_INFO_VERSION_INVALID;
-
-       if(!strcmp(ver_str,"3.0"))
-       {
-               return APP_INFO_VERSION_3_0;
-       }
-       else if(!strcmp(ver_str,"2.2"))
-       {
-               return APP_INFO_VERSION_2_2;
-       }
-       else if(!strcmp(ver_str,"2.1"))
-       {
-               return APP_INFO_VERSION_2_1;
-       }
-       else if(!strcmp(ver_str,"2.0"))
-       {
-               return APP_INFO_VERSION_2_0;
-       }
-       else if(!strcmp(ver_str,"1.2"))
-       {
-               return APP_INFO_VERSION_1_2;
-       }
-       else if(!strcmp(ver_str,"1.1"))
-       {
-               return APP_INFO_VERSION_1_1;
-       }
-       else if(!strcmp(ver_str,"1.0.2"))
-       {
-               return APP_INFO_VERSION_1_0_2;
-       }
-       else if(!strcmp(ver_str,"1.0"))
-       {
-               return APP_INFO_VERSION_1_0;
-       }
-       else
-       {
-               return APP_INFO_VERSION_INVALID;
-       }
-
-}
 
 /**
  * @brief      Initializes the appinfo structure
@@ -229,6 +185,51 @@ appinfo_get_api_str_by_version(int ver)
        }
 }
 
+app_info_version_e appinfo_get_api_version_from_str(const char * ver_str)
+{
+       if(ver_str == NULL)
+       {
+               return APP_INFO_VERSION_INVALID;
+       }
+
+       if(!strcmp(ver_str,"3.0"))
+       {
+               return APP_INFO_VERSION_3_0;
+       }
+       else if(!strcmp(ver_str,"2.2"))
+       {
+               return APP_INFO_VERSION_2_2;
+       }
+       else if(!strcmp(ver_str,"2.1"))
+       {
+               return APP_INFO_VERSION_2_1;
+       }
+       else if(!strcmp(ver_str,"2.0"))
+       {
+               return APP_INFO_VERSION_2_0;
+       }
+       else if(!strcmp(ver_str,"1.2"))
+       {
+               return APP_INFO_VERSION_1_2;
+       }
+       else if(!strcmp(ver_str,"1.1"))
+       {
+               return APP_INFO_VERSION_1_1;
+       }
+       else if(!strcmp(ver_str,"1.0.2"))
+       {
+               return APP_INFO_VERSION_1_0_2;
+       }
+       else if(!strcmp(ver_str,"1.0"))
+       {
+               return APP_INFO_VERSION_1_0;
+       }
+       else
+       {
+               return APP_INFO_VERSION_INVALID;
+       }
+}
+
 /**
  * @brief      Returns whether the application is compat mode or not
  *
@@ -323,7 +324,7 @@ appinfo_is_initialized(void)
 int
 appinfo_set_argv(int argc, char** argv)
 {
-       if(argc > 0 && !argv)
+       if(argc > 0 && argv)
        {
                _argc = argc;
                _argv = argv;
@@ -334,15 +335,33 @@ appinfo_set_argv(int argc, char** argv)
 
 int appinfo_get_argv(int* argc, char*** argv)
 {
-       if(_app_info_init)
+       if(_app_info_init && argc && argv)
        {
-               _argc = _argc;
-               _argv = _argv;
+               *argc = _argc;
+               *argv = _argv;
+
                return 1;
        }
        return 0;
 }
 
+#define MIN(a,b)  ((a) < (b) ? (a) : (b))
+
+int appinfo_update_submode_execname_and_appid(const char* execname)
+{
+       if (execname == NULL)
+       {
+               return 0;
+       }
+
+       const size_t max_len = MAX_APPID - MAX_OSP_PKGID - 1;
+       const size_t size = MIN(strlen(execname), max_len);
+       strncpy(__appid + MAX_OSP_PKGID + 1, execname, size);
+       __appid[size + MAX_OSP_PKGID + 1] = '\0';
+
+       return 1;
+}
+
 #ifdef __cplusplus
 }
 #endif
similarity index 92%
rename from include/appinfo.h
rename to appinfo/appinfo.h
index 232dd64..70c2a1c 100644 (file)
@@ -38,15 +38,6 @@ typedef enum
        APP_INFO_VERSION_MAX = 65535,
 } app_info_version_e;
 
-const char* app_info_version_str[] = {
-       "1.0",
-       "1.02",
-       "1.1",
-       "2.0",
-       "2.1",
-       "2.2",
-       "3.0"
-};
 
 /**
  * @brief      Enumerations of error code
@@ -95,6 +86,14 @@ int appinfo_set_api_version(app_info_version_e ver);
 const char* appinfo_get_api_str_by_version(int ver);
 
 /**
+ * @brief      Returns the API version by given version string
+ *
+ * @param[in]  ver_str Given version string
+ * @return     the API version
+ */
+app_info_version_e appinfo_get_api_version_from_str(const char* ver_str);
+
+/**
  * @brief      Returns whether the application is compat mode or not
  *
  * @return     @c 1 for compat mode, @c 0 otherwise
@@ -143,6 +142,8 @@ int appinfo_set_argv(int argc, char** argv);
 
 int appinfo_get_argv(int* argc, char*** argv);
 
+int appinfo_update_submode_execname_and_appid(const char* execname);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/appinfo/appinfo.pc.in b/appinfo/appinfo.pc.in
new file mode 100644 (file)
index 0000000..d83c28c
--- /dev/null
@@ -0,0 +1,13 @@
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=/usr/lib/osp
+includedir=/usr/include/osp
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
old mode 100755 (executable)
new mode 100644 (file)
index ecb6552..a19c713
@@ -1,6 +1,6 @@
 Name:          osp-env-config
 Summary:       osp application environment cofiguration serivce
-Version:       1.2.2.0
+Version:       1.2.2.1
 Release:       2
 Group:         System/Libraries
 License:       Apache-2.0
@@ -10,10 +10,19 @@ BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(vconf)
 
 Requires(post): coreutils
+Requires(post): /sbin/ldconfig
 
 %description
 osp application environment cofiguration serivce
 
+%package devel
+Summary:       osp application environment cofiguration serivce (devel)
+Group:         System/Libraries
+Requires:      %{name} = %{version}-%{release}
+
+%description devel
+osp application environment cofiguration serivce (devel)
+
 %prep
 %setup -q
 
@@ -44,4 +53,8 @@ cp %{_builddir}/%{name}-%{version}/LICENSE.APLv2  %{buildroot}/usr/share/license
 %manifest osp-env-config.manifest
 /usr/share/license/%{name}
 %{_libdir}/*.so*
+%{_libdir}/osp/libappinfo.so*
 
+%files devel
+%{_includedir}/osp/*.h
+%{_libdir}/pkgconfig/appinfo.pc