Providing appinfo API separately
authorYong Song <yong.song@samsung.com>
Tue, 6 Aug 2013 07:00:53 +0000 (16:00 +0900)
committerYong Song <yong.song@samsung.com>
Tue, 6 Aug 2013 08:24:48 +0000 (17:24 +0900)
Change-Id: Ic69bb7425c354b354d3618ca58e38527eddc554a

CMakeLists.txt
appinfo/CMakeLists.txt [new file with mode: 0644]
appinfo/appinfo.c [new file with mode: 0644]
include/appinfo.h [new file with mode: 0644]

index 628bedf..0185e08 100644 (file)
@@ -11,6 +11,8 @@ SET (${this_target}_SOURCE_FILES
        ${CMAKE_CURRENT_SOURCE_DIR}/osp-env-config.c
        )
        
+ADD_SUBDIRECTORY(appinfo)
+
 ADD_LIBRARY(${this_target} SHARED ${${this_target}_SOURCE_FILES})
 
 SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
diff --git a/appinfo/CMakeLists.txt b/appinfo/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e9ee8a8
--- /dev/null
@@ -0,0 +1,32 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+SET(this_target osp-appinfo)
+
+SET(VERSION 0.1.1)
+SET(VERSION_MAJOR 0)
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(
+       /usr/include/dlog
+)
+
+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})
+
+SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+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")
+
+INSTALL(TARGETS ${this_target} DESTINATION ${LIB_INSTALL_DIR}
+                               PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
+               GROUP_EXECUTE GROUP_READ
+               WORLD_EXECUTE WORLD_READ)
+
diff --git a/appinfo/appinfo.c b/appinfo/appinfo.c
new file mode 100644 (file)
index 0000000..7ef3de5
--- /dev/null
@@ -0,0 +1,349 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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 <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <dlog.h>
+
+#include "appinfo.h"
+
+#undef LOG_TAG
+#define LOG_TAG "APPINFO"
+
+#ifdef _SECURE_LOG
+#define _SECURE_LOGI LOGI
+#define _SECURE_LOGE LOGE
+#else
+#define _SECURE_LOGI(...)
+#define _SECURE_LOGE(...)
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+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;
+
+#define MAX_OSP_PKGID 10
+#define MAX_APPID 256
+
+static char __pkgid[MAX_OSP_PKGID+1]={'\0',};
+static char __appid[MAX_APPID]={'\0',};
+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
+ *
+ * @param[in] appid    The application id to initialize
+ * @param[in] is_invalid_appid @c 1 for invalid appid compatibility mode, @c 0 otherwise
+ * @return     0 on success, otherwise a negative error value
+ * @retval     APP_INFO_ERROR_NONE Succesful
+ * @retval     APP_INFO_ERROR_INVALID_ARG The appid is invalid
+ * @remarks    It initialize the platform API version to APP_INFO_VERSION_3_0 and compat mode 0.
+ */
+int
+appinfo_init(const char* appid, int is_invalid_appid)
+{
+       if(!appid && strlen(appid) >= sizeof(__appid))
+       {
+               return APP_INFO_ERROR_INVALID_ARG;
+       }
+
+       strncpy(__appid, appid, strlen(appid));
+       if (is_invalid_appid)
+       {
+               // SLP-style old appid
+               _pkgid = __appid;
+               _appid = __appid;
+               _execname = __appid;
+       }
+       else
+       {
+               if(strlen(appid) < sizeof(MAX_OSP_PKGID))
+               {
+                       return APP_INFO_ERROR_INVALID_ARG;
+               }
+               // proper OSP or Web appid
+               strncpy(__pkgid, appid, MAX_OSP_PKGID);
+               _appid = __appid;
+               _pkgid = __pkgid;
+               _execname = __appid+(MAX_OSP_PKGID+1);
+       }
+
+       _current_api_ver = APP_INFO_VERSION_2_2;
+       _compat_mode = 0;
+       _app_info_init = 1;
+
+       return APP_INFO_ERROR_NONE;
+}
+
+/**
+ * @brief      Returns the API version
+ *
+ * @return     app_info_version_e value
+ */
+int
+appinfo_get_api_version(void)
+{
+       return _current_api_ver;
+}
+
+/**
+ * @brief      Sets the API version for the current process
+ *
+ * @param[in]  ver Given API version
+ * @return     0 on success, otherwise a negative error value
+ * @retval     APP_INFO_ERROR_NONE Succesful
+ */
+
+int
+appinfo_set_api_version(app_info_version_e ver)
+{
+       if (ver < 0)
+       {
+               return APP_INFO_ERROR_INVALID_ARG;
+       }
+
+       _current_api_ver = ver;
+
+       return 0;
+}
+
+/*
+int
+appinfo_set_api_version(int ver)
+{
+       app_info_version_e temp_ver;
+       temp_ver = __get_api_version_from_str(appinfo_get_api_str_by_version(ver));
+
+       if( temp_ver == APP_INFO_VERSION_INVALID)
+       {
+               return APP_INFO_ERROR_INVALID_ARG;
+       }
+       else
+       {
+               _current_api_ver = temp_ver;
+               return APP_INFO_ERROR_NONE;
+       }
+}
+*/
+
+/**
+ * @brief      Returns the API version string by given API version
+ *
+ * @param[in]  ver Given API version
+ * @return     the API version string by the given version
+ * @remakr     If wrong API version, return NULL
+ */
+const char*
+appinfo_get_api_str_by_version(int ver)
+{
+       switch (ver) {
+       case APP_INFO_VERSION_1_0 :
+               return "1.0";
+       case APP_INFO_VERSION_1_0_2 :
+               return "1.0.2";
+       case APP_INFO_VERSION_1_1 :
+               return "1.1";
+       case APP_INFO_VERSION_1_2 :
+               return "1.2";
+       case APP_INFO_VERSION_2_0 :
+               return "2.0";
+       case APP_INFO_VERSION_2_1 :
+               return "2.1";
+        case APP_INFO_VERSION_2_2 :
+               return "2.2";
+       case APP_INFO_VERSION_3_0 :
+               return "3.0";
+       default :
+               return NULL;
+       }
+}
+
+/**
+ * @brief      Returns whether the application is compat mode or not
+ *
+ * @return     @c 1 for compat mode, @c 0 otherwise
+ */
+int
+appinfo_is_compat(void)
+{
+       return _compat_mode;
+}
+
+/**
+ * @brief      Sets the application compat mode
+ *
+ * @param[in]  the compatibility mode
+ * @return     0 on success, otherwise a negative error value
+ * @retval     APP_INFO_ERROR_NONE Succesful
+ * @retval     APP_INFO_ERROR_INVALID_ARG compat should be either @c 0 or @c 1.
+ */
+int
+appinfo_set_compat(int compat)
+{
+       if(compat == 0 || compat == 1)
+       {
+               _compat_mode = compat;
+               return APP_INFO_ERROR_NONE;
+       }
+       return APP_INFO_ERROR_INVALID_ARG;
+
+}
+
+/**
+ * @brief      Returns the appid for the application
+ *
+ * @retval     application ID if valid, @c NULL otherwise
+ */
+const char*
+appinfo_get_appid(void)
+{
+       if(_app_info_init)
+       {
+               return _appid;
+       }
+
+       return NULL;
+}
+
+/**
+ * @brief       Returns the exec name for the application
+ *
+ * @retval      application exec name if valid, @c NULL otherwise
+ */
+const char*
+appinfo_get_execname(void)
+{
+       if(_app_info_init)
+       {
+               return _execname;
+       }
+
+       return NULL;
+}
+
+
+/**
+ * @brief      Returns the packageid for the application
+ *
+ * @retval     package ID if valid, @c NULL otherwise
+ */
+const char*
+appinfo_get_packageid(void)
+{
+       if(_app_info_init)
+       {
+               return _pkgid;
+       }
+
+       return NULL;
+}
+
+/**
+ * @brief      Returns whether the appinfo is initialized or not
+ *
+ * @return     @c 1 if initialized, @c 0 otherwise
+ */
+int
+appinfo_is_initialized(void)
+{
+       return _app_info_init;
+}
+
+int
+appinfo_set_argv(int argc, char** argv)
+{
+       if(argc > 0 && !argv)
+       {
+               _argc = argc;
+               _argv = argv;
+               return 1;
+       }
+       return 0;
+}
+
+int appinfo_get_argv(int* argc, char*** argv)
+{
+       if(_app_info_init)
+       {
+               _argc = _argc;
+               _argv = _argv;
+               return 1;
+       }
+       return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/include/appinfo.h b/include/appinfo.h
new file mode 100644 (file)
index 0000000..232dd64
--- /dev/null
@@ -0,0 +1,151 @@
+//
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// 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 _APP_INFO_H_
+#define _APP_INFO_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief      Enumeration of API version
+ */
+typedef enum
+{
+       APP_INFO_VERSION_INVALID = -1,
+       APP_INFO_VERSION_1_0 = 100,
+       APP_INFO_VERSION_1_0_2 = 102,
+       APP_INFO_VERSION_1_1 = 110,
+       APP_INFO_VERSION_1_2 = 120,
+       APP_INFO_VERSION_2_0 = 200,
+       APP_INFO_VERSION_2_1 = 210,
+       APP_INFO_VERSION_2_2 = 220,
+       APP_INFO_VERSION_3_0 = 300,
+       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
+ */
+typedef enum
+{
+       APP_INFO_ERROR_NONE = 0,        /**< Successful */
+       APP_INFO_ERROR_INVALID_ARG = -1,        /**< Invalid argument */
+} app_info_error_e;
+
+/**
+ * @brief      Initializes the appinfo structure
+ *
+ * @param[in] appid    The application id to initialize
+ * @param[in] is_invalid_appid @c 1 for invalid appid compatibility mode, @c 0 otherwise
+ * @return     0 on success, otherwise a negative error value
+ * @retval     APP_INFO_ERROR_NONE Succesful
+ * @retval     APP_INFO_ERROR_INVALID_ARG The appid is invalid
+ * @remarks    It initialize the platform API version to APP_INFO_VERSION_3_0 and compat mode 0.
+ */
+int appinfo_init(const char* appid, int is_invalid_appid);
+
+/**
+ * @brief      Returns the API version
+ *
+ * @return     app_info_version_e value
+ */
+int appinfo_get_api_version(void);
+
+/**
+ * @brief      Sets the API version for the current process
+ *
+ * @param[in]  ver Given API version
+ * @return     0 on success, otherwise a negative error value
+ * @retval     APP_INFO_ERROR_NONE Succesful
+ */
+//int appinfo_set_api_version(int ver);
+int appinfo_set_api_version(app_info_version_e ver);
+
+/**
+ * @brief      Returns the API version string by given API version
+ *
+ * @param[in]  ver Given API version
+ * @return     the API version string by the given version
+ */
+const char* appinfo_get_api_str_by_version(int ver);
+
+/**
+ * @brief      Returns whether the application is compat mode or not
+ *
+ * @return     @c 1 for compat mode, @c 0 otherwise
+ */
+int appinfo_is_compat(void);
+
+/**
+ * @brief      Sets the application compat mode
+ *
+ * @param[in]  the compatibility mode
+ * @return     0 on success, otherwise a negative error value
+ * @retval     APP_INFO_ERROR_NONE Succesful
+ * @retval     APP_INFO_ERROR_INVALID_ARG compat should be either @c 0 or @c 1.
+ */
+int appinfo_set_compat(int compat);
+
+/**
+ * @brief      Returns the appid for the application
+ *
+ * @retval     application ID if valid, @c NULL otherwise
+ */
+const char* appinfo_get_appid(void);
+
+/**
+ * @brief      Returns the exec name for the application
+ *
+ * @retval     application exec name if valid, @c NULL otherwise
+ */
+const char* appinfo_get_execname(void);
+
+/**
+ * @brief      Returns the packageid for the application
+ *
+ * @retval     package ID if valid, @c NULL otherwise
+ */
+const char* appinfo_get_packageid(void);
+
+/**
+ * @brief      Returns whether the appinfo is initialized or not
+ *
+ * @return     @c 1 if initialized, @c 0 otherwise
+ */
+int appinfo_is_initialized(void);
+
+int appinfo_set_argv(int argc, char** argv);
+
+int appinfo_get_argv(int* argc, char*** argv);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //_APP_INFO_H_
+