From c96b20ac5256879e40e4e5ac49b3d01531e5c062 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Tue, 26 May 2015 17:55:30 +0900 Subject: [PATCH] Add event system api. Add new api (add/remove event handler and publish user event) for native application. - new api list event_add_event_handler() event_remove_event_handler() event_publish_app_event() event_publish_trusted_app_event() JIRA ticket : TC-2473 Change-Id: I6ac68ecf85cc3db45a79c91abe6525d59e33564a Signed-off-by: Jiwoong Im --- CMakeLists.txt | 5 +- app_control/app_control.c | 6 + event/CMakeLists.txt | 65 +++ event/event.c | 312 +++++++++++++ include/app_control.h | 8 + include/app_event.h | 834 ++++++++++++++++++++++++++++++++++ packaging/capi-appfw-application.spec | 3 + 7 files changed, 1231 insertions(+), 2 deletions(-) create mode 100644 event/CMakeLists.txt create mode 100644 event/event.c create mode 100644 include/app_event.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c201a07..f920faa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 capi-appfw-alarm capi-appfw-app-control capi-appfw-app-common capi-appfw-preference") +SET(pc_requires "capi-base-common vconf-internal-keys capi-appfw-alarm capi-appfw-app-control capi-appfw-app-common capi-appfw-preference capi-appfw-event") INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${requires}) @@ -37,8 +37,9 @@ ADD_SUBDIRECTORY(app_control) ADD_SUBDIRECTORY(app_common) ADD_SUBDIRECTORY(alarm) ADD_SUBDIRECTORY(preference) +ADD_SUBDIRECTORY(event) -TARGET_LINK_LIBRARIES(${fw_name} capi-appfw-app-control capi-appfw-app-common capi-appfw-alarm capi-appfw-preference ${${fw_name}_LDFLAGS}) +TARGET_LINK_LIBRARIES(${fw_name} capi-appfw-app-control capi-appfw-app-common capi-appfw-alarm capi-appfw-preference capi-appfw-event ${${fw_name}_LDFLAGS}) SET_TARGET_PROPERTIES(${fw_name} PROPERTIES diff --git a/app_control/app_control.c b/app_control/app_control.c index 4a813f2..b1d7ee7 100755 --- a/app_control/app_control.c +++ b/app_control/app_control.c @@ -705,6 +705,12 @@ int app_control_send_launch_request(app_control_h app_control, app_control_reply operation = APP_CONTROL_OPERATION_DEFAULT; } + if (!strcmp(operation, APP_CONTROL_OPERATION_LAUNCH_ON_EVENT)) + { + return app_control_error(APP_CONTROL_ERROR_LAUNCH_REJECTED, __FUNCTION__, + "Not supported operation value"); + } + // TODO: Check the privilege for call operation // operation : default diff --git a/event/CMakeLists.txt b/event/CMakeLists.txt new file mode 100644 index 0000000..f4ae553 --- /dev/null +++ b/event/CMakeLists.txt @@ -0,0 +1,65 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(fw_name "capi-appfw-event") + +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 "glib-2.0 dlog bundle eventsystem 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") +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 + 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/event/event.c b/event/event.c new file mode 100644 index 0000000..51bbc16 --- /dev/null +++ b/event/event.c @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "CAPI_APPFW_EVENT" + +typedef struct event_handler { + char *event_name; + int event_type; + unsigned int reg_id; + event_cb cb; + void *user_data; +} event_handler_s; + +typedef struct event_cb_data { + bundle *event_data; + void *user_data; +} event_cb_data_s; + +static GHashTable *interested_event_table; +static int _initialized; + +static const char *event_error_to_string(event_error_e error) +{ + switch (error) { + case EVENT_ERROR_NONE: + return "NONE"; + + case EVENT_ERROR_INVALID_PARAMETER: + return "INVALID_PARAMETER"; + + case EVENT_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; + + case EVENT_ERROR_TIMED_OUT: + return "TIMED_OUT"; + + case EVENT_ERROR_IO_ERROR: + return "IO ERROR"; + + case EVENT_ERROR_PERMISSION_DENIED: + return "PERMISSION DENIED"; + + default: + return "UNKNOWN"; + } +} + +int event_error(event_error_e error, const char *function, const char *description) +{ + if (description) { + LOGE("[%s] %s(0x%08x) : %s", function, event_error_to_string(error), + error, description); + } else { + LOGE("[%s] %s(0x%08x)", function, event_error_to_string(error), error); + } + + return error; +} + +static void event_do_cb(gpointer data, gpointer user_data) +{ + event_handler_h handler = (event_handler_h)data; + event_cb_data_s *cb_data = (event_cb_data_s *)user_data; + + if (handler->cb) { + handler->cb(handler->event_name, + cb_data->event_data, cb_data->user_data); + } +} + +static void event_eventsystem_callback(const char *event_name, + bundle_raw *event_data, int len, void *user_data) +{ + bundle *b_to = NULL; + bundle *b = NULL; + LOGD("event_name(%s)", event_name); + + GList *handler_list = (GList *)g_hash_table_lookup(interested_event_table, + event_name); + if (handler_list) { + event_cb_data_s *cb_data = NULL; + cb_data = calloc(1, sizeof(event_cb_data_s)); + if (cb_data == NULL) { + LOGE("memory alloc failed"); + return; + } + b_to = bundle_decode(event_data, len); + if (b_to == NULL) { + LOGE("bundle_decode failed"); + return; + } + b = bundle_dup(b_to); + bundle_free(b_to); + + cb_data->event_data = b; + cb_data->user_data = user_data; + + g_list_foreach(handler_list, event_do_cb, cb_data); + + bundle_free(b); + } +} + +static void event_remove_handler_list(gpointer data, gpointer user_data) +{ + int ret = 0; + + event_handler_h handler = (event_handler_h)data; + + if (handler) { + ret = eventsystem_unregister_application_event(handler->reg_id); + if (ret < 0) { + LOGE("unregister event error"); + return; + } + free(handler->event_name); + free(handler); + } +} + +static void event_finalize(void *data) +{ + GHashTableIter iter; + gpointer key, value; + + LOGD("event finalizer"); + + if (interested_event_table) { + g_hash_table_iter_init(&iter, interested_event_table); + + while (g_hash_table_iter_next(&iter, &key, &value)) { + GList *handler_list = (GList *)value; + if (handler_list) { + g_list_foreach(handler_list, event_remove_handler_list, NULL); + g_list_free(handler_list); + } else { + LOGE("handler list is NULL"); + } + } + + g_hash_table_unref(interested_event_table); + interested_event_table = NULL; + } + + eventsystem_application_finalize(); +} + +int event_add_event_handler(const char *event_name, event_cb callback, void *user_data, + event_handler_h *event_handler) +{ + int ret = 0; + int event_type = 0; + unsigned int reg_id = 0; + event_handler_h handler = NULL; + + if (!_initialized) { + if (interested_event_table == NULL) { + interested_event_table = g_hash_table_new(g_str_hash, g_str_equal); + if (interested_event_table == NULL) { + return event_error(EVENT_ERROR_OUT_OF_MEMORY, + __FUNCTION__, NULL); + } + } + ret = app_finalizer_add(event_finalize, NULL); + if (ret != APP_ERROR_NONE) { + return event_error(EVENT_ERROR_OUT_OF_MEMORY, __FUNCTION__, + "add finalizer error"); + } + _initialized = 1; + } + + if (event_handler == NULL || event_name == NULL || callback == NULL) { + return event_error(EVENT_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + handler = calloc(1, sizeof(event_handler_s)); + if (handler == NULL) { + return event_error(EVENT_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + } + + ret = eventsystem_register_application_event(event_name, ®_id, &event_type, + (eventsystem_cb)event_eventsystem_callback, user_data); + if (ret < 0) { + free(handler); + if (ret == ES_R_ENOTPERMITTED) { + return event_error(EVENT_ERROR_PERMISSION_DENIED, __FUNCTION__, NULL); + } else { + return event_error(EVENT_ERROR_IO_ERROR, __FUNCTION__, NULL); + } + } + + handler->event_name = strdup(event_name); + if (handler->event_name == NULL) { + free(handler); + return event_error(EVENT_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); + } + + handler->reg_id = reg_id; + handler->event_type = event_type; + handler->cb = callback; + handler->user_data = user_data; + + *event_handler = handler; + + GList *handler_list = (GList *)g_hash_table_lookup(interested_event_table, + handler->event_name); + if (handler_list) { + LOGD("add new handler"); + handler_list = g_list_append(handler_list, handler); + } else { + LOGD("add new table item"); + GList *ehl = NULL; + ehl = g_list_append(ehl, handler); + g_hash_table_insert(interested_event_table, handler->event_name, ehl); + } + + return EVENT_ERROR_NONE; +} + +int event_remove_event_handler(event_handler_h event_handler) +{ + int ret = 0; + + if (!_initialized) { + LOGI("handler list is not initialized"); + return EVENT_ERROR_NONE; + } + + if (event_handler == NULL) { + return event_error(EVENT_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + ret = eventsystem_unregister_application_event(event_handler->reg_id); + if (ret < 0) { + return event_error(EVENT_ERROR_IO_ERROR, __FUNCTION__, NULL); + } + + GList *handler_list = (GList *)g_hash_table_lookup(interested_event_table, + event_handler->event_name); + if (handler_list) { + GList *list = NULL; + list = g_list_find(handler_list, event_handler); + if (list) { + LOGD("remove match handler"); + handler_list = g_list_remove_all(handler_list, event_handler); + GList *first_list = NULL; + first_list = g_list_first(handler_list); + if (first_list == NULL) { + LOGD("remove table item"); + g_hash_table_remove(interested_event_table, + event_handler->event_name); + } + } + } + + free(event_handler->event_name); + free(event_handler); + + return EVENT_ERROR_NONE; +} + +int event_publish_app_event(const char *event_name, bundle *event_data) +{ + if (event_data == NULL) { + return event_error(EVENT_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (eventsystem_send_user_event(event_name, event_data, false) < 0) { + return event_error(EVENT_ERROR_IO_ERROR, __FUNCTION__, NULL); + } + + return EVENT_ERROR_NONE; +} + +int event_publish_trusted_app_event(const char *event_name, bundle *event_data) +{ + if (event_data == NULL) { + return event_error(EVENT_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (eventsystem_send_user_event(event_name, event_data, true) < 0) { + return event_error(EVENT_ERROR_IO_ERROR, __FUNCTION__, NULL); + } + + return EVENT_ERROR_NONE; +} diff --git a/include/app_control.h b/include/app_control.h index dea3a07..7671bad 100755 --- a/include/app_control.h +++ b/include/app_control.h @@ -197,6 +197,14 @@ typedef enum #define APP_CONTROL_OPERATION_COMPOSE "http://tizen.org/appcontrol/operation/compose" /** + * @brief Definition for the app_control operation: can be launched by interested event. + * @since_tizen 2.4 + * @remarks This operation is for handling event from the platform or other application. This operation can not be requested via app_control_send_launch_request(). + * @remarks Refer to "Launch on Event" section of Event module. + */ +#define APP_CONTROL_OPERATION_LAUNCH_ON_EVENT "http://tizen.org/appcontrol/operation/launch_on_event" + +/** * @brief Definition for app_control optional data: the subject of a message. * @since_tizen 2.3 */ diff --git a/include/app_event.h b/include/app_event.h new file mode 100644 index 0000000..80c1a31 --- /dev/null +++ b/include/app_event.h @@ -0,0 +1,834 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __TIZEN_APPFW_EVENT_H__ +#define __TIZEN_APPFW_EVENT_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file event.h + */ + +/** + * @addtogroup CAPI_EVENT_MODULE + * @{ + */ + + +/** + * @brief Event handle. + * @since_tizen 2.4 + */ +typedef struct event_handler* event_handler_h; + +/** + * @brief Event callback. + * + * @since_tizen 2.4 + * @param[in] event_name The interested event name + * @param[in] event_data The data of interested event + * @param[in] user_data The user data set by event_add_event_handler() + * @see event_add_event_handler + */ +typedef void (*event_cb)(const char *event_name, bundle *event_data, void *user_data); + +/** + * @brief Enumeration for Event Error. + * @since_tizen 2.4 + */ +typedef enum +{ + EVENT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + EVENT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + EVENT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + EVENT_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< Time out */ + EVENT_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< IO error */ + EVENT_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED /**< Permisiion denied */ +} event_error_e; + +/** + * @brief Definition for system-event of battery : charger status. + * @since_tizen 2.4 + * @remarks If there is earlier occurrence regarding this event, you will receive the event as soon as you register event handler for this event. You can use this earlier event-data as initial value. + * @see EVENT_KEY_BATTERY_CHARGER_STATUS + */ +#define SYSTEM_EVENT_BATTERY_CHARGER_STATUS "tizen.system.event.battery_charger_status" + +/** + * @brief Definition for key of SYSTEM_EVENT_BATTERY_CHARGER_STATUS. + * @since_tizen 2.4 + * @see EVENT_VAL_BATTERY_CHARGER_DISCONNECTED + * @see EVENT_VAL_BATTERY_CHARGER_CONNECTED + * @see EVENT_VAL_BATTERY_CHARGER_CHARGING + */ +#define EVENT_KEY_BATTERY_CHARGER_STATUS "battery_charger_status" + +/** + * @brief Definition for value of EVENT_KEY_BATTERY_CHARGER_STATUS. + * @since_tizen 2.4 + */ +#define EVENT_VAL_BATTERY_CHARGER_DISCONNECTED "disconnected" + +/** + * @brief Definition for value of EVENT_KEY_BATTERY_CHARGER_STATUS. + * @since_tizen 2.4 + * @remarks Connected but not-available. + */ +#define EVENT_VAL_BATTERY_CHARGER_CONNECTED "connected" + +/** + * @brief Definition for value of EVENT_KEY_BATTERY_CHARGER_STATUS. + * @since_tizen 2.4 + */ +#define EVENT_VAL_BATTERY_CHARGER_CHARGING "charging" + +/** + * @brief Definition for system-event of battery : level status. + * @since_tizen 2.4 + * @see EVENT_KEY_BATTERY_LEVEL_STATUS + */ +#define SYSTEM_EVENT_BATTERY_LEVEL_STATUS "tizen.system.event.battery_level_status" + +/** + * @brief Definition for key of SYSTEM_EVENT_BATTERY_LEVEL_STATUS. + * @since_tizen 2.4 + * @see EVENT_VAL_BATTERY_LEVEL_EMPTY + * @see EVENT_VAL_BATTERY_LEVEL_CRITICAL + * @see EVENT_VAL_BATTERY_LEVEL_LOW + * @see EVENT_VAL_BATTERY_LEVEL_HIGH + * @see EVENT_VAL_BATTERY_LEVEL_FULL + */ +#define EVENT_KEY_BATTERY_LEVEL_STATUS "battery_level_status" + +/** + * @brief Definition for value of EVENT_KEY_BATTERY_LEVEL_STATUS. + * @since_tizen 2.4 + */ +#define EVENT_VAL_BATTERY_LEVEL_EMPTY "empty" + +/** + * @brief Definition for value of EVENT_KEY_BATTERY_LEVEL_STATUS. + * @since_tizen 2.4 + */ +#define EVENT_VAL_BATTERY_LEVEL_CRITICAL "critical" + +/** + * @brief Definition for value of EVENT_KEY_BATTERY_LEVEL_STATUS. + * @since_tizen 2.4 + */ +#define EVENT_VAL_BATTERY_LEVEL_LOW "low" + +/** + * @brief Definition for value of EVENT_KEY_BATTERY_LEVEL_STATUS. + * @since_tizen 2.4 + */ +#define EVENT_VAL_BATTERY_LEVEL_HIGH "high" + +/** + * @brief Definition for value of EVENT_KEY_BATTERY_LEVEL_STATUS. + * @since_tizen 2.4 + */ +#define EVENT_VAL_BATTERY_LEVEL_FULL "full" + +/** + * @brief Definition for system-event of usb : status of usb connection. + * @since_tizen 2.4 + * @remarks If there is earlier occurrence regarding this event, you will receive the event as soon as you register event handler for this event. You can use this earlier event-data as initial value. + * @see EVENT_KEY_USB_STATUS + */ +#define SYSTEM_EVENT_USB_STATUS "tizen.system.event.usb_status" + +/** + * @brief Definition for key of SYSTEM_EVENT_USB_STATUS. + * @since_tizen 2.4 + * @see EVENT_VAL_USB_DISCONNECTED + * @see EVENT_VAL_USB_CONNECTED + * @see EVENT_VAL_USB_AVAILABLE + */ +#define EVENT_KEY_USB_STATUS "usb_status" + +/** + * @brief Definition for value of EVENT_KEY_USB_STATUS. + * @since_tizen 2.4 + */ +#define EVENT_VAL_USB_DISCONNECTED "disconnected" + +/** + * @brief Definition for value of EVENT_KEY_USB_STATUS. + * @since_tizen 2.4 + * @remarks Connected but not-available. + */ +#define EVENT_VAL_USB_CONNECTED "connected" + +/** + * @brief Definition for value of EVENT_KEY_USB_STATUS. + * @since_tizen 2.4 + */ +#define EVENT_VAL_USB_AVAILABLE "available" + +/** + * @brief Definition for system-event of ear-jack : status of ear-jack connection. + * @since_tizen 2.4 + * @see EVENT_KEY_EARJACK_STATUS + */ +#define SYSTEM_EVENT_EARJACK_STATUS "tizen.system.event.earjack_status" + +/** + * @brief Definition for key of SYSTEM_EVENT_EARJACK_STATUS. + * @since_tizen 2.4 + * @see EVENT_VAL_EARJACK_DISCONNECTED + * @see EVENT_VAL_EARJACK_CONNECTED + */ +#define EVENT_KEY_EARJACK_STATUS "earjack_status" + +/** + * @brief Definition for value of EVENT_KEY_EARJACK_STATUS. + * @since_tizen 2.4 + */ +#define EVENT_VAL_EARJACK_DISCONNECTED "disconnected" + +/** + * @brief Definition for value of EVENT_KEY_EARJACK_STATUS. + * @since_tizen 2.4 + */ +#define EVENT_VAL_EARJACK_CONNECTED "connected" + +/** + * @brief Definition for system-event of display : state of display. + * @since_tizen 2.4 + * @privilege %http://tizen.org/privilege/display + * @remarks If you want to receive this event, you must declare this privilege. + * @see EVENT_KEY_DISPLAY_STATE + */ +#define SYSTEM_EVENT_DISPLAY_STATE "tizen.system.event.display_state" + +/** + * @brief Definition for key of SYSTEM_EVENT_DISPLAY_STATE. + * @since_tizen 2.4 + * @see EVENT_VAL_DISPLAY_NORMAL + * @see EVENT_VAL_DISPLAY_DIM + * @see EVENT_VAL_DISPLAY_OFF + */ +#define EVENT_KEY_DISPLAY_STATE "display_state" + +/** + * @brief Definition for value of EVENT_KEY_DISPLAY_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_DISPLAY_NORMAL "normal" + +/** + * @brief Definition for value of EVENT_KEY_DISPLAY_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_DISPLAY_DIM "dim" + +/** + * @brief Definition for value of EVENT_KEY_DISPLAY_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_DISPLAY_OFF "off" + +/** + * @brief Definition for system-event of system : boot completion. + * @since_tizen 2.4 + * @remarks There is no corresponding key/value. + * @remarks You can treat the initial value as "false" before you receive this event. + * @remarks If it's already boot-completed state before you regiser event handler, you can receive the event as soon as you register the event handler. + */ +#define SYSTEM_EVENT_BOOT_COMPLETED "tizen.system.event.boot_completed" + +/** + * @brief Definition for system-event of system : shutdown. + * @since_tizen 2.4 + * @remarks There is no corresponding key/value. + * @remarks You can treat the inital value as "false" before you receive this event. + * @remarks If it's already shutting-down state before you regiser event handler, you can receive the event as soon as you register the event handler. +*/ +#define SYSTEM_EVENT_SYSTEM_SHUTDOWN "tizen.system.event.system_shutdown" + +/** + * @brief Definition for system-event of system : low memory. + * @since_tizen 2.4 + * @see EVENT_KEY_LOW_MEMORY + */ +#define SYSTEM_EVENT_LOW_MEMORY "tizen.system.event.low_memory" + +/** + * @brief Definition for key of SYSTEM_EVENT_LOW_MEMORY. + * @since_tizen 2.4 + * @remarks If there is earlier occurrence regarding this event, you will receive the event as soon as you register event handler for this event. You can use this earlier event-data as initial value. + * @see EVENT_VAL_MEMORY_NORMAL + * @see EVENT_VAL_MEMORY_SOFT_WARNING + * @see EVENT_VAL_MEMORY_HARD_WARNING + */ +#define EVENT_KEY_LOW_MEMORY "low_memory" + +/** + * @brief Definition for value of EVENT_KEY_LOW_MEMORY. + * @since_tizen 2.4 + */ +#define EVENT_VAL_MEMORY_NORMAL "normal" + +/** + * @brief Definition for value of EVENT_KEY_LOW_MEMORY. + * @since_tizen 2.4 + */ +#define EVENT_VAL_MEMORY_SOFT_WARNING "soft_warning" + +/** + * @brief Definition for value of EVENT_KEY_LOW_MEMORY. + * @since_tizen 2.4 + */ +#define EVENT_VAL_MEMORY_HARD_WARNING "hard_warning" + +/** + * @brief Definition for system-event of wifi : state of wifi. + * @since_tizen 2.4 + * @privilege %http://tizen.org/privilege/network.get + * @remarks If you want to receive this event, you must declare this privilege. + * @see EVENT_KEY_WIFI_STATE + */ +#define SYSTEM_EVENT_WIFI_STATE "tizen.system.event.wifi_state" + +/** + * @brief Definition for key of SYSTEM_EVENT_WIFI_STATE. + * @since_tizen 2.4 + * @see EVENT_VAL_WIFI_OFF + * @see EVENT_VAL_WIFI_ON + * @see EVENT_VAL_WIFI_CONNECTED + */ +#define EVENT_KEY_WIFI_STATE "wifi_state" + +/** + * @brief Definition for value of EVENT_KEY_WIFI_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_WIFI_OFF "off" + +/** + * @brief Definition for value of EVENT_KEY_WIFI_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_WIFI_ON "on" + +/** + * @brief Definition for value of EVENT_KEY_WIFI_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_WIFI_CONNECTED "connected" + +/** + * @brief Definition for system-event of bluetooth : status of bluetooth. + * @since_tizen 2.4 + * @see EVENT_KEY_BT_STATE + * @see EVENT_KEY_BT_LE_STATE + * @see EVENT_KEY_BT_TRANSFERING_STATE + */ +#define SYSTEM_EVENT_BT_STATE "tizen.system.event.bt_state" + +/** + * @brief Definition for key of SYSTEM_EVENT_BT_STATE. + * @since_tizen 2.4 + * @see EVENT_VAL_BT_STATE_OFF + * @see EVENT_VAL_BT_STATE_ON + */ +#define EVENT_KEY_BT_STATE "bt_state" + +/** + * @brief Definition for value of EVENT_KEY_BT_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_BT_OFF "off" + +/** + * @brief Definition for value of EVENT_KEY_BT_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_BT_ON "on" + +/** + * @brief Definition for key of SYSTEM_EVENT_BT_STATE. + * @since_tizen 2.4 + * @see EVENT_VAL_BT_LE_STATE_OFF + * @see EVENT_VAL_BT_LE_STATE_ON + */ +#define EVENT_KEY_BT_LE_STATE "bt_le_state" + +/** + * @brief Definition for value of EVENT_KEY_BT_LE_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_BT_LE_OFF "off" + +/** + * @brief Definition for value of EVENT_KEY_BT_LE_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_BT_LE_ON "on" + +/** + * @brief Definition for key of SYSTEM_EVENT_BT_STATE. + * @since_tizen 2.4 + * @remarks If it's already transfering state before you register this event, you can't receive the event regarding current transfer but you can receive the following transfers. + * @see EVENT_VAL_BT_NON_TRANSFERING + * @see EVENT_VAL_BT_TRANSFERING + */ +#define EVENT_KEY_BT_TRANSFERING_STATE "bt_transfering_state" + +/** + * @brief Definition for value of EVENT_KEY_BT_TRANSFERING_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_BT_NON_TRANSFERING "non_transfering" + +/** + * @brief Definition for value of EVENT_KEY_BT_TRANSFERING_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_BT_TRANSFERING "transfering" + +/** + * @brief Definition for system-event of location : enable state of location. + * @since_tizen 2.4 + * @see EVENT_KEY_LOCATION_ENABLE_STATE + */ +#define SYSTEM_EVENT_LOCATION_ENABLE_STATE "tizen.system.event.location_enable_state" + +/** + * @brief Definition for key of SYSTEM_EVENT_LOCATION_ENABLE_STATE. + * @since_tizen 2.4 + * @see EVENT_VAL_LOCATION_DISABLED + * @see EVENT_VAL_LOCATION_ENABLED + */ +#define EVENT_KEY_LOCATION_ENABLE_STATE "location_enable_state" + +/** + * @brief Definition for value of EVENT_KEY_LOCATION_ENABLE_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_LOCATION_DISABLED "disabled" + +/** + * @brief Definition for value of EVENT_KEY_LOCATION_ENABLE_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_LOCATION_ENABLED "enabled" + +/** + * @brief Definition for system-event of location : enable state of gps. + * @since_tizen 2.4 + * @see EVENT_KEY_GPS_ENABLE_STATE + */ +#define SYSTEM_EVENT_GPS_ENABLE_STATE "tizen.system.event.gps_enable_state" + +/** + * @brief Definition for key of SYSTEM_EVENT_GPS_ENABLE_STATE. + * @since_tizen 2.4 + * @see EVENT_VAL_GPS_DISABLED + * @see EVENT_VAL_GPS_ENABLED + */ +#define EVENT_KEY_GPS_ENABLE_STATE "gps_enable_state" + +/** + * @brief Definition for value of EVENT_KEY_GPS_ENABLE_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_GPS_DISABLED "disabled" + +/** + * @brief Definition for value of EVENT_KEY_GPS_ENABLE_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_GPS_ENABLED "enabled" + +/** + * @brief Definition for system-event of location : enable state of nps. + * @since_tizen 2.4 + * @see EVENT_KEY_NPS_ENABLE_STATE + */ +#define SYSTEM_EVENT_NPS_ENABLE_STATE "tizen.system.event.nps_enable_state" + +/** + * @brief Definition for key of SYSTEM_EVENT_NPS_ENABLE_STATE. + * @since_tizen 2.4 + * @see EVENT_VAL_NPS_DISABLED + * @see EVENT_VAL_NPS_ENABLED + */ +#define EVENT_KEY_NPS_ENABLE_STATE "nps_enable_state" + +/** + * @brief Definition for value of EVENT_KEY_NPS_ENABLE_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_NPS_DISABLED "disabled" + +/** + * @brief Definition for value of EVENT_KEY_NPS_ENABLE_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_NPS_ENABLED "enabled" + +/** + * @brief Definition for system-event of message : incoming msg. + * @since_tizen 2.4 + * @privilege %http://tizen.org/privilege/message.read + * @remarks If you want to receive this event, you must declare this privilege. + * @see EVENT_KEY_MSG_TYPE + * @see EVENT_KEY_MSG_ID + */ +#define SYSTEM_EVENT_INCOMMING_MSG "tizen.system.event.incoming_msg" + +/** + * @brief Definition for key of SYSTEM_EVENT_INCOMMING_MSG. + * @since_tizen 2.4 + * @see EVENT_VAL_SMS + * @see EVENT_VAL_PUSH + * @see EVENT_VAL_CB + */ +#define EVENT_KEY_MSG_TYPE "msg_type" + +/** + * @brief Definition for value of EVENT_KEY_MSG_TYPE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_SMS "sms" + +/** + * @brief Definition for value of EVENT_KEY_MSG_TYPE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_PUSH "push" + +/** + * @brief Definition for value of EVENT_KEY_MSG_TYPE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_CB "cb" + +/** + * @brief Definition for key of SYSTEM_EVENT_INCOMMING_MSG. + * @since_tizen 2.4 + * @remarks The value of this key is a string of unsigned int value : new message id. + */ +#define EVENT_KEY_MSG_ID "msg_id" + +/** + * @brief Definition for system-event of setting : time changed. + * @since_tizen 2.4 + * @remarks There is no corresponding key/value. + * @remarks You can use a @a alarm_get_current_time() API for checking new time after receiving this event. + */ +#define SYSTEM_EVENT_TIME_CHANGED "tizen.system.event.time_changed" + +/** + * @brief Definition for system-event of setting : timezone setting. + * @since_tizen 2.4 + * @see EVENT_KEY_TIME_ZONE + */ +#define SYSTEM_EVENT_TIME_ZONE "tizen.system.event.time_zone" + +/** + * @brief Definition for key of SYSTEM_EVENT_TIME_ZONE. + * @since_tizen 2.4 + * @remarks The value of this key is timezone value of tz database, + * for example, "Asia/Seoul", "America/New_York", + * refer to the Time Zone Database of IANA. + */ +#define EVENT_KEY_TIME_ZONE "time_zone" + +/** + * @brief Definition for system-event of setting : hour format. + * @since_tizen 2.4 + * @see EVENT_KEY_HOUR_FORMAT + */ +#define SYSTEM_EVENT_HOUR_FORMAT "tizen.system.event.hour_format" + +/** + * @brief Definition for key of SYSTEM_EVENT_HOUR_FORMAT. + * @since_tizen 2.4 + * @see EVENT_VAL_HOURFORMAT_12 + * @see EVENT_VAL_HOURFORMAT_24 + */ +#define EVENT_KEY_HOUR_FORMAT "hour_format" + +/** + * @brief Definition for value of EVENT_KEY_HOUR_FORMAT. + * @since_tizen 2.4 + */ +#define EVENT_VAL_HOURFORMAT_12 "12" + +/** + * @brief Definition for value of EVENT_KEY_HOUR_FORMAT. + * @since_tizen 2.4 + */ +#define EVENT_VAL_HOURFORMAT_24 "24" + +/** + * @brief Definition for system-event of setting : language setting. + * @since_tizen 2.4 + * @see EVENT_KEY_LANGUAGE_SET + */ +#define SYSTEM_EVENT_LANGUAGE_SET "tizen.system.event.language_set" + +/** + * @brief Definition for key of SYSTEM_EVENT_LANGUAGE_SET. + * @since_tizen 2.4 + * @remarks The value of this key is full name of locale, for example, + * "ko_KR.UTF8" : in case of Korean language + * "en_US.UTF8" : in case of USA language, + * refer to linux locale info. + */ +#define EVENT_KEY_LANGUAGE_SET "language_set" + +/** + * @brief Definition for system-event of setting : region format. + * @since_tizen 2.4 + * @see EVENT_KEY_REGION_FORMAT + */ +#define SYSTEM_EVENT_REGION_FORMAT "tizen.system.event.region_format" + +/** + * @brief Definition for key of SYSTEM_EVENT_REGION_FORMAT. + * @since_tizen 2.4 + * @remarks The value of this key is full name of locale, for example, + * "ko_KR.UTF8" : in case of Korean region format + * "en_US.UTF8" : in case of USA region format, + * refer to linux locale info. + */ +#define EVENT_KEY_REGION_FORMAT "region_format" + +/** + * @brief Definition for system-event of setting : silent_mode. + * @since_tizen 2.4 + * @see EVENT_KEY_SILENT_MODE + */ +#define SYSTEM_EVENT_SILENT_MODE "tizen.system.event.silent_mode" + +/** + * @brief Definition for key of SYSTEM_EVENT_SILENT_MODE. + * @since_tizen 2.4 + * @see EVENT_VAL_SILENTMODE_ON + * @see EVENT_VAL_SILENTMODE_OFF + */ +#define EVENT_KEY_SILENT_MODE "silent_mode" + +/** + * @brief Definition for value of EVENT_KEY_SILENT_MODE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_SILENTMODE_ON "on" + +/** + * @brief Definition for value of EVENT_KEY_SILENT_MODE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_SILENTMODE_OFF "off" + +/** + * @brief Definition for system-event of setting : state of vibration. + * @since_tizen 2.4 + * @see EVENT_KEY_VIBRATION_STATE + */ +#define SYSTEM_EVENT_VIBRATION_STATE "tizen.system.event.vibration_state" + +/** + * @brief Definition for key of SYSTEM_EVENT_VIBRATION_STATE. + * @since_tizen 2.4 + * @see EVENT_VAL_VIBRATION_ON + * @see EVENT_VAL_VIBRATION_OFF + */ +#define EVENT_KEY_VIBRATION_STATE "vibration_state" + +/** + * @brief Definition for value of EVENT_KEY_VIBRATION_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_VIBRATION_ON "on" + +/** + * @brief Definition for value of EVENT_KEY_VIBRATION_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_VIBRATION_OFF "off" + +/** + * @brief Definition for system-event of setting : state of screen's auto-rotation. + * @since_tizen 2.4 + * @see EVENT_KEY_SCREEN_AUTOROTATE_STATE + */ +#define SYSTEM_EVENT_SCREEN_AUTOROTATE_STATE "tizen.system.event.screen_autorotate_state" + +/** + * @brief Definition for key of SYSTEM_EVENT_SCREEN_AUTOROTATE_STATE. + * @since_tizen 2.4 + * @see EVENT_VAL_SCREEN_AUTOROTATE_ON + * @see EVENT_VAL_SCREEN_AUTOROTATE_OFF + */ +#define EVENT_KEY_SCREEN_AUTOROTATE_STATE "screen_autorotate_state" + +/** + * @brief Definition for value of EVENT_KEY_SCREEN_AUTOROTATE_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_SCREEN_AUTOROTATE_ON "on" + +/** + * @brief Definition for value of EVENT_KEY_SCREEN_AUTOROTATE_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_SCREEN_AUTOROTATE_OFF "off" + +/** + * @brief Definition for system-event of setting : state of mobile data. + * @since_tizen 2.4 + * @see EVENT_KEY_MOBILE_DATA_STATE + */ +#define SYSTEM_EVENT_MOBILE_DATA_STATE "tizen.system.event.mobile_data_state" + +/** + * @brief Definition for key of SYSTEM_EVENT_MOBILE_DATA_STATE. + * @since_tizen 2.4 + * @see EVENT_VAL_MOBILE_DATA_OFF + * @see EVENT_VAL_MOBILE_DATA_ON + */ +#define EVENT_KEY_MOBILE_DATA_STATE "mobile_data_state" + +/** + * @brief Definition for value of EVENT_KEY_MOBILE_DATA_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_MOBILE_DATA_OFF "off" + +/** + * @brief Definition for value of EVENT_KEY_MOBILE_DATA_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_MOBILE_DATA_ON "on" + +/** + * @brief Definition for system-event of setting : state of data roaming. + * @since_tizen 2.4 + * @see EVENT_KEY_DATA_ROAMING_STATE + */ +#define SYSTEM_EVENT_DATA_ROAMING_STATE "tizen.system.event.data_roaming_state" + +/** + * @brief Definition for key of SYSTEM_EVENT_DATA_ROAMING_STATE. + * @since_tizen 2.4 + * @see EVENT_VAL_DATA_ROAMING_OFF + * @see EVENT_VAL_DATA_ROAMING_ON + */ +#define EVENT_KEY_DATA_ROAMING_STATE "data_roaming_state" + +/** + * @brief Definition for value of EVENT_KEY_DATA_ROAMING_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_DATA_ROAMING_OFF "off" + +/** + * @brief Definition for value of EVENT_KEY_DATA_ROAMING_STATE. + * @since_tizen 2.4 + */ +#define EVENT_VAL_DATA_ROAMING_ON "on" + +/** + * @brief Definition for system-event of setting : font setting. + * @since_tizen 2.4 + * @see EVENT_KEY_FONT_SET + */ +#define SYSTEM_EVENT_FONT_SET "tizen.system.event.font_set" + +/** + * @brief Definition for key of SYSTEM_EVENT_FONT_SET. + * @since_tizen 2.4 + * @remarks The value of this key is font name of string type by font-config. + */ +#define EVENT_KEY_FONT_SET "font_set" + +/** + * @brief Adds the event handler for receiving event-data of interested events. + * + * @since_tizen 2.4 + * @remarks If you want to add the privileged event, you MUST declare right privilge first. Unless that, this function returns #EVENT_ERROR_PERMISSION_DENIED. The privileged events are commented on remarks of it's definitions. + * @param[in] event_name The interested event name + * @param[in] callback The event callback called when the event occurs + * @param[in] user_data The user data for passing to callback + * @param[out] event_handler The event handler + * @return 0 on success, otherwise a negative error value + * @retval #EVENT_ERROR_NONE Successful + * @retval #EVENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #EVENT_ERROR_PERMISSION_DENIED Permission denied + */ +int event_add_event_handler(const char *event_name, event_cb callback, void *user_data, + event_handler_h *event_handler); + +/** + * @brief Removes the registered event handler. + * + * @since_tizen 2.4 + * @param[in] event_handler The event handler + * @return 0 on success, otherwise a negative error value + * @retval #EVENT_ERROR_NONE Successful + * @retval #EVENT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int event_remove_event_handler(event_handler_h event_handler); + +/** + * @brief Sends the User-Event to receiver applications. + * + * @since_tizen 2.4 + * @remarks The format of User-Event's name MUST be "event.{sender's appid}.{user-defined name}", refer to 'The name-format of User-Event' section, If the event_name is invalid, the function returns #EVENT_ERROR_IO_ERROR. + * @param[in] event_name The event's name to send + * @param[in] event_data The event's data to send + * @return 0 on success, otherwise a negative error value + * @retval #EVENT_ERROR_NONE Successful + * @retval #EVENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #EVENT_ERROR_IO_ERROR Sending operation failed + */ +int event_publish_app_event(const char *event_name, bundle *event_data); + +/** + * @brief Sends the User-Event to trusted receiver-applications. + * + * @since_tizen 2.4 + * @remarks The application which has same certification with sender can receive the event. + * @remarks The format of User-Event's name MUST be "event.{sender's appid}.{user-defined name}", refer to 'The name-format of User-Event' section, If the event_name is invalid, the function returns #EVENT_ERROR_IO_ERROR. + * @param[in] event_name The event's name to send + * @param[in] event_data The event's data to send + * @return 0 on success, otherwise a negative error value + * @retval #EVENT_ERROR_NONE Successful + * @retval #EVENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #EVENT_ERROR_IO_ERROR Sending operation failed + */ +int event_publish_trusted_app_event(const char *event_name, bundle *event_data); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_APPFW_EVENT_H__ */ diff --git a/packaging/capi-appfw-application.spec b/packaging/capi-appfw-application.spec index 6ca2112..a7996e3 100755 --- a/packaging/capi-appfw-application.spec +++ b/packaging/capi-appfw-application.spec @@ -20,6 +20,7 @@ BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(vconf-internal-keys) +BuildRequires: pkgconfig(eventsystem) %description An Application library in SLP C API package. @@ -58,6 +59,7 @@ cp LICENSE %{buildroot}%{_datadir}/license/%{name} %{_libdir}/libcapi-appfw-app-common.so.* %{_libdir}/libcapi-appfw-alarm.so.* %{_libdir}/libcapi-appfw-preference.so.* +%{_libdir}/libcapi-appfw-event.so.* %{_datadir}/license/%{name} @@ -70,4 +72,5 @@ cp LICENSE %{buildroot}%{_datadir}/license/%{name} %{_libdir}/libcapi-appfw-app-common.so %{_libdir}/libcapi-appfw-alarm.so %{_libdir}/libcapi-appfw-preference.so +%{_libdir}/libcapi-appfw-event.so -- 2.7.4