Separate app-control, alarm, preference, and common api.
authorJiwoong Im <jiwoong.im@samsung.com>
Fri, 17 Apr 2015 07:32:59 +0000 (16:32 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Fri, 17 Apr 2015 07:38:14 +0000 (16:38 +0900)
JIRA ticket : TC-2497

- In tizen 2.3 release, capi-appfw-application package was separated by
function. (app-control, alarm, preference, app-common).
- To apply this change with no build break, temporarily add all separated
package to pc_requires in capi-appfw-application.pc file

Change-Id: Id92d5a9abbfd6ff478e0469da5596b4967444ca8
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
26 files changed:
CMakeLists.txt
alarm/CMakeLists.txt [new file with mode: 0644]
alarm/alarm.c [new file with mode: 0755]
app_common/CMakeLists.txt [new file with mode: 0644]
app_common/app_error.c [new file with mode: 0755]
app_common/app_event.c [new file with mode: 0755]
app_common/app_finalizer.c [new file with mode: 0755]
app_common/app_package.c [new file with mode: 0755]
app_common/app_path.c [new file with mode: 0755]
app_control/CMakeLists.txt [new file with mode: 0644]
app_control/app_control.c [new file with mode: 0755]
capi-appfw-application.pc.in [deleted file]
capi-appfw-module.pc.in [new file with mode: 0644]
include/app.h
include/app_common.h [new file with mode: 0644]
packaging/capi-appfw-application.spec
preference/CMakeLists.txt [new file with mode: 0644]
preference/preference.c [new file with mode: 0755]
src/alarm.c [deleted file]
src/app_control.c [deleted file]
src/app_error.c [deleted file]
src/app_event.c [deleted file]
src/app_finalizer.c [deleted file]
src/app_package.c [deleted file]
src/app_path.c [deleted file]
src/preference.c [deleted file]

index 2037196184dbbc067eb673ff7d7ab3f0c31a8716..c201a07417efe879bf39881ca9f62e43cbb79272 100644 (file)
@@ -10,7 +10,7 @@ SET(INC_DIR include)
 INCLUDE_DIRECTORIES(${INC_DIR})
 
 SET(requires "dlog bundle appcore-common appcore-efl aul ail appsvc elementary capi-base-common alarm-service sqlite3 libtzplatform-config")
-SET(pc_requires "capi-base-common vconf-internal-keys")
+SET(pc_requires "capi-base-common vconf-internal-keys capi-appfw-alarm capi-appfw-app-control capi-appfw-app-common capi-appfw-preference")
 
 INCLUDE(FindPkgConfig)
 pkg_check_modules(${fw_name} REQUIRED ${requires})
@@ -33,7 +33,12 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
 aux_source_directory(src SOURCES)
 ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
 
-TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
+ADD_SUBDIRECTORY(app_control)
+ADD_SUBDIRECTORY(app_common)
+ADD_SUBDIRECTORY(alarm)
+ADD_SUBDIRECTORY(preference)
+
+TARGET_LINK_LIBRARIES(${fw_name} capi-appfw-app-control capi-appfw-app-common capi-appfw-alarm capi-appfw-preference ${${fw_name}_LDFLAGS})
 
 SET_TARGET_PROPERTIES(${fw_name}
      PROPERTIES
@@ -55,7 +60,7 @@ SET(PC_REQUIRED ${pc_requires})
 SET(PC_LDFLAGS -l${fw_name})
 
 CONFIGURE_FILE(
-    capi-appfw-application.pc.in
+    capi-appfw-module.pc.in
     ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc
     @ONLY
 )
diff --git a/alarm/CMakeLists.txt b/alarm/CMakeLists.txt
new file mode 100644 (file)
index 0000000..f989184
--- /dev/null
@@ -0,0 +1,65 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-appfw-alarm")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR ${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+SET(requires "dlog bundle alarm-service capi-base-common")
+SET(pc_requires "capi-base-common capi-appfw-app-control")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${requires})
+FOREACH(flag ${${fw_name}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+IF("${ARCH}" STREQUAL "arm")
+    ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DSLP_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
+
+add_library(${fw_name} SHARED
+               alarm.c
+               )
+
+TARGET_LINK_LIBRARIES(${fw_name} capi-appfw-app-control ${${fw_name}_LDFLAGS})
+
+SET_TARGET_PROPERTIES(${fw_name}
+     PROPERTIES
+     VERSION ${FULLVER}
+     SOVERSION ${MAJORVER}
+     CLEAN_DIRECT_OUTPUT 1
+)
+
+INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(
+        DIRECTORY ${INC_DIR}/ DESTINATION include/appfw
+        FILES_MATCHING
+        PATTERN "*_private.h" EXCLUDE
+        PATTERN "${INC_DIR}/*.h"
+        )
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${pc_requires})
+SET(PC_LDFLAGS -l${fw_name})
+
+CONFIGURE_FILE(
+    ${CMAKE_SOURCE_DIR}/capi-appfw-module.pc.in
+    ${CMAKE_SOURCE_DIR}/${fw_name}.pc
+    @ONLY
+)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+
diff --git a/alarm/alarm.c b/alarm/alarm.c
new file mode 100755 (executable)
index 0000000..374fd04
--- /dev/null
@@ -0,0 +1,492 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+
+#include <aul.h>
+#include <alarm.h>
+#include <dlog.h>
+
+#include <app_private.h>
+#include <app_alarm.h>
+#include <app_control_internal.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "CAPI_APPFW_APPLICATION_ALARM"
+
+typedef struct {
+       alarm_registered_alarm_cb cb;
+       void* user_data;
+       bool* foreach_break;
+} alarm_foreach_item_cb_context;
+
+static int alarm_registered_alarm_cb_broker(int alarm_id, void *user_data)
+{
+       alarm_foreach_item_cb_context* foreach_cb_context = NULL;
+
+       if (user_data == NULL)
+       {
+               return 0;
+       }
+
+       foreach_cb_context = (alarm_foreach_item_cb_context*)user_data;
+
+       if (foreach_cb_context != NULL && *(foreach_cb_context->foreach_break) == false)
+       {
+               if (foreach_cb_context->cb(alarm_id, foreach_cb_context->user_data) == false)
+               {
+                       *(foreach_cb_context->foreach_break) = true;
+               }
+       }
+
+       return 0;
+}
+
+static int convert_error_code_to_alarm(const char* function, alarm_error_t alarm_error)
+{
+       switch(alarm_error)
+       {
+       case ERR_ALARM_INVALID_PARAM:
+       case ERR_ALARM_INVALID_REPEAT:
+               LOGE("[%s] INVALID_PARAMETER(0x%08x)", function, ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+               break;
+
+       case ERR_ALARM_INVALID_ID:
+               LOGE("[%s] INVALID_PARAMETER(0x%08x)", function, ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+               break;
+
+       case ERR_ALARM_INVALID_TIME:
+               LOGE("[%s] INVALID_TIME(0x%08x)", function, ALARM_ERROR_INVALID_TIME);
+               return ALARM_ERROR_INVALID_TIME;
+               break;
+
+       case ERR_ALARM_INVALID_DATE:
+               LOGE("[%s] INVALID_DATE(0x%08x)", function, ALARM_ERROR_INVALID_DATE);
+               return ALARM_ERROR_INVALID_DATE;
+               break;
+
+       case ERR_ALARM_NO_SERVICE_NAME:
+               LOGE("[%s] INVALID_PARAMETER(0x%08x)", function, ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+               break;
+
+       case ERR_ALARM_SYSTEM_FAIL:
+               LOGE("[%s] CONNECTION_FAIL(0x%08x)", function, ALARM_ERROR_CONNECTION_FAIL);
+               return ALARM_ERROR_CONNECTION_FAIL;
+               break;
+
+       case ALARMMGR_RESULT_SUCCESS:
+               return ALARM_ERROR_NONE;
+               break;
+
+       default:
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+}
+
+static int _remove_alarm_cb(alarm_id_t alarm_id, void* user_param)
+{
+       return alarmmgr_remove_alarm(alarm_id);
+}
+
+int alarm_get_scheduled_date(int alarm_id, struct tm* date)
+{
+       alarm_error_t result;
+       time_t due_time = 0;
+
+       if (date == NULL)
+       {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       result = alarmmgr_get_next_duetime(alarm_id, &due_time);
+       if (result != ALARMMGR_RESULT_SUCCESS)
+       {
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       localtime_r(&due_time, date);
+
+       return ALARM_ERROR_NONE;
+
+}
+
+int alarm_get_scheduled_period(int alarm_id, int* period)
+{
+       alarm_error_t result;
+       alarm_entry_t *entry = NULL;
+       alarm_repeat_mode_t mode;
+       int value;
+
+       if (period == NULL)
+       {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       entry = alarmmgr_create_alarm();
+
+       result = alarmmgr_get_info(alarm_id, entry);
+       if (result != ALARMMGR_RESULT_SUCCESS)
+       {
+               if (entry != NULL)
+               {
+                       alarmmgr_free_alarm(entry);
+               }
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       result = alarmmgr_get_repeat_mode(entry, &mode, &value);
+       if (result != ALARMMGR_RESULT_SUCCESS)
+       {
+               if (entry != NULL)
+               {
+                       alarmmgr_free_alarm(entry);
+               }
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       result = alarmmgr_free_alarm(entry);
+       if(result != ALARMMGR_RESULT_SUCCESS)
+       {
+               if (entry != NULL)
+               {
+                       alarmmgr_free_alarm(entry);
+               }
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       (*period) = value;
+
+       return ALARM_ERROR_NONE;
+
+}
+
+int alarm_schedule_after_delay(app_control_h app_control, int delay, int period, int *alarm_id)
+{
+       bundle *bundle_data;
+       int result = 0;
+
+       if (app_control == NULL)
+       {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE)
+       {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, delay, period, bundle_data, alarm_id);
+
+       return  convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_schedule_at_date(app_control_h app_control, struct tm *date, int period_in_second, int *alarm_id)
+{
+       alarm_date_t internal_time;
+       alarm_entry_t* alarm_info;
+       bundle *bundle_data;
+       int result;
+
+       if (app_control == NULL || date == NULL)
+       {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE)
+       {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       alarm_info = alarmmgr_create_alarm();
+
+       internal_time.year = date->tm_year + 1900;
+       internal_time.month = date->tm_mon +1;
+       internal_time.day = date->tm_mday;
+
+       internal_time.hour = date->tm_hour;
+       internal_time.min = date->tm_min;
+       internal_time.sec = date->tm_sec;
+
+       result = alarmmgr_set_time(alarm_info,internal_time);
+
+       if (result < 0)
+       {
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+
+       if (period_in_second > 0)
+       {
+               result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_REPEAT, period_in_second);
+       }
+       else
+       {
+               result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, period_in_second);
+       }
+
+       if (result < 0)
+       {
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
+
+       if (result < 0)
+       {
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id);
+
+       if (result < 0)
+       {
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       alarmmgr_free_alarm(alarm_info);
+       return ALARM_ERROR_NONE;
+}
+
+int alarm_cancel(int alarm_id)
+{
+       int result;
+
+       result = alarmmgr_remove_alarm(alarm_id);
+
+       return convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_cancel_all()
+{
+       int result;
+
+       result = alarmmgr_enum_alarm_ids( _remove_alarm_cb, NULL);
+
+       return convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_foreach_registered_alarm(alarm_registered_alarm_cb callback, void* user_data)
+{
+       int result;
+       bool foreach_break = false;
+
+       if (callback == NULL)
+       {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       //alarm_registered_alarm_cb_broker
+       alarm_foreach_item_cb_context foreach_cb_context = {
+               .cb = callback,
+               .user_data = user_data,
+               .foreach_break = &foreach_break
+       };
+
+       result = alarmmgr_enum_alarm_ids(alarm_registered_alarm_cb_broker, &foreach_cb_context);
+
+       return convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_get_current_time(struct tm* date)
+{
+       time_t now;
+
+       if (date == NULL)
+       {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       time(&now);
+       localtime_r(&now, date);
+       return ALARM_ERROR_NONE;
+}
+
+
+int alarm_schedule_with_recurrence_week_flag(app_control_h app_control, struct tm *date, int week_flag,int *alarm_id)
+{
+       alarm_date_t internal_time;
+       alarm_entry_t* alarm_info;
+       bundle *bundle_data;
+       int result;
+
+       if (app_control == NULL || date == NULL)
+       {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE)
+       {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       alarm_info = alarmmgr_create_alarm();
+
+       internal_time.year = date->tm_year + 1900;
+       internal_time.month = date->tm_mon +1;
+       internal_time.day = date->tm_mday;
+
+       internal_time.hour = date->tm_hour;
+       internal_time.min = date->tm_min;
+       internal_time.sec = date->tm_sec;
+
+       result = alarmmgr_set_time(alarm_info,internal_time);
+
+       if (result < 0)
+       {
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       if (week_flag > 0)
+       {
+               result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_WEEKLY, week_flag);
+       }
+
+       if (result < 0)
+       {
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
+
+       if (result < 0)
+       {
+               alarmmgr_free_alarm(alarm_info);
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id);
+
+       alarmmgr_free_alarm(alarm_info);
+       return convert_error_code_to_alarm(__FUNCTION__, result);
+}
+
+int alarm_get_scheduled_recurrence_week_flag(int alarm_id, int *week_flag)
+{
+       alarm_error_t result;
+       alarm_entry_t *entry = NULL;
+       alarm_repeat_mode_t mode;
+       int value;
+
+       if(week_flag == NULL)
+       {
+               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       entry = alarmmgr_create_alarm();
+
+       result = alarmmgr_get_info(alarm_id, entry);
+       if(result != ALARMMGR_RESULT_SUCCESS)
+       {
+               if (entry != NULL)
+               {
+                       alarmmgr_free_alarm(entry);
+               }
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       result = alarmmgr_get_repeat_mode(entry, &mode, &value);
+
+       if(mode != ALARM_REPEAT_MODE_WEEKLY)
+       {
+               if (entry != NULL)
+               {
+                       alarmmgr_free_alarm(entry);
+               }
+               return ALARM_ERROR_INVALID_PARAMETER;
+       }
+
+       if(result != ALARMMGR_RESULT_SUCCESS)
+       {
+               if (entry != NULL)
+               {
+                       alarmmgr_free_alarm(entry);
+               }
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       result = alarmmgr_free_alarm(entry);
+       if(result != ALARMMGR_RESULT_SUCCESS)
+       {
+               if (entry != NULL)
+               {
+                       alarmmgr_free_alarm(entry);
+               }
+               return convert_error_code_to_alarm(__FUNCTION__, result);
+       }
+
+       (*week_flag) = value;
+
+       return ALARM_ERROR_NONE;
+}
+
+int alarm_get_app_control(int alarm_id, app_control_h *app_control)
+{
+    bundle *b = NULL;
+    int error_code = 0;
+
+    b = alarmmgr_get_alarm_appsvc_info(alarm_id, &error_code);
+
+    if(error_code != ALARMMGR_RESULT_SUCCESS)
+    {
+        return convert_error_code_to_alarm(__FUNCTION__, error_code);
+    }
+
+    if(b == NULL)
+    {
+        return ALARM_ERROR_INVALID_PARAMETER;
+    }
+
+    error_code = app_control_create_request(b, app_control);
+
+    if(error_code != APP_CONTROL_ERROR_NONE)
+    {
+        return ALARM_ERROR_OUT_OF_MEMORY;
+    }
+
+    bundle_free(b);
+
+    return ALARM_ERROR_NONE;
+
+}
diff --git a/app_common/CMakeLists.txt b/app_common/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3f65c0d
--- /dev/null
@@ -0,0 +1,69 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-appfw-app-common")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR ${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+SET(requires "dlog aul ail capi-base-common appcore-common libtzplatform-config")
+SET(pc_requires "capi-base-common")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${requires})
+FOREACH(flag ${${fw_name}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC ")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -Wall -Werror")
+
+IF("${ARCH}" STREQUAL "arm")
+    ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DSLP_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
+
+add_library(${fw_name} SHARED
+               app_package.c
+               app_path.c
+               app_error.c
+               app_finalizer.c
+               app_event.c
+               )
+
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
+
+SET_TARGET_PROPERTIES(${fw_name}
+     PROPERTIES
+     VERSION ${FULLVER}
+     SOVERSION ${MAJORVER}
+     CLEAN_DIRECT_OUTPUT 1
+)
+
+INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(
+        DIRECTORY ${INC_DIR}/ DESTINATION include/appfw
+        FILES_MATCHING
+        PATTERN "*_private.h" EXCLUDE
+        PATTERN "${INC_DIR}/*.h"
+        )
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${pc_requires})
+SET(PC_LDFLAGS -l${fw_name})
+
+CONFIGURE_FILE(
+    ${CMAKE_SOURCE_DIR}/capi-appfw-module.pc.in
+    ${CMAKE_SOURCE_DIR}/${fw_name}.pc
+    @ONLY
+)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+
diff --git a/app_common/app_error.c b/app_common/app_error.c
new file mode 100755 (executable)
index 0000000..b3c8c0c
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libintl.h>
+
+#include <dlog.h>
+
+#include <app_private.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "CAPI_APPFW_APPLICATION"
+
+static const char* app_error_to_string(app_error_e error)
+{
+       switch (error)
+       {
+       case APP_ERROR_NONE:
+               return "NONE";
+
+       case APP_ERROR_INVALID_PARAMETER:
+               return "INVALID_PARAMETER";
+
+       case APP_ERROR_OUT_OF_MEMORY:
+               return "OUT_OF_MEMORY";
+
+       case APP_ERROR_INVALID_CONTEXT:
+               return "INVALID_CONTEXT";
+
+       case APP_ERROR_NO_SUCH_FILE:
+               return "NO_SUCH_FILE";
+
+       case APP_ERROR_ALREADY_RUNNING:
+               return "ALREADY_RUNNING";
+
+       default :
+               return "UNKNOWN";
+       }
+}
+
+int app_error(app_error_e error, const char* function, const char *description)
+{
+       if (description)
+       {
+               LOGE("[%s] %s(0x%08x) : %s", function, app_error_to_string(error), error, description); 
+       }
+       else
+       {
+               LOGE("[%s] %s(0x%08x)", function, app_error_to_string(error), error);   
+       }
+
+       return error;
+}
diff --git a/app_common/app_event.c b/app_common/app_event.c
new file mode 100755 (executable)
index 0000000..4a72e01
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2011 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 <string.h>
+
+#include <vconf-internal-keys.h>
+#include <app_common.h>
+#include <app_private.h>
+
+app_device_orientation_e app_convert_appcore_rm(enum appcore_rm rm)
+{
+       app_device_orientation_e dev_orientation;
+
+       switch (rm)
+       {
+       case APPCORE_RM_PORTRAIT_NORMAL:
+               dev_orientation = APP_DEVICE_ORIENTATION_0;
+               break;
+
+       case APPCORE_RM_PORTRAIT_REVERSE:
+               dev_orientation = APP_DEVICE_ORIENTATION_180;
+               break;
+
+       case APPCORE_RM_LANDSCAPE_NORMAL:
+               dev_orientation = APP_DEVICE_ORIENTATION_270;
+               break;
+
+       case APPCORE_RM_LANDSCAPE_REVERSE:
+               dev_orientation = APP_DEVICE_ORIENTATION_90;
+               break;
+
+       default:
+               dev_orientation = APP_DEVICE_ORIENTATION_0;
+               break;
+       }
+
+       return dev_orientation;
+}
+
+static int _app_convert_low_memory(void *val)
+{
+       switch (*(int *)val) {
+       case VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL:
+               return APP_EVENT_LOW_MEMORY_NORMAL;
+       case VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING:
+               return APP_EVENT_LOW_MEMORY_SOFT_WARNING;
+       case VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING:
+               return APP_EVENT_LOW_MEMORY_HARD_WARNING;
+       default:
+               return -1;
+       }
+}
+
+static int _app_convert_low_battery(void *val)
+{
+       switch (*(int *)val) {
+       case VCONFKEY_SYSMAN_BAT_POWER_OFF:
+               return APP_EVENT_LOW_BATTERY_POWER_OFF;
+       case VCONFKEY_SYSMAN_BAT_CRITICAL_LOW:
+               return APP_EVENT_LOW_BATTERY_CRITICAL_LOW;
+       default:
+               return -1;
+       }
+}
+
+int app_event_get_low_memory_status(app_event_info_h event_info, app_event_low_memory_status_e *status)
+{
+       int ret;
+
+       if (event_info == NULL || status == NULL)
+               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
+
+       if (event_info->type != APP_EVENT_LOW_MEMORY)
+               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "event type mismatching");
+
+       ret = _app_convert_low_memory(event_info->value);
+       if (ret < 0)
+               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "invalid event info");
+
+       *status = ret;
+
+       return APP_ERROR_NONE;
+}
+
+int app_event_get_low_battery_status(app_event_info_h event_info, app_event_low_battery_status_e *status)
+{
+       int ret;
+
+       if (event_info == NULL || status == NULL)
+               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
+
+       if (event_info->type != APP_EVENT_LOW_BATTERY)
+               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "event type mismatching");
+
+       ret = _app_convert_low_battery(event_info->value);
+       if (ret < 0)
+               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "invalid event info");
+
+       *status = ret;
+
+       return APP_ERROR_NONE;
+}
+
+int app_event_get_language(app_event_info_h event_info, char **lang)
+{
+       if (event_info == NULL || lang == NULL)
+               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
+
+       if (event_info->type != APP_EVENT_LANGUAGE_CHANGED)
+               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
+
+       *lang = strdup(event_info->value);
+
+       return APP_ERROR_NONE;
+}
+
+int app_event_get_region_format(app_event_info_h event_info, char **region)
+{
+       if (event_info == NULL || region == NULL)
+               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
+
+       if (event_info->type != APP_EVENT_REGION_FORMAT_CHANGED)
+               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
+
+       *region = strdup(event_info->value);
+
+       return APP_ERROR_NONE;
+}
+
+int app_event_get_device_orientation(app_event_info_h event_info, app_device_orientation_e *orientation)
+{
+       if (event_info == NULL || orientation == NULL)
+               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
+
+       if (event_info->type != APP_EVENT_DEVICE_ORIENTATION_CHANGED)
+               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
+
+       *orientation = app_convert_appcore_rm(*(enum appcore_rm *)(event_info->value));
+
+       return APP_ERROR_NONE;
+}
+
diff --git a/app_common/app_finalizer.c b/app_common/app_finalizer.c
new file mode 100755 (executable)
index 0000000..ae0b41c
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libintl.h>
+
+#include <app_private.h>
+
+typedef struct _app_finalizer_s_ {
+       app_finalizer_cb callback;
+       void *data;
+       struct _app_finalizer_s_ *next;
+} app_finalizer_s;
+
+typedef app_finalizer_s *app_finalizer_h;
+
+static app_finalizer_s finalizer_head = {
+       .callback = NULL,
+       .data = NULL,
+       .next = NULL
+};
+
+int app_finalizer_add(app_finalizer_cb callback, void *data)
+{
+       app_finalizer_h finalizer_tail = &finalizer_head;
+       app_finalizer_h finalizer_new;
+
+       finalizer_new = malloc(sizeof(app_finalizer_s));
+
+       if (finalizer_new == NULL)
+       {
+               return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+       }
+
+       finalizer_new->callback = callback;
+       finalizer_new->data = data;
+       finalizer_new->next = NULL;
+
+       while (finalizer_tail->next)
+       {
+               finalizer_tail = finalizer_tail->next;
+       }
+       
+       finalizer_tail->next = finalizer_new;
+
+       return APP_ERROR_NONE;
+}
+
+int app_finalizer_remove(app_finalizer_cb callback)
+{
+       app_finalizer_h finalizer_node = &finalizer_head;
+
+       while (finalizer_node->next)
+       {
+               if (finalizer_node->next->callback == callback)
+               {
+                       app_finalizer_h removed_node = finalizer_node->next;
+                       finalizer_node->next = removed_node->next;
+                       free(removed_node);
+                       return APP_ERROR_NONE;
+               }
+
+               finalizer_node = finalizer_node->next;
+       }       
+
+       return APP_ERROR_INVALID_PARAMETER;
+}
+
+void app_finalizer_execute(void)
+{
+       app_finalizer_h finalizer_node = &finalizer_head;
+       app_finalizer_h finalizer_executed;
+       app_finalizer_cb finalizer_cb = NULL;
+
+       if(finalizer_node)
+               finalizer_node = finalizer_node->next;
+
+       while (finalizer_node)
+       {
+               finalizer_cb = finalizer_node->callback;
+
+               finalizer_cb(finalizer_node->data);
+
+               finalizer_executed = finalizer_node;
+
+               finalizer_node = finalizer_node->next;
+
+               free(finalizer_executed);
+       }
+
+       finalizer_head.next = NULL;
+}
+
diff --git a/app_common/app_package.c b/app_common/app_package.c
new file mode 100755 (executable)
index 0000000..56893a1
--- /dev/null
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <bundle.h>
+#include <appcore-common.h>
+#include <aul.h>
+#include <ail.h>
+#include <dlog.h>
+
+#include <app_private.h>
+#include <app_service_private.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "CAPI_APPFW_APPLICATION"
+
+int app_get_package_app_name(const char *appid, char **name)
+{
+       char *name_token = NULL;
+
+       if (appid == NULL)
+       {
+               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       // com.vendor.name -> name
+       name_token = strrchr(appid, '.');
+
+       if (name_token == NULL)
+       {
+               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+       }
+
+       name_token++;
+
+       *name = strdup(name_token);
+
+       if (*name == NULL)
+       {
+               return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+       }
+
+       return APP_ERROR_NONE;
+}
+
+int app_get_package(char **package)
+{
+       return app_get_id(package);
+}
+
+int app_get_id(char **id)
+{
+       static char id_buf[TIZEN_PATH_MAX] = {0, };
+       int ret = -1;
+
+       if (id == NULL)
+       {
+               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (id_buf[0] == '\0')
+       {
+               ret = aul_app_get_appid_bypid(getpid(), id_buf, sizeof(id_buf));
+               if (ret < 0) {
+                       return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID");
+               }
+       }
+
+       if (id_buf[0] == '\0')
+       {
+               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID");
+       }
+
+       *id = strdup(id_buf);
+
+       if (*id == NULL)
+       {
+               return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+       }
+
+       return APP_ERROR_NONE;
+}
+
+static int app_get_appinfo(const char *package, const char *property, char **value)
+{
+       ail_appinfo_h appinfo;
+       char *appinfo_value;
+       char *appinfo_value_dup;
+
+       if (ail_get_appinfo(package, &appinfo) != 0)
+       {
+               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-info");
+       }
+       
+       if (ail_appinfo_get_str(appinfo, property, &appinfo_value) != 0)
+       {
+               ail_destroy_appinfo(appinfo);
+               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-property");
+       }
+
+       appinfo_value_dup = strdup(appinfo_value);
+
+       ail_destroy_appinfo(appinfo);
+
+       if (appinfo_value_dup == NULL)
+       {
+               return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+       }
+
+       *value = appinfo_value_dup;
+       
+       return APP_ERROR_NONE;
+}
+
+int app_get_name(char **name)
+{
+       char *package = NULL;
+       int retval;
+
+       if(name == NULL)
+       {
+               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (app_get_id(&package) != 0)
+       {
+               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
+       }
+
+       retval = app_get_appinfo(package, AIL_PROP_NAME_STR, name);
+
+       if (package != NULL)
+       {
+               free(package);
+       }
+
+       return retval;
+}
+
+int app_get_version(char **version)
+{
+       char *package;
+       int retval;
+
+       if(version == NULL)
+       {
+               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (app_get_id(&package) != 0)
+       {
+               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
+       }
+
+       retval = app_get_appinfo(package, AIL_PROP_VERSION_STR, version);
+
+       if (package != NULL)
+       {
+               free(package);
+       }
+
+       return retval;  
+}
+
diff --git a/app_common/app_path.c b/app_common/app_path.c
new file mode 100755 (executable)
index 0000000..82b2a9b
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2014 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 <string.h>
+#include <aul.h>
+
+#define _STRDUP(s) ((s) ? strdup(s) : NULL)
+
+char *app_get_data_path(void)
+{
+       const char *buf = aul_get_app_data_path();
+       return _STRDUP(buf);
+}
+
+char *app_get_cache_path(void)
+{
+       const char *buf = aul_get_app_cache_path();
+       return _STRDUP(buf);
+}
+
+char *app_get_resource_path(void)
+{
+       const char *buf = aul_get_app_resource_path();
+       return _STRDUP(buf);
+}
+
+char *app_get_shared_data_path(void)
+{
+       const char *buf = aul_get_app_shared_data_path();
+       return _STRDUP(buf);
+}
+
+char *app_get_shared_resource_path(void)
+{
+       const char *buf = aul_get_app_shared_resource_path();
+       return _STRDUP(buf);
+}
+
+char *app_get_shared_trusted_path(void)
+{
+       const char *buf = aul_get_app_shared_trusted_path();
+       return _STRDUP(buf);
+}
+
+char *app_get_external_data_path(void)
+{
+       const char *buf = aul_get_app_external_data_path();
+       return _STRDUP(buf);
+}
+
+char *app_get_external_cache_path(void)
+{
+       const char *buf = aul_get_app_external_cache_path();
+       return _STRDUP(buf);
+}
+
+char *app_get_external_shared_data_path(void)
+{
+       const char *buf = aul_get_app_external_shared_data_path();
+       return _STRDUP(buf);
+}
diff --git a/app_control/CMakeLists.txt b/app_control/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b0f2f1e
--- /dev/null
@@ -0,0 +1,65 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-appfw-app-control")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR ${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+SET(requires "dlog bundle aul appsvc capi-base-common")
+SET(pc_requires "capi-base-common")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${requires})
+FOREACH(flag ${${fw_name}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+IF("${ARCH}" STREQUAL "arm")
+    ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DSLP_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
+
+add_library(${fw_name} SHARED
+               app_control.c
+               )
+
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
+
+SET_TARGET_PROPERTIES(${fw_name}
+     PROPERTIES
+     VERSION ${FULLVER}
+     SOVERSION ${MAJORVER}
+     CLEAN_DIRECT_OUTPUT 1
+)
+
+INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(
+        DIRECTORY ${INC_DIR}/ DESTINATION include/appfw
+        FILES_MATCHING
+        PATTERN "*_private.h" EXCLUDE
+        PATTERN "${INC_DIR}/*.h"
+        )
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${pc_requires})
+SET(PC_LDFLAGS -l${fw_name})
+
+CONFIGURE_FILE(
+    ${CMAKE_SOURCE_DIR}/capi-appfw-module.pc.in
+    ${CMAKE_SOURCE_DIR}/${fw_name}.pc
+    @ONLY
+)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+
diff --git a/app_control/app_control.c b/app_control/app_control.c
new file mode 100755 (executable)
index 0000000..9603792
--- /dev/null
@@ -0,0 +1,1335 @@
+/*
+ * Copyright (c) 2011 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 <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <bundle.h>
+#include <aul.h>
+#include <appsvc.h>
+#include <dlog.h>
+
+#include <app_control.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "CAPI_APPFW_APP_CONTROL"
+
+#ifndef TIZEN_PATH_MAX
+#define TIZEN_PATH_MAX 1024
+#endif
+
+#define BUNDLE_KEY_PREFIX_AUL "__AUL_"
+#define BUNDLE_KEY_PREFIX_SERVICE "__APP_SVC_"
+
+#define BUNDLE_KEY_OPERATION   "__APP_SVC_OP_TYPE__"
+#define BUNDLE_KEY_URI         "__APP_SVC_URI__"
+#define BUNDLE_KEY_MIME                "__APP_SVC_MIME_TYPE__"
+#define BUNDLE_KEY_DATA                "__APP_SVC_DATA__"
+#define BUNDLE_KEY_PACKAGE     "__APP_SVC_PKG_NAME__"
+#define BUNDLE_KEY_WINDOW      "__APP_SVC_K_WIN_ID__"
+#define BUNDLE_KEY_CATEGORY    "__APP_SVC_CATEGORY__"
+
+typedef enum {
+       APP_CONTROL_TYPE_REQUEST,
+       APP_CONTROL_TYPE_EVENT,
+       APP_CONTROL_TYPE_REPLY,
+} app_control_type_e;
+
+struct app_control_s {
+       int id;
+       app_control_type_e type;
+       bundle *data;
+       int launch_pid;
+};
+
+typedef struct app_control_request_context_s {
+       app_control_h app_control;
+       app_control_reply_cb reply_cb;
+       void *user_data;
+} *app_control_request_context_h;
+
+extern int appsvc_allow_transient_app(bundle *b, unsigned int id);
+extern int appsvc_request_transient_app(bundle *b, unsigned int callee_id, appsvc_host_res_fn cbfunc, void *data);
+
+static int app_control_create_reply(bundle *data, struct app_control_s **app_control);
+
+static const char* app_control_error_to_string(app_control_error_e error)
+{
+       switch (error)
+       {
+       case APP_CONTROL_ERROR_NONE:
+               return "NONE";
+
+       case APP_CONTROL_ERROR_INVALID_PARAMETER:
+               return "INVALID_PARAMETER";
+
+       case APP_CONTROL_ERROR_OUT_OF_MEMORY:
+               return "OUT_OF_MEMORY";
+
+       case APP_CONTROL_ERROR_APP_NOT_FOUND:
+               return "APP_NOT_FOUND";
+
+       case APP_CONTROL_ERROR_KEY_NOT_FOUND:
+               return "KEY_NOT_FOUND";
+
+       case APP_CONTROL_ERROR_KEY_REJECTED:
+               return "KEY_REJECTED";
+
+       case APP_CONTROL_ERROR_INVALID_DATA_TYPE:
+               return "INVALID_DATA_TYPE";
+
+       case APP_CONTROL_ERROR_LAUNCH_REJECTED:
+               return "LAUNCH_REJECTED";
+
+       case APP_CONTROL_ERROR_PERMISSION_DENIED:
+               return "PERMISSION_DENIED";
+
+       case APP_CONTROL_ERROR_LAUNCH_FAILED:
+               return "LAUNCH_FAILED";
+
+       case APP_CONTROL_ERROR_TIMED_OUT:
+               return "TIMED_OUT";
+
+       default :
+               return "UNKNOWN";
+       }
+}
+
+int app_control_error(app_control_error_e error, const char* function, const char *description)
+{
+       if (description)
+       {
+               LOGE("[%s] %s(0x%08x) : %s", function, app_control_error_to_string(error), error, description);
+       }
+       else
+       {
+               if(error == APP_CONTROL_ERROR_KEY_NOT_FOUND)
+                       LOGW("[%s] %s(0x%08x)", function, app_control_error_to_string(error), error);
+               else
+                       LOGE("[%s] %s(0x%08x)", function, app_control_error_to_string(error), error);
+       }
+
+       return error;
+}
+
+static int app_control_validate_extra_data(const char *data)
+{
+       if (data == NULL || data[0] == '\0')
+       {
+               return APP_CONTROL_ERROR_INVALID_PARAMETER;
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+static int app_control_validate(app_control_h app_control)
+{
+       if (app_control == NULL || app_control->data == NULL)
+       {
+               return APP_CONTROL_ERROR_INVALID_PARAMETER;
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+static int app_control_new_id()
+{
+       static int sid = 0;
+       return sid++;
+}
+
+int app_control_validate_internal_key(const char *key)
+{
+       if (strncmp(BUNDLE_KEY_PREFIX_AUL, key, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
+       {
+               return -1;
+       }
+
+       if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, key, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
+       {
+               return -1;
+       }
+
+       return 0;
+}
+
+static void app_control_request_result_broker(bundle *appsvc_bundle, int appsvc_request_code, appsvc_result_val appsvc_result, void *appsvc_data)
+{
+       app_control_request_context_h request_context;
+       app_control_h request;
+       app_control_h reply = NULL;
+       app_control_result_e result;
+       void *user_data;
+       app_control_reply_cb reply_cb;
+
+       if (appsvc_data == NULL)
+       {
+               app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid app_control reply");
+               return;
+       }
+
+       if (app_control_create_reply(appsvc_bundle, &reply) != 0)
+       {
+               app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create app_control reply");
+               return;
+       }
+
+       request_context = appsvc_data;
+       request = request_context->app_control;
+
+       switch (appsvc_result)
+       {
+       case APPSVC_RES_OK:
+               result = APP_CONTROL_RESULT_SUCCEEDED;
+               break;
+
+       case APPSVC_RES_NOT_OK:
+               result = APP_CONTROL_RESULT_FAILED;
+               break;
+
+       case APPSVC_RES_CANCEL:
+               result = APP_CONTROL_RESULT_CANCELED;
+               break;
+
+       default:
+               result = APP_CONTROL_RESULT_CANCELED;
+               break;
+       }
+
+       user_data = request_context->user_data;
+       reply_cb = request_context->reply_cb;
+
+       if (reply_cb != NULL)
+       {
+               reply_cb(request, reply, result, user_data);
+       }
+       else
+       {
+               app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid callback ");
+       }
+
+       app_control_destroy(reply);
+
+       if (request_context->app_control != NULL)
+       {
+               app_control_destroy(request_context->app_control);
+       }
+
+       free(request_context);
+}
+
+int app_control_create_request(bundle *data, app_control_h *app_control)
+{
+       struct app_control_s *app_control_request;
+
+       if (app_control == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       app_control_request = malloc(sizeof(struct app_control_s));
+
+       if (app_control_request == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a app_control handle");
+       }
+
+       app_control_request->type = APP_CONTROL_TYPE_REQUEST;
+
+       if (data != NULL)
+       {
+               app_control_request->data = bundle_dup(data);
+       }
+       else
+       {
+               app_control_request->data = bundle_create();
+       }
+
+       if (app_control_request->data == NULL)
+       {
+               free(app_control_request);
+               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a bundle");
+       }
+
+       app_control_request->id = app_control_new_id();
+       app_control_request->launch_pid = -1;
+
+       *app_control = app_control_request;
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+int app_control_create(app_control_h *app_control)
+{
+       return app_control_create_request(NULL, app_control);
+}
+
+int app_control_create_event(bundle *data, struct app_control_s **app_control)
+{
+       struct app_control_s *app_control_event;
+
+       const char *operation;
+
+       if (data == NULL || app_control == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       app_control_event = malloc(sizeof(struct app_control_s));
+
+       if (app_control_event == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a app_control handle");
+       }
+
+       app_control_event->type = APP_CONTROL_TYPE_EVENT;
+       app_control_event->data = bundle_dup(data);
+       app_control_event->id = app_control_new_id();
+
+       operation = appsvc_get_operation(app_control_event->data);
+
+       if (operation == NULL)
+       {
+               appsvc_set_operation(app_control_event->data, APP_CONTROL_OPERATION_DEFAULT);
+       }
+
+       *app_control = app_control_event;
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+static int app_control_create_reply(bundle *data, struct app_control_s **app_control)
+{
+       struct app_control_s *app_control_reply;
+
+       if (data == NULL || app_control == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       app_control_reply = malloc(sizeof(struct app_control_s));
+
+       if (app_control_reply == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a app_control handle");
+       }
+
+       app_control_reply->type = APP_CONTROL_TYPE_REPLY;
+       app_control_reply->data = bundle_dup(data);
+       app_control_reply->id = app_control_new_id();
+
+       *app_control = app_control_reply;
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+int app_control_destroy(app_control_h app_control)
+{
+       if (app_control_validate(app_control))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       bundle_free(app_control->data);
+       app_control->data = NULL;
+       free(app_control);
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+int app_control_to_bundle(app_control_h app_control, bundle **data)
+{
+       if (app_control_validate(app_control) || data == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       *data = app_control->data;
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+int app_control_set_operation(app_control_h app_control, const char *operation)
+{
+       if (app_control_validate(app_control))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (operation != NULL)
+       {
+               if (appsvc_set_operation(app_control->data, operation) != 0)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid operation");
+               }
+       }
+       else
+       {
+               bundle_del(app_control->data, BUNDLE_KEY_OPERATION);
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+int app_control_get_operation(app_control_h app_control, char **operation)
+{
+       const char *operation_value;
+
+       if (app_control_validate(app_control) || operation == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       operation_value = appsvc_get_operation(app_control->data);
+
+       if (operation_value != NULL)
+       {
+               *operation = strdup(operation_value);
+       }
+       else
+       {
+               *operation = NULL;
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_set_uri(app_control_h app_control, const char *uri)
+{
+       if (app_control_validate(app_control))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (uri != NULL)
+       {
+               if (appsvc_set_uri(app_control->data, uri) != 0)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid URI");
+               }
+       }
+       else
+       {
+               bundle_del(app_control->data, BUNDLE_KEY_URI);
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_get_uri(app_control_h app_control, char **uri)
+{
+       const char *uri_value;
+
+       if (app_control_validate(app_control) || uri == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       uri_value = appsvc_get_uri(app_control->data);
+
+       if (uri_value != NULL)
+       {
+               *uri = strdup(uri_value);
+       }
+       else
+       {
+               *uri = NULL;
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_set_mime(app_control_h app_control, const char *mime)
+{
+       if (app_control_validate(app_control))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (mime != NULL)
+       {
+               if (appsvc_set_mime(app_control->data, mime) != 0)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid MIME type");
+               }
+       }
+       else
+       {
+               bundle_del(app_control->data, BUNDLE_KEY_MIME);
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_get_mime(app_control_h app_control, char **mime)
+{
+       const char *mime_value;
+
+       if (app_control_validate(app_control) || mime == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       mime_value = appsvc_get_mime(app_control->data);
+
+       if (mime_value != NULL)
+       {
+               *mime = strdup(mime_value);
+       }
+       else
+       {
+               *mime = NULL;
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_set_category(app_control_h app_control, const char *category)
+{
+       if (app_control_validate(app_control))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (category != NULL)
+       {
+               if (appsvc_set_category(app_control->data, category) != 0)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid Category");
+               }
+       }
+       else
+       {
+               bundle_del(app_control->data, BUNDLE_KEY_CATEGORY);
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_get_category(app_control_h app_control, char **category)
+{
+       const char *category_value;
+
+       if (app_control_validate(app_control) || category == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       category_value = appsvc_get_category(app_control->data);
+
+       if (category_value != NULL)
+       {
+               *category = strdup(category_value);
+       }
+       else
+       {
+               *category = NULL;
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_set_package(app_control_h app_control, const char *package)
+{
+       // TODO: this function must be deprecated
+       return app_control_set_app_id(app_control, package);
+}
+
+int app_control_get_package(app_control_h app_control, char **package)
+{
+       // TODO: this function must be deprecated
+       return app_control_get_app_id(app_control, package);
+}
+
+
+int app_control_set_app_id(app_control_h app_control, const char *app_id)
+{
+       if (app_control_validate(app_control))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (app_id != NULL)
+       {
+               if (appsvc_set_appid(app_control->data, app_id) != 0)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid application ID");
+               }
+       }
+       else
+       {
+               bundle_del(app_control->data, BUNDLE_KEY_PACKAGE);
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_get_app_id(app_control_h app_control, char **app_id)
+{
+       const char *app_id_value;
+
+       if (app_control_validate(app_control) || app_id == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       app_id_value = appsvc_get_appid(app_control->data);
+
+       if (app_id_value != NULL)
+       {
+               *app_id = strdup(app_id_value);
+       }
+       else
+       {
+               *app_id = NULL;
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+int app_control_set_window(app_control_h app_control, unsigned int id)
+{
+       if (app_control_validate(app_control))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (id > 0)
+       {
+               if (appsvc_allow_transient_app(app_control->data, id) != 0)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid id");
+               }
+       }
+       else
+       {
+               bundle_del(app_control->data, BUNDLE_KEY_WINDOW);
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+int app_control_get_window(app_control_h app_control, unsigned int *id)
+{
+       const char *window_id;
+
+       if (app_control_validate(app_control) || id == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       window_id = bundle_get_val(app_control->data, BUNDLE_KEY_WINDOW);
+
+       if (window_id != NULL)
+       {
+               *id = atoi(window_id);
+       }
+       else
+       {
+               *id = 0;
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+int app_control_clone(app_control_h *clone, app_control_h app_control)
+{
+       app_control_h app_control_clone;
+
+       if (app_control_validate(app_control) || clone == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       app_control_clone = malloc(sizeof(struct app_control_s));
+
+       if (app_control_clone == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a app_control handle");
+       }
+
+       app_control_clone->id = app_control_new_id();
+       app_control_clone->type = app_control->type;
+       app_control_clone->data = bundle_dup(app_control->data);
+
+       *clone = app_control_clone;
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+int app_control_send_launch_request(app_control_h app_control, app_control_reply_cb callback, void *user_data)
+{
+       const char *operation;
+
+       bool implicit_default_operation = false;
+       int launch_pid;
+
+       app_control_request_context_h request_context = NULL;
+
+       if (app_control_validate(app_control))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       operation = appsvc_get_operation(app_control->data);
+       if (operation == NULL)
+       {
+               implicit_default_operation = true;
+               operation = APP_CONTROL_OPERATION_DEFAULT;
+       }
+
+       // TODO: Check the privilege for call operation
+
+       // operation : default
+       if (!strcmp(operation, APP_CONTROL_OPERATION_DEFAULT))
+       {
+               const char *appid  = appsvc_get_appid(app_control->data);
+               if (appid == NULL)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_APP_NOT_FOUND, __FUNCTION__, "package must be specified if the operation is default value");
+               }
+       }
+
+       if (callback != NULL)
+       {
+               app_control_h request_clone = NULL;
+
+               request_context = calloc(1, sizeof(struct app_control_request_context_s));
+
+               if (request_context == NULL)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+               }
+
+               request_context->reply_cb = callback;
+
+               if (app_control_clone(&request_clone, app_control) != APP_CONTROL_ERROR_NONE)
+               {
+                       free(request_context);
+                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to clone the app_control request handle");
+               }
+
+               request_context->app_control = request_clone;
+               request_context->user_data = user_data;
+       }
+
+       if (implicit_default_operation == true)
+       {
+               appsvc_set_operation(app_control->data, APP_CONTROL_OPERATION_DEFAULT);
+       }
+
+       launch_pid = appsvc_run_service(app_control->data, app_control->id, callback ? app_control_request_result_broker : NULL, request_context);
+
+       if (implicit_default_operation == true)
+       {
+               bundle_del(app_control->data, BUNDLE_KEY_OPERATION);
+       }
+
+       if (launch_pid < 0)
+       {
+               if (launch_pid == APPSVC_RET_ENOMATCH)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_APP_NOT_FOUND, __FUNCTION__, NULL);
+               }
+               else if (launch_pid == APPSVC_RET_EILLACC)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_PERMISSION_DENIED, __FUNCTION__, NULL);
+               }
+               else if (launch_pid == APPSVC_RET_EINVAL)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+               }
+               else
+               {
+                       return app_control_error(APP_CONTROL_ERROR_LAUNCH_REJECTED, __FUNCTION__, NULL);
+               }
+       }
+
+       app_control->launch_pid = launch_pid;
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_send_terminate_request(app_control_h app_control)
+{
+       if (app_control_validate(app_control))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if(app_control->type != APP_CONTROL_TYPE_REQUEST || app_control->launch_pid < 0)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       appsvc_subapp_terminate_request_pid(app_control->launch_pid);
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+static bool app_control_copy_reply_data_cb(app_control_h app_control, const char *key, void *user_data)
+{
+       bundle *reply_data = user_data;
+       char *value = NULL;
+       char **value_array = NULL;
+       int value_array_length = 0;
+       int value_array_index = 0;
+
+       if (reply_data == NULL)
+       {
+               app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+               return false;
+       }
+
+       if (appsvc_data_is_array(app_control->data, key))
+       {
+               app_control_get_extra_data_array(app_control, key, &value_array, &value_array_length);
+               appsvc_add_data_array(reply_data, key, (const char**)value_array, value_array_length);
+
+               for (value_array_index=0; value_array_index < value_array_length; value_array_index++)
+               {
+                       free(value_array[value_array_index]);
+               }
+
+               free(value_array);
+       }
+       else
+       {
+               app_control_get_extra_data(app_control, key, &value);
+               appsvc_add_data(reply_data, key, value);
+               free(value);
+       }
+
+       return true;
+}
+
+int app_control_reply_to_launch_request(app_control_h reply, app_control_h request, app_control_result_e result)
+{
+       bundle *reply_data;
+       int appsvc_result;
+       int ret = 0;
+
+       if (app_control_validate(reply) || app_control_validate(request))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (appsvc_create_result_bundle(request->data, &reply_data) != 0)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create a result bundle");
+       }
+
+       app_control_foreach_extra_data(reply, app_control_copy_reply_data_cb, reply_data);
+
+       switch (result)
+       {
+       case APP_CONTROL_RESULT_SUCCEEDED:
+               appsvc_result = APPSVC_RES_OK;
+               break;
+
+       case APP_CONTROL_RESULT_FAILED:
+               appsvc_result = APPSVC_RES_NOT_OK;
+               break;
+
+       case APP_CONTROL_RESULT_CANCELED:
+               appsvc_result = APPSVC_RES_CANCEL;
+               break;
+
+       default:
+               appsvc_result = APPSVC_RES_CANCEL;
+               break;
+       }
+
+       ret = appsvc_send_result(reply_data, appsvc_result);
+       if (ret < 0)
+       {
+               if (ret == APPSVC_RET_EINVAL)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+               }
+               else
+               {
+                       return app_control_error(APP_CONTROL_ERROR_LAUNCH_REJECTED, __FUNCTION__, NULL);
+               }
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_add_extra_data(app_control_h app_control, const char *key, const char *value)
+{
+       if (app_control_validate(app_control) || app_control_validate_extra_data(key) || app_control_validate_extra_data(value))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (app_control_validate_internal_key(key))
+       {
+               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
+       }
+
+       if (appsvc_get_data(app_control->data, key) != NULL)
+       {
+               // overwrite any existing value
+               bundle_del(app_control->data, key);
+       }
+
+       if (appsvc_add_data(app_control->data, key, value) != 0)
+       {
+               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "failed to add data to the appsvc handle");
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_add_extra_data_array(app_control_h app_control, const char *key, const char* value[], int length)
+{
+       if (app_control_validate(app_control) || app_control_validate_extra_data(key))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (value == NULL || length <= 0)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid array");
+       }
+
+       if (app_control_validate_internal_key(key))
+       {
+               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
+       }
+
+       if (appsvc_get_data_array(app_control->data, key, NULL) != NULL)
+       {
+               // overwrite any existing value
+               bundle_del(app_control->data,key);
+       }
+
+       if (appsvc_add_data_array(app_control->data, key, value, length) != 0)
+       {
+               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "failed to add array data to the appsvc handle");
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_remove_extra_data(app_control_h app_control, const char *key)
+{
+       if (app_control_validate(app_control) || app_control_validate_extra_data(key))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (app_control_validate_internal_key(key))
+       {
+               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
+       }
+
+       if (bundle_del(app_control->data, key))
+       {
+               return app_control_error(APP_CONTROL_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL);
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_get_extra_data(app_control_h app_control, const char *key, char **value)
+{
+       const char *data_value;
+
+       if (app_control_validate(app_control) || app_control_validate_extra_data(key) || value == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+
+       if (app_control_validate_internal_key(key))
+       {
+               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
+       }
+
+       data_value = appsvc_get_data(app_control->data, key);
+
+       if (data_value == NULL)
+       {
+               if (errno == ENOTSUP)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_INVALID_DATA_TYPE, __FUNCTION__, NULL);
+               }
+               else
+               {
+                       return app_control_error(APP_CONTROL_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL);
+               }
+       }
+
+       *value = strdup(data_value);
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_get_extra_data_array(app_control_h app_control, const char *key, char ***value, int *length)
+{
+       const char **array_data;
+       int array_data_length;
+       char **array_data_clone;
+       int i;
+
+       if (app_control_validate(app_control) || app_control_validate_extra_data(key))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (value == NULL || length == 0)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (app_control_validate_internal_key(key))
+       {
+               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
+       }
+
+       array_data = appsvc_get_data_array(app_control->data, key, &array_data_length);
+
+       if (array_data == NULL)
+       {
+               if (errno == ENOTSUP)
+               {
+                       return app_control_error(APP_CONTROL_ERROR_INVALID_DATA_TYPE, __FUNCTION__, NULL);
+               }
+               else
+               {
+                       return app_control_error(APP_CONTROL_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL);
+               }
+       }
+
+       array_data_clone = calloc(array_data_length, sizeof(char*));
+
+       if (array_data_clone == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+       }
+
+       for (i=0; i<array_data_length; i++)
+       {
+               if (array_data[i] != NULL)
+               {
+                       array_data_clone[i] = strdup(array_data[i]);
+               }
+       }
+
+       *value = array_data_clone;
+       *length = array_data_length;
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_is_extra_data_array(app_control_h app_control, const char *key, bool *array)
+{
+       if (app_control_validate(app_control) || app_control_validate_extra_data(key) || array == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (app_control_validate_internal_key(key))
+       {
+               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
+\r      }
+
+       if (!appsvc_data_is_array(app_control->data, key))
+       {
+               *array = false;
+       }
+       else
+       {
+               *array = true;
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+typedef struct {
+       app_control_h app_control;
+       app_control_extra_data_cb callback;
+       void* user_data;
+       bool foreach_break;
+} foreach_context_extra_data_t;
+
+static void app_control_cb_broker_bundle_iterator(const char *key, const int type, const bundle_keyval_t *kv, void *user_data)
+{
+       foreach_context_extra_data_t* foreach_context = NULL;
+       app_control_extra_data_cb extra_data_cb;
+
+       if (key == NULL || !(type == BUNDLE_TYPE_STR || type == BUNDLE_TYPE_STR_ARRAY))
+       {
+               return;
+       }
+
+       foreach_context = (foreach_context_extra_data_t*)user_data;
+
+       if (foreach_context->foreach_break == true)
+       {
+               return;
+       }
+
+       if (app_control_validate_internal_key(key))
+       {
+               return;
+       }
+
+       extra_data_cb = foreach_context->callback;
+
+       if (extra_data_cb != NULL)
+       {
+               bool stop_foreach = false;
+
+               stop_foreach = !extra_data_cb(foreach_context->app_control, key, foreach_context->user_data);
+
+               foreach_context->foreach_break = stop_foreach;
+       }
+
+}
+
+
+int app_control_foreach_extra_data(app_control_h app_control, app_control_extra_data_cb callback, void *user_data)
+{
+       foreach_context_extra_data_t foreach_context = {
+               .app_control = app_control,
+               .callback = callback,
+               .user_data = user_data,
+               .foreach_break = false
+       };
+
+       if (app_control_validate(app_control) || callback == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       bundle_foreach(app_control->data, app_control_cb_broker_bundle_iterator, &foreach_context);
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+typedef struct {
+       app_control_h app_control;
+       app_control_app_matched_cb callback;
+       void* user_data;
+       bool foreach_break;
+} foreach_context_launchable_app_t;
+
+int app_control_cb_broker_foreach_app_matched(const char *package, void *data)
+{
+       foreach_context_launchable_app_t *foreach_context;
+       app_control_app_matched_cb app_matched_cb;
+
+       if (package == NULL || data == NULL)
+       {
+               app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+               return -1;
+       }
+
+       foreach_context = (foreach_context_launchable_app_t*)data;
+
+       if (foreach_context->foreach_break == true)
+       {
+               return -1;
+       }
+
+       app_matched_cb = foreach_context->callback;
+
+       if (app_matched_cb != NULL)
+       {
+               bool stop_foreach = false;
+
+               stop_foreach = !app_matched_cb(foreach_context->app_control, package, foreach_context->user_data);
+
+               foreach_context->foreach_break = stop_foreach;
+       }
+
+       return 0;
+}
+
+int app_control_foreach_app_matched(app_control_h app_control, app_control_app_matched_cb callback, void *user_data)
+{
+       foreach_context_launchable_app_t foreach_context = {
+               .app_control = app_control,
+               .callback = callback,
+               .user_data = user_data,
+               .foreach_break = false
+       };
+
+       if (app_control_validate(app_control) || callback == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       appsvc_get_list(app_control->data, app_control_cb_broker_foreach_app_matched, &foreach_context);
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_get_caller(app_control_h app_control, char **package)
+{
+       const char *bundle_value;
+       char *package_dup;
+
+       if (app_control_validate(app_control) || package == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (app_control->type != APP_CONTROL_TYPE_EVENT)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid app_control handle type");
+       }
+
+        bundle_value = bundle_get_val(app_control->data, AUL_K_CALLER_APPID);
+        if (bundle_value == NULL)
+        {
+                return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to retrieve the appid of the caller");
+        }
+
+        package_dup = strdup(bundle_value);
+
+        if (package_dup == NULL)
+        {
+                return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+        }
+
+        *package = package_dup;
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_is_reply_requested(app_control_h app_control, bool *requested)
+{
+       const char *bundle_value;
+
+       if (app_control_validate(app_control) || requested == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       if (app_control->type != APP_CONTROL_TYPE_EVENT)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid app_control handle type");
+       }
+
+       bundle_value = bundle_get_val(app_control->data, AUL_K_WAIT_RESULT);
+
+       if (bundle_value != NULL)
+       {
+               *requested = true;
+       }
+       else
+       {
+               *requested = false;
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+int app_control_import_from_bundle(app_control_h app_control, bundle *data)
+{
+       bundle *data_dup = NULL;
+
+       if (app_control_validate(app_control) || data == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       data_dup = bundle_dup(data);
+
+       if (data_dup == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to duplicate the bundle");
+       }
+
+       if (app_control->data != NULL)
+       {
+               bundle_free(app_control->data);
+       }
+
+       app_control->data = data_dup;
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+int app_control_export_as_bundle(app_control_h app_control, bundle **data)
+{
+       bundle *data_dup = NULL;
+
+       if (app_control_validate(app_control) || data == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       data_dup = bundle_dup(app_control->data);
+
+       if (data_dup == NULL)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to duplicate the bundle");
+       }
+
+       *data = data_dup;
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
+
+int app_control_request_transient_app(app_control_h app_control, unsigned int callee_id, app_control_host_res_fn cbfunc, void *data)
+{
+       int ret;
+
+       if (app_control_validate(app_control))
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       ret = appsvc_request_transient_app(app_control->data, callee_id, (appsvc_host_res_fn)cbfunc, data);
+
+       if (ret < 0)
+       {
+               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+       }
+
+       return APP_CONTROL_ERROR_NONE;
+}
+
diff --git a/capi-appfw-application.pc.in b/capi-appfw-application.pc.in
deleted file mode 100755 (executable)
index d0ff7f2..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-
-# Package Information for pkg-config
-
-prefix=@PREFIX@
-exec_prefix=/usr
-libdir=@LIB_INSTALL_DIR@
-includedir=@INCLUDE_INSTALL_DIR@/appfw
-
-Name: @PC_NAME@
-Description: @PACKAGE_DESCRIPTION@
-Version: @VERSION@
-Requires: @PC_REQUIRED@ 
-Libs: -L${libdir} @PC_LDFLAGS@
-Cflags: -I${includedir}
-
diff --git a/capi-appfw-module.pc.in b/capi-appfw-module.pc.in
new file mode 100644 (file)
index 0000000..f4504d4
--- /dev/null
@@ -0,0 +1,13 @@
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@/appfw
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
index f52cffaf4f5d80fcd66e02e9e638971acb698534..c54b3e1d1c249d7262995db34ee90e0ecf2c6bac 100755 (executable)
@@ -22,6 +22,7 @@
 #include <app_service.h>
 #include <app_control.h>
 #include <app_alarm.h>
+#include <app_common.h>
 #include <app_preference.h>
 #include <app_i18n.h>
 
@@ -49,18 +50,6 @@ typedef enum
 } app_error_e;
 
 
-/**
- * @brief Enumerations of the device orientation.
- */
-typedef enum
-{
-       APP_DEVICE_ORIENTATION_0 = 0, /**< The device is oriented in natural position */
-       APP_DEVICE_ORIENTATION_90 = 90, /**< The device's left side is at the top */
-       APP_DEVICE_ORIENTATION_180 = 180, /**< The device is upside down */
-       APP_DEVICE_ORIENTATION_270 = 270, /**<The device's right side is to the top */
-} app_device_orientation_e;
-
-
 /**
  * @brief Called at the start of the application.
  *
@@ -313,374 +302,6 @@ int app_efl_main(int *argc, char ***argv, app_event_callback_s *callback, void *
 void app_efl_exit(void);
 
 
-/**
- * @brief Enumeration for system events
- */
-typedef enum
-{
-       APP_EVENT_LOW_MEMORY, /**< The low memory event */
-       APP_EVENT_LOW_BATTERY, /**< The low battery event */
-       APP_EVENT_LANGUAGE_CHANGED, /**< The system language changed event */
-       APP_EVENT_DEVICE_ORIENTATION_CHANGED, /**< The device orientation changed event */
-       APP_EVENT_REGION_FORMAT_CHANGED, /**< The region format changed event */
-} app_event_type_e;
-
-
-/**
- * @brief Enumeration for low memory status.
- */
-typedef enum
-{
-       APP_EVENT_LOW_MEMORY_NORMAL = 0x01, /**< Normal status */
-       APP_EVENT_LOW_MEMORY_SOFT_WARNING = 0x02, /**< Soft warning status */
-       APP_EVENT_LOW_MEMORY_HARD_WARNING = 0x04, /**< Hard warning status */
-} app_event_low_memory_status_e;
-
-
-/**
- * @brief Enumeration for battery status.
- */
-typedef enum
-{
-       APP_EVENT_LOW_BATTERY_POWER_OFF = 1, /**< The battery status is under 1% */
-       APP_EVENT_LOW_BATTERY_CRITICAL_LOW, /**< The battery status is under 5% */
-} app_event_low_battery_status_e;
-
-
-/**
- * @brief The event handler that returned from add event handler function
- *
- * @see app_event_type_e
- * @see app_add_event_handler
- * @see app_remove_event_handler
- * @see app_event_info_h
- */
-typedef struct app_event_handler* app_event_handler_h;
-
-
-/**
- * @brief The system event information
- *
- * @see app_event_get_low_memory_status
- * @see app_event_get_low_battery_status
- * @see app_event_get_language
- * @see app_event_get_region_format
- * @see app_event_get_device_orientation
- */
-typedef struct app_event_info* app_event_info_h;
-
-
-/**
- * @brief The system event callback function
- *
- * @param[in] event_info The system event information
- * @param[in] user_data The user data passed from the add event handler function
- *
- * @see app_add_event_handler
- * @see app_event_info_h
- */
-typedef void (*app_event_cb)(app_event_info_h event_info, void *user_data);
-
-
-/**
- * @brief Gets the low memory status from given event info
- *
- * @param[in] event_info The system event info
- * @param[out] status The low memory status
- *
- * @return 0 on success, otherwise a negative error value
- * @retval #APP_ERROR_NONE Successful
- * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #APP_ERROR_INVALID_CONTEXT Invalid event context
- *
- * @see app_event_info_h
- * @see app_event_low_memory_status_e
- */
-int app_event_get_low_memory_status(app_event_info_h event_info, app_event_low_memory_status_e *status);
-
-
-/**
- * @brief Gets the low battery status from given event info
- *
- * @param[in] event_info The system event info
- * @param[out] status The low battery status
- *
- * @return 0 on success, otherwise a negative error value
- * @retval #APP_ERROR_NONE Successful
- * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #APP_ERROR_INVALID_CONTEXT Invalid event context
- *
- * @see app_event_info_h
- * @see app_event_low_battery_status_e
- */
-int app_event_get_low_battery_status(app_event_info_h event_info, app_event_low_battery_status_e *status);
-
-
-/**
- * @brief Gets the language from given event info
- *
- * @remarks @a lang must be released using free()
- * @param[in] event_info The system event info
- * @param[out] lang The language changed
- *
- * @return 0 on success, otherwise a negative error value
- * @retval #APP_ERROR_NONE Successful
- * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #APP_ERROR_INVALID_CONTEXT Invalid event context
- *
- * @see app_event_info_h
- */
-int app_event_get_language(app_event_info_h event_info, char **lang);
-
-
-/**
- * @brief Gets the region format from given event info
- *
- * @remarks @a region must be released using free()
- * @param[in] event_info The system event info
- * @param[out] region The region format changed
- *
- * @return 0 on success, otherwise a negative error value
- * @retval #APP_ERROR_NONE Successful
- * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #APP_ERROR_INVALID_CONTEXT Invalid event context
- *
- * @see app_event_info_h
- */
-int app_event_get_region_format(app_event_info_h event_info, char **region);
-
-
-/**
- * @brief Gets the device orientation from given event info
- *
- * @param[in] event_info The system event info
- * @param[out] orientation The device orientation changed
- *
- * @return 0 on success, otherwise a negative error value
- * @retval #APP_ERROR_NONE Successful
- * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #APP_ERROR_INVALID_CONTEXT Invalid event context
- *
- * @see app_event_info_h
- * @see app_device_orientation_e
- */
-int app_event_get_device_orientation(app_event_info_h event_info, app_device_orientation_e *orientation);
-
-
-/**
- * @brief Gets the name of the application package.
- *
- * @remarks @a package must be released with free() by you.
- *
- * @param [out] package The name of the application package
- *
- * @return 0 on success, otherwise a negative error value.
- *
- * @retval #APP_ERROR_NONE Successful
- * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #APP_ERROR_INVALID_CONTEXT The application is illegally launched, not launched by the launch system.
- * @retval #APP_ERROR_OUT_OF_MEMORY Out of memory
- */
-int app_get_package(char **package);
-
-
-/**
- * @brief Gets the ID of the application.
- *
- * @remarks @a ID must be released with free() by you.
- *
- * @param [out] id The ID of the application
- *
- * @return 0 on success, otherwise a negative error value.
- *
- * @retval #APP_ERROR_NONE Successful
- * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #APP_ERROR_INVALID_CONTEXT The application is illegally launched, not launched by the launch system.
- * @retval #APP_ERROR_OUT_OF_MEMORY Out of memory
- */
-int app_get_id(char **id);
-
-
-/**
- * @brief Gets the localized name of the application.
- *
- * @remarks @a name must be released with free() by you.
- *
- * @param [out] name The name of the application
- *
- * @return 0 on success, otherwise a negative error value.
- *
- * @retval #APP_ERROR_NONE Successful
- * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #APP_ERROR_INVALID_CONTEXT The application is illegally launched, not launched by the launch system.
- * @retval #APP_ERROR_OUT_OF_MEMORY Out of memory
- */
-int app_get_name(char **name);
-
-
-/**
- * @brief Gets the version of the application package.
- *
- * @remarks @a version must be released with free() by you.
- *
- * @param [out] version The version of the application
- *
- * @return 0 on success, otherwise a negative error value.
- *
- * @retval #APP_ERROR_NONE Successful
- * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter 
- * @retval #APP_ERROR_INVALID_CONTEXT The application is illegally launched, not launched by the launch system.
- * @retval #APP_ERROR_OUT_OF_MEMORY Out of memory
- */
-int app_get_version(char **version);
-
-
-/**
- * @brief Gets the absolute path to the resource included in application package
- *
- * @details The application cannot write and modify any resource files.
- *
- * @remarks This function stores the absolute path into the @a buffer at most one less than @a size bytes 
- * and a null character is appended  in @a buffer after the path stored.
- *
- * @param [in] resource The resource's path relative to the resource directory of the application package (e.g. edje/app.edj or images/background.png)
- * @param [in] buffer The pre-allocated buffer where the absolute path to the resource is stored. 
- * @param [in] size The size of @a buffer in bytes
- * @return  @a buffer on success, otherwise NULL.
- */
-char* app_get_resource(const char *resource, char *buffer, int size);
-
-
-/**
- * @brief Gets the absolute path to the application's data directory.
- *
- * @details An application can read and write its own data files in the application's data directory.
- *
- * @remarks This function stores the absolute path into the @a buffer at most one less than @a size bytes 
- * and a null character is appended  in @a buffer after the path stored.
- *
- * @param [in] buffer The pre-allocated buffer where the absolute path to the application data directory
- * @param [in] size The size of @a buffer in bytes
- * @return  @a buffer on success, otherwise NULL.
- */
-char* app_get_data_directory(char *buffer, int size);
-
-
-/**
- * @brief      Gets the absolute path to the application's data directory which is used to store private
- *                     data of the application.
- * @details    An application can read and write its own files in the application's data directory.
- * @remarks    The returned path should be released.
- *
- * @return     The absolute path to the application's data directory, @n
- *                     else @a null pointer if the memory is insufficient
- */
-char *app_get_data_path(void);
-
-/**
- * @brief      Gets the absolute path to the application's cache directory which is used to store
- *                     temporary data of the application.
- * @details    An application can read and write its own files in the application's cache directory.
- * @remarks    The returned path should be released. @n
- *                     The files stored in the application's cache directory can be removed by Setting
- *                     application or platform while the application is running.
- *
- * @return     The absolute path to the application's cache directory, @n
- *                     else @a null pointer if the memory is insufficient
- */
-char *app_get_cache_path(void);
-
-/**
- * @brief      Gets the absolute path to the application resource directory. The resource files
- *                     are delivered with the application package.
- * @details    An application can only read its own files in the application's resource directory.
- * @remarks    The returned path should be released.
- *
- * @return     The absolute path to the application's resource directory, @n
- *                     else @a null pointer if the memory is insufficient
- */
-char *app_get_resource_path(void);
-
-/**
- * @brief      Gets the absolute path to the application's shared data directory which is used to share
- *                     data with other applications.
- * @details    An application can read and write its own files in the application's shared data
- *                     directory and others can only read the files.
- * @remarks    The returned path should be released.
- *
- * @return     The absolute path to the application's shared data directory, @n
- *                     else @a null pointer if the memory is insufficient
- */
-char *app_get_shared_data_path(void);
-
-/**
- * @brief      Gets the absolute path to the application's shared resource directory which is used to
- *                     share resources with other applications.
- * @details    An application can read its own files in the application's shared resource directory
- *                     and others can only read the files.
- * @remarks    The returned path should be released.
- *
- * @return     The absolute path to the application's shared resource directory, @n
- *                     else @a null pointer if the memory is insufficient
- */
-char *app_get_shared_resource_path(void);
-
-/**
- * @brief      Gets the absolute path to the application's shared trusted directory which is used to share data
- *                     with family of trusted applications
- * @details    An application can read and write its own files in the application's shared trusted directory
- *                     and the family applications signed with the same certificate can read and write the files in the
- *                     shared trusted directory.
- * @remarks    The returned path should be released.
- *
- * @return     The absolute path to the application's shared trusted directory, @n
- *                     else @a null pointer if the memory is insufficient
- */
-char *app_get_shared_trusted_path(void);
-
-/**
- * @brief      Gets the absolute path to the application's external data directory which is used to
- *                     store data of the application.
- * @details    An application can read and write its own files in the application's external data
- *                     directory.
- * @remarks    The returned path should be released. @n
- *                     The important files stored in the application's external data directory should be
- *                     encrypted because they can be exported via the external sdcard.
- *
- * @return     The absolute path to the application's external data directory, @n
- *                     else @a null pointer if the memory is insufficient
- */
-char *app_get_external_data_path(void);
-
-/**
- * @brief      Gets the absolute path to the application's external cache directory which is used to
- *                     store temporary data of the application.
- * @details    An application can read and write its own files in the application's external cache
- *                     directory.
- * @remarks The returned path should be released. @n
- *                     The files stored in the application's external cache directory can be removed by
- *                     Setting application while the application is running. @n
- *                     The important files stored in the application's external cache directory should be
- *                     encrypted because they can be exported via the external sdcard.
- *
- * @return     The absolute path to the application's external cache directory, @n
- *                     else @a null pointer if the memory is insufficient
- */
-char *app_get_external_cache_path(void);
-
-/**
- * @brief      Gets the absolute path to the application's external shared data directory which is
- *                     used to share data with other applications.
- * @details    An application can read and write its own files in the application's external shared
- *                     data directory and others can only read the files.
- * @remarks    The specified @a path should be released.
- *
- * @return     The absolute path to the application's external shared data directory, @n
- *                     else @a null pointer if the memory is insufficient
- */
-char *app_get_external_shared_data_path(void);
-
-
 /**
  * @brief Gets the current device orientation.
  *
diff --git a/include/app_common.h b/include/app_common.h
new file mode 100644 (file)
index 0000000..7bb505c
--- /dev/null
@@ -0,0 +1,409 @@
+/*
+ * Copyright (c) 2014 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_APPFW_APP_COMMON_H__
+#define __TIZEN_APPFW_APP_COMMON_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file app_common.h
+ */
+
+/**
+ * @addtogroup CAPI_APP_COMMON_MODULE
+ * @{
+ */
+
+
+/**
+ * @brief Enumeration for system events
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       APP_EVENT_LOW_MEMORY, /**< The low memory event */
+       APP_EVENT_LOW_BATTERY, /**< The low battery event */
+       APP_EVENT_LANGUAGE_CHANGED, /**< The system language changed event */
+       APP_EVENT_DEVICE_ORIENTATION_CHANGED, /**< The device orientation changed event */
+       APP_EVENT_REGION_FORMAT_CHANGED, /**< The region format changed event */
+} app_event_type_e;
+
+
+/**
+ * @brief Enumeration for device orientation.
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       APP_DEVICE_ORIENTATION_0 = 0, /**< The device is oriented in a natural position */
+       APP_DEVICE_ORIENTATION_90 = 90, /**< The device's left side is at the top */
+       APP_DEVICE_ORIENTATION_180 = 180, /**< The device is upside down */
+       APP_DEVICE_ORIENTATION_270 = 270, /**< The device's right side is at the top */
+} app_device_orientation_e;
+
+
+/**
+ * @brief Enumeration for low memory status.
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       APP_EVENT_LOW_MEMORY_NORMAL = 0x01, /**< Normal status */
+       APP_EVENT_LOW_MEMORY_SOFT_WARNING = 0x02, /**< Soft warning status */
+       APP_EVENT_LOW_MEMORY_HARD_WARNING = 0x04, /**< Hard warning status */
+} app_event_low_memory_status_e;
+
+
+/**
+ * @brief Enumeration for battery status.
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       APP_EVENT_LOW_BATTERY_POWER_OFF = 1, /**< The battery status is under 1% */
+       APP_EVENT_LOW_BATTERY_CRITICAL_LOW, /**< The battery status is under 5% */
+} app_event_low_battery_status_e;
+
+
+/**
+ * @brief The event handler that returned from add event handler function
+ *
+ * @since_tizen 2.3
+ * @see app_event_type_e
+ * @see app_add_event_handler
+ * @see app_remove_event_handler
+ * @see app_event_info_h
+ */
+typedef struct app_event_handler* app_event_handler_h;
+
+
+/**
+ * @brief The system event information
+ *
+ * @since_tizen 2.3
+ * @see app_event_get_low_memory_status
+ * @see app_event_get_low_battery_status
+ * @see app_event_get_language
+ * @see app_event_get_region_format
+ * @see app_event_get_device_orientation
+ */
+typedef struct app_event_info* app_event_info_h;
+
+
+/**
+ * @brief The system event callback function
+ *
+ * @since_tizen 2.3
+ * @param[in] event_info The system event information
+ * @param[in] user_data The user data passed from the add event handler function
+ *
+ * @see app_add_event_handler
+ * @see app_event_info_h
+ */
+typedef void (*app_event_cb)(app_event_info_h event_info, void *user_data);
+
+
+/**
+ * @brief Gets the low memory status from given event info
+ *
+ * @since_tizen 2.3
+ * @param[in] event_info The system event info
+ * @param[out] status The low memory status
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_NONE Successful
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_INVALID_CONTEXT Invalid event context
+ *
+ * @see app_event_info_h
+ * @see app_event_low_memory_status_e
+ */
+int app_event_get_low_memory_status(app_event_info_h event_info, app_event_low_memory_status_e *status);
+
+
+/**
+ * @brief Gets the low battery status from given event info
+ *
+ * @since_tizen 2.3
+ * @param[in] event_info The system event info
+ * @param[out] status The low battery status
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_NONE Successful
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_INVALID_CONTEXT Invalid event context
+ *
+ * @see app_event_info_h
+ * @see app_event_low_battery_status_e
+ */
+int app_event_get_low_battery_status(app_event_info_h event_info, app_event_low_battery_status_e *status);
+
+
+/**
+ * @brief Gets the language from given event info
+ *
+ * @since_tizen 2.3
+ * @remarks @a lang must be released using free()
+ * @param[in] event_info The system event info
+ * @param[out] lang The language changed
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_NONE Successful
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_INVALID_CONTEXT Invalid event context
+ *
+ * @see app_event_info_h
+ */
+int app_event_get_language(app_event_info_h event_info, char **lang);
+
+
+/**
+ * @brief Gets the region format from given event info
+ *
+ * @since_tizen 2.3
+ * @remarks @a region must be released using free()
+ * @param[in] event_info The system event info
+ * @param[out] region The region format changed
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_NONE Successful
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_INVALID_CONTEXT Invalid event context
+ *
+ * @see app_event_info_h
+ */
+int app_event_get_region_format(app_event_info_h event_info, char **region);
+
+
+/**
+ * @brief Gets the device orientation from given event info
+ *
+ * @since_tizen 2.3
+ * @param[in] event_info The system event info
+ * @param[out] orientation The device orientation changed
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_NONE Successful
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_INVALID_CONTEXT Invalid event context
+ *
+ * @see app_event_info_h
+ * @see app_device_orientation_e
+ */
+int app_event_get_device_orientation(app_event_info_h event_info, app_device_orientation_e *orientation);
+
+
+/**
+ * @brief Gets the ID of the application.
+ *
+ * @since_tizen 2.3
+ * @remarks @a id must be released using free().
+ *
+ * @param[out] id The ID of the application
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #APP_ERROR_NONE Successful
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_INVALID_CONTEXT The application is illegally launched, not launched by the launch system
+ * @retval #APP_ERROR_OUT_OF_MEMORY Out of memory
+ */
+int app_get_id(char **id);
+
+
+/**
+ * @brief Gets the localized name of the application.
+ *
+ * @since_tizen 2.3
+ * @remarks @a name must be released using free().
+ *
+ * @param[out] name The name of the application
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #APP_ERROR_NONE Successful
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_INVALID_CONTEXT The application is illegally launched, not launched by the launch system
+ * @retval #APP_ERROR_OUT_OF_MEMORY Out of memory
+ */
+int app_get_name(char **name);
+
+
+/**
+ * @brief Gets the version of the application package.
+ *
+ * @since_tizen 2.3
+ * @remarks @a version must be released using free().
+ *
+ * @param[out] version The version of the application
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #APP_ERROR_NONE Successful
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_INVALID_CONTEXT The application is illegally launched, not launched by the launch system
+ * @retval #APP_ERROR_OUT_OF_MEMORY Out of memory
+ */
+int app_get_version(char **version);
+
+
+/**
+ * @brief      Gets the absolute path to the application's data directory which is used to store private
+ *          data of the application.
+ * @details    An application can read and write its own files in the application's data directory.
+ * @since_tizen 2.3
+ * @remarks    The returned path should be released.
+ *
+ * @return     The absolute path to the application's data directory, @n
+ *             otherwise a null pointer if the memory is insufficient
+ */
+char *app_get_data_path(void);
+
+
+/**
+ * @brief      Gets the absolute path to the application's cache directory which is used to store
+ *          temporary data of the application.
+ * @details    An application can read and write its own files in the application's cache directory.
+ * @since_tizen 2.3
+ * @remarks    The returned path should be released. @n
+ *          The files stored in the application's cache directory can be removed by Setting
+ *          application or platform while the application is running.
+ *
+ * @return     The absolute path to the application's cache directory, @n
+ *          otherwise a null pointer if the memory is insufficient
+ */
+char *app_get_cache_path(void);
+
+
+/**
+ * @brief      Gets the absolute path to the application resource directory. The resource files
+ *          are delivered with the application package.
+ * @details    An application can only read its own files in the application's resource directory.
+ * @since_tizen 2.3
+ * @remarks    The returned path should be released.
+ *
+ * @return     The absolute path to the application's resource directory, @n
+ *          otherwise a null pointer if the memory is insufficient
+ */
+char *app_get_resource_path(void);
+
+
+/**
+ * @brief      Gets the absolute path to the application's shared data directory which is used to share
+ *          data with other applications.
+ * @details    An application can read and write its own files in the application's shared data
+ *          directory and others can only read the files.
+ * @since_tizen 2.3
+ * @remarks    The returned path should be released.
+ *
+ * @return     The absolute path to the application's shared data directory, @n
+ *          otherwise a null pointer if the memory is insufficient
+ */
+char *app_get_shared_data_path(void);
+
+
+/**
+ * @brief      Gets the absolute path to the application's shared resource directory which is used to
+ *          share resources with other applications.
+ * @details    An application can read its own files in the application's shared resource directory
+ *          and others can only read the files.
+ * @since_tizen 2.3
+ * @remarks    The returned path should be released.
+ *
+ * @return     The absolute path to the application's shared resource directory, @n
+ *          otherwise a null pointer if the memory is insufficient
+ */
+char *app_get_shared_resource_path(void);
+
+
+/**
+ * @brief      Gets the absolute path to the application's shared trusted directory which is used to share data
+ *          with a family of trusted applications.
+ * @details    An application can read and write its own files in the application's shared trusted directory
+ *          and the family applications signed with the same certificate can read and write the files in the
+ *          shared trusted directory.
+ * @since_tizen 2.3
+ * @remarks    The returned path should be released.
+ *
+ * @return     The absolute path to the application's shared trusted directory, @n
+ *          otherwise a null pointer if the memory is insufficient
+ */
+char *app_get_shared_trusted_path(void);
+
+
+/**
+ * @brief      Gets the absolute path to the application's external data directory which is used to
+ *          store data of the application.
+ * @details    An application can read and write its own files in the application's external data
+ *          directory.
+ * @since_tizen 2.3
+ * @remarks    The returned path should be released. @n
+ *          The important files stored in the application's external data directory should be
+ *          encrypted because they can be exported via the external sdcard.
+ *
+ * @return     The absolute path to the application's external data directory, @n
+ *                     otherwise a null pointer if the memory is insufficient
+ */
+char *app_get_external_data_path(void);
+
+
+/**
+ * @brief      Gets the absolute path to the application's external cache directory which is used to
+ *          store temporary data of the application.
+ * @details    An application can read and write its own files in the application's external cache
+ *          directory.
+ * @since_tizen 2.3
+ * @remarks The returned path should be released. @n
+ *          The files stored in the application's external cache directory can be removed by
+ *          Setting application while the application is running. @n
+ *          The important files stored in the application's external cache directory should be
+ *          encrypted because they can be exported via the external sdcard.
+ *
+ * @return     The absolute path to the application's external cache directory, @n
+ *          otherwise a null pointer if the memory is insufficient
+ */
+char *app_get_external_cache_path(void);
+
+
+/**
+ * @brief      Gets the absolute path to the application's external shared data directory which is
+ *          used to share data with other applications.
+ * @details    An application can read and write its own files in the application's external shared
+ *          data directory and others can only read the files.
+ * @since_tizen 2.3
+ * @remarks    The specified @a path should be released.
+ *
+ * @return     The absolute path to the application's external shared data directory, @n
+ *          otherwise a null pointer if the memory is insufficient
+ */
+char *app_get_external_shared_data_path(void);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_APP_H__ */
index db4dbe5dc31be9f72c90c06b228694c6a0e80fd6..6ca21128b47eb28b3fec5962149a36e7f8cb2b80 100755 (executable)
@@ -54,6 +54,11 @@ cp LICENSE %{buildroot}%{_datadir}/license/%{name}
 %files
 %manifest %{name}.manifest
 %{_libdir}/libcapi-appfw-application.so.*
+%{_libdir}/libcapi-appfw-app-control.so.*
+%{_libdir}/libcapi-appfw-app-common.so.*
+%{_libdir}/libcapi-appfw-alarm.so.*
+%{_libdir}/libcapi-appfw-preference.so.*
+
 %{_datadir}/license/%{name}
 
 %files devel
@@ -61,3 +66,8 @@ cp LICENSE %{buildroot}%{_datadir}/license/%{name}
 %{_includedir}/appfw/*.h
 %{_libdir}/pkgconfig/*.pc
 %{_libdir}/libcapi-appfw-application.so
+%{_libdir}/libcapi-appfw-app-control.so
+%{_libdir}/libcapi-appfw-app-common.so
+%{_libdir}/libcapi-appfw-alarm.so
+%{_libdir}/libcapi-appfw-preference.so
+
diff --git a/preference/CMakeLists.txt b/preference/CMakeLists.txt
new file mode 100644 (file)
index 0000000..73b2d4e
--- /dev/null
@@ -0,0 +1,65 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(fw_name "capi-appfw-preference")
+
+PROJECT(${fw_name})
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+SET(INC_DIR ${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${INC_DIR})
+
+SET(requires "dlog capi-base-common sqlite3")
+SET(pc_requires "capi-base-common capi-appfw-app-common")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_name} REQUIRED ${requires})
+FOREACH(flag ${${fw_name}_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+
+IF("${ARCH}" STREQUAL "arm")
+    ADD_DEFINITIONS("-DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DSLP_DEBUG")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
+
+add_library(${fw_name} SHARED
+               preference.c
+               )
+
+TARGET_LINK_LIBRARIES(${fw_name} capi-appfw-app-common ${${fw_name}_LDFLAGS})
+
+SET_TARGET_PROPERTIES(${fw_name}
+     PROPERTIES
+     VERSION ${FULLVER}
+     SOVERSION ${MAJORVER}
+     CLEAN_DIRECT_OUTPUT 1
+)
+
+INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(
+        DIRECTORY ${INC_DIR}/ DESTINATION include/appfw
+        FILES_MATCHING
+        PATTERN "*_private.h" EXCLUDE
+        PATTERN "${INC_DIR}/*.h"
+        )
+
+SET(PC_NAME ${fw_name})
+SET(PC_REQUIRED ${pc_requires})
+SET(PC_LDFLAGS -l${fw_name})
+
+CONFIGURE_FILE(
+    ${CMAKE_SOURCE_DIR}/capi-appfw-module.pc.in
+    ${CMAKE_SOURCE_DIR}/${fw_name}.pc
+    @ONLY
+)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+
diff --git a/preference/preference.c b/preference/preference.c
new file mode 100755 (executable)
index 0000000..f9751c2
--- /dev/null
@@ -0,0 +1,803 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sqlite3.h>
+
+#include <app_private.h>
+
+#include <app_preference.h>
+#include <app_preference_private.h>
+
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "CAPI_APPFW_APPLICATION_PREFERENCE"
+#define DBG_MODE (1)
+
+static sqlite3 *pref_db;
+static bool is_update_hook_registered;
+static pref_changed_cb_node_t *head;
+
+static void _finish(void *data)
+{
+       if (pref_db != NULL) {
+               sqlite3_close(pref_db);
+               pref_db = NULL;
+       }
+}
+
+static int _busy_handler(void *pData, int count)
+{
+       if (count < 5) {
+               LOGD("Busy Handler Called! : PID(%d) / CNT(%d)\n",
+                               getpid(), count+1);
+               usleep((count+1)*100000);
+               return 1;
+       } else {
+               LOGD("Busy Handler will be returned SQLITE_BUSY error : PID(%d)\n",
+                               getpid());
+               return 0;
+       }
+}
+
+static int _initialize(void)
+{
+       char *data_path;
+       char db_path[TIZEN_PATH_MAX];
+       int ret;
+       char *errmsg;
+
+       data_path = app_get_data_path();
+       if (data_path == NULL) {
+               LOGE("IO_ERROR(0x%08x) : fail to get data directory",
+                               PREFERENCE_ERROR_IO_ERROR);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+       snprintf(db_path, sizeof(db_path), "%s/%s", data_path, PREF_DB_NAME);
+       free(data_path);
+
+       ret = sqlite3_open(db_path, &pref_db);
+       if (ret != SQLITE_OK) {
+               LOGE("IO_ERROR(0x%08x) : fail to open db(%s)",
+                               PREFERENCE_ERROR_IO_ERROR, sqlite3_errmsg(pref_db));
+               _finish(NULL);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       ret = sqlite3_busy_handler(pref_db, _busy_handler, NULL);
+       if (ret != SQLITE_OK) {
+               LOGW("IO_ERROR(0x%08x) : fail to register busy handler(%s)\n",
+                               PREFERENCE_ERROR_IO_ERROR, sqlite3_errmsg(pref_db));
+       }
+
+       ret = sqlite3_exec(pref_db,
+                       "CREATE TABLE IF NOT EXISTS pref ( pref_key TEXT PRIMARY KEY, pref_type TEXT, pref_data TEXT)",
+                       NULL, NULL, &errmsg);
+       if (ret != SQLITE_OK) {
+               LOGE("IO_ERROR(0x%08x) : fail to create db table(%s)",
+                               PREFERENCE_ERROR_IO_ERROR, errmsg);
+               sqlite3_free(errmsg);
+               _finish(NULL);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       app_finalizer_add(_finish, NULL);
+
+       return PREFERENCE_ERROR_NONE;
+}
+
+static int _prepare_and_bind_stmt(char *buf, const char *type,
+               const char *data, const char *key, sqlite3_stmt **stmt)
+{
+       int ret;
+
+       ret = sqlite3_prepare(pref_db, buf, -1, stmt, NULL);
+       if (ret != SQLITE_OK) {
+               LOGE("IO_ERROR(0x%08x) : fail to prepare query (%d/%s)",
+                               PREFERENCE_ERROR_IO_ERROR,
+                               sqlite3_extended_errcode(pref_db),
+                               sqlite3_errmsg(pref_db));
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       ret = sqlite3_bind_text(*stmt, 1, type, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               LOGE("IO_ERROR(0x%08x) : fail to bind(1) query (%d/%s)",
+                               PREFERENCE_ERROR_IO_ERROR,
+                               sqlite3_extended_errcode(pref_db),
+                               sqlite3_errmsg(pref_db));
+               sqlite3_finalize(*stmt);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+       ret = sqlite3_bind_text(*stmt, 2, data, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               LOGE("IO_ERROR(0x%08x) : fail to bind(2) query (%d/%s)",
+                               PREFERENCE_ERROR_IO_ERROR,
+                               sqlite3_extended_errcode(pref_db),
+                               sqlite3_errmsg(pref_db));
+               sqlite3_finalize(*stmt);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+       ret = sqlite3_bind_text(*stmt, 3, key, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               LOGE("IO_ERROR(0x%08x) : fail to bind(3) query (%d/%s)",
+                               PREFERENCE_ERROR_IO_ERROR,
+                               sqlite3_extended_errcode(pref_db),
+                               sqlite3_errmsg(pref_db));
+               sqlite3_finalize(*stmt);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       return PREFERENCE_ERROR_NONE;
+}
+
+static int _write_data(const char *key, const char *type, const char *data)
+{
+       int ret;
+       bool exist = false;
+       sqlite3_stmt *stmt;
+       char buf[BUF_LEN];
+
+       if (key == NULL || key[0] == '\0' || data == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)",
+                               PREFERENCE_ERROR_INVALID_PARAMETER);
+               return PREFERENCE_ERROR_INVALID_PARAMETER;
+       }
+       /* insert data or update data if data already exist */
+       ret = preference_is_existing(key, &exist);
+       if (ret != PREFERENCE_ERROR_NONE)
+               return ret;
+
+       if (exist)
+               snprintf(buf, sizeof(buf), "UPDATE %s SET %s=?1, %s=?2 WHERE %s=?3;",
+                               PREF_TBL_NAME, PREF_F_TYPE_NAME,
+                               PREF_F_DATA_NAME, PREF_F_KEY_NAME);
+       else
+               snprintf(buf, sizeof(buf),
+                               "INSERT INTO %s (%s, %s, %s) values (?3, ?1, ?2);",
+                               PREF_TBL_NAME, PREF_F_KEY_NAME,
+                               PREF_F_TYPE_NAME, PREF_F_DATA_NAME);
+
+       ret = _prepare_and_bind_stmt(buf, type, data, key, &stmt);
+
+       if (ret != PREFERENCE_ERROR_NONE)
+               return ret;
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_DONE) {
+               LOGE("IO_ERROR(0x%08x): fail to write data(%d/%s)",
+                       PREFERENCE_ERROR_IO_ERROR,
+                       sqlite3_extended_errcode(pref_db),
+                       sqlite3_errmsg(pref_db));
+               sqlite3_finalize(stmt);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       sqlite3_finalize(stmt);
+
+       return PREFERENCE_ERROR_NONE;
+}
+
+static int _read_data(const char *key, char *type, char *data)
+{
+       int ret;
+       char *buf;
+       char **result;
+       int rows;
+       int columns;
+       char *errmsg;
+
+       if (key == NULL || key[0] == '\0'  || data == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)",
+                               PREFERENCE_ERROR_INVALID_PARAMETER);
+               return PREFERENCE_ERROR_INVALID_PARAMETER;
+       }
+
+       if (pref_db == NULL) {
+               if (_initialize() != PREFERENCE_ERROR_NONE) {
+                       LOGE("IO_ERROR(0x%08x) : fail to initialize db",
+                                       PREFERENCE_ERROR_IO_ERROR);
+                       return PREFERENCE_ERROR_IO_ERROR;
+               }
+       }
+
+       buf = sqlite3_mprintf("SELECT %s, %s, %s FROM %s WHERE %s=%Q;",
+                       PREF_F_KEY_NAME, PREF_F_TYPE_NAME, PREF_F_DATA_NAME,
+                       PREF_TBL_NAME, PREF_F_KEY_NAME, key);
+
+       if (buf == NULL) {
+               LOGE("IO_ERROR(0x%08x) : fail to create query string",
+                               PREFERENCE_ERROR_IO_ERROR);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
+       sqlite3_free(buf);
+       if (ret != SQLITE_OK) {
+               LOGE("IO_ERROR(0x%08x) : fail to read data (%s)",
+                               PREFERENCE_ERROR_IO_ERROR, errmsg);
+               sqlite3_free(errmsg);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       if (rows == 0) {
+               LOGE("NO_KEY(0x%08x) : fail to find given key(%s)",
+                               PREFERENCE_ERROR_NO_KEY, key);
+               sqlite3_free_table(result);
+               return PREFERENCE_ERROR_NO_KEY;
+       }
+
+       snprintf(type, 2, "%s", result[4]);
+       snprintf(data, BUF_LEN, "%s", result[5]);
+
+       sqlite3_free_table(result);
+
+       return PREFERENCE_ERROR_NONE;
+}
+
+
+int preference_set_int(const char *key, int value)
+{
+       char type[2];
+       char data[BUF_LEN];
+       snprintf(type, 2, "%d", PREFERENCE_TYPE_INT);
+       snprintf(data, BUF_LEN, "%d", value);
+       return _write_data(key, type, data);
+}
+
+int preference_get_int(const char *key, int *value)
+{
+       char type[2];
+       char data[BUF_LEN];
+       int ret;
+
+       if (value == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)",
+                               PREFERENCE_ERROR_INVALID_PARAMETER);
+               return PREFERENCE_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = _read_data(key, type, data);
+       if (ret == PREFERENCE_ERROR_NONE) {
+               if (atoi(type) == PREFERENCE_TYPE_INT)
+                       *value = atoi(data);
+               else {
+                       LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)",
+                                       PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
+                       return PREFERENCE_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       return ret;
+}
+
+int preference_set_double(const char *key, double value)
+{
+       char type[2];
+       char data[BUF_LEN];
+       snprintf(type, 2, "%d", PREFERENCE_TYPE_DOUBLE);
+       snprintf(data, BUF_LEN, "%f", value);
+       return _write_data(key, type, data);
+}
+
+int preference_get_double(const char *key, double *value)
+{
+       char type[2];
+       char data[BUF_LEN];
+
+       int ret;
+
+       if (value == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)",
+                               PREFERENCE_ERROR_INVALID_PARAMETER);
+               return PREFERENCE_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = _read_data(key, type, data);
+       if (ret == PREFERENCE_ERROR_NONE) {
+               if (atoi(type) == PREFERENCE_TYPE_DOUBLE)
+                       *value = atof(data);
+               else {
+                       LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)",
+                                       PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
+                       return PREFERENCE_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       return ret;
+}
+
+int preference_set_string(const char *key, const char *value)
+{
+       char type[2];
+
+       snprintf(type, 2, "%d", PREFERENCE_TYPE_STRING);
+       if (strlen(value) > (BUF_LEN-1)) {
+               LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)",
+                               PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
+               return PREFERENCE_ERROR_INVALID_PARAMETER;
+       }
+       return _write_data(key, type, value);
+}
+
+int preference_get_string(const char *key, char **value)
+{
+       char type[2];
+       char data[BUF_LEN];
+
+       int ret;
+
+       if (value == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)",
+                               PREFERENCE_ERROR_INVALID_PARAMETER);
+               return PREFERENCE_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = _read_data(key, type, data);
+       if (ret == PREFERENCE_ERROR_NONE) {
+               if (atoi(type) == PREFERENCE_TYPE_STRING) {
+                       *value = strdup(data);
+                       if (value == NULL) {
+                               LOGE("OUT_OF_MEMORY(0x%08x)",
+                                               PREFERENCE_ERROR_OUT_OF_MEMORY);
+                               return PREFERENCE_ERROR_OUT_OF_MEMORY;
+                       }
+               } else {
+                       LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)",
+                                       PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
+                       return PREFERENCE_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       return ret;
+}
+
+int preference_set_boolean(const char *key, bool value)
+{
+       char type[2];
+       char data[BUF_LEN];
+       snprintf(type, 2, "%d", PREFERENCE_TYPE_BOOLEAN);
+       snprintf(data, BUF_LEN, "%d", value);
+       return _write_data(key, type, data);
+}
+
+int preference_get_boolean(const char *key, bool *value)
+{
+       char type[2];
+       char data[BUF_LEN];
+
+       int ret;
+
+       if (value == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)",
+                               PREFERENCE_ERROR_INVALID_PARAMETER);
+               return PREFERENCE_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = _read_data(key, type, data);
+       if (ret == PREFERENCE_ERROR_NONE) {
+               if (atoi(type) == PREFERENCE_TYPE_BOOLEAN)
+                       *value = (bool)atoi(data);
+               else {
+                       LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)",
+                                       PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
+                       return PREFERENCE_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       return ret;
+}
+
+
+/* TODO: below operation is too heavy, let's find the light way to check. */
+int preference_is_existing(const char *key, bool *exist)
+{
+       int ret;
+       char *buf;
+       char **result;
+       int rows;
+       int columns;
+       char *errmsg;
+
+       if (key == NULL  || key[0] == '\0'  || exist == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)",
+                               PREFERENCE_ERROR_INVALID_PARAMETER);
+               return PREFERENCE_ERROR_INVALID_PARAMETER;
+       }
+
+       if (pref_db == NULL) {
+               if (_initialize() != PREFERENCE_ERROR_NONE) {
+                       LOGE("IO_ERROR(0x%08x) : fail to initialize db",
+                                       PREFERENCE_ERROR_IO_ERROR);
+                       return PREFERENCE_ERROR_IO_ERROR;
+               }
+       }
+
+       /* check data is exist */
+       buf = sqlite3_mprintf("SELECT %s FROM %s WHERE %s=%Q;",
+                       PREF_F_KEY_NAME, PREF_TBL_NAME, PREF_F_KEY_NAME, key);
+
+       if (buf == NULL) {
+               LOGE("IO_ERROR(0x%08x) : fail to create query string",
+                               PREFERENCE_ERROR_IO_ERROR);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
+       sqlite3_free(buf);
+       if (ret != SQLITE_OK) {
+               LOGE("IO_ERROR(0x%08x) : fail to read data(%s)",
+                               PREFERENCE_ERROR_IO_ERROR, errmsg);
+               sqlite3_free(errmsg);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       if (rows > 0)
+               *exist = true;
+       else
+               *exist = false;
+
+       sqlite3_free_table(result);
+       return PREFERENCE_ERROR_NONE;
+}
+
+static pref_changed_cb_node_t *_find_node(const char *key)
+{
+       pref_changed_cb_node_t *tmp_node;
+
+       if (key == NULL || key[0] == '\0')
+               return NULL;
+
+       tmp_node = head;
+
+       while (tmp_node) {
+               if (strcmp(tmp_node->key, key) == 0)
+                       break;
+               tmp_node = tmp_node->next;
+       }
+
+       return tmp_node;
+}
+
+
+static int _add_node(const char *key, preference_changed_cb cb, void *user_data)
+{
+       pref_changed_cb_node_t *tmp_node;
+
+       if (key == NULL || key[0] == '\0' || cb == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)",
+                               PREFERENCE_ERROR_INVALID_PARAMETER);
+               return PREFERENCE_ERROR_INVALID_PARAMETER;
+       }
+
+       tmp_node = _find_node(key);
+
+       if (tmp_node != NULL) {
+               tmp_node->cb = cb;
+               tmp_node->user_data = user_data;
+       } else {
+               tmp_node =
+                       (pref_changed_cb_node_t *)malloc(sizeof(pref_changed_cb_node_t));
+               if (tmp_node == NULL) {
+                       LOGE("OUT_OF_MEMORY(0x%08x)",
+                                       PREFERENCE_ERROR_OUT_OF_MEMORY);
+                       return PREFERENCE_ERROR_OUT_OF_MEMORY;
+               }
+
+               tmp_node->key = strdup(key);
+               if (tmp_node->key == NULL) {
+                       free(tmp_node);
+                       LOGE("OUT_OF_MEMORY(0x%08x)", PREFERENCE_ERROR_OUT_OF_MEMORY);
+                       return PREFERENCE_ERROR_OUT_OF_MEMORY;
+               }
+
+               if (head != NULL)
+                       head->prev = tmp_node;
+               tmp_node->cb = cb;
+               tmp_node->user_data = user_data;
+               tmp_node->prev = NULL;
+               tmp_node->next = head;
+               head = tmp_node;
+       }
+
+       return PREFERENCE_ERROR_NONE;
+}
+
+static int _remove_node(const char *key)
+{
+       pref_changed_cb_node_t *tmp_node;
+
+       if (key == NULL || key[0] == '\0') {
+               LOGE("INVALID_PARAMETER(0x%08x)",
+                               PREFERENCE_ERROR_INVALID_PARAMETER);
+               return PREFERENCE_ERROR_INVALID_PARAMETER;
+       }
+
+       tmp_node = _find_node(key);
+
+       if (tmp_node == NULL)
+               return PREFERENCE_ERROR_NONE;
+
+       if (tmp_node->prev != NULL)
+               tmp_node->prev->next = tmp_node->next;
+       else
+               head = tmp_node->next;
+
+       if (tmp_node->next != NULL)
+               tmp_node->next->prev = tmp_node->prev;
+
+       if (tmp_node->key)
+               free(tmp_node->key);
+
+       free(tmp_node);
+
+       return PREFERENCE_ERROR_NONE;
+}
+
+
+static void _remove_all_node(void)
+{
+       pref_changed_cb_node_t *tmp_node;
+
+       while (head) {
+               tmp_node = head;
+               head = tmp_node->next;
+
+               if (tmp_node->key)
+                       free(tmp_node->key);
+
+               free(tmp_node);
+       }
+}
+
+
+static void _update_cb(void *data, int action, char const *db_name,
+               char const *table_name, sqlite_int64 rowid)
+{
+       int ret;
+       char *buf;
+       char **result;
+       int rows;
+       int columns;
+       char *errmsg;
+       pref_changed_cb_node_t *tmp_node;
+
+       if (action != SQLITE_UPDATE)
+               return;
+
+       if (strcmp(table_name, PREF_TBL_NAME) != 0) {
+               SECURE_LOGE("given table name (%s) is not same", table_name);
+               return;
+       }
+
+       buf = sqlite3_mprintf("SELECT %s FROM %s WHERE rowid='%lld';",
+                       PREF_F_KEY_NAME, PREF_TBL_NAME, rowid);
+       if (buf == NULL)
+               return;
+
+       ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
+       sqlite3_free(buf);
+       if (ret != SQLITE_OK) {
+               LOGI("fail to read data(%s)", errmsg);
+               sqlite3_free(errmsg);
+               return;
+       }
+
+       if (rows == 0) {
+               sqlite3_free_table(result);
+               return;
+       }
+
+       tmp_node = _find_node(result[1]);
+
+       if (tmp_node != NULL && tmp_node->cb != NULL)
+               tmp_node->cb(result[1], tmp_node->user_data);
+
+       sqlite3_free_table(result);
+}
+
+
+int preference_remove(const char *key)
+{
+       int ret;
+       char buf[BUF_LEN];
+       bool exist;
+       sqlite3_stmt *stmt;
+
+       ret = preference_is_existing(key, &exist);
+       if (ret != PREFERENCE_ERROR_NONE)
+               return ret;
+
+       if (!exist)
+               return PREFERENCE_ERROR_NO_KEY;
+
+       snprintf(buf, sizeof(buf), "DELETE FROM %s WHERE %s = ?",
+                       PREF_TBL_NAME, PREF_F_KEY_NAME);
+
+       ret = sqlite3_prepare(pref_db, buf, -1, &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               LOGE("IO_ERROR(0x%08x) : fail to prepare query (%d/%s)",
+                       PREFERENCE_ERROR_IO_ERROR,
+                       sqlite3_extended_errcode(pref_db),
+                       sqlite3_errmsg(pref_db));
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       ret = sqlite3_bind_text(stmt, 1, key, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               LOGE("IO_ERROR(0x%08x) : fail to bind(1) query (%d/%s)",
+                       PREFERENCE_ERROR_IO_ERROR,
+                       sqlite3_extended_errcode(pref_db),
+                       sqlite3_errmsg(pref_db));
+               sqlite3_finalize(stmt);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_DONE) {
+               LOGE("IO_ERROR(0x%08x): fail to delete data(%d/%s)",
+                       PREFERENCE_ERROR_IO_ERROR,
+                       sqlite3_extended_errcode(pref_db),
+                       sqlite3_errmsg(pref_db));
+               sqlite3_finalize(stmt);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       sqlite3_finalize(stmt);
+
+        _remove_node(key);
+
+       return PREFERENCE_ERROR_NONE;
+}
+
+
+int preference_remove_all(void)
+{
+       int ret;
+       char *buf;
+       char *errmsg;
+
+       if (pref_db == NULL) {
+               if (_initialize() != PREFERENCE_ERROR_NONE) {
+                       LOGE("IO_ERROR(0x%08x) : fail to initialize db",
+                                       PREFERENCE_ERROR_IO_ERROR);
+                       return PREFERENCE_ERROR_IO_ERROR;
+               }
+       }
+
+       /* insert data or update data if data already exist */
+       buf = sqlite3_mprintf("DELETE FROM %s;", PREF_TBL_NAME);
+       if (buf == NULL) {
+               LOGE("IO_ERROR(0x%08x) : fail to create query string",
+                               PREFERENCE_ERROR_IO_ERROR);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       ret = sqlite3_exec(pref_db, buf, NULL, NULL, &errmsg);
+       sqlite3_free(buf);
+       if (ret != SQLITE_OK) {
+               LOGE("IO_ERROR(0x%08x) : fail to delete data (%s)",
+                               PREFERENCE_ERROR_IO_ERROR, errmsg);
+               sqlite3_free(errmsg);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       _remove_all_node();
+
+       return PREFERENCE_ERROR_NONE;
+}
+
+
+int preference_set_changed_cb(const char *key,
+               preference_changed_cb callback, void *user_data)
+{
+       int ret;
+       bool exist;
+
+       ret = preference_is_existing(key, &exist);
+       if (ret != PREFERENCE_ERROR_NONE)
+               return ret;
+
+       if (!exist) {
+               LOGE("NO_KEY(0x%08x) : fail to find given key(%s)",
+                               PREFERENCE_ERROR_NO_KEY, key);
+               return PREFERENCE_ERROR_NO_KEY;
+       }
+
+       if (!is_update_hook_registered) {
+               sqlite3_update_hook(pref_db, _update_cb, NULL);
+               is_update_hook_registered = true;
+       }
+
+       return _add_node(key, callback, user_data);
+}
+
+int preference_unset_changed_cb(const char *key)
+{
+       int ret;
+       bool exist;
+
+       ret = preference_is_existing(key, &exist);
+       if (ret != PREFERENCE_ERROR_NONE)
+               return ret;
+
+       if (!exist) {
+               LOGE("NO_KEY(0x%08x) : fail to find given key(%s)",
+                               PREFERENCE_ERROR_NO_KEY, key);
+               return PREFERENCE_ERROR_NO_KEY;
+       }
+
+       return _remove_node(key);
+}
+
+int preference_foreach_item(preference_item_cb callback, void *user_data)
+{
+       int ret;
+       char *buf;
+       char **result;
+       int rows;
+       int columns;
+       char *errmsg;
+       int i;
+
+       if (callback == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)",
+                               PREFERENCE_ERROR_INVALID_PARAMETER);
+               return PREFERENCE_ERROR_INVALID_PARAMETER;
+       }
+
+       if (pref_db == NULL) {
+               if (_initialize() != PREFERENCE_ERROR_NONE) {
+                       LOGE("IO_ERROR(0x%08x) : fail to initialize db",
+                                       PREFERENCE_ERROR_IO_ERROR);
+                       return PREFERENCE_ERROR_IO_ERROR;
+               }
+       }
+
+       buf = sqlite3_mprintf("SELECT %s FROM %s;",
+                       PREF_F_KEY_NAME, PREF_TBL_NAME);
+       if (buf == NULL) {
+               LOGE("IO_ERROR(0x%08x) : fail to create query string",
+                               PREFERENCE_ERROR_IO_ERROR);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
+       sqlite3_free(buf);
+       if (ret != SQLITE_OK) {
+               LOGE("IO_ERROR(0x%08x) : fail to read data (%s)",
+                               PREFERENCE_ERROR_IO_ERROR, errmsg);
+               sqlite3_free(errmsg);
+               return PREFERENCE_ERROR_IO_ERROR;
+       }
+
+       for (i = 1; i <= rows; i++) {
+               if (callback(result[i], user_data) != true)
+                       break;
+       }
+
+       sqlite3_free_table(result);
+
+       return PREFERENCE_ERROR_NONE;
+}
diff --git a/src/alarm.c b/src/alarm.c
deleted file mode 100755 (executable)
index 374fd04..0000000
+++ /dev/null
@@ -1,492 +0,0 @@
-/*
- * Copyright (c) 2011 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <time.h>
-
-#include <aul.h>
-#include <alarm.h>
-#include <dlog.h>
-
-#include <app_private.h>
-#include <app_alarm.h>
-#include <app_control_internal.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "CAPI_APPFW_APPLICATION_ALARM"
-
-typedef struct {
-       alarm_registered_alarm_cb cb;
-       void* user_data;
-       bool* foreach_break;
-} alarm_foreach_item_cb_context;
-
-static int alarm_registered_alarm_cb_broker(int alarm_id, void *user_data)
-{
-       alarm_foreach_item_cb_context* foreach_cb_context = NULL;
-
-       if (user_data == NULL)
-       {
-               return 0;
-       }
-
-       foreach_cb_context = (alarm_foreach_item_cb_context*)user_data;
-
-       if (foreach_cb_context != NULL && *(foreach_cb_context->foreach_break) == false)
-       {
-               if (foreach_cb_context->cb(alarm_id, foreach_cb_context->user_data) == false)
-               {
-                       *(foreach_cb_context->foreach_break) = true;
-               }
-       }
-
-       return 0;
-}
-
-static int convert_error_code_to_alarm(const char* function, alarm_error_t alarm_error)
-{
-       switch(alarm_error)
-       {
-       case ERR_ALARM_INVALID_PARAM:
-       case ERR_ALARM_INVALID_REPEAT:
-               LOGE("[%s] INVALID_PARAMETER(0x%08x)", function, ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-               break;
-
-       case ERR_ALARM_INVALID_ID:
-               LOGE("[%s] INVALID_PARAMETER(0x%08x)", function, ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-               break;
-
-       case ERR_ALARM_INVALID_TIME:
-               LOGE("[%s] INVALID_TIME(0x%08x)", function, ALARM_ERROR_INVALID_TIME);
-               return ALARM_ERROR_INVALID_TIME;
-               break;
-
-       case ERR_ALARM_INVALID_DATE:
-               LOGE("[%s] INVALID_DATE(0x%08x)", function, ALARM_ERROR_INVALID_DATE);
-               return ALARM_ERROR_INVALID_DATE;
-               break;
-
-       case ERR_ALARM_NO_SERVICE_NAME:
-               LOGE("[%s] INVALID_PARAMETER(0x%08x)", function, ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-               break;
-
-       case ERR_ALARM_SYSTEM_FAIL:
-               LOGE("[%s] CONNECTION_FAIL(0x%08x)", function, ALARM_ERROR_CONNECTION_FAIL);
-               return ALARM_ERROR_CONNECTION_FAIL;
-               break;
-
-       case ALARMMGR_RESULT_SUCCESS:
-               return ALARM_ERROR_NONE;
-               break;
-
-       default:
-               return ALARM_ERROR_INVALID_PARAMETER;
-       }
-
-}
-
-static int _remove_alarm_cb(alarm_id_t alarm_id, void* user_param)
-{
-       return alarmmgr_remove_alarm(alarm_id);
-}
-
-int alarm_get_scheduled_date(int alarm_id, struct tm* date)
-{
-       alarm_error_t result;
-       time_t due_time = 0;
-
-       if (date == NULL)
-       {
-               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-       }
-
-       result = alarmmgr_get_next_duetime(alarm_id, &due_time);
-       if (result != ALARMMGR_RESULT_SUCCESS)
-       {
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-       localtime_r(&due_time, date);
-
-       return ALARM_ERROR_NONE;
-
-}
-
-int alarm_get_scheduled_period(int alarm_id, int* period)
-{
-       alarm_error_t result;
-       alarm_entry_t *entry = NULL;
-       alarm_repeat_mode_t mode;
-       int value;
-
-       if (period == NULL)
-       {
-               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-       }
-
-       entry = alarmmgr_create_alarm();
-
-       result = alarmmgr_get_info(alarm_id, entry);
-       if (result != ALARMMGR_RESULT_SUCCESS)
-       {
-               if (entry != NULL)
-               {
-                       alarmmgr_free_alarm(entry);
-               }
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-       result = alarmmgr_get_repeat_mode(entry, &mode, &value);
-       if (result != ALARMMGR_RESULT_SUCCESS)
-       {
-               if (entry != NULL)
-               {
-                       alarmmgr_free_alarm(entry);
-               }
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-       result = alarmmgr_free_alarm(entry);
-       if(result != ALARMMGR_RESULT_SUCCESS)
-       {
-               if (entry != NULL)
-               {
-                       alarmmgr_free_alarm(entry);
-               }
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-       (*period) = value;
-
-       return ALARM_ERROR_NONE;
-
-}
-
-int alarm_schedule_after_delay(app_control_h app_control, int delay, int period, int *alarm_id)
-{
-       bundle *bundle_data;
-       int result = 0;
-
-       if (app_control == NULL)
-       {
-               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-       }
-
-       if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE)
-       {
-               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-       }
-
-       result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, delay, period, bundle_data, alarm_id);
-
-       return  convert_error_code_to_alarm(__FUNCTION__, result);
-}
-
-int alarm_schedule_at_date(app_control_h app_control, struct tm *date, int period_in_second, int *alarm_id)
-{
-       alarm_date_t internal_time;
-       alarm_entry_t* alarm_info;
-       bundle *bundle_data;
-       int result;
-
-       if (app_control == NULL || date == NULL)
-       {
-               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-       }
-
-       if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE)
-       {
-               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-       }
-
-       alarm_info = alarmmgr_create_alarm();
-
-       internal_time.year = date->tm_year + 1900;
-       internal_time.month = date->tm_mon +1;
-       internal_time.day = date->tm_mday;
-
-       internal_time.hour = date->tm_hour;
-       internal_time.min = date->tm_min;
-       internal_time.sec = date->tm_sec;
-
-       result = alarmmgr_set_time(alarm_info,internal_time);
-
-       if (result < 0)
-       {
-               alarmmgr_free_alarm(alarm_info);
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-
-       if (period_in_second > 0)
-       {
-               result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_REPEAT, period_in_second);
-       }
-       else
-       {
-               result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, period_in_second);
-       }
-
-       if (result < 0)
-       {
-               alarmmgr_free_alarm(alarm_info);
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-       result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
-
-       if (result < 0)
-       {
-               alarmmgr_free_alarm(alarm_info);
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-       result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id);
-
-       if (result < 0)
-       {
-               alarmmgr_free_alarm(alarm_info);
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-       alarmmgr_free_alarm(alarm_info);
-       return ALARM_ERROR_NONE;
-}
-
-int alarm_cancel(int alarm_id)
-{
-       int result;
-
-       result = alarmmgr_remove_alarm(alarm_id);
-
-       return convert_error_code_to_alarm(__FUNCTION__, result);
-}
-
-int alarm_cancel_all()
-{
-       int result;
-
-       result = alarmmgr_enum_alarm_ids( _remove_alarm_cb, NULL);
-
-       return convert_error_code_to_alarm(__FUNCTION__, result);
-}
-
-int alarm_foreach_registered_alarm(alarm_registered_alarm_cb callback, void* user_data)
-{
-       int result;
-       bool foreach_break = false;
-
-       if (callback == NULL)
-       {
-               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-       }
-
-       //alarm_registered_alarm_cb_broker
-       alarm_foreach_item_cb_context foreach_cb_context = {
-               .cb = callback,
-               .user_data = user_data,
-               .foreach_break = &foreach_break
-       };
-
-       result = alarmmgr_enum_alarm_ids(alarm_registered_alarm_cb_broker, &foreach_cb_context);
-
-       return convert_error_code_to_alarm(__FUNCTION__, result);
-}
-
-int alarm_get_current_time(struct tm* date)
-{
-       time_t now;
-
-       if (date == NULL)
-       {
-               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-       }
-
-       time(&now);
-       localtime_r(&now, date);
-       return ALARM_ERROR_NONE;
-}
-
-
-int alarm_schedule_with_recurrence_week_flag(app_control_h app_control, struct tm *date, int week_flag,int *alarm_id)
-{
-       alarm_date_t internal_time;
-       alarm_entry_t* alarm_info;
-       bundle *bundle_data;
-       int result;
-
-       if (app_control == NULL || date == NULL)
-       {
-               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-       }
-
-       if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE)
-       {
-               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-       }
-
-       alarm_info = alarmmgr_create_alarm();
-
-       internal_time.year = date->tm_year + 1900;
-       internal_time.month = date->tm_mon +1;
-       internal_time.day = date->tm_mday;
-
-       internal_time.hour = date->tm_hour;
-       internal_time.min = date->tm_min;
-       internal_time.sec = date->tm_sec;
-
-       result = alarmmgr_set_time(alarm_info,internal_time);
-
-       if (result < 0)
-       {
-               alarmmgr_free_alarm(alarm_info);
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-       if (week_flag > 0)
-       {
-               result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_WEEKLY, week_flag);
-       }
-
-       if (result < 0)
-       {
-               alarmmgr_free_alarm(alarm_info);
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-       result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
-
-       if (result < 0)
-       {
-               alarmmgr_free_alarm(alarm_info);
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-       result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id);
-
-       alarmmgr_free_alarm(alarm_info);
-       return convert_error_code_to_alarm(__FUNCTION__, result);
-}
-
-int alarm_get_scheduled_recurrence_week_flag(int alarm_id, int *week_flag)
-{
-       alarm_error_t result;
-       alarm_entry_t *entry = NULL;
-       alarm_repeat_mode_t mode;
-       int value;
-
-       if(week_flag == NULL)
-       {
-               LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
-               return ALARM_ERROR_INVALID_PARAMETER;
-       }
-
-       entry = alarmmgr_create_alarm();
-
-       result = alarmmgr_get_info(alarm_id, entry);
-       if(result != ALARMMGR_RESULT_SUCCESS)
-       {
-               if (entry != NULL)
-               {
-                       alarmmgr_free_alarm(entry);
-               }
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-       result = alarmmgr_get_repeat_mode(entry, &mode, &value);
-
-       if(mode != ALARM_REPEAT_MODE_WEEKLY)
-       {
-               if (entry != NULL)
-               {
-                       alarmmgr_free_alarm(entry);
-               }
-               return ALARM_ERROR_INVALID_PARAMETER;
-       }
-
-       if(result != ALARMMGR_RESULT_SUCCESS)
-       {
-               if (entry != NULL)
-               {
-                       alarmmgr_free_alarm(entry);
-               }
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-       result = alarmmgr_free_alarm(entry);
-       if(result != ALARMMGR_RESULT_SUCCESS)
-       {
-               if (entry != NULL)
-               {
-                       alarmmgr_free_alarm(entry);
-               }
-               return convert_error_code_to_alarm(__FUNCTION__, result);
-       }
-
-       (*week_flag) = value;
-
-       return ALARM_ERROR_NONE;
-}
-
-int alarm_get_app_control(int alarm_id, app_control_h *app_control)
-{
-    bundle *b = NULL;
-    int error_code = 0;
-
-    b = alarmmgr_get_alarm_appsvc_info(alarm_id, &error_code);
-
-    if(error_code != ALARMMGR_RESULT_SUCCESS)
-    {
-        return convert_error_code_to_alarm(__FUNCTION__, error_code);
-    }
-
-    if(b == NULL)
-    {
-        return ALARM_ERROR_INVALID_PARAMETER;
-    }
-
-    error_code = app_control_create_request(b, app_control);
-
-    if(error_code != APP_CONTROL_ERROR_NONE)
-    {
-        return ALARM_ERROR_OUT_OF_MEMORY;
-    }
-
-    bundle_free(b);
-
-    return ALARM_ERROR_NONE;
-
-}
diff --git a/src/app_control.c b/src/app_control.c
deleted file mode 100755 (executable)
index 9603792..0000000
+++ /dev/null
@@ -1,1335 +0,0 @@
-/*
- * Copyright (c) 2011 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 <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
-#include <bundle.h>
-#include <aul.h>
-#include <appsvc.h>
-#include <dlog.h>
-
-#include <app_control.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "CAPI_APPFW_APP_CONTROL"
-
-#ifndef TIZEN_PATH_MAX
-#define TIZEN_PATH_MAX 1024
-#endif
-
-#define BUNDLE_KEY_PREFIX_AUL "__AUL_"
-#define BUNDLE_KEY_PREFIX_SERVICE "__APP_SVC_"
-
-#define BUNDLE_KEY_OPERATION   "__APP_SVC_OP_TYPE__"
-#define BUNDLE_KEY_URI         "__APP_SVC_URI__"
-#define BUNDLE_KEY_MIME                "__APP_SVC_MIME_TYPE__"
-#define BUNDLE_KEY_DATA                "__APP_SVC_DATA__"
-#define BUNDLE_KEY_PACKAGE     "__APP_SVC_PKG_NAME__"
-#define BUNDLE_KEY_WINDOW      "__APP_SVC_K_WIN_ID__"
-#define BUNDLE_KEY_CATEGORY    "__APP_SVC_CATEGORY__"
-
-typedef enum {
-       APP_CONTROL_TYPE_REQUEST,
-       APP_CONTROL_TYPE_EVENT,
-       APP_CONTROL_TYPE_REPLY,
-} app_control_type_e;
-
-struct app_control_s {
-       int id;
-       app_control_type_e type;
-       bundle *data;
-       int launch_pid;
-};
-
-typedef struct app_control_request_context_s {
-       app_control_h app_control;
-       app_control_reply_cb reply_cb;
-       void *user_data;
-} *app_control_request_context_h;
-
-extern int appsvc_allow_transient_app(bundle *b, unsigned int id);
-extern int appsvc_request_transient_app(bundle *b, unsigned int callee_id, appsvc_host_res_fn cbfunc, void *data);
-
-static int app_control_create_reply(bundle *data, struct app_control_s **app_control);
-
-static const char* app_control_error_to_string(app_control_error_e error)
-{
-       switch (error)
-       {
-       case APP_CONTROL_ERROR_NONE:
-               return "NONE";
-
-       case APP_CONTROL_ERROR_INVALID_PARAMETER:
-               return "INVALID_PARAMETER";
-
-       case APP_CONTROL_ERROR_OUT_OF_MEMORY:
-               return "OUT_OF_MEMORY";
-
-       case APP_CONTROL_ERROR_APP_NOT_FOUND:
-               return "APP_NOT_FOUND";
-
-       case APP_CONTROL_ERROR_KEY_NOT_FOUND:
-               return "KEY_NOT_FOUND";
-
-       case APP_CONTROL_ERROR_KEY_REJECTED:
-               return "KEY_REJECTED";
-
-       case APP_CONTROL_ERROR_INVALID_DATA_TYPE:
-               return "INVALID_DATA_TYPE";
-
-       case APP_CONTROL_ERROR_LAUNCH_REJECTED:
-               return "LAUNCH_REJECTED";
-
-       case APP_CONTROL_ERROR_PERMISSION_DENIED:
-               return "PERMISSION_DENIED";
-
-       case APP_CONTROL_ERROR_LAUNCH_FAILED:
-               return "LAUNCH_FAILED";
-
-       case APP_CONTROL_ERROR_TIMED_OUT:
-               return "TIMED_OUT";
-
-       default :
-               return "UNKNOWN";
-       }
-}
-
-int app_control_error(app_control_error_e error, const char* function, const char *description)
-{
-       if (description)
-       {
-               LOGE("[%s] %s(0x%08x) : %s", function, app_control_error_to_string(error), error, description);
-       }
-       else
-       {
-               if(error == APP_CONTROL_ERROR_KEY_NOT_FOUND)
-                       LOGW("[%s] %s(0x%08x)", function, app_control_error_to_string(error), error);
-               else
-                       LOGE("[%s] %s(0x%08x)", function, app_control_error_to_string(error), error);
-       }
-
-       return error;
-}
-
-static int app_control_validate_extra_data(const char *data)
-{
-       if (data == NULL || data[0] == '\0')
-       {
-               return APP_CONTROL_ERROR_INVALID_PARAMETER;
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-static int app_control_validate(app_control_h app_control)
-{
-       if (app_control == NULL || app_control->data == NULL)
-       {
-               return APP_CONTROL_ERROR_INVALID_PARAMETER;
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-static int app_control_new_id()
-{
-       static int sid = 0;
-       return sid++;
-}
-
-int app_control_validate_internal_key(const char *key)
-{
-       if (strncmp(BUNDLE_KEY_PREFIX_AUL, key, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
-       {
-               return -1;
-       }
-
-       if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, key, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
-       {
-               return -1;
-       }
-
-       return 0;
-}
-
-static void app_control_request_result_broker(bundle *appsvc_bundle, int appsvc_request_code, appsvc_result_val appsvc_result, void *appsvc_data)
-{
-       app_control_request_context_h request_context;
-       app_control_h request;
-       app_control_h reply = NULL;
-       app_control_result_e result;
-       void *user_data;
-       app_control_reply_cb reply_cb;
-
-       if (appsvc_data == NULL)
-       {
-               app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid app_control reply");
-               return;
-       }
-
-       if (app_control_create_reply(appsvc_bundle, &reply) != 0)
-       {
-               app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create app_control reply");
-               return;
-       }
-
-       request_context = appsvc_data;
-       request = request_context->app_control;
-
-       switch (appsvc_result)
-       {
-       case APPSVC_RES_OK:
-               result = APP_CONTROL_RESULT_SUCCEEDED;
-               break;
-
-       case APPSVC_RES_NOT_OK:
-               result = APP_CONTROL_RESULT_FAILED;
-               break;
-
-       case APPSVC_RES_CANCEL:
-               result = APP_CONTROL_RESULT_CANCELED;
-               break;
-
-       default:
-               result = APP_CONTROL_RESULT_CANCELED;
-               break;
-       }
-
-       user_data = request_context->user_data;
-       reply_cb = request_context->reply_cb;
-
-       if (reply_cb != NULL)
-       {
-               reply_cb(request, reply, result, user_data);
-       }
-       else
-       {
-               app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid callback ");
-       }
-
-       app_control_destroy(reply);
-
-       if (request_context->app_control != NULL)
-       {
-               app_control_destroy(request_context->app_control);
-       }
-
-       free(request_context);
-}
-
-int app_control_create_request(bundle *data, app_control_h *app_control)
-{
-       struct app_control_s *app_control_request;
-
-       if (app_control == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       app_control_request = malloc(sizeof(struct app_control_s));
-
-       if (app_control_request == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a app_control handle");
-       }
-
-       app_control_request->type = APP_CONTROL_TYPE_REQUEST;
-
-       if (data != NULL)
-       {
-               app_control_request->data = bundle_dup(data);
-       }
-       else
-       {
-               app_control_request->data = bundle_create();
-       }
-
-       if (app_control_request->data == NULL)
-       {
-               free(app_control_request);
-               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a bundle");
-       }
-
-       app_control_request->id = app_control_new_id();
-       app_control_request->launch_pid = -1;
-
-       *app_control = app_control_request;
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-int app_control_create(app_control_h *app_control)
-{
-       return app_control_create_request(NULL, app_control);
-}
-
-int app_control_create_event(bundle *data, struct app_control_s **app_control)
-{
-       struct app_control_s *app_control_event;
-
-       const char *operation;
-
-       if (data == NULL || app_control == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       app_control_event = malloc(sizeof(struct app_control_s));
-
-       if (app_control_event == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a app_control handle");
-       }
-
-       app_control_event->type = APP_CONTROL_TYPE_EVENT;
-       app_control_event->data = bundle_dup(data);
-       app_control_event->id = app_control_new_id();
-
-       operation = appsvc_get_operation(app_control_event->data);
-
-       if (operation == NULL)
-       {
-               appsvc_set_operation(app_control_event->data, APP_CONTROL_OPERATION_DEFAULT);
-       }
-
-       *app_control = app_control_event;
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-static int app_control_create_reply(bundle *data, struct app_control_s **app_control)
-{
-       struct app_control_s *app_control_reply;
-
-       if (data == NULL || app_control == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       app_control_reply = malloc(sizeof(struct app_control_s));
-
-       if (app_control_reply == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a app_control handle");
-       }
-
-       app_control_reply->type = APP_CONTROL_TYPE_REPLY;
-       app_control_reply->data = bundle_dup(data);
-       app_control_reply->id = app_control_new_id();
-
-       *app_control = app_control_reply;
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-int app_control_destroy(app_control_h app_control)
-{
-       if (app_control_validate(app_control))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       bundle_free(app_control->data);
-       app_control->data = NULL;
-       free(app_control);
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-int app_control_to_bundle(app_control_h app_control, bundle **data)
-{
-       if (app_control_validate(app_control) || data == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       *data = app_control->data;
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-int app_control_set_operation(app_control_h app_control, const char *operation)
-{
-       if (app_control_validate(app_control))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (operation != NULL)
-       {
-               if (appsvc_set_operation(app_control->data, operation) != 0)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid operation");
-               }
-       }
-       else
-       {
-               bundle_del(app_control->data, BUNDLE_KEY_OPERATION);
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-int app_control_get_operation(app_control_h app_control, char **operation)
-{
-       const char *operation_value;
-
-       if (app_control_validate(app_control) || operation == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       operation_value = appsvc_get_operation(app_control->data);
-
-       if (operation_value != NULL)
-       {
-               *operation = strdup(operation_value);
-       }
-       else
-       {
-               *operation = NULL;
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_set_uri(app_control_h app_control, const char *uri)
-{
-       if (app_control_validate(app_control))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (uri != NULL)
-       {
-               if (appsvc_set_uri(app_control->data, uri) != 0)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid URI");
-               }
-       }
-       else
-       {
-               bundle_del(app_control->data, BUNDLE_KEY_URI);
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_get_uri(app_control_h app_control, char **uri)
-{
-       const char *uri_value;
-
-       if (app_control_validate(app_control) || uri == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       uri_value = appsvc_get_uri(app_control->data);
-
-       if (uri_value != NULL)
-       {
-               *uri = strdup(uri_value);
-       }
-       else
-       {
-               *uri = NULL;
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_set_mime(app_control_h app_control, const char *mime)
-{
-       if (app_control_validate(app_control))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (mime != NULL)
-       {
-               if (appsvc_set_mime(app_control->data, mime) != 0)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid MIME type");
-               }
-       }
-       else
-       {
-               bundle_del(app_control->data, BUNDLE_KEY_MIME);
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_get_mime(app_control_h app_control, char **mime)
-{
-       const char *mime_value;
-
-       if (app_control_validate(app_control) || mime == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       mime_value = appsvc_get_mime(app_control->data);
-
-       if (mime_value != NULL)
-       {
-               *mime = strdup(mime_value);
-       }
-       else
-       {
-               *mime = NULL;
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_set_category(app_control_h app_control, const char *category)
-{
-       if (app_control_validate(app_control))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (category != NULL)
-       {
-               if (appsvc_set_category(app_control->data, category) != 0)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid Category");
-               }
-       }
-       else
-       {
-               bundle_del(app_control->data, BUNDLE_KEY_CATEGORY);
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_get_category(app_control_h app_control, char **category)
-{
-       const char *category_value;
-
-       if (app_control_validate(app_control) || category == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       category_value = appsvc_get_category(app_control->data);
-
-       if (category_value != NULL)
-       {
-               *category = strdup(category_value);
-       }
-       else
-       {
-               *category = NULL;
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_set_package(app_control_h app_control, const char *package)
-{
-       // TODO: this function must be deprecated
-       return app_control_set_app_id(app_control, package);
-}
-
-int app_control_get_package(app_control_h app_control, char **package)
-{
-       // TODO: this function must be deprecated
-       return app_control_get_app_id(app_control, package);
-}
-
-
-int app_control_set_app_id(app_control_h app_control, const char *app_id)
-{
-       if (app_control_validate(app_control))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (app_id != NULL)
-       {
-               if (appsvc_set_appid(app_control->data, app_id) != 0)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid application ID");
-               }
-       }
-       else
-       {
-               bundle_del(app_control->data, BUNDLE_KEY_PACKAGE);
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_get_app_id(app_control_h app_control, char **app_id)
-{
-       const char *app_id_value;
-
-       if (app_control_validate(app_control) || app_id == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       app_id_value = appsvc_get_appid(app_control->data);
-
-       if (app_id_value != NULL)
-       {
-               *app_id = strdup(app_id_value);
-       }
-       else
-       {
-               *app_id = NULL;
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-int app_control_set_window(app_control_h app_control, unsigned int id)
-{
-       if (app_control_validate(app_control))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (id > 0)
-       {
-               if (appsvc_allow_transient_app(app_control->data, id) != 0)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid id");
-               }
-       }
-       else
-       {
-               bundle_del(app_control->data, BUNDLE_KEY_WINDOW);
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-int app_control_get_window(app_control_h app_control, unsigned int *id)
-{
-       const char *window_id;
-
-       if (app_control_validate(app_control) || id == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       window_id = bundle_get_val(app_control->data, BUNDLE_KEY_WINDOW);
-
-       if (window_id != NULL)
-       {
-               *id = atoi(window_id);
-       }
-       else
-       {
-               *id = 0;
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-int app_control_clone(app_control_h *clone, app_control_h app_control)
-{
-       app_control_h app_control_clone;
-
-       if (app_control_validate(app_control) || clone == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       app_control_clone = malloc(sizeof(struct app_control_s));
-
-       if (app_control_clone == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a app_control handle");
-       }
-
-       app_control_clone->id = app_control_new_id();
-       app_control_clone->type = app_control->type;
-       app_control_clone->data = bundle_dup(app_control->data);
-
-       *clone = app_control_clone;
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-int app_control_send_launch_request(app_control_h app_control, app_control_reply_cb callback, void *user_data)
-{
-       const char *operation;
-
-       bool implicit_default_operation = false;
-       int launch_pid;
-
-       app_control_request_context_h request_context = NULL;
-
-       if (app_control_validate(app_control))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       operation = appsvc_get_operation(app_control->data);
-       if (operation == NULL)
-       {
-               implicit_default_operation = true;
-               operation = APP_CONTROL_OPERATION_DEFAULT;
-       }
-
-       // TODO: Check the privilege for call operation
-
-       // operation : default
-       if (!strcmp(operation, APP_CONTROL_OPERATION_DEFAULT))
-       {
-               const char *appid  = appsvc_get_appid(app_control->data);
-               if (appid == NULL)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_APP_NOT_FOUND, __FUNCTION__, "package must be specified if the operation is default value");
-               }
-       }
-
-       if (callback != NULL)
-       {
-               app_control_h request_clone = NULL;
-
-               request_context = calloc(1, sizeof(struct app_control_request_context_s));
-
-               if (request_context == NULL)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
-               }
-
-               request_context->reply_cb = callback;
-
-               if (app_control_clone(&request_clone, app_control) != APP_CONTROL_ERROR_NONE)
-               {
-                       free(request_context);
-                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to clone the app_control request handle");
-               }
-
-               request_context->app_control = request_clone;
-               request_context->user_data = user_data;
-       }
-
-       if (implicit_default_operation == true)
-       {
-               appsvc_set_operation(app_control->data, APP_CONTROL_OPERATION_DEFAULT);
-       }
-
-       launch_pid = appsvc_run_service(app_control->data, app_control->id, callback ? app_control_request_result_broker : NULL, request_context);
-
-       if (implicit_default_operation == true)
-       {
-               bundle_del(app_control->data, BUNDLE_KEY_OPERATION);
-       }
-
-       if (launch_pid < 0)
-       {
-               if (launch_pid == APPSVC_RET_ENOMATCH)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_APP_NOT_FOUND, __FUNCTION__, NULL);
-               }
-               else if (launch_pid == APPSVC_RET_EILLACC)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_PERMISSION_DENIED, __FUNCTION__, NULL);
-               }
-               else if (launch_pid == APPSVC_RET_EINVAL)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-               }
-               else
-               {
-                       return app_control_error(APP_CONTROL_ERROR_LAUNCH_REJECTED, __FUNCTION__, NULL);
-               }
-       }
-
-       app_control->launch_pid = launch_pid;
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_send_terminate_request(app_control_h app_control)
-{
-       if (app_control_validate(app_control))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if(app_control->type != APP_CONTROL_TYPE_REQUEST || app_control->launch_pid < 0)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       appsvc_subapp_terminate_request_pid(app_control->launch_pid);
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-static bool app_control_copy_reply_data_cb(app_control_h app_control, const char *key, void *user_data)
-{
-       bundle *reply_data = user_data;
-       char *value = NULL;
-       char **value_array = NULL;
-       int value_array_length = 0;
-       int value_array_index = 0;
-
-       if (reply_data == NULL)
-       {
-               app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-               return false;
-       }
-
-       if (appsvc_data_is_array(app_control->data, key))
-       {
-               app_control_get_extra_data_array(app_control, key, &value_array, &value_array_length);
-               appsvc_add_data_array(reply_data, key, (const char**)value_array, value_array_length);
-
-               for (value_array_index=0; value_array_index < value_array_length; value_array_index++)
-               {
-                       free(value_array[value_array_index]);
-               }
-
-               free(value_array);
-       }
-       else
-       {
-               app_control_get_extra_data(app_control, key, &value);
-               appsvc_add_data(reply_data, key, value);
-               free(value);
-       }
-
-       return true;
-}
-
-int app_control_reply_to_launch_request(app_control_h reply, app_control_h request, app_control_result_e result)
-{
-       bundle *reply_data;
-       int appsvc_result;
-       int ret = 0;
-
-       if (app_control_validate(reply) || app_control_validate(request))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (appsvc_create_result_bundle(request->data, &reply_data) != 0)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create a result bundle");
-       }
-
-       app_control_foreach_extra_data(reply, app_control_copy_reply_data_cb, reply_data);
-
-       switch (result)
-       {
-       case APP_CONTROL_RESULT_SUCCEEDED:
-               appsvc_result = APPSVC_RES_OK;
-               break;
-
-       case APP_CONTROL_RESULT_FAILED:
-               appsvc_result = APPSVC_RES_NOT_OK;
-               break;
-
-       case APP_CONTROL_RESULT_CANCELED:
-               appsvc_result = APPSVC_RES_CANCEL;
-               break;
-
-       default:
-               appsvc_result = APPSVC_RES_CANCEL;
-               break;
-       }
-
-       ret = appsvc_send_result(reply_data, appsvc_result);
-       if (ret < 0)
-       {
-               if (ret == APPSVC_RET_EINVAL)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-               }
-               else
-               {
-                       return app_control_error(APP_CONTROL_ERROR_LAUNCH_REJECTED, __FUNCTION__, NULL);
-               }
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_add_extra_data(app_control_h app_control, const char *key, const char *value)
-{
-       if (app_control_validate(app_control) || app_control_validate_extra_data(key) || app_control_validate_extra_data(value))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (app_control_validate_internal_key(key))
-       {
-               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
-       }
-
-       if (appsvc_get_data(app_control->data, key) != NULL)
-       {
-               // overwrite any existing value
-               bundle_del(app_control->data, key);
-       }
-
-       if (appsvc_add_data(app_control->data, key, value) != 0)
-       {
-               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "failed to add data to the appsvc handle");
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_add_extra_data_array(app_control_h app_control, const char *key, const char* value[], int length)
-{
-       if (app_control_validate(app_control) || app_control_validate_extra_data(key))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (value == NULL || length <= 0)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid array");
-       }
-
-       if (app_control_validate_internal_key(key))
-       {
-               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
-       }
-
-       if (appsvc_get_data_array(app_control->data, key, NULL) != NULL)
-       {
-               // overwrite any existing value
-               bundle_del(app_control->data,key);
-       }
-
-       if (appsvc_add_data_array(app_control->data, key, value, length) != 0)
-       {
-               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "failed to add array data to the appsvc handle");
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_remove_extra_data(app_control_h app_control, const char *key)
-{
-       if (app_control_validate(app_control) || app_control_validate_extra_data(key))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (app_control_validate_internal_key(key))
-       {
-               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
-       }
-
-       if (bundle_del(app_control->data, key))
-       {
-               return app_control_error(APP_CONTROL_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL);
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_get_extra_data(app_control_h app_control, const char *key, char **value)
-{
-       const char *data_value;
-
-       if (app_control_validate(app_control) || app_control_validate_extra_data(key) || value == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-
-       if (app_control_validate_internal_key(key))
-       {
-               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
-       }
-
-       data_value = appsvc_get_data(app_control->data, key);
-
-       if (data_value == NULL)
-       {
-               if (errno == ENOTSUP)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_INVALID_DATA_TYPE, __FUNCTION__, NULL);
-               }
-               else
-               {
-                       return app_control_error(APP_CONTROL_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL);
-               }
-       }
-
-       *value = strdup(data_value);
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_get_extra_data_array(app_control_h app_control, const char *key, char ***value, int *length)
-{
-       const char **array_data;
-       int array_data_length;
-       char **array_data_clone;
-       int i;
-
-       if (app_control_validate(app_control) || app_control_validate_extra_data(key))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (value == NULL || length == 0)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (app_control_validate_internal_key(key))
-       {
-               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
-       }
-
-       array_data = appsvc_get_data_array(app_control->data, key, &array_data_length);
-
-       if (array_data == NULL)
-       {
-               if (errno == ENOTSUP)
-               {
-                       return app_control_error(APP_CONTROL_ERROR_INVALID_DATA_TYPE, __FUNCTION__, NULL);
-               }
-               else
-               {
-                       return app_control_error(APP_CONTROL_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL);
-               }
-       }
-
-       array_data_clone = calloc(array_data_length, sizeof(char*));
-
-       if (array_data_clone == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
-       }
-
-       for (i=0; i<array_data_length; i++)
-       {
-               if (array_data[i] != NULL)
-               {
-                       array_data_clone[i] = strdup(array_data[i]);
-               }
-       }
-
-       *value = array_data_clone;
-       *length = array_data_length;
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_is_extra_data_array(app_control_h app_control, const char *key, bool *array)
-{
-       if (app_control_validate(app_control) || app_control_validate_extra_data(key) || array == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (app_control_validate_internal_key(key))
-       {
-               return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
-\r      }
-
-       if (!appsvc_data_is_array(app_control->data, key))
-       {
-               *array = false;
-       }
-       else
-       {
-               *array = true;
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-typedef struct {
-       app_control_h app_control;
-       app_control_extra_data_cb callback;
-       void* user_data;
-       bool foreach_break;
-} foreach_context_extra_data_t;
-
-static void app_control_cb_broker_bundle_iterator(const char *key, const int type, const bundle_keyval_t *kv, void *user_data)
-{
-       foreach_context_extra_data_t* foreach_context = NULL;
-       app_control_extra_data_cb extra_data_cb;
-
-       if (key == NULL || !(type == BUNDLE_TYPE_STR || type == BUNDLE_TYPE_STR_ARRAY))
-       {
-               return;
-       }
-
-       foreach_context = (foreach_context_extra_data_t*)user_data;
-
-       if (foreach_context->foreach_break == true)
-       {
-               return;
-       }
-
-       if (app_control_validate_internal_key(key))
-       {
-               return;
-       }
-
-       extra_data_cb = foreach_context->callback;
-
-       if (extra_data_cb != NULL)
-       {
-               bool stop_foreach = false;
-
-               stop_foreach = !extra_data_cb(foreach_context->app_control, key, foreach_context->user_data);
-
-               foreach_context->foreach_break = stop_foreach;
-       }
-
-}
-
-
-int app_control_foreach_extra_data(app_control_h app_control, app_control_extra_data_cb callback, void *user_data)
-{
-       foreach_context_extra_data_t foreach_context = {
-               .app_control = app_control,
-               .callback = callback,
-               .user_data = user_data,
-               .foreach_break = false
-       };
-
-       if (app_control_validate(app_control) || callback == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       bundle_foreach(app_control->data, app_control_cb_broker_bundle_iterator, &foreach_context);
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-typedef struct {
-       app_control_h app_control;
-       app_control_app_matched_cb callback;
-       void* user_data;
-       bool foreach_break;
-} foreach_context_launchable_app_t;
-
-int app_control_cb_broker_foreach_app_matched(const char *package, void *data)
-{
-       foreach_context_launchable_app_t *foreach_context;
-       app_control_app_matched_cb app_matched_cb;
-
-       if (package == NULL || data == NULL)
-       {
-               app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-               return -1;
-       }
-
-       foreach_context = (foreach_context_launchable_app_t*)data;
-
-       if (foreach_context->foreach_break == true)
-       {
-               return -1;
-       }
-
-       app_matched_cb = foreach_context->callback;
-
-       if (app_matched_cb != NULL)
-       {
-               bool stop_foreach = false;
-
-               stop_foreach = !app_matched_cb(foreach_context->app_control, package, foreach_context->user_data);
-
-               foreach_context->foreach_break = stop_foreach;
-       }
-
-       return 0;
-}
-
-int app_control_foreach_app_matched(app_control_h app_control, app_control_app_matched_cb callback, void *user_data)
-{
-       foreach_context_launchable_app_t foreach_context = {
-               .app_control = app_control,
-               .callback = callback,
-               .user_data = user_data,
-               .foreach_break = false
-       };
-
-       if (app_control_validate(app_control) || callback == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       appsvc_get_list(app_control->data, app_control_cb_broker_foreach_app_matched, &foreach_context);
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_get_caller(app_control_h app_control, char **package)
-{
-       const char *bundle_value;
-       char *package_dup;
-
-       if (app_control_validate(app_control) || package == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (app_control->type != APP_CONTROL_TYPE_EVENT)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid app_control handle type");
-       }
-
-        bundle_value = bundle_get_val(app_control->data, AUL_K_CALLER_APPID);
-        if (bundle_value == NULL)
-        {
-                return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to retrieve the appid of the caller");
-        }
-
-        package_dup = strdup(bundle_value);
-
-        if (package_dup == NULL)
-        {
-                return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
-        }
-
-        *package = package_dup;
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_is_reply_requested(app_control_h app_control, bool *requested)
-{
-       const char *bundle_value;
-
-       if (app_control_validate(app_control) || requested == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (app_control->type != APP_CONTROL_TYPE_EVENT)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid app_control handle type");
-       }
-
-       bundle_value = bundle_get_val(app_control->data, AUL_K_WAIT_RESULT);
-
-       if (bundle_value != NULL)
-       {
-               *requested = true;
-       }
-       else
-       {
-               *requested = false;
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-int app_control_import_from_bundle(app_control_h app_control, bundle *data)
-{
-       bundle *data_dup = NULL;
-
-       if (app_control_validate(app_control) || data == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       data_dup = bundle_dup(data);
-
-       if (data_dup == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to duplicate the bundle");
-       }
-
-       if (app_control->data != NULL)
-       {
-               bundle_free(app_control->data);
-       }
-
-       app_control->data = data_dup;
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-int app_control_export_as_bundle(app_control_h app_control, bundle **data)
-{
-       bundle *data_dup = NULL;
-
-       if (app_control_validate(app_control) || data == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       data_dup = bundle_dup(app_control->data);
-
-       if (data_dup == NULL)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to duplicate the bundle");
-       }
-
-       *data = data_dup;
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
-
-int app_control_request_transient_app(app_control_h app_control, unsigned int callee_id, app_control_host_res_fn cbfunc, void *data)
-{
-       int ret;
-
-       if (app_control_validate(app_control))
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       ret = appsvc_request_transient_app(app_control->data, callee_id, (appsvc_host_res_fn)cbfunc, data);
-
-       if (ret < 0)
-       {
-               return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       return APP_CONTROL_ERROR_NONE;
-}
-
diff --git a/src/app_error.c b/src/app_error.c
deleted file mode 100755 (executable)
index b3c8c0c..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2011 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <libintl.h>
-
-#include <dlog.h>
-
-#include <app_private.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "CAPI_APPFW_APPLICATION"
-
-static const char* app_error_to_string(app_error_e error)
-{
-       switch (error)
-       {
-       case APP_ERROR_NONE:
-               return "NONE";
-
-       case APP_ERROR_INVALID_PARAMETER:
-               return "INVALID_PARAMETER";
-
-       case APP_ERROR_OUT_OF_MEMORY:
-               return "OUT_OF_MEMORY";
-
-       case APP_ERROR_INVALID_CONTEXT:
-               return "INVALID_CONTEXT";
-
-       case APP_ERROR_NO_SUCH_FILE:
-               return "NO_SUCH_FILE";
-
-       case APP_ERROR_ALREADY_RUNNING:
-               return "ALREADY_RUNNING";
-
-       default :
-               return "UNKNOWN";
-       }
-}
-
-int app_error(app_error_e error, const char* function, const char *description)
-{
-       if (description)
-       {
-               LOGE("[%s] %s(0x%08x) : %s", function, app_error_to_string(error), error, description); 
-       }
-       else
-       {
-               LOGE("[%s] %s(0x%08x)", function, app_error_to_string(error), error);   
-       }
-
-       return error;
-}
diff --git a/src/app_event.c b/src/app_event.c
deleted file mode 100755 (executable)
index b07645f..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (c) 2011 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 <string.h>
-
-#include <vconf-internal-keys.h>
-#include <app.h>
-#include <app_private.h>
-
-app_device_orientation_e app_convert_appcore_rm(enum appcore_rm rm)
-{
-       app_device_orientation_e dev_orientation;
-
-       switch (rm)
-       {
-       case APPCORE_RM_PORTRAIT_NORMAL:
-               dev_orientation = APP_DEVICE_ORIENTATION_0;
-               break;
-
-       case APPCORE_RM_PORTRAIT_REVERSE:
-               dev_orientation = APP_DEVICE_ORIENTATION_180;
-               break;
-
-       case APPCORE_RM_LANDSCAPE_NORMAL:
-               dev_orientation = APP_DEVICE_ORIENTATION_270;
-               break;
-
-       case APPCORE_RM_LANDSCAPE_REVERSE:
-               dev_orientation = APP_DEVICE_ORIENTATION_90;
-               break;
-
-       default:
-               dev_orientation = APP_DEVICE_ORIENTATION_0;
-               break;
-       }
-
-       return dev_orientation;
-}
-
-static int _app_convert_low_memory(void *val)
-{
-       switch (*(int *)val) {
-       case VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL:
-               return APP_EVENT_LOW_MEMORY_NORMAL;
-       case VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING:
-               return APP_EVENT_LOW_MEMORY_SOFT_WARNING;
-       case VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING:
-               return APP_EVENT_LOW_MEMORY_HARD_WARNING;
-       default:
-               return -1;
-       }
-}
-
-static int _app_convert_low_battery(void *val)
-{
-       switch (*(int *)val) {
-       case VCONFKEY_SYSMAN_BAT_POWER_OFF:
-               return APP_EVENT_LOW_BATTERY_POWER_OFF;
-       case VCONFKEY_SYSMAN_BAT_CRITICAL_LOW:
-               return APP_EVENT_LOW_BATTERY_CRITICAL_LOW;
-       default:
-               return -1;
-       }
-}
-
-int app_event_get_low_memory_status(app_event_info_h event_info, app_event_low_memory_status_e *status)
-{
-       int ret;
-
-       if (event_info == NULL || status == NULL)
-               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
-
-       if (event_info->type != APP_EVENT_LOW_MEMORY)
-               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "event type mismatching");
-
-       ret = _app_convert_low_memory(event_info->value);
-       if (ret < 0)
-               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "invalid event info");
-
-       *status = ret;
-
-       return APP_ERROR_NONE;
-}
-
-int app_event_get_low_battery_status(app_event_info_h event_info, app_event_low_battery_status_e *status)
-{
-       int ret;
-
-       if (event_info == NULL || status == NULL)
-               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
-
-       if (event_info->type != APP_EVENT_LOW_BATTERY)
-               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "event type mismatching");
-
-       ret = _app_convert_low_battery(event_info->value);
-       if (ret < 0)
-               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "invalid event info");
-
-       *status = ret;
-
-       return APP_ERROR_NONE;
-}
-
-int app_event_get_language(app_event_info_h event_info, char **lang)
-{
-       if (event_info == NULL || lang == NULL)
-               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
-
-       if (event_info->type != APP_EVENT_LANGUAGE_CHANGED)
-               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
-
-       *lang = strdup(event_info->value);
-
-       return APP_ERROR_NONE;
-}
-
-int app_event_get_region_format(app_event_info_h event_info, char **region)
-{
-       if (event_info == NULL || region == NULL)
-               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
-
-       if (event_info->type != APP_EVENT_REGION_FORMAT_CHANGED)
-               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
-
-       *region = strdup(event_info->value);
-
-       return APP_ERROR_NONE;
-}
-
-int app_event_get_device_orientation(app_event_info_h event_info, app_device_orientation_e *orientation)
-{
-       if (event_info == NULL || orientation == NULL)
-               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
-
-       if (event_info->type != APP_EVENT_DEVICE_ORIENTATION_CHANGED)
-               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
-
-       *orientation = app_convert_appcore_rm(*(enum appcore_rm *)(event_info->value));
-
-       return APP_ERROR_NONE;
-}
-
diff --git a/src/app_finalizer.c b/src/app_finalizer.c
deleted file mode 100755 (executable)
index ae0b41c..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (c) 2011 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <libintl.h>
-
-#include <app_private.h>
-
-typedef struct _app_finalizer_s_ {
-       app_finalizer_cb callback;
-       void *data;
-       struct _app_finalizer_s_ *next;
-} app_finalizer_s;
-
-typedef app_finalizer_s *app_finalizer_h;
-
-static app_finalizer_s finalizer_head = {
-       .callback = NULL,
-       .data = NULL,
-       .next = NULL
-};
-
-int app_finalizer_add(app_finalizer_cb callback, void *data)
-{
-       app_finalizer_h finalizer_tail = &finalizer_head;
-       app_finalizer_h finalizer_new;
-
-       finalizer_new = malloc(sizeof(app_finalizer_s));
-
-       if (finalizer_new == NULL)
-       {
-               return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
-       }
-
-       finalizer_new->callback = callback;
-       finalizer_new->data = data;
-       finalizer_new->next = NULL;
-
-       while (finalizer_tail->next)
-       {
-               finalizer_tail = finalizer_tail->next;
-       }
-       
-       finalizer_tail->next = finalizer_new;
-
-       return APP_ERROR_NONE;
-}
-
-int app_finalizer_remove(app_finalizer_cb callback)
-{
-       app_finalizer_h finalizer_node = &finalizer_head;
-
-       while (finalizer_node->next)
-       {
-               if (finalizer_node->next->callback == callback)
-               {
-                       app_finalizer_h removed_node = finalizer_node->next;
-                       finalizer_node->next = removed_node->next;
-                       free(removed_node);
-                       return APP_ERROR_NONE;
-               }
-
-               finalizer_node = finalizer_node->next;
-       }       
-
-       return APP_ERROR_INVALID_PARAMETER;
-}
-
-void app_finalizer_execute(void)
-{
-       app_finalizer_h finalizer_node = &finalizer_head;
-       app_finalizer_h finalizer_executed;
-       app_finalizer_cb finalizer_cb = NULL;
-
-       if(finalizer_node)
-               finalizer_node = finalizer_node->next;
-
-       while (finalizer_node)
-       {
-               finalizer_cb = finalizer_node->callback;
-
-               finalizer_cb(finalizer_node->data);
-
-               finalizer_executed = finalizer_node;
-
-               finalizer_node = finalizer_node->next;
-
-               free(finalizer_executed);
-       }
-
-       finalizer_head.next = NULL;
-}
-
diff --git a/src/app_package.c b/src/app_package.c
deleted file mode 100755 (executable)
index 56893a1..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright (c) 2011 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 <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#include <bundle.h>
-#include <appcore-common.h>
-#include <aul.h>
-#include <ail.h>
-#include <dlog.h>
-
-#include <app_private.h>
-#include <app_service_private.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "CAPI_APPFW_APPLICATION"
-
-int app_get_package_app_name(const char *appid, char **name)
-{
-       char *name_token = NULL;
-
-       if (appid == NULL)
-       {
-               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       // com.vendor.name -> name
-       name_token = strrchr(appid, '.');
-
-       if (name_token == NULL)
-       {
-               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
-       }
-
-       name_token++;
-
-       *name = strdup(name_token);
-
-       if (*name == NULL)
-       {
-               return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
-       }
-
-       return APP_ERROR_NONE;
-}
-
-int app_get_package(char **package)
-{
-       return app_get_id(package);
-}
-
-int app_get_id(char **id)
-{
-       static char id_buf[TIZEN_PATH_MAX] = {0, };
-       int ret = -1;
-
-       if (id == NULL)
-       {
-               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (id_buf[0] == '\0')
-       {
-               ret = aul_app_get_appid_bypid(getpid(), id_buf, sizeof(id_buf));
-               if (ret < 0) {
-                       return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID");
-               }
-       }
-
-       if (id_buf[0] == '\0')
-       {
-               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID");
-       }
-
-       *id = strdup(id_buf);
-
-       if (*id == NULL)
-       {
-               return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
-       }
-
-       return APP_ERROR_NONE;
-}
-
-static int app_get_appinfo(const char *package, const char *property, char **value)
-{
-       ail_appinfo_h appinfo;
-       char *appinfo_value;
-       char *appinfo_value_dup;
-
-       if (ail_get_appinfo(package, &appinfo) != 0)
-       {
-               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-info");
-       }
-       
-       if (ail_appinfo_get_str(appinfo, property, &appinfo_value) != 0)
-       {
-               ail_destroy_appinfo(appinfo);
-               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-property");
-       }
-
-       appinfo_value_dup = strdup(appinfo_value);
-
-       ail_destroy_appinfo(appinfo);
-
-       if (appinfo_value_dup == NULL)
-       {
-               return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
-       }
-
-       *value = appinfo_value_dup;
-       
-       return APP_ERROR_NONE;
-}
-
-int app_get_name(char **name)
-{
-       char *package = NULL;
-       int retval;
-
-       if(name == NULL)
-       {
-               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (app_get_id(&package) != 0)
-       {
-               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
-       }
-
-       retval = app_get_appinfo(package, AIL_PROP_NAME_STR, name);
-
-       if (package != NULL)
-       {
-               free(package);
-       }
-
-       return retval;
-}
-
-int app_get_version(char **version)
-{
-       char *package;
-       int retval;
-
-       if(version == NULL)
-       {
-               return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
-       }
-
-       if (app_get_id(&package) != 0)
-       {
-               return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
-       }
-
-       retval = app_get_appinfo(package, AIL_PROP_VERSION_STR, version);
-
-       if (package != NULL)
-       {
-               free(package);
-       }
-
-       return retval;  
-}
-
diff --git a/src/app_path.c b/src/app_path.c
deleted file mode 100755 (executable)
index 82b2a9b..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2014 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 <string.h>
-#include <aul.h>
-
-#define _STRDUP(s) ((s) ? strdup(s) : NULL)
-
-char *app_get_data_path(void)
-{
-       const char *buf = aul_get_app_data_path();
-       return _STRDUP(buf);
-}
-
-char *app_get_cache_path(void)
-{
-       const char *buf = aul_get_app_cache_path();
-       return _STRDUP(buf);
-}
-
-char *app_get_resource_path(void)
-{
-       const char *buf = aul_get_app_resource_path();
-       return _STRDUP(buf);
-}
-
-char *app_get_shared_data_path(void)
-{
-       const char *buf = aul_get_app_shared_data_path();
-       return _STRDUP(buf);
-}
-
-char *app_get_shared_resource_path(void)
-{
-       const char *buf = aul_get_app_shared_resource_path();
-       return _STRDUP(buf);
-}
-
-char *app_get_shared_trusted_path(void)
-{
-       const char *buf = aul_get_app_shared_trusted_path();
-       return _STRDUP(buf);
-}
-
-char *app_get_external_data_path(void)
-{
-       const char *buf = aul_get_app_external_data_path();
-       return _STRDUP(buf);
-}
-
-char *app_get_external_cache_path(void)
-{
-       const char *buf = aul_get_app_external_cache_path();
-       return _STRDUP(buf);
-}
-
-char *app_get_external_shared_data_path(void)
-{
-       const char *buf = aul_get_app_external_shared_data_path();
-       return _STRDUP(buf);
-}
diff --git a/src/preference.c b/src/preference.c
deleted file mode 100755 (executable)
index f9751c2..0000000
+++ /dev/null
@@ -1,803 +0,0 @@
-/*
- * Copyright (c) 2011 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 <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sqlite3.h>
-
-#include <app_private.h>
-
-#include <app_preference.h>
-#include <app_preference_private.h>
-
-#include <dlog.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "CAPI_APPFW_APPLICATION_PREFERENCE"
-#define DBG_MODE (1)
-
-static sqlite3 *pref_db;
-static bool is_update_hook_registered;
-static pref_changed_cb_node_t *head;
-
-static void _finish(void *data)
-{
-       if (pref_db != NULL) {
-               sqlite3_close(pref_db);
-               pref_db = NULL;
-       }
-}
-
-static int _busy_handler(void *pData, int count)
-{
-       if (count < 5) {
-               LOGD("Busy Handler Called! : PID(%d) / CNT(%d)\n",
-                               getpid(), count+1);
-               usleep((count+1)*100000);
-               return 1;
-       } else {
-               LOGD("Busy Handler will be returned SQLITE_BUSY error : PID(%d)\n",
-                               getpid());
-               return 0;
-       }
-}
-
-static int _initialize(void)
-{
-       char *data_path;
-       char db_path[TIZEN_PATH_MAX];
-       int ret;
-       char *errmsg;
-
-       data_path = app_get_data_path();
-       if (data_path == NULL) {
-               LOGE("IO_ERROR(0x%08x) : fail to get data directory",
-                               PREFERENCE_ERROR_IO_ERROR);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-       snprintf(db_path, sizeof(db_path), "%s/%s", data_path, PREF_DB_NAME);
-       free(data_path);
-
-       ret = sqlite3_open(db_path, &pref_db);
-       if (ret != SQLITE_OK) {
-               LOGE("IO_ERROR(0x%08x) : fail to open db(%s)",
-                               PREFERENCE_ERROR_IO_ERROR, sqlite3_errmsg(pref_db));
-               _finish(NULL);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       ret = sqlite3_busy_handler(pref_db, _busy_handler, NULL);
-       if (ret != SQLITE_OK) {
-               LOGW("IO_ERROR(0x%08x) : fail to register busy handler(%s)\n",
-                               PREFERENCE_ERROR_IO_ERROR, sqlite3_errmsg(pref_db));
-       }
-
-       ret = sqlite3_exec(pref_db,
-                       "CREATE TABLE IF NOT EXISTS pref ( pref_key TEXT PRIMARY KEY, pref_type TEXT, pref_data TEXT)",
-                       NULL, NULL, &errmsg);
-       if (ret != SQLITE_OK) {
-               LOGE("IO_ERROR(0x%08x) : fail to create db table(%s)",
-                               PREFERENCE_ERROR_IO_ERROR, errmsg);
-               sqlite3_free(errmsg);
-               _finish(NULL);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       app_finalizer_add(_finish, NULL);
-
-       return PREFERENCE_ERROR_NONE;
-}
-
-static int _prepare_and_bind_stmt(char *buf, const char *type,
-               const char *data, const char *key, sqlite3_stmt **stmt)
-{
-       int ret;
-
-       ret = sqlite3_prepare(pref_db, buf, -1, stmt, NULL);
-       if (ret != SQLITE_OK) {
-               LOGE("IO_ERROR(0x%08x) : fail to prepare query (%d/%s)",
-                               PREFERENCE_ERROR_IO_ERROR,
-                               sqlite3_extended_errcode(pref_db),
-                               sqlite3_errmsg(pref_db));
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       ret = sqlite3_bind_text(*stmt, 1, type, -1, SQLITE_STATIC);
-       if (ret != SQLITE_OK) {
-               LOGE("IO_ERROR(0x%08x) : fail to bind(1) query (%d/%s)",
-                               PREFERENCE_ERROR_IO_ERROR,
-                               sqlite3_extended_errcode(pref_db),
-                               sqlite3_errmsg(pref_db));
-               sqlite3_finalize(*stmt);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-       ret = sqlite3_bind_text(*stmt, 2, data, -1, SQLITE_STATIC);
-       if (ret != SQLITE_OK) {
-               LOGE("IO_ERROR(0x%08x) : fail to bind(2) query (%d/%s)",
-                               PREFERENCE_ERROR_IO_ERROR,
-                               sqlite3_extended_errcode(pref_db),
-                               sqlite3_errmsg(pref_db));
-               sqlite3_finalize(*stmt);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-       ret = sqlite3_bind_text(*stmt, 3, key, -1, SQLITE_STATIC);
-       if (ret != SQLITE_OK) {
-               LOGE("IO_ERROR(0x%08x) : fail to bind(3) query (%d/%s)",
-                               PREFERENCE_ERROR_IO_ERROR,
-                               sqlite3_extended_errcode(pref_db),
-                               sqlite3_errmsg(pref_db));
-               sqlite3_finalize(*stmt);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       return PREFERENCE_ERROR_NONE;
-}
-
-static int _write_data(const char *key, const char *type, const char *data)
-{
-       int ret;
-       bool exist = false;
-       sqlite3_stmt *stmt;
-       char buf[BUF_LEN];
-
-       if (key == NULL || key[0] == '\0' || data == NULL) {
-               LOGE("INVALID_PARAMETER(0x%08x)",
-                               PREFERENCE_ERROR_INVALID_PARAMETER);
-               return PREFERENCE_ERROR_INVALID_PARAMETER;
-       }
-       /* insert data or update data if data already exist */
-       ret = preference_is_existing(key, &exist);
-       if (ret != PREFERENCE_ERROR_NONE)
-               return ret;
-
-       if (exist)
-               snprintf(buf, sizeof(buf), "UPDATE %s SET %s=?1, %s=?2 WHERE %s=?3;",
-                               PREF_TBL_NAME, PREF_F_TYPE_NAME,
-                               PREF_F_DATA_NAME, PREF_F_KEY_NAME);
-       else
-               snprintf(buf, sizeof(buf),
-                               "INSERT INTO %s (%s, %s, %s) values (?3, ?1, ?2);",
-                               PREF_TBL_NAME, PREF_F_KEY_NAME,
-                               PREF_F_TYPE_NAME, PREF_F_DATA_NAME);
-
-       ret = _prepare_and_bind_stmt(buf, type, data, key, &stmt);
-
-       if (ret != PREFERENCE_ERROR_NONE)
-               return ret;
-
-       ret = sqlite3_step(stmt);
-       if (ret != SQLITE_DONE) {
-               LOGE("IO_ERROR(0x%08x): fail to write data(%d/%s)",
-                       PREFERENCE_ERROR_IO_ERROR,
-                       sqlite3_extended_errcode(pref_db),
-                       sqlite3_errmsg(pref_db));
-               sqlite3_finalize(stmt);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       sqlite3_finalize(stmt);
-
-       return PREFERENCE_ERROR_NONE;
-}
-
-static int _read_data(const char *key, char *type, char *data)
-{
-       int ret;
-       char *buf;
-       char **result;
-       int rows;
-       int columns;
-       char *errmsg;
-
-       if (key == NULL || key[0] == '\0'  || data == NULL) {
-               LOGE("INVALID_PARAMETER(0x%08x)",
-                               PREFERENCE_ERROR_INVALID_PARAMETER);
-               return PREFERENCE_ERROR_INVALID_PARAMETER;
-       }
-
-       if (pref_db == NULL) {
-               if (_initialize() != PREFERENCE_ERROR_NONE) {
-                       LOGE("IO_ERROR(0x%08x) : fail to initialize db",
-                                       PREFERENCE_ERROR_IO_ERROR);
-                       return PREFERENCE_ERROR_IO_ERROR;
-               }
-       }
-
-       buf = sqlite3_mprintf("SELECT %s, %s, %s FROM %s WHERE %s=%Q;",
-                       PREF_F_KEY_NAME, PREF_F_TYPE_NAME, PREF_F_DATA_NAME,
-                       PREF_TBL_NAME, PREF_F_KEY_NAME, key);
-
-       if (buf == NULL) {
-               LOGE("IO_ERROR(0x%08x) : fail to create query string",
-                               PREFERENCE_ERROR_IO_ERROR);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
-       sqlite3_free(buf);
-       if (ret != SQLITE_OK) {
-               LOGE("IO_ERROR(0x%08x) : fail to read data (%s)",
-                               PREFERENCE_ERROR_IO_ERROR, errmsg);
-               sqlite3_free(errmsg);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       if (rows == 0) {
-               LOGE("NO_KEY(0x%08x) : fail to find given key(%s)",
-                               PREFERENCE_ERROR_NO_KEY, key);
-               sqlite3_free_table(result);
-               return PREFERENCE_ERROR_NO_KEY;
-       }
-
-       snprintf(type, 2, "%s", result[4]);
-       snprintf(data, BUF_LEN, "%s", result[5]);
-
-       sqlite3_free_table(result);
-
-       return PREFERENCE_ERROR_NONE;
-}
-
-
-int preference_set_int(const char *key, int value)
-{
-       char type[2];
-       char data[BUF_LEN];
-       snprintf(type, 2, "%d", PREFERENCE_TYPE_INT);
-       snprintf(data, BUF_LEN, "%d", value);
-       return _write_data(key, type, data);
-}
-
-int preference_get_int(const char *key, int *value)
-{
-       char type[2];
-       char data[BUF_LEN];
-       int ret;
-
-       if (value == NULL) {
-               LOGE("INVALID_PARAMETER(0x%08x)",
-                               PREFERENCE_ERROR_INVALID_PARAMETER);
-               return PREFERENCE_ERROR_INVALID_PARAMETER;
-       }
-
-       ret = _read_data(key, type, data);
-       if (ret == PREFERENCE_ERROR_NONE) {
-               if (atoi(type) == PREFERENCE_TYPE_INT)
-                       *value = atoi(data);
-               else {
-                       LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)",
-                                       PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
-                       return PREFERENCE_ERROR_INVALID_PARAMETER;
-               }
-       }
-
-       return ret;
-}
-
-int preference_set_double(const char *key, double value)
-{
-       char type[2];
-       char data[BUF_LEN];
-       snprintf(type, 2, "%d", PREFERENCE_TYPE_DOUBLE);
-       snprintf(data, BUF_LEN, "%f", value);
-       return _write_data(key, type, data);
-}
-
-int preference_get_double(const char *key, double *value)
-{
-       char type[2];
-       char data[BUF_LEN];
-
-       int ret;
-
-       if (value == NULL) {
-               LOGE("INVALID_PARAMETER(0x%08x)",
-                               PREFERENCE_ERROR_INVALID_PARAMETER);
-               return PREFERENCE_ERROR_INVALID_PARAMETER;
-       }
-
-       ret = _read_data(key, type, data);
-       if (ret == PREFERENCE_ERROR_NONE) {
-               if (atoi(type) == PREFERENCE_TYPE_DOUBLE)
-                       *value = atof(data);
-               else {
-                       LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)",
-                                       PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
-                       return PREFERENCE_ERROR_INVALID_PARAMETER;
-               }
-       }
-
-       return ret;
-}
-
-int preference_set_string(const char *key, const char *value)
-{
-       char type[2];
-
-       snprintf(type, 2, "%d", PREFERENCE_TYPE_STRING);
-       if (strlen(value) > (BUF_LEN-1)) {
-               LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)",
-                               PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
-               return PREFERENCE_ERROR_INVALID_PARAMETER;
-       }
-       return _write_data(key, type, value);
-}
-
-int preference_get_string(const char *key, char **value)
-{
-       char type[2];
-       char data[BUF_LEN];
-
-       int ret;
-
-       if (value == NULL) {
-               LOGE("INVALID_PARAMETER(0x%08x)",
-                               PREFERENCE_ERROR_INVALID_PARAMETER);
-               return PREFERENCE_ERROR_INVALID_PARAMETER;
-       }
-
-       ret = _read_data(key, type, data);
-       if (ret == PREFERENCE_ERROR_NONE) {
-               if (atoi(type) == PREFERENCE_TYPE_STRING) {
-                       *value = strdup(data);
-                       if (value == NULL) {
-                               LOGE("OUT_OF_MEMORY(0x%08x)",
-                                               PREFERENCE_ERROR_OUT_OF_MEMORY);
-                               return PREFERENCE_ERROR_OUT_OF_MEMORY;
-                       }
-               } else {
-                       LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)",
-                                       PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
-                       return PREFERENCE_ERROR_INVALID_PARAMETER;
-               }
-       }
-
-       return ret;
-}
-
-int preference_set_boolean(const char *key, bool value)
-{
-       char type[2];
-       char data[BUF_LEN];
-       snprintf(type, 2, "%d", PREFERENCE_TYPE_BOOLEAN);
-       snprintf(data, BUF_LEN, "%d", value);
-       return _write_data(key, type, data);
-}
-
-int preference_get_boolean(const char *key, bool *value)
-{
-       char type[2];
-       char data[BUF_LEN];
-
-       int ret;
-
-       if (value == NULL) {
-               LOGE("INVALID_PARAMETER(0x%08x)",
-                               PREFERENCE_ERROR_INVALID_PARAMETER);
-               return PREFERENCE_ERROR_INVALID_PARAMETER;
-       }
-
-       ret = _read_data(key, type, data);
-       if (ret == PREFERENCE_ERROR_NONE) {
-               if (atoi(type) == PREFERENCE_TYPE_BOOLEAN)
-                       *value = (bool)atoi(data);
-               else {
-                       LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)",
-                                       PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
-                       return PREFERENCE_ERROR_INVALID_PARAMETER;
-               }
-       }
-
-       return ret;
-}
-
-
-/* TODO: below operation is too heavy, let's find the light way to check. */
-int preference_is_existing(const char *key, bool *exist)
-{
-       int ret;
-       char *buf;
-       char **result;
-       int rows;
-       int columns;
-       char *errmsg;
-
-       if (key == NULL  || key[0] == '\0'  || exist == NULL) {
-               LOGE("INVALID_PARAMETER(0x%08x)",
-                               PREFERENCE_ERROR_INVALID_PARAMETER);
-               return PREFERENCE_ERROR_INVALID_PARAMETER;
-       }
-
-       if (pref_db == NULL) {
-               if (_initialize() != PREFERENCE_ERROR_NONE) {
-                       LOGE("IO_ERROR(0x%08x) : fail to initialize db",
-                                       PREFERENCE_ERROR_IO_ERROR);
-                       return PREFERENCE_ERROR_IO_ERROR;
-               }
-       }
-
-       /* check data is exist */
-       buf = sqlite3_mprintf("SELECT %s FROM %s WHERE %s=%Q;",
-                       PREF_F_KEY_NAME, PREF_TBL_NAME, PREF_F_KEY_NAME, key);
-
-       if (buf == NULL) {
-               LOGE("IO_ERROR(0x%08x) : fail to create query string",
-                               PREFERENCE_ERROR_IO_ERROR);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
-       sqlite3_free(buf);
-       if (ret != SQLITE_OK) {
-               LOGE("IO_ERROR(0x%08x) : fail to read data(%s)",
-                               PREFERENCE_ERROR_IO_ERROR, errmsg);
-               sqlite3_free(errmsg);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       if (rows > 0)
-               *exist = true;
-       else
-               *exist = false;
-
-       sqlite3_free_table(result);
-       return PREFERENCE_ERROR_NONE;
-}
-
-static pref_changed_cb_node_t *_find_node(const char *key)
-{
-       pref_changed_cb_node_t *tmp_node;
-
-       if (key == NULL || key[0] == '\0')
-               return NULL;
-
-       tmp_node = head;
-
-       while (tmp_node) {
-               if (strcmp(tmp_node->key, key) == 0)
-                       break;
-               tmp_node = tmp_node->next;
-       }
-
-       return tmp_node;
-}
-
-
-static int _add_node(const char *key, preference_changed_cb cb, void *user_data)
-{
-       pref_changed_cb_node_t *tmp_node;
-
-       if (key == NULL || key[0] == '\0' || cb == NULL) {
-               LOGE("INVALID_PARAMETER(0x%08x)",
-                               PREFERENCE_ERROR_INVALID_PARAMETER);
-               return PREFERENCE_ERROR_INVALID_PARAMETER;
-       }
-
-       tmp_node = _find_node(key);
-
-       if (tmp_node != NULL) {
-               tmp_node->cb = cb;
-               tmp_node->user_data = user_data;
-       } else {
-               tmp_node =
-                       (pref_changed_cb_node_t *)malloc(sizeof(pref_changed_cb_node_t));
-               if (tmp_node == NULL) {
-                       LOGE("OUT_OF_MEMORY(0x%08x)",
-                                       PREFERENCE_ERROR_OUT_OF_MEMORY);
-                       return PREFERENCE_ERROR_OUT_OF_MEMORY;
-               }
-
-               tmp_node->key = strdup(key);
-               if (tmp_node->key == NULL) {
-                       free(tmp_node);
-                       LOGE("OUT_OF_MEMORY(0x%08x)", PREFERENCE_ERROR_OUT_OF_MEMORY);
-                       return PREFERENCE_ERROR_OUT_OF_MEMORY;
-               }
-
-               if (head != NULL)
-                       head->prev = tmp_node;
-               tmp_node->cb = cb;
-               tmp_node->user_data = user_data;
-               tmp_node->prev = NULL;
-               tmp_node->next = head;
-               head = tmp_node;
-       }
-
-       return PREFERENCE_ERROR_NONE;
-}
-
-static int _remove_node(const char *key)
-{
-       pref_changed_cb_node_t *tmp_node;
-
-       if (key == NULL || key[0] == '\0') {
-               LOGE("INVALID_PARAMETER(0x%08x)",
-                               PREFERENCE_ERROR_INVALID_PARAMETER);
-               return PREFERENCE_ERROR_INVALID_PARAMETER;
-       }
-
-       tmp_node = _find_node(key);
-
-       if (tmp_node == NULL)
-               return PREFERENCE_ERROR_NONE;
-
-       if (tmp_node->prev != NULL)
-               tmp_node->prev->next = tmp_node->next;
-       else
-               head = tmp_node->next;
-
-       if (tmp_node->next != NULL)
-               tmp_node->next->prev = tmp_node->prev;
-
-       if (tmp_node->key)
-               free(tmp_node->key);
-
-       free(tmp_node);
-
-       return PREFERENCE_ERROR_NONE;
-}
-
-
-static void _remove_all_node(void)
-{
-       pref_changed_cb_node_t *tmp_node;
-
-       while (head) {
-               tmp_node = head;
-               head = tmp_node->next;
-
-               if (tmp_node->key)
-                       free(tmp_node->key);
-
-               free(tmp_node);
-       }
-}
-
-
-static void _update_cb(void *data, int action, char const *db_name,
-               char const *table_name, sqlite_int64 rowid)
-{
-       int ret;
-       char *buf;
-       char **result;
-       int rows;
-       int columns;
-       char *errmsg;
-       pref_changed_cb_node_t *tmp_node;
-
-       if (action != SQLITE_UPDATE)
-               return;
-
-       if (strcmp(table_name, PREF_TBL_NAME) != 0) {
-               SECURE_LOGE("given table name (%s) is not same", table_name);
-               return;
-       }
-
-       buf = sqlite3_mprintf("SELECT %s FROM %s WHERE rowid='%lld';",
-                       PREF_F_KEY_NAME, PREF_TBL_NAME, rowid);
-       if (buf == NULL)
-               return;
-
-       ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
-       sqlite3_free(buf);
-       if (ret != SQLITE_OK) {
-               LOGI("fail to read data(%s)", errmsg);
-               sqlite3_free(errmsg);
-               return;
-       }
-
-       if (rows == 0) {
-               sqlite3_free_table(result);
-               return;
-       }
-
-       tmp_node = _find_node(result[1]);
-
-       if (tmp_node != NULL && tmp_node->cb != NULL)
-               tmp_node->cb(result[1], tmp_node->user_data);
-
-       sqlite3_free_table(result);
-}
-
-
-int preference_remove(const char *key)
-{
-       int ret;
-       char buf[BUF_LEN];
-       bool exist;
-       sqlite3_stmt *stmt;
-
-       ret = preference_is_existing(key, &exist);
-       if (ret != PREFERENCE_ERROR_NONE)
-               return ret;
-
-       if (!exist)
-               return PREFERENCE_ERROR_NO_KEY;
-
-       snprintf(buf, sizeof(buf), "DELETE FROM %s WHERE %s = ?",
-                       PREF_TBL_NAME, PREF_F_KEY_NAME);
-
-       ret = sqlite3_prepare(pref_db, buf, -1, &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               LOGE("IO_ERROR(0x%08x) : fail to prepare query (%d/%s)",
-                       PREFERENCE_ERROR_IO_ERROR,
-                       sqlite3_extended_errcode(pref_db),
-                       sqlite3_errmsg(pref_db));
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       ret = sqlite3_bind_text(stmt, 1, key, -1, SQLITE_STATIC);
-       if (ret != SQLITE_OK) {
-               LOGE("IO_ERROR(0x%08x) : fail to bind(1) query (%d/%s)",
-                       PREFERENCE_ERROR_IO_ERROR,
-                       sqlite3_extended_errcode(pref_db),
-                       sqlite3_errmsg(pref_db));
-               sqlite3_finalize(stmt);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       ret = sqlite3_step(stmt);
-       if (ret != SQLITE_DONE) {
-               LOGE("IO_ERROR(0x%08x): fail to delete data(%d/%s)",
-                       PREFERENCE_ERROR_IO_ERROR,
-                       sqlite3_extended_errcode(pref_db),
-                       sqlite3_errmsg(pref_db));
-               sqlite3_finalize(stmt);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       sqlite3_finalize(stmt);
-
-        _remove_node(key);
-
-       return PREFERENCE_ERROR_NONE;
-}
-
-
-int preference_remove_all(void)
-{
-       int ret;
-       char *buf;
-       char *errmsg;
-
-       if (pref_db == NULL) {
-               if (_initialize() != PREFERENCE_ERROR_NONE) {
-                       LOGE("IO_ERROR(0x%08x) : fail to initialize db",
-                                       PREFERENCE_ERROR_IO_ERROR);
-                       return PREFERENCE_ERROR_IO_ERROR;
-               }
-       }
-
-       /* insert data or update data if data already exist */
-       buf = sqlite3_mprintf("DELETE FROM %s;", PREF_TBL_NAME);
-       if (buf == NULL) {
-               LOGE("IO_ERROR(0x%08x) : fail to create query string",
-                               PREFERENCE_ERROR_IO_ERROR);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       ret = sqlite3_exec(pref_db, buf, NULL, NULL, &errmsg);
-       sqlite3_free(buf);
-       if (ret != SQLITE_OK) {
-               LOGE("IO_ERROR(0x%08x) : fail to delete data (%s)",
-                               PREFERENCE_ERROR_IO_ERROR, errmsg);
-               sqlite3_free(errmsg);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       _remove_all_node();
-
-       return PREFERENCE_ERROR_NONE;
-}
-
-
-int preference_set_changed_cb(const char *key,
-               preference_changed_cb callback, void *user_data)
-{
-       int ret;
-       bool exist;
-
-       ret = preference_is_existing(key, &exist);
-       if (ret != PREFERENCE_ERROR_NONE)
-               return ret;
-
-       if (!exist) {
-               LOGE("NO_KEY(0x%08x) : fail to find given key(%s)",
-                               PREFERENCE_ERROR_NO_KEY, key);
-               return PREFERENCE_ERROR_NO_KEY;
-       }
-
-       if (!is_update_hook_registered) {
-               sqlite3_update_hook(pref_db, _update_cb, NULL);
-               is_update_hook_registered = true;
-       }
-
-       return _add_node(key, callback, user_data);
-}
-
-int preference_unset_changed_cb(const char *key)
-{
-       int ret;
-       bool exist;
-
-       ret = preference_is_existing(key, &exist);
-       if (ret != PREFERENCE_ERROR_NONE)
-               return ret;
-
-       if (!exist) {
-               LOGE("NO_KEY(0x%08x) : fail to find given key(%s)",
-                               PREFERENCE_ERROR_NO_KEY, key);
-               return PREFERENCE_ERROR_NO_KEY;
-       }
-
-       return _remove_node(key);
-}
-
-int preference_foreach_item(preference_item_cb callback, void *user_data)
-{
-       int ret;
-       char *buf;
-       char **result;
-       int rows;
-       int columns;
-       char *errmsg;
-       int i;
-
-       if (callback == NULL) {
-               LOGE("INVALID_PARAMETER(0x%08x)",
-                               PREFERENCE_ERROR_INVALID_PARAMETER);
-               return PREFERENCE_ERROR_INVALID_PARAMETER;
-       }
-
-       if (pref_db == NULL) {
-               if (_initialize() != PREFERENCE_ERROR_NONE) {
-                       LOGE("IO_ERROR(0x%08x) : fail to initialize db",
-                                       PREFERENCE_ERROR_IO_ERROR);
-                       return PREFERENCE_ERROR_IO_ERROR;
-               }
-       }
-
-       buf = sqlite3_mprintf("SELECT %s FROM %s;",
-                       PREF_F_KEY_NAME, PREF_TBL_NAME);
-       if (buf == NULL) {
-               LOGE("IO_ERROR(0x%08x) : fail to create query string",
-                               PREFERENCE_ERROR_IO_ERROR);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
-       sqlite3_free(buf);
-       if (ret != SQLITE_OK) {
-               LOGE("IO_ERROR(0x%08x) : fail to read data (%s)",
-                               PREFERENCE_ERROR_IO_ERROR, errmsg);
-               sqlite3_free(errmsg);
-               return PREFERENCE_ERROR_IO_ERROR;
-       }
-
-       for (i = 1; i <= rows; i++) {
-               if (callback(result[i], user_data) != true)
-                       break;
-       }
-
-       sqlite3_free_table(result);
-
-       return PREFERENCE_ERROR_NONE;
-}