tizen 2.4 release accepted/tizen_2.4_mobile tizen_2.4 accepted/tizen/2.4/mobile/20151029.033935 submit/tizen_2.4/20151028.063855 tizen_2.4_mobile_release
authorjk7744.park <jk7744.park@samsung.com>
Sat, 24 Oct 2015 07:31:24 +0000 (16:31 +0900)
committerjk7744.park <jk7744.park@samsung.com>
Sat, 24 Oct 2015 07:31:24 +0000 (16:31 +0900)
AUTHORS [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0755]
LICENSE [new file with mode: 0644]
eventsystem.manifest.in [new file with mode: 0644]
eventsystem.pc.in [new file with mode: 0644]
include/eventsystem.h [new file with mode: 0755]
include/eventsystem_internal.h [new file with mode: 0644]
packaging/eventsystem.spec [new file with mode: 0755]
src/eventsystem.c [new file with mode: 0755]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..cf4d288
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,2 @@
+Jongmyeong Ko <jongmyeong.ko@samsung.com>
+Jusung Son <jusung07.son@samsung.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..08cad00
--- /dev/null
@@ -0,0 +1,54 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+PROJECT(eventsystem C)
+
+SET(VERSION 0.0.1)
+SET(VERSION_MAJOR 0)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+
+set(CMAKE_SKIP_BUILD_RPATH true)
+
+### Local include directories
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)
+
+### Required packages
+INCLUDE(FindPkgConfig)
+
+pkg_check_modules(libpkgs REQUIRED dlog bundle openssl glib-2.0 capi-base-common)
+
+#FIND_LIBRARY(LIB_DL dl)
+
+FOREACH(flag ${libpkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+## Additional flag
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+## Linker flags
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+
+## build eventsystem library
+add_library(eventsystem SHARED
+               src/eventsystem.c
+               )
+
+#TARGET_LINK_LIBRARIES(eventsystem "-ldl")
+TARGET_LINK_LIBRARIES(eventsystem ${libpkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(eventsystem PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(eventsystem PROPERTIES VERSION ${VERSION})
+
+# pkgconfig file
+CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/eventsystem.pc.in ${CMAKE_BINARY_DIR}/eventsystem.pc @ONLY)
+configure_file(eventsystem.manifest.in eventsystem.manifest @ONLY)
+
+INSTALL(TARGETS eventsystem DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/eventsystem.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/eventsystem.h DESTINATION include)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/eventsystem_internal.h DESTINATION include)
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..9c13a9b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,204 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+\r
+                                 Apache License\r
+                           Version 2.0, January 2004\r
+                        http://www.apache.org/licenses/\r
+\r
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
+\r
+   1. Definitions.\r
+\r
+      "License" shall mean the terms and conditions for use, reproduction,\r
+      and distribution as defined by Sections 1 through 9 of this document.\r
+\r
+      "Licensor" shall mean the copyright owner or entity authorized by\r
+      the copyright owner that is granting the License.\r
+\r
+      "Legal Entity" shall mean the union of the acting entity and all\r
+      other entities that control, are controlled by, or are under common\r
+      control with that entity. For the purposes of this definition,\r
+      "control" means (i) the power, direct or indirect, to cause the\r
+      direction or management of such entity, whether by contract or\r
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
+      outstanding shares, or (iii) beneficial ownership of such entity.\r
+\r
+      "You" (or "Your") shall mean an individual or Legal Entity\r
+      exercising permissions granted by this License.\r
+\r
+      "Source" form shall mean the preferred form for making modifications,\r
+      including but not limited to software source code, documentation\r
+      source, and configuration files.\r
+\r
+      "Object" form shall mean any form resulting from mechanical\r
+      transformation or translation of a Source form, including but\r
+      not limited to compiled object code, generated documentation,\r
+      and conversions to other media types.\r
+\r
+      "Work" shall mean the work of authorship, whether in Source or\r
+      Object form, made available under the License, as indicated by a\r
+      copyright notice that is included in or attached to the work\r
+      (an example is provided in the Appendix below).\r
+\r
+      "Derivative Works" shall mean any work, whether in Source or Object\r
+      form, that is based on (or derived from) the Work and for which the\r
+      editorial revisions, annotations, elaborations, or other modifications\r
+      represent, as a whole, an original work of authorship. For the purposes\r
+      of this License, Derivative Works shall not include works that remain\r
+      separable from, or merely link (or bind by name) to the interfaces of,\r
+      the Work and Derivative Works thereof.\r
+\r
+      "Contribution" shall mean any work of authorship, including\r
+      the original version of the Work and any modifications or additions\r
+      to that Work or Derivative Works thereof, that is intentionally\r
+      submitted to Licensor for inclusion in the Work by the copyright owner\r
+      or by an individual or Legal Entity authorized to submit on behalf of\r
+      the copyright owner. For the purposes of this definition, "submitted"\r
+      means any form of electronic, verbal, or written communication sent\r
+      to the Licensor or its representatives, including but not limited to\r
+      communication on electronic mailing lists, source code control systems,\r
+      and issue tracking systems that are managed by, or on behalf of, the\r
+      Licensor for the purpose of discussing and improving the Work, but\r
+      excluding communication that is conspicuously marked or otherwise\r
+      designated in writing by the copyright owner as "Not a Contribution."\r
+\r
+      "Contributor" shall mean Licensor and any individual or Legal Entity\r
+      on behalf of whom a Contribution has been received by Licensor and\r
+      subsequently incorporated within the Work.\r
+\r
+   2. Grant of Copyright License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      copyright license to reproduce, prepare Derivative Works of,\r
+      publicly display, publicly perform, sublicense, and distribute the\r
+      Work and such Derivative Works in Source or Object form.\r
+\r
+   3. Grant of Patent License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      (except as stated in this section) patent license to make, have made,\r
+      use, offer to sell, sell, import, and otherwise transfer the Work,\r
+      where such license applies only to those patent claims licensable\r
+      by such Contributor that are necessarily infringed by their\r
+      Contribution(s) alone or by combination of their Contribution(s)\r
+      with the Work to which such Contribution(s) was submitted. If You\r
+      institute patent litigation against any entity (including a\r
+      cross-claim or counterclaim in a lawsuit) alleging that the Work\r
+      or a Contribution incorporated within the Work constitutes direct\r
+      or contributory patent infringement, then any patent licenses\r
+      granted to You under this License for that Work shall terminate\r
+      as of the date such litigation is filed.\r
+\r
+   4. Redistribution. You may reproduce and distribute copies of the\r
+      Work or Derivative Works thereof in any medium, with or without\r
+      modifications, and in Source or Object form, provided that You\r
+      meet the following conditions:\r
+\r
+      (a) You must give any other recipients of the Work or\r
+          Derivative Works a copy of this License; and\r
+\r
+      (b) You must cause any modified files to carry prominent notices\r
+          stating that You changed the files; and\r
+\r
+      (c) You must retain, in the Source form of any Derivative Works\r
+          that You distribute, all copyright, patent, trademark, and\r
+          attribution notices from the Source form of the Work,\r
+          excluding those notices that do not pertain to any part of\r
+          the Derivative Works; and\r
+\r
+      (d) If the Work includes a "NOTICE" text file as part of its\r
+          distribution, then any Derivative Works that You distribute must\r
+          include a readable copy of the attribution notices contained\r
+          within such NOTICE file, excluding those notices that do not\r
+          pertain to any part of the Derivative Works, in at least one\r
+          of the following places: within a NOTICE text file distributed\r
+          as part of the Derivative Works; within the Source form or\r
+          documentation, if provided along with the Derivative Works; or,\r
+          within a display generated by the Derivative Works, if and\r
+          wherever such third-party notices normally appear. The contents\r
+          of the NOTICE file are for informational purposes only and\r
+          do not modify the License. You may add Your own attribution\r
+          notices within Derivative Works that You distribute, alongside\r
+          or as an addendum to the NOTICE text from the Work, provided\r
+          that such additional attribution notices cannot be construed\r
+          as modifying the License.\r
+\r
+      You may add Your own copyright statement to Your modifications and\r
+      may provide additional or different license terms and conditions\r
+      for use, reproduction, or distribution of Your modifications, or\r
+      for any such Derivative Works as a whole, provided Your use,\r
+      reproduction, and distribution of the Work otherwise complies with\r
+      the conditions stated in this License.\r
+\r
+   5. Submission of Contributions. Unless You explicitly state otherwise,\r
+      any Contribution intentionally submitted for inclusion in the Work\r
+      by You to the Licensor shall be under the terms and conditions of\r
+      this License, without any additional terms or conditions.\r
+      Notwithstanding the above, nothing herein shall supersede or modify\r
+      the terms of any separate license agreement you may have executed\r
+      with Licensor regarding such Contributions.\r
+\r
+   6. Trademarks. This License does not grant permission to use the trade\r
+      names, trademarks, service marks, or product names of the Licensor,\r
+      except as required for reasonable and customary use in describing the\r
+      origin of the Work and reproducing the content of the NOTICE file.\r
+\r
+   7. Disclaimer of Warranty. Unless required by applicable law or\r
+      agreed to in writing, Licensor provides the Work (and each\r
+      Contributor provides its Contributions) on an "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
+      implied, including, without limitation, any warranties or conditions\r
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
+      PARTICULAR PURPOSE. You are solely responsible for determining the\r
+      appropriateness of using or redistributing the Work and assume any\r
+      risks associated with Your exercise of permissions under this License.\r
+\r
+   8. Limitation of Liability. In no event and under no legal theory,\r
+      whether in tort (including negligence), contract, or otherwise,\r
+      unless required by applicable law (such as deliberate and grossly\r
+      negligent acts) or agreed to in writing, shall any Contributor be\r
+      liable to You for damages, including any direct, indirect, special,\r
+      incidental, or consequential damages of any character arising as a\r
+      result of this License or out of the use or inability to use the\r
+      Work (including but not limited to damages for loss of goodwill,\r
+      work stoppage, computer failure or malfunction, or any and all\r
+      other commercial damages or losses), even if such Contributor\r
+      has been advised of the possibility of such damages.\r
+\r
+   9. Accepting Warranty or Additional Liability. While redistributing\r
+      the Work or Derivative Works thereof, You may choose to offer,\r
+      and charge a fee for, acceptance of support, warranty, indemnity,\r
+      or other liability obligations and/or rights consistent with this\r
+      License. However, in accepting such obligations, You may act only\r
+      on Your own behalf and on Your sole responsibility, not on behalf\r
+      of any other Contributor, and only if You agree to indemnify,\r
+      defend, and hold each Contributor harmless for any liability\r
+      incurred by, or claims asserted against, such Contributor by reason\r
+      of your accepting any such warranty or additional liability.\r
+\r
+   END OF TERMS AND CONDITIONS\r
+\r
+   APPENDIX: How to apply the Apache License to your work.\r
+\r
+      To apply the Apache License to your work, attach the following\r
+      boilerplate notice, with the fields enclosed by brackets "[]"\r
+      replaced with your own identifying information. (Don't include\r
+      the brackets!)  The text should be enclosed in the appropriate\r
+      comment syntax for the file format. We also recommend that a\r
+      file or class name and description of purpose be included on the\r
+      same "printed page" as the copyright notice for easier\r
+      identification within third-party archives.\r
+\r
+   Copyright [yyyy] [name of copyright owner]\r
+\r
+   Licensed under the Apache License, Version 2.0 (the "License");\r
+   you may not use this file except in compliance with the License.\r
+   You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
diff --git a/eventsystem.manifest.in b/eventsystem.manifest.in
new file mode 100644 (file)
index 0000000..f0a27f6
--- /dev/null
@@ -0,0 +1,11 @@
+<manifest>
+       <define>
+               <domain name="event-system"/>
+       </define>
+       <request>
+               <domain name="event-system" />
+       </request>
+       <assign>
+               <filesystem path="@LIB_INSTALL_DIR@/libeventsystem.*" label="_"/>
+       </assign>
+</manifest>
diff --git a/eventsystem.pc.in b/eventsystem.pc.in
new file mode 100644 (file)
index 0000000..85881d4
--- /dev/null
@@ -0,0 +1,13 @@
+# Package Information for pkg-config
+
+prefix=/usr
+exec_prefix=${prefix}
+libdir=@LIB_INSTALL_DIR@
+includedir=${prefix}/include
+
+Name: libeventsystem
+Description: event system library
+Version: @VERSION@
+Requires: bundle openssl glib-2.0 gio-2.0
+Libs: -L${libdir} -leventsystem
+Cflags: -I${includedir}
diff --git a/include/eventsystem.h b/include/eventsystem.h
new file mode 100755 (executable)
index 0000000..ae4b723
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * 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 __EVENT_SYSTEM_H__
+#define __EVENT_SYSTEM_H__
+
+/**
+ * header file for eventsystem
+ */
+
+#include <stdbool.h>
+#include <eventsystem_internal.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define APPFW_EVENT_SYSTEM_EARLIER_FEATURE
+
+typedef enum _eventsystem_return_val {
+       ES_R_ENOTPERMITTED = -4,        /* Not permitted */
+       ES_R_ENOMEM = -3,               /* Memory allocation error */
+       ES_R_EINVAL = -2,               /* Invalid argument */
+       ES_R_ERROR = -1,                /* General error */
+       ES_R_OK = 0,                    /* General success */
+       ES_R_REMOVE = 1                 /* Neet to remove something */
+} eventsystem_return_val;
+
+typedef enum _eventsystem_event_type {
+       ES_TYPE_UNKNOWN = 0,    /* unknown event */
+       ES_TYPE_USER,           /* user event */
+       ES_TYPE_SYSTEM          /* system event */
+} eventsystem_event_type;
+
+#define FREE_AND_NULL(ptr) do { \
+       if (ptr) { \
+               free((void *)ptr); \
+               ptr = NULL; \
+       } \
+} while (0)
+
+
+/**
+ * APIs for Application Framework.
+ */
+
+/**
+ * interface : Callback for app core
+ */
+typedef void (*eventsystem_cb)(const char *event_name, bundle_raw *event_data,
+               int len, void *user_data);
+
+/**
+ * function : Send the user-event
+ */
+API int eventsystem_send_user_event(const char *event_name, bundle *data, bool is_trusted);
+
+/**
+ * function : Register the event of the application
+ */
+API int eventsystem_register_application_event(const char *event_name, unsigned int *reg_id,
+               int *event_type, eventsystem_cb callback, void *user_data);
+
+/**
+ * function : Unregister the event of the application
+ */
+API int eventsystem_unregister_application_event(unsigned int reg_id);
+
+/**
+ *function : Finalizer for releasing all resources
+ */
+API int eventsystem_application_finalize(void);
+
+
+/**
+ * APIs for Internal-Use (daemon or privileged app for sending system-event)
+ */
+
+/**
+ * interface : Callback for internal use
+ *
+ * example :
+#include <eventsystem.h>
+#include <bundle.h>
+void battery_level_event_handler(const char *event_name, bundle *data, void *user_data)
+{
+       const char *batt_level_status = NULL;
+       _I("battery event(%s) received", event_name);
+
+       batt_level_status = bundle_get_val(data, EVT_KEY_BATTERY_LEVEL_STATUS);
+       _I("batt_level_status(%s)", batt_level_status);
+}
+ *
+ */
+
+typedef void (*eventsystem_handler)(const char *event_name, bundle *data, void *user_data);
+
+/**
+ * function : Register the event
+ *
+ * example :
+#include <eventsystem.h>
+static void init_func(void *user_data)
+{
+       int ret = 0;
+       ret = eventsystem_register_event(SYS_EVENT_BATTERY_LEVEL_STATUS,
+               &batt_level_reg_id,
+               (eventsystem_handler)battery_level_event_handler,
+               user_data);
+       if (ret != ES_R_OK) {
+               printf("error");
+       }
+}
+ *
+ */
+API int eventsystem_register_event(const char *event_name, unsigned int *reg_id,
+               eventsystem_handler callback, void *user_data);
+
+/**
+ * function : Unregister the event
+ *
+ * example :
+static void exit_func(void *data)
+{
+       int ret = 0;
+       ret = eventsystem_unregister_event(batt_level_reg_id);
+       if (ret != ES_R_OK) {
+               printf("error");
+       }
+}
+ *
+ */
+API int eventsystem_unregister_event(unsigned int reg_id);
+
+/**
+ * function : Send the system-event
+ *
+ * example :
+static void send_func(void *user_data)
+{
+       bundle *b = NULL;
+       b = bundle_create();
+       bundle_add_str(b, EVT_KEY_BATTERY_LEVEL_STATUS, EVT_VAL_BATTERY_LEVEL_HIGH);
+       eventsystem_send_system_event(SYS_EVENT_BATTERY_LEVEL_STATUS, b);
+       bundle_free(b);
+}
+ *
+ */
+API int eventsystem_send_system_event(const char *event_name, bundle *data);
+
+/**
+ * function : Request sending the event
+ * note : This API is only for privileged application which can not use eventsystem_send_system_event() API because of dbus policy. This API need a privilege.
+ * example : similar to event_send_system_event().
+ *
+ */
+API int eventsystem_request_sending_system_event(const char *event_name, bundle *data);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __EVENT_SYSTEM_H__ */
diff --git a/include/eventsystem_internal.h b/include/eventsystem_internal.h
new file mode 100644 (file)
index 0000000..b70a24a
--- /dev/null
@@ -0,0 +1,274 @@
+/*
+ * 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 __EVENTSYSTEM_INTERNAL_H__
+#define ___EVENTSYSTEM_INTERNAL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ESD_BUS_NAME "tizen.system.event.app2esd"
+#define ESD_OBJECT_PATH "/tizen/system/event/app2esd"
+#define ESD_INTERFACE_NAME "tizen.system.event.app2esd"
+
+#define USER_EVENT_NAME_PREFIX "event."
+
+/**
+ * system-event definitions
+ */
+
+/** esd : for checking esd available */
+#define SYS_EVENT_ESD_STATUS "tizen.system.event.esd_status"
+/* key */
+#define EVT_KEY_ESD_STATUS "esd_status"
+/* value */
+#define EVT_VAL_ESD_STARTED "started"
+#define EVT_VAL_ESD_STOPPED "stopped"
+
+/** battery : charger status */
+#define SYS_EVENT_BATTERY_CHARGER_STATUS "tizen.system.event.battery_charger_status"
+/* key */
+#define EVT_KEY_BATTERY_CHARGER_STATUS "battery_charger_status"
+/* value */
+#define EVT_VAL_BATTERY_CHARGER_DISCONNECTED "disconnected"
+#define EVT_VAL_BATTERY_CHARGER_CONNECTED "connected"
+#define EVT_VAL_BATTERY_CHARGER_CHARGING "charging"
+#define EVT_VAL_BATTERY_CHARGER_DISCHARGING "discharging"
+
+/** battery : level status */
+#define SYS_EVENT_BATTERY_LEVEL_STATUS "tizen.system.event.battery_level_status"
+/* key */
+#define EVT_KEY_BATTERY_LEVEL_STATUS "battery_level_status"
+/* value */
+#define EVT_VAL_BATTERY_LEVEL_EMPTY "empty"
+#define EVT_VAL_BATTERY_LEVEL_CRITICAL "critical"
+#define EVT_VAL_BATTERY_LEVEL_LOW "low"
+#define EVT_VAL_BATTERY_LEVEL_HIGH "high"
+#define EVT_VAL_BATTERY_LEVEL_FULL "full"
+
+/** usb : status of usb connection */
+#define SYS_EVENT_USB_STATUS "tizen.system.event.usb_status"
+/* key */
+#define EVT_KEY_USB_STATUS "usb_status"
+/* value */
+#define EVT_VAL_USB_DISCONNECTED "disconnected"
+#define EVT_VAL_USB_CONNECTED "connected"
+#define EVT_VAL_USB_AVAILABLE "available"
+
+/** ear-jack : status of ear-jack connection */
+#define SYS_EVENT_EARJACK_STATUS "tizen.system.event.earjack_status"
+/* key */
+#define EVT_KEY_EARJACK_STATUS "earjack_status"
+/* value */
+#define EVT_VAL_EARJACK_DISCONNECTED "disconnected"
+#define EVT_VAL_EARJACK_CONNECTED "connected"
+
+/** display : state of display */
+#define SYS_EVENT_DISPLAY_STATE "tizen.system.event.display_state"
+/* key */
+#define EVT_KEY_DISPLAY_STATE "display_state"
+/* value */
+#define EVT_VAL_DISPLAY_NORMAL "normal"
+#define EVT_VAL_DISPLAY_DIM "dim"
+#define EVT_VAL_DISPLAY_OFF "off"
+
+/** system : boot completion */
+#define SYS_EVENT_BOOT_COMPLETED "tizen.system.event.boot_completed"
+/* key */
+#define EVT_KEY_BOOT_COMPLETED "boot_completed"
+/* value */
+#define EVT_VAL_BOOT_COMPLETED_TRUE "true"
+
+/** system : shutdown */
+#define SYS_EVENT_SYSTEM_SHUTDOWN "tizen.system.event.system_shutdown"
+/* key */
+#define EVT_KEY_SYSTEM_SHUTDOWN "system_shutdown"
+/* value */
+#define EVT_VAL_SYSTEM_SHUTDOWN_TRUE "true" /* go to shutdown */
+
+/** resource : low memory */
+#define SYS_EVENT_LOW_MEMORY "tizen.system.event.low_memory"
+/* key */
+#define EVT_KEY_LOW_MEMORY "low_memory"
+/* value */
+#define EVT_VAL_MEMORY_NORMAL "normal"
+#define EVT_VAL_MEMORY_SOFT_WARNING "soft_warning"
+#define EVT_VAL_MEMORY_HARD_WARNING "hard_warning"
+
+/** wifi : state of wifi */
+#define SYS_EVENT_WIFI_STATE "tizen.system.event.wifi_state"
+/* key */
+#define EVT_KEY_WIFI_STATE "wifi_state"
+/* value */
+#define EVT_VAL_WIFI_OFF "off"
+#define EVT_VAL_WIFI_ON "on"
+#define EVT_VAL_WIFI_CONNECTED "connected"
+
+/** bluetooth : state of bluetooth */
+#define SYS_EVENT_BT_STATE "tizen.system.event.bt_state"
+/* key */
+#define EVT_KEY_BT_STATE "bt_state"
+/* value */
+#define EVT_VAL_BT_OFF "off"
+#define EVT_VAL_BT_ON "on"
+/* key */
+#define EVT_KEY_BT_LE_STATE "bt_le_state"
+/* value */
+#define EVT_VAL_BT_LE_OFF "off"
+#define EVT_VAL_BT_LE_ON "on"
+/* key */
+#define EVT_KEY_BT_TRANSFERING_STATE "bt_transfering_state"
+/* value */
+#define EVT_VAL_BT_NON_TRANSFERING "non_transfering"
+#define EVT_VAL_BT_TRANSFERING "transfering"
+
+/** location : enable state of location */
+#define SYS_EVENT_LOCATION_ENABLE_STATE "tizen.system.event.location_enable_state"
+/* key */
+#define EVT_KEY_LOCATION_ENABLE_STATE "location_enable_state"
+/* value */
+#define EVT_VAL_LOCATION_DISABLED "disabled"
+#define EVT_VAL_LOCATION_ENABLED "enabled"
+
+/** location : enable state of gps */
+#define SYS_EVENT_GPS_ENABLE_STATE "tizen.system.event.gps_enable_state"
+/* key */
+#define EVT_KEY_GPS_ENABLE_STATE "gps_enable_state"
+/* value */
+#define EVT_VAL_GPS_DISABLED "disabled"
+#define EVT_VAL_GPS_ENABLED "enabled"
+
+/** location : enable state of nps */
+#define SYS_EVENT_NPS_ENABLE_STATE "tizen.system.event.nps_enable_state"
+/* key */
+#define EVT_KEY_NPS_ENABLE_STATE "nps_enable_state"
+/* value */
+#define EVT_VAL_NPS_DISABLED "disabled"
+#define EVT_VAL_NPS_ENABLED "enabled"
+
+/** message : incoming msg */
+#define SYS_EVENT_INCOMMING_MSG "tizen.system.event.incoming_msg"
+/* key */
+#define EVT_KEY_MSG_TYPE "msg_type"
+/* value */
+#define EVT_VAL_SMS "sms"
+#define EVT_VAL_PUSH "push"
+#define EVT_VAL_CB "cb"
+/* key */
+#define EVT_KEY_MSG_ID "msg_id"
+/* value description
+ *"{unsigned int value}" : new message id
+ */
+
+/** setting : time changed */
+#define SYS_EVENT_TIME_CHANGED "tizen.system.event.time_changed"
+/* key */
+#define EVT_KEY_TIME_CHANGED "time_changed"
+/* value */
+/* do not set "false", just set "true" for broadcasting time_changed */
+#define EVT_VAL_TIME_CHANGED_TRUE "true"
+
+/** setting : timezone setting */
+#define SYS_EVENT_TIME_ZONE "tizen.system.event.time_zone"
+/* key */
+#define EVT_KEY_TIME_ZONE "time_zone"
+/* vlaue description
+ * "Asia/Seoul" : tzpaht value
+ */
+
+/** setting : hour format */
+#define SYS_EVENT_HOUR_FORMAT "tizen.system.event.hour_format"
+/* key */
+#define EVT_KEY_HOUR_FORMAT "hour_format"
+/* value */
+#define EVT_VAL_HOURFORMAT_12 "12"
+#define EVT_VAL_HOURFORMAT_24 "24"
+
+/** setting : language setting */
+#define SYS_EVENT_LANGUAGE_SET "tizen.system.event.language_set"
+/* key */
+#define EVT_KEY_LANGUAGE_SET "language_set"
+/* value description
+ * "ko_KR.UTF8" : in case of Korean language
+ * "en_US.UTF8" : in case of USA language
+ * ...
+ */
+
+/** setting : region format */
+#define SYS_EVENT_REGION_FORMAT "tizen.system.event.region_format"
+/* key */
+#define EVT_KEY_REGION_FORMAT "region_format"
+/* value description
+ * "ko_KR.UTF8" : in case of Korean region format
+ * "en_US.UTF8" : in case of USA region format
+ * "en_UK.UTF8" : in case of United Kingdom
+ * ...
+ */
+
+/** setting : silent mode */
+#define SYS_EVENT_SILENT_MODE "tizen.system.event.silent_mode"
+/* key */
+#define EVT_KEY_SILENT_MODE "silent_mode"
+/* value */
+#define EVT_VAL_SILENTMODE_ON "on"
+#define EVT_VAL_SILENTMODE_OFF "off"
+
+/** setting : state of vibration */
+#define SYS_EVENT_VIBRATION_STATE "tizen.system.event.vibration_state"
+/* key */
+#define EVT_KEY_VIBRATION_STATE "vibration_state"
+/* value */
+#define EVT_VAL_VIBRATION_ON "on"
+#define EVT_VAL_VIBRATION_OFF "off"
+
+/** setting : state of screen's auto-rotation */
+#define SYS_EVENT_SCREEN_AUTOROTATE_STATE "tizen.system.event.screen_autorotate_state"
+/* key */
+#define EVT_KEY_SCREEN_AUTOROTATE_STATE "screen_autorotate_state"
+/* value */
+#define EVT_VAL_SCREEN_AUTOROTATE_ON "on"
+#define EVT_VAL_SCREEN_AUTOROTATE_OFF "off"
+
+/** setting : state of mobile data */
+#define SYS_EVENT_MOBILE_DATA_STATE "tizen.system.event.mobile_data_state"
+/* key */
+#define EVT_KEY_MOBILE_DATA_STATE "mobile_data_state"
+/* value */
+#define EVT_VAL_MOBILE_DATA_OFF "off"
+#define EVT_VAL_MOBILE_DATA_ON "on"
+
+/** setting : state of data roaming */
+#define SYS_EVENT_DATA_ROAMING_STATE "tizen.system.event.data_roaming_state"
+/* key */
+#define EVT_KEY_DATA_ROAMING_STATE "data_roaming_state"
+/* value */
+#define EVT_VAL_DATA_ROAMING_OFF "off"
+#define EVT_VAL_DATA_ROAMING_ON "on"
+
+/** setting : font setting */
+#define SYS_EVENT_FONT_SET "tizen.system.event.font_set"
+/* key */
+#define EVT_KEY_FONT_SET "font_set"
+/* value description
+ * font name of string type by font-config.
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __EVENTSYSTEM_INTERNAL_H__ */
diff --git a/packaging/eventsystem.spec b/packaging/eventsystem.spec
new file mode 100755 (executable)
index 0000000..4333791
--- /dev/null
@@ -0,0 +1,63 @@
+Name:       eventsystem
+Summary:    Event system library
+Version:    0.0.1
+Release:    1
+Group:      System/Libraries
+License:    Apache-2.0
+Source0:    %{name}-%{version}.tar.gz
+BuildRequires:  cmake
+BuildRequires:  pkgconfig(ecore)
+BuildRequires:  pkgconfig(bundle)
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(gio-2.0)
+BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(capi-base-common)
+
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+%description
+Event System Library
+
+%package devel
+Summary:    Event system library (devel)
+Group:      Development/Libraries
+Requires:   %{name} = %{version}-%{release}
+
+%description devel
+Event system library (devel)
+
+%prep
+%setup -q
+
+%build
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
+export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
+
+
+%cmake .
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE %{buildroot}/usr/share/license/%{name}
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+%manifest eventsystem.manifest
+%defattr(-,root,root,-)
+%{_libdir}/libeventsystem.so.*
+/usr/share/license/%{name}
+
+%files devel
+%defattr(-,root,root,-)
+%{_includedir}/*.h
+%{_libdir}/libeventsystem.so
+%{_libdir}/pkgconfig/eventsystem.pc
diff --git a/src/eventsystem.c b/src/eventsystem.c
new file mode 100755 (executable)
index 0000000..4ed3904
--- /dev/null
@@ -0,0 +1,1798 @@
+/**
+ * event system low-level API
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <dlog.h>
+#include <bundle.h>
+#include <bundle_internal.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <eventsystem.h>
+#include <fcntl.h>
+
+#undef LOG_TAG
+#define LOG_TAG "eventsystem"
+
+#define SYS_EVENT_NAME_PREFIX "tizen.system.event"
+#define EVENT_SYSTEM_PREFIX "eventsystem.id_"
+#define EVENT_SYSTEM_PREFIX_LEN 15
+#define EVENT_SYSTEM_MEMBER "eventsystem"
+#define VALID_COUNT_OF_EVENTNAME_TOKEN 3
+#define VALID_LAST_COUNT_FOR_EVENTNAME (VALID_COUNT_OF_EVENTNAME_TOKEN + 1)
+#define MAX_COUNT_FOR_EVENTNAME_CHECK (VALID_LAST_COUNT_FOR_EVENTNAME + 1)
+
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+#define _D(fmt, arg...) LOGD(fmt, ##arg)
+#define _W(fmt, arg...) LOGW(fmt, ##arg)
+#define _I(fmt, arg...) LOGI(fmt, ##arg)
+
+#define retvm_if(expr, val, fmt, arg...) do { \
+       if (expr) { \
+               _E(fmt, ##arg); \
+               _E("(%s) -> %s() return", #expr, __func__); \
+               return val; \
+       } \
+} while (0)
+
+#define retv_if(expr, val) do { \
+       if (expr) { \
+               _E("(%s) -> %s() return", #expr, __func__); \
+               return val; \
+       } \
+} while (0)
+
+#define tryvm_if(expr, val, fmt, arg...) do { \
+        if (expr) { \
+               _E("(%s) "fmt, #expr, ##arg); \
+               val; \
+               goto catch; \
+       } \
+} while (0)
+
+pthread_mutex_t send_sync_lock = PTHREAD_MUTEX_INITIALIZER;
+
+static GList *system_event_list;
+static int _initialized;
+static GHashTable *check_tbl;
+static GHashTable *filter_tbl;
+
+typedef struct eventmap {
+       char *event_name;
+       char *interface_name;
+       char *member_name;
+       guint reg_id;
+       GBusType bus_type;
+       int event_type;
+       union {
+               eventsystem_cb es_cb;
+               eventsystem_handler ep_cb;
+       };
+} eventmap_s;
+
+typedef struct eventinfo {
+       char *event_name;
+       char *destination_name;
+       char *interface_name;
+       char *object_path;
+       char *member_name;
+       bool is_user_event;
+       bundle *event_data;
+} eventinfo_s;
+
+typedef struct sysevent_info {
+       guint owner_id;
+       guint owner_id_session;
+       char *own_name_system_bus;
+       char *own_name_session_bus;
+} sysevent_info_s;
+static sysevent_info_s s_info;
+
+static int __eventsystem_check_user_send_validation(const char *event_name);
+static int __eventsystem_requet_destination_list(const char *event_name, GList **dest_list);
+static int __eventsystem_check_sender_validation(int sender_pid,
+               const char *event_name, char **sender);
+
+static int __event_compare_name_cb(gconstpointer a, gconstpointer b)
+{
+       eventmap_s *key1 = (eventmap_s *)a;
+       eventmap_s *key2 = (eventmap_s *)b;
+       return strcmp(key1->interface_name, key2->interface_name) |
+                       strcmp(key1->member_name, key2->member_name);
+}
+
+static int __event_compare_reg_id_cb(gconstpointer a, gconstpointer b)
+{
+       eventmap_s *key1 = (eventmap_s *)a;
+       eventmap_s *key2 = (eventmap_s *)b;
+       return !(key1->reg_id == key2->reg_id);
+}
+
+static void __initialize(void)
+{
+#if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36)
+       g_type_init();
+#endif
+
+       _initialized = 1;
+}
+
+static int __eventsystem_get_sender_pid(GDBusConnection *conn, const char *sender_name)
+{
+       GDBusMessage *msg = NULL;
+       GDBusMessage *reply = NULL;
+       GError *err = NULL;
+       GVariant *body;
+       int pid = 0;
+
+       msg = g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus",
+               "org.freedesktop.DBus", "GetConnectionUnixProcessID");
+       if (!msg) {
+               _E("Can't allocate new method call");
+               goto out;
+       }
+
+       g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
+       reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
+               G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
+
+       if (!reply) {
+               if (err != NULL) {
+                       _E("Failed to get pid [%s]", err->message);
+                       g_error_free(err);
+               }
+               goto out;
+       }
+
+       body = g_dbus_message_get_body(reply);
+       g_variant_get(body, "(u)", &pid);
+
+out:
+       if (msg)
+               g_object_unref(msg);
+       if (reply)
+               g_object_unref(reply);
+
+       return pid;
+}
+
+static char *__get_object_path(char *interface_name)
+{
+       int i;
+       char *object_path = (char *)calloc(strlen(interface_name), sizeof(char)+2);
+
+       if (object_path == NULL) {
+               _E("failed to allocate memory");
+               return NULL;
+       }
+
+       object_path[0] = '/';
+
+       for (i = 0 ; interface_name[i] ; i++) {
+
+               if (interface_name[i] == '.') {
+                       object_path[i+1] = '/';
+               } else {
+                       object_path[i+1] = interface_name[i];
+               }
+       }
+
+       return object_path;
+}
+
+static char *__get_encoded_interface_name(char *interface_name)
+{
+       char *evtid = NULL;
+       int evtid_len = 0;
+       gchar *encoded_value;
+
+       encoded_value = g_compute_checksum_for_string(G_CHECKSUM_MD5,
+               interface_name, strlen(interface_name));
+
+       evtid_len = EVENT_SYSTEM_PREFIX_LEN + strlen(encoded_value) + 1;
+
+       evtid = (char *)calloc(evtid_len, sizeof(char));
+       if (evtid == NULL) {
+               _D("memory alloc failed");
+               g_free(encoded_value);
+               return NULL;
+       }
+
+       snprintf(evtid, evtid_len, "%s%s", EVENT_SYSTEM_PREFIX, (char *)encoded_value);
+
+       g_free(encoded_value);
+
+       return evtid;
+}
+
+static char *__get_member_name_from_eventname(char *event_name)
+{
+       char *ptr = NULL;
+       char *ptr_last = NULL;
+       char *temp_name = NULL;
+       char *member_name = NULL;
+       char *save_ptr = NULL;
+       int count = 0;
+
+       temp_name = strdup(event_name);
+       if (temp_name == NULL) {
+               _E("out of memory");
+               return NULL;
+       }
+
+       ptr = strtok_r(temp_name, ".", &save_ptr);
+       if (ptr == NULL) {
+               _E("invalid event_name(%s), count(%d)", event_name, count);
+               FREE_AND_NULL(temp_name);
+               return NULL;
+       }
+       count++;
+
+       while (count < MAX_COUNT_FOR_EVENTNAME_CHECK) {
+               ptr = strtok_r(NULL, ".", &save_ptr);
+               if (ptr == NULL)
+                       break;
+               /* _D("(%d)ptr(%s)(%d)", count, ptr, strlen(ptr)); */
+               ptr_last = ptr;
+               count++;
+       }
+       FREE_AND_NULL(temp_name);
+
+       if (count != VALID_LAST_COUNT_FOR_EVENTNAME) {
+               _E("invalid event_name(%s), count(%d)", event_name, count);
+               return NULL;
+       }
+
+       if (ptr_last) {
+               /* _D("new member_name(%s)(%d)", ptr_last, strlen(ptr_last)); */
+               member_name = strdup(ptr_last);
+               if (!member_name) {
+                       _E("out_of_memory");
+                       return NULL;
+               }
+       } else {
+               _E("ptr_last is NULL");
+               return NULL;
+       }
+
+       _D("member_name(%s)", member_name);
+
+       return member_name;
+}
+
+static int __check_validation_usrevent_sender(int sender_pid,
+               const char *interface_name, const char *event_name)
+{
+       char *sender_id = NULL;
+       char *key = NULL;
+       char *val = NULL;
+
+       if (__eventsystem_check_sender_validation(sender_pid,
+               event_name, &sender_id) < 0) {
+               _E("invalid user-event sender");
+               return ES_R_EINVAL;
+       }
+
+       if (sender_id == NULL) {
+               _E("sender_id is null");
+               return ES_R_EINVAL;
+       }
+
+       key = strdup(interface_name);
+       if (key == NULL) {
+               _E("out of memory");
+               return ES_R_ENOMEM;
+       }
+
+       val = strdup(sender_id);
+       if (val == NULL) {
+               _E("out of memory");
+               free(key);
+               return ES_R_ENOMEM;
+       }
+
+       g_hash_table_insert(filter_tbl, key, val);
+
+       return ES_R_OK;
+}
+
+static int __check_validation_user_defined_name(const char *event_name)
+{
+       char *event_id = NULL;
+       char *key = NULL;
+       int ret = 1;
+
+       if (check_tbl == NULL) {
+               check_tbl = g_hash_table_new(g_str_hash, g_str_equal);
+       }
+
+       event_id = (char *)g_hash_table_lookup(check_tbl, event_name);
+
+       if (event_id == NULL) {
+               if (__eventsystem_check_user_send_validation(event_name) < 0) {
+                       _E("invalid user-event name");
+                       ret = 0;
+               } else {
+                       key = strdup(event_name);
+                       if (key == NULL) {
+                               _E("out_of_memory");
+                               ret = 0;
+                       } else {
+                               g_hash_table_insert(check_tbl, key, key);
+                       }
+               }
+       }
+
+       return ret;
+}
+
+static int __check_interface_validation_user(char *interface_name)
+{
+       int ret = 1;
+       int len = strlen(EVENT_SYSTEM_PREFIX);
+
+       if (strncmp(interface_name, EVENT_SYSTEM_PREFIX, len) != 0) {
+               ret = 0;
+       }
+
+       return ret;
+}
+
+static int __check_eventname_validation_user(char *event_name)
+{
+       int ret = 1;
+       int len = strlen(USER_EVENT_NAME_PREFIX);
+
+       if (strncmp(event_name, USER_EVENT_NAME_PREFIX, len) != 0) {
+               ret = 0;
+       }
+
+       return ret;
+}
+
+static int __check_eventname_validation_system(char *event_name)
+{
+       int ret = 1;
+       int len = strlen(SYS_EVENT_NAME_PREFIX);
+
+       if (strncmp(event_name, SYS_EVENT_NAME_PREFIX, len) != 0) {
+               ret = 0;
+       }
+
+       return ret;
+}
+
+static int __get_gdbus_shared_connection(GDBusConnection **connection, GBusType bus_type,
+               eventsystem_event_type event_type)
+{
+       GError *error = NULL;
+       guint owner_id = 0;
+
+       if (!_initialized) {
+               __initialize();
+       }
+
+       *connection = g_bus_get_sync(bus_type, NULL, &error);
+       if (*connection == NULL) {
+               if (error != NULL) {
+                       _E("Failed to get dbus [%s], bus_type [%d]",
+                               error->message, bus_type);
+                       g_error_free(error);
+               }
+               return ES_R_ERROR;
+       }
+
+       if (((bus_type == G_BUS_TYPE_SYSTEM && !s_info.owner_id) ||
+               (bus_type == G_BUS_TYPE_SESSION && !s_info.owner_id_session))) {
+               gchar *guid = NULL;
+               char own_name[128] = {0, };
+
+               guid = g_dbus_generate_guid();
+               if (guid == NULL) {
+                       _E("failed to get guid");
+                       return ES_R_ERROR;
+               }
+               snprintf(own_name, 128, "%s_%s_%s_%d", "event.busname",
+                       (bus_type == G_BUS_TYPE_SESSION ? "session" : "system"),
+                       guid, getpid());
+               g_free(guid);
+
+               _D("bus_name is [%s]", own_name);
+               owner_id = g_bus_own_name_on_connection(*connection, own_name,
+                       G_BUS_NAME_OWNER_FLAGS_NONE,
+                       NULL, NULL, NULL, NULL);
+               if (!owner_id) {
+                       _E("g_bus_own_name_on_connection, error");
+                       return ES_R_ERROR;
+               }
+
+               if (bus_type == G_BUS_TYPE_SESSION && event_type == ES_TYPE_USER) {
+                       /* set same name on system-bus */
+                       GDBusConnection *conn_system = NULL;
+
+                       error = NULL;
+                       conn_system = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+                       if (conn_system == NULL) {
+                               _E("failed to get system connection");
+                               if (error != NULL) {
+                                       _E("error(%s)", error->message);
+                                       g_error_free(error);
+                               }
+                               return ES_R_ERROR;
+                       } else {
+                               owner_id = g_bus_own_name_on_connection(conn_system,
+                                       own_name, G_BUS_NAME_OWNER_FLAGS_NONE,
+                                       NULL, NULL, NULL, NULL);
+                               if (!owner_id) {
+                                       _E("g_bus_own_name_on_connection(for system), error");
+                                       g_object_unref(conn_system);
+                                       return ES_R_ERROR;
+                               }
+
+                               g_object_unref(conn_system);
+                       }
+               }
+
+               if (bus_type == G_BUS_TYPE_SESSION) {
+                       s_info.owner_id_session = owner_id;
+                       s_info.own_name_session_bus = strdup(own_name);
+                       if (s_info.own_name_session_bus == NULL) {
+                               _E("out of memory");
+                               return ES_R_ERROR;
+                       }
+               } else {
+                       s_info.owner_id = owner_id;
+                       s_info.own_name_system_bus = strdup(own_name);
+                       if (s_info.own_name_system_bus == NULL) {
+                               _E("out of memory");
+                               return ES_R_ERROR;
+                       }
+               }
+       }
+
+       return ES_R_OK;
+}
+
+static void __eventsystem_event_handler(GDBusConnection *connection,
+               const gchar *sender_name, const gchar *object_path,
+               const gchar *interface_name, const gchar *signal_name,
+               GVariant *parameters, gpointer user_data)
+{
+       int len;
+       eventmap_s em;
+       GList *cb_list = NULL;
+       bundle *buf = NULL;
+       bundle_raw *raw = NULL;
+
+       em.interface_name = (char *)interface_name;
+       em.member_name = (char *)signal_name;
+
+       _D("sender_name(%s), interface_name(%s), signal_name(%s)",
+               sender_name, interface_name, signal_name);
+
+       cb_list = g_list_find_custom(system_event_list, &em,
+               (GCompareFunc)__event_compare_name_cb);
+       if (cb_list == NULL) {
+               return;
+       }
+
+       g_variant_get(parameters, "(us)", &len, &raw);
+
+       buf = bundle_decode((bundle_raw *)raw, len);
+
+       em.event_name = ((eventmap_s *)cb_list->data)->event_name;
+       em.ep_cb = ((eventmap_s *)cb_list->data)->ep_cb;
+       if (em.ep_cb) {
+               em.ep_cb(em.event_name, buf, user_data);
+       }
+
+       bundle_free_encoded_rawdata(&raw);
+       bundle_free(buf);
+}
+
+static void __eventsystem_application_event_handler(int sender_pid,
+               const gchar *interface_name, const gchar *signal_name,
+               GVariant *parameters, gpointer user_data)
+{
+       GList *cb_list = NULL;
+       eventmap_s em;
+       bundle_raw *raw = NULL;
+       int len;
+
+       em.interface_name = (char *)interface_name;
+       em.member_name = (char *)signal_name;
+
+       cb_list = g_list_find_custom(system_event_list, &em,
+               (GCompareFunc)__event_compare_name_cb);
+
+       if (cb_list == NULL) {
+               _E("not interested event");
+               return;
+       }
+
+       em.event_name = ((eventmap_s *)cb_list->data)->event_name;
+
+       if (sender_pid > 0 && __check_interface_validation_user((char *)interface_name)) {
+               if (__check_validation_usrevent_sender(sender_pid,
+                       (const char *)interface_name, em.event_name) < 0) {
+                       _E("invalid sender");
+                       return;
+               }
+       }
+
+       g_variant_get(parameters, "(us)", &len, &raw);
+       em.es_cb = ((eventmap_s *)cb_list->data)->es_cb;
+       if (em.es_cb) {
+               em.es_cb(em.event_name, raw, len, user_data);
+       }
+
+       bundle_free_encoded_rawdata(&raw);
+}
+
+/**
+ * application-use filter for user-event
+ */
+static void __eventsystem_filter_userevent_for_application(GDBusConnection *connection,
+               const gchar *sender_name, const gchar *object_path,
+               const gchar *interface_name, const gchar *signal_name,
+               GVariant *parameters, gpointer user_data)
+{
+       char *sender_id = NULL;
+       int sender_pid = -1;
+
+       _D("sender_name(%s), interface_name(%s)", sender_name, interface_name);
+
+       if (filter_tbl == NULL) {
+               filter_tbl = g_hash_table_new(g_str_hash, g_str_equal);
+       }
+
+       sender_id = (char *)g_hash_table_lookup(filter_tbl, interface_name);
+
+       if (sender_id == NULL) {
+               sender_pid = __eventsystem_get_sender_pid(connection, sender_name);
+               if (sender_pid <= 0) {
+                       _E("failed to get pid of sender(%s)", sender_name);
+                       return;
+               }
+               _D("sender_pid(%d)", sender_pid);
+       }
+
+       __eventsystem_application_event_handler(sender_pid, interface_name,
+               signal_name, parameters, user_data);
+}
+
+/**
+ * application-use filter for system-event
+ */
+static void __eventsystem_filter_sysevent_for_application(GDBusConnection *connection,
+               const gchar *sender_name, const gchar *object_path,
+               const gchar *interface_name, const gchar *signal_name,
+               GVariant *parameters, gpointer user_data)
+{
+       _D("sender_name(%s), interface_name(%s)", sender_name, interface_name);
+
+       __eventsystem_application_event_handler(-1, interface_name,
+               signal_name, parameters, user_data);
+}
+
+/**
+ * internal-use filter for user-event
+ */
+static void __eventsystem_filter_userevent_for_internal(GDBusConnection *connection,
+               const gchar *sender_name, const gchar *object_path,
+               const gchar *interface_name, const gchar *signal_name,
+               GVariant *parameters, gpointer user_data)
+{
+       _D("sender_name(%s), interface_name(%s), signal_name(%s)",
+               sender_name, interface_name, signal_name);
+
+       __eventsystem_event_handler(connection, sender_name,
+               object_path, interface_name, signal_name, parameters, user_data);
+}
+
+/**
+ * internal-use filter for system-event
+ */
+static void __eventsystem_filter_sysevent_for_internal(GDBusConnection *connection,
+               const gchar *sender_name, const gchar *object_path,
+               const gchar *interface_name, const gchar *signal_name,
+               GVariant *parameters, gpointer user_data)
+{
+       _D("sender_name(%s), interface_name(%s), signal_name(%s)",
+               sender_name, interface_name, signal_name);
+
+       __eventsystem_event_handler(connection, sender_name,
+               object_path, interface_name, signal_name, parameters, user_data);
+}
+
+static int __eventsystem_register_event_internal(const char *event_name,
+               eventmap_s **em_s, void *user_data)
+{
+       eventmap_s *em = NULL;
+       char *interface_name = NULL;
+       char *object_path = NULL;
+       char *member_name = NULL;
+       char *sender_name = NULL;
+       GDBusSignalCallback filter;
+       GBusType bus_type;
+       guint subscription_id = 0;
+       int ret = 0;
+       int evt_type = ES_TYPE_UNKNOWN;
+       GDBusConnection *conn = NULL;
+
+       if (__check_eventname_validation_system((char *)event_name)) {
+               evt_type = ES_TYPE_SYSTEM;
+       } else if (__check_eventname_validation_user((char *)event_name)) {
+               evt_type = ES_TYPE_USER;
+       } else {
+               evt_type = ES_TYPE_UNKNOWN;
+               _E("unknown type event(%s)", event_name);
+               return ES_R_EINVAL;
+       }
+
+       if (evt_type == ES_TYPE_SYSTEM) {
+               interface_name = strdup(SYS_EVENT_NAME_PREFIX);
+               if (interface_name == NULL) {
+                       _E("out of memory");
+                       ret = ES_R_ENOMEM;
+                       goto out_1;
+               }
+
+               member_name = __get_member_name_from_eventname((char *)event_name);
+               if (member_name == NULL) {
+                       _E("invalid member_name");
+                       ret = ES_R_ERROR;
+                       goto out_2;
+               }
+
+               if (!g_dbus_is_member_name(member_name)) {
+                       _E("invalid member name");
+                       ret = ES_R_EINVAL;
+                       goto out_3;
+               }
+               filter = __eventsystem_filter_sysevent_for_internal;
+       } else {
+               interface_name = __get_encoded_interface_name((char *)event_name);
+               if (!interface_name) {
+                       _E("interface_name is NULL");
+                       ret = ES_R_ERROR;
+                       goto out_1;
+               }
+               if (!g_dbus_is_interface_name(interface_name)) {
+                       _E("invalid interface_name(%s)", interface_name);
+                       ret = ES_R_EINVAL;
+                       goto out_2;
+               }
+               member_name = strdup(EVENT_SYSTEM_MEMBER);
+               if (!member_name) {
+                       _E("out_of_memory");
+                       ret = ES_R_ERROR;
+                       goto out_2;
+               }
+               filter = __eventsystem_filter_userevent_for_internal;
+       }
+
+       object_path = __get_object_path(interface_name);
+       if (!object_path) {
+               _E("object_path is NULL");
+               ret = ES_R_ERROR;
+               goto out_3;
+       }
+       sender_name = NULL;
+
+       bus_type = G_BUS_TYPE_SYSTEM;
+
+       if (__get_gdbus_shared_connection(&conn, bus_type, evt_type) < 0) {
+               _E("getting gdbus-connetion error");
+               goto out_4;
+       }
+
+       subscription_id = g_dbus_connection_signal_subscribe(conn,
+               sender_name, /* sender */
+               interface_name,
+               member_name, /* member */
+               object_path, /* object_path */
+               NULL, /* arg0 */
+               G_DBUS_SIGNAL_FLAGS_NONE,
+               filter,
+               user_data,
+               NULL); /* user_data_free_func */
+
+       _D("event_name(%s), interface_name(%s)", event_name, interface_name);
+       _D("member_name(%s), subscription_id(%d), bus_type(%d)",
+               member_name, subscription_id, bus_type);
+
+       if (subscription_id != 0) {
+               em = calloc(1, sizeof(eventmap_s));
+               if (!em) {
+                       _E("memory alloc failed");
+                       ret = ES_R_ENOMEM;
+               } else {
+                       em->interface_name = strdup(interface_name);
+                       em->member_name = strdup(member_name);
+                       em->event_name = strdup(event_name);
+                       em->bus_type = bus_type;
+                       em->reg_id = subscription_id;
+                       em->event_type = evt_type;
+
+                       if (!em->interface_name || !em->member_name || !em->event_name) {
+                               _E("out_of_memory");
+                               FREE_AND_NULL(em->interface_name);
+                               FREE_AND_NULL(em->member_name);
+                               FREE_AND_NULL(em->event_name);
+                               FREE_AND_NULL(em);
+                               ret = ES_R_ENOMEM;
+                               goto out_4;
+                       }
+
+                       *em_s = em;
+                       ret = ES_R_OK;
+               }
+       } else {
+               _D("dbus subscribe: error(%d), event(%s)", subscription_id, event_name);
+               ret = ES_R_ERROR;
+       }
+
+out_4:
+       FREE_AND_NULL(object_path);
+out_3:
+       FREE_AND_NULL(member_name);
+out_2:
+       FREE_AND_NULL(interface_name);
+out_1:
+       if (conn) {
+               g_object_unref(conn);
+       }
+
+       return ret;
+}
+
+/**
+ * function : register the event
+ */
+int eventsystem_register_event(const char *event_name, unsigned int *reg_id,
+               eventsystem_handler callback, void *user_data)
+{
+       eventmap_s *em = NULL;
+       int ret = ES_R_ERROR;
+
+       retvm_if(!g_dbus_is_interface_name(event_name), ES_R_EINVAL,
+               "Invalid argument : event_name(%s)", event_name);
+       retvm_if(!reg_id, ES_R_EINVAL, "Invalid argument : reg_id");
+       retvm_if(!callback, ES_R_EINVAL, "Invalid argument : callback");
+
+       if (!_initialized) {
+               __initialize();
+       }
+
+       ret = __eventsystem_register_event_internal(event_name, &em, user_data);
+
+       if (ret == ES_R_OK && em) {
+               em->ep_cb = callback;
+               system_event_list = g_list_append(system_event_list, em);
+               *reg_id = em->reg_id;
+               ret = ES_R_OK;
+       } else {
+               _E("error, ret(%d), em(%s)", ret, em);
+       }
+
+       return ret;
+}
+
+/**
+ * function : unregister the event
+ */
+int eventsystem_unregister_event(unsigned int reg_id)
+{
+       eventmap_s em;
+       eventmap_s *em_data = NULL;
+       GBusType bus_type;
+       GList *cb_list = NULL;
+       GDBusConnection *conn = NULL;
+       eventsystem_event_type evt_type;
+
+       retvm_if(reg_id == 0, ES_R_EINVAL, "Invalid argument : reg_id");
+
+       if (!_initialized) {
+               __initialize();
+       }
+
+       em.reg_id = reg_id;
+       cb_list = g_list_find_custom(system_event_list, &em,
+               (GCompareFunc)__event_compare_reg_id_cb);
+       if (cb_list) {
+               em_data = (eventmap_s *)cb_list->data;
+
+               bus_type = em_data->bus_type;
+               evt_type = em_data->event_type;
+
+               _D("unsubscribe: reg_id(%d), bus_type(%d)", reg_id, bus_type);
+
+               if (__get_gdbus_shared_connection(&conn, bus_type, evt_type) < 0) {
+                       _E("getting gdbus-connetion error");
+                       return ES_R_ERROR;
+               }
+               g_dbus_connection_signal_unsubscribe(conn, reg_id);
+
+               system_event_list = g_list_remove(system_event_list, cb_list->data);
+
+               FREE_AND_NULL(em_data->interface_name);
+               FREE_AND_NULL(em_data->member_name);
+               FREE_AND_NULL(em_data->event_name);
+               FREE_AND_NULL(em_data);
+               g_object_unref(conn);
+       }
+
+       return ES_R_OK;
+}
+
+static int __eventsystem_send_event(GDBusConnection *conn, eventinfo_s *evti, bundle *data)
+{
+       GError *error = NULL;
+       GVariant *param = NULL;
+       gboolean ret;
+
+       bundle_raw *raw = NULL;
+       bundle *buf = data;
+       int len;
+
+       bundle_encode(buf, &raw, &len);
+
+       param = g_variant_new("(us)", len, raw);
+       ret = g_dbus_connection_emit_signal(conn,
+               evti->destination_name,
+               evti->object_path,
+               evti->interface_name,
+               evti->member_name,
+               param,
+               &error);
+
+       _D("interface_name(%s)", evti->interface_name);
+       _D("object_path(%s)", evti->object_path);
+       _D("member_name(%s)", evti->member_name);
+
+       bundle_free_encoded_rawdata(&raw);
+
+       if (ret == FALSE) {
+               _E("Unable to connect to dbus: %s", error->message);
+               g_error_free(error);
+               return ES_R_ERROR;
+       }
+
+       return ES_R_OK;
+}
+
+static void __eventsystem_free_trusted_list(gpointer data)
+{
+       char *name = (char *)data;
+
+       FREE_AND_NULL(name);
+}
+
+static int __eventsystem_send_trusted_event(GDBusConnection *conn, eventinfo_s *evti,
+               bundle *data, GList *dest_list)
+{
+       GList *tmp_list = NULL;
+       int ret = 0;
+
+       if (dest_list) {
+               tmp_list = g_list_first(dest_list);
+
+               while (tmp_list != NULL) {
+                       char *dest_name = (char *)tmp_list->data;
+                       if (dest_name && dest_name[0] != '\0') {
+                               _D("dest_name(%s)", dest_name);
+                               evti->destination_name = dest_name;
+                               ret = __eventsystem_send_event(conn, evti, data);
+                               if (ret != ES_R_OK) {
+                                       _E("send error");
+                                       ret = ES_R_ERROR;
+                                       break;
+                               }
+                       }
+                       tmp_list = g_list_next(tmp_list);
+               }
+               g_list_free_full(dest_list, __eventsystem_free_trusted_list);
+       } else {
+               _E("dest_list is null");
+       }
+
+       return ES_R_OK;
+}
+
+/**
+ * function : send the user-event
+ */
+int eventsystem_send_user_event(const char *event_name, bundle *data, bool is_trusted)
+{
+       int ret = 0;
+
+       /* check validation */
+       retvm_if(!event_name, ES_R_EINVAL, "Invalid argument : event_name is NULL");
+       retvm_if(!data, ES_R_EINVAL, "Invalid argument : data is NULL");
+       retvm_if(!__check_eventname_validation_user((char *)event_name), ES_R_EINVAL,
+               "Invalid argument : event_name(%s)", event_name);
+
+       if (!__check_validation_user_defined_name(event_name)) {
+               _E("Invalid event name(%s)", event_name);
+               return ES_R_EINVAL;
+       }
+
+       eventinfo_s *evti = NULL;
+       evti = calloc(1, sizeof(eventinfo_s));
+       if (!evti) {
+               _E("memory alloc failed");
+               return ES_R_ENOMEM;
+       }
+       evti->event_name = strdup(event_name);
+       if (!evti->event_name) {
+               _E("memory alloc failed");
+               ret = ES_R_ENOMEM;
+               goto out_1;
+       }
+
+       evti->interface_name = __get_encoded_interface_name(evti->event_name);
+       if (!evti->interface_name) {
+               _E("interface_name is NULL");
+               ret = ES_R_ERROR;
+               goto out_2;
+       }
+       evti->member_name = strdup(EVENT_SYSTEM_MEMBER);
+       if (!evti->member_name) {
+               _E("memory alloc failed");
+               ret = ES_R_ENOMEM;
+               goto out_3;
+       }
+
+       evti->object_path = __get_object_path(evti->interface_name);
+       if (!evti->object_path) {
+               _E("object_path is NULL");
+               ret = ES_R_ERROR;
+               goto out_4;
+       }
+
+       evti->destination_name = NULL;
+       evti->is_user_event = true;
+
+       GDBusConnection *conn = NULL;
+       if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SESSION, ES_TYPE_USER) == ES_R_OK) {
+               if (is_trusted) {
+                       GList *dest_list = NULL;
+                       ret = __eventsystem_requet_destination_list(evti->event_name, &dest_list);
+                       if (ret < 0) {
+                               _E("failed to get dest list");
+                               ret = ES_R_ERROR;
+                       } else {
+                               ret = __eventsystem_send_trusted_event(conn, evti,
+                                       data, dest_list);
+                       }
+               } else {
+                       ret = __eventsystem_send_event(conn, evti, data);
+               }
+       } else {
+               _E("getting gdbus-connetion error");
+               ret = ES_R_ERROR;
+       }
+
+       if (conn) {
+               g_object_unref(conn);
+       }
+       FREE_AND_NULL(evti->object_path);
+out_4:
+       FREE_AND_NULL(evti->member_name);
+out_3:
+       FREE_AND_NULL(evti->interface_name);
+out_2:
+       FREE_AND_NULL(evti->event_name);
+out_1:
+       FREE_AND_NULL(evti);
+
+       return ret;
+}
+
+/**
+ * function : send the system-event
+ */
+int eventsystem_send_system_event(const char *event_name, bundle *data)
+{
+       int ret = 0;
+
+       pthread_mutex_lock(&send_sync_lock);
+
+       /* check validation */
+       tryvm_if(!event_name, ret = ES_R_EINVAL, "Invalid argument : event_name is NULL");
+       tryvm_if(!data, ret = ES_R_EINVAL, "Invalid argument : data is NULL");
+       tryvm_if(!__check_eventname_validation_system((char *)event_name), ret = ES_R_EINVAL,
+               "Invalid argument : event_name(%s)", event_name);
+       tryvm_if(!g_dbus_is_interface_name(event_name), ret = ES_R_EINVAL,
+               "Invalid argument : event_name(%s)", event_name);
+
+       _D("event_name(%s)", event_name);
+
+       eventinfo_s *evti = NULL;
+       evti = calloc(1, sizeof(eventinfo_s));
+       if (!evti) {
+               _E("memory alloc failed");
+               pthread_mutex_unlock(&send_sync_lock);
+               return ES_R_ENOMEM;
+       }
+       evti->event_name = strdup(event_name);
+       if (!evti->event_name) {
+               _E("out_of_memory");
+               ret = ES_R_ENOMEM;
+               goto out_1;
+       }
+       evti->interface_name = strdup(SYS_EVENT_NAME_PREFIX);
+       if (!evti->interface_name) {
+               _E("out of memory");
+               ret = ES_R_ENOMEM;
+               goto out_2;
+       }
+       evti->member_name = __get_member_name_from_eventname(evti->event_name);
+       if (!evti->member_name) {
+               _E("member_name is NULL");
+               ret = ES_R_ERROR;
+               goto out_3;
+       }
+       if (!g_dbus_is_member_name(evti->member_name)) {
+               _E("Invalid member_name(%s)", evti->member_name);
+               ret = ES_R_EINVAL;
+               goto out_4;
+       }
+       evti->object_path = __get_object_path(evti->interface_name);
+       if (!evti->object_path) {
+               _E("object_path is NULL");
+               ret = ES_R_ERROR;
+               goto out_4;
+       }
+       evti->destination_name = NULL;
+       evti->is_user_event = false;
+
+       GDBusConnection *conn = NULL;
+       if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) == ES_R_OK) {
+               ret = __eventsystem_send_event(conn, evti, data);
+       } else {
+               _E("getting gdbus-connection error");
+               ret = ES_R_ERROR;
+       }
+
+       if (conn) {
+               g_object_unref(conn);
+       }
+       FREE_AND_NULL(evti->object_path);
+out_4:
+       FREE_AND_NULL(evti->member_name);
+out_3:
+       FREE_AND_NULL(evti->interface_name);
+out_2:
+       FREE_AND_NULL(evti->event_name);
+out_1:
+       FREE_AND_NULL(evti);
+
+catch:
+       pthread_mutex_unlock(&send_sync_lock);
+
+       return ret;
+}
+
+/**
+ * function : request sending the event
+ */
+int eventsystem_request_sending_system_event(const char *event_name, bundle *data)
+{
+       int ret = 0;
+       GDBusConnection *conn = NULL;
+       GError *error = NULL;
+       GDBusProxy *proxy = NULL;
+       GVariant *param = NULL;
+       GVariant *value = NULL;
+       gint result = 0;
+       bundle_raw *raw = NULL;
+       int len = 0;
+
+       _D("event_name(%s)", event_name);
+
+       if (!_initialized) {
+               __initialize();
+       }
+
+       if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
+               _E("getting gdbus-connetion error");
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       proxy = g_dbus_proxy_new_sync(conn,
+               G_DBUS_PROXY_FLAGS_NONE, NULL,
+               ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
+               NULL, &error);
+       if (proxy == NULL) {
+               _E("failed to create new proxy, error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       bundle_encode(data, &raw, &len);
+
+       param = g_variant_new("(ssi)", event_name, raw, len);
+       value = g_dbus_proxy_call_sync(proxy, "RequestSendingEvent", param,
+               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (error != NULL) {
+               _E("proxy call sync error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_2;
+       }
+
+       g_variant_get(value, "(i)", &result);
+
+       _D("result(%d)", result);
+
+       ret = ES_R_OK;
+
+out_2:
+       g_variant_unref(value);
+out_1:
+       if (conn) {
+               g_object_unref(conn);
+       }
+
+       return ret;
+}
+
+static int __eventsystem_check_sender_validation(int sender_pid, const char *event_name,
+               char **sender_id)
+{
+       int ret = ES_R_EINVAL;
+       GDBusConnection *conn = NULL;
+       GError *error = NULL;
+       GDBusProxy *proxy = NULL;
+       GVariant *param = NULL;
+       GVariant *value = NULL;
+       gint result = 0;
+
+       if (!_initialized) {
+               __initialize();
+       }
+
+       if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
+               _E("getting gdbus-connetion error");
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       proxy = g_dbus_proxy_new_sync(conn,
+               G_DBUS_PROXY_FLAGS_NONE, NULL,
+               ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
+               NULL, &error);
+       if (proxy == NULL) {
+               _E("failed to create new proxy, error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       param = g_variant_new("(is)", sender_pid, event_name);
+       value = g_dbus_proxy_call_sync(proxy, "CheckSenderValidation", param,
+               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (error != NULL) {
+               _E("proxy call sync error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_2;
+       }
+
+       g_variant_get(value, "(is)", &result, sender_id);
+
+       _D("result(%d)", result);
+
+       if (result == 1) {
+               ret = ES_R_OK;
+       }
+out_2:
+       g_variant_unref(value);
+out_1:
+       if (conn) {
+               g_object_unref(conn);
+       }
+
+       return ret;
+}
+
+static int __eventsystem_check_user_send_validation(const char *event_name)
+{
+       int ret = ES_R_EINVAL;
+       GDBusConnection *conn = NULL;
+       GError *error = NULL;
+       GDBusProxy *proxy = NULL;
+       GVariant *param = NULL;
+       GVariant *value = NULL;
+       gint result = 0;
+
+       if (!_initialized) {
+               __initialize();
+       }
+
+       if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
+               _E("getting gdbus-connetion error");
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       proxy = g_dbus_proxy_new_sync(conn,
+               G_DBUS_PROXY_FLAGS_NONE, NULL,
+               ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
+               NULL, &error);
+       if (proxy == NULL) {
+               _E("failed to create new proxy, error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       param = g_variant_new("(s)", event_name);
+       value = g_dbus_proxy_call_sync(proxy, "CheckUserSendValidation", param,
+               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (error != NULL) {
+               _E("proxy call sync error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_2;
+       }
+
+       g_variant_get(value, "(i)", &result);
+
+       _D("result(%d)", result);
+
+       if (result == 1) {
+               ret = ES_R_OK;
+       }
+out_2:
+       g_variant_unref(value);
+out_1:
+       if (conn) {
+               g_object_unref(conn);
+       }
+
+       return ret;
+}
+
+static int __eventsystem_check_privilege_validation(const char *event_name)
+{
+       int ret = ES_R_ENOTPERMITTED;
+       GDBusConnection *conn = NULL;
+       GError *error = NULL;
+       GDBusProxy *proxy = NULL;
+       GVariant *param = NULL;
+       GVariant *value = NULL;
+       gint result = 0;
+
+       if (!_initialized) {
+               __initialize();
+       }
+
+       if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
+               _E("getting gdbus-connetion error");
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       proxy = g_dbus_proxy_new_sync(conn,
+               G_DBUS_PROXY_FLAGS_NONE, NULL,
+               ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
+               NULL, &error);
+       if (proxy == NULL) {
+               _E("failed to create new proxy, error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       param = g_variant_new("(s)", event_name);
+       value = g_dbus_proxy_call_sync(proxy, "CheckPrivilegeValidation", param,
+               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (error != NULL) {
+               _E("proxy call sync error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_2;
+       }
+
+       g_variant_get(value, "(i)", &result);
+
+       _D("result(%d)", result);
+
+       if (result == 1) {
+               ret = ES_R_OK;
+       }
+out_2:
+       g_variant_unref(value);
+out_1:
+       if (conn) {
+               g_object_unref(conn);
+       }
+
+       return ret;
+}
+
+static int __eventsystem_setup_trusted_peer(const char *event_name, const char *dest_bus_name)
+{
+       int ret = ES_R_ERROR;
+       GDBusConnection *conn = NULL;
+       GError *error = NULL;
+       GDBusProxy *proxy = NULL;
+       GVariant *param = NULL;
+       GVariant *value = NULL;
+       gint result = 0;
+
+       if (!_initialized) {
+               __initialize();
+       }
+
+       if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
+               _E("getting gdbus-connetion error");
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       proxy = g_dbus_proxy_new_sync(conn,
+               G_DBUS_PROXY_FLAGS_NONE, NULL,
+               ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
+               NULL, &error);
+       if (proxy == NULL) {
+               _E("failed to create new proxy, error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       param = g_variant_new("(ss)", event_name, dest_bus_name);
+
+       value = g_dbus_proxy_call_sync(proxy, "SetupTrustedPeer", param,
+               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (error != NULL) {
+               _E("proxy call sync error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_2;
+       }
+
+       g_variant_get(value, "(i)", &result);
+
+       _D("result(%d)", result);
+
+       if (result == 1) {
+               ret = ES_R_OK;
+       }
+out_2:
+       g_variant_unref(value);
+out_1:
+       if (conn) {
+               g_object_unref(conn);
+       }
+
+       return ret;
+}
+
+static int __eventsystem_requet_destination_list(const char *event_name, GList **dest_list)
+{
+       int ret = ES_R_ERROR;
+       GDBusConnection *conn = NULL;
+       GError *error = NULL;
+       GDBusProxy *proxy = NULL;
+       GVariant *param = NULL;
+       GVariant *value = NULL;
+       GVariantIter *iter;
+       gchar *str;
+       char *dest_name = NULL;
+       gint result = 0;
+
+       if (!_initialized) {
+               __initialize();
+       }
+
+       if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
+               _E("getting gdbus-connetion error");
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       proxy = g_dbus_proxy_new_sync(conn,
+               G_DBUS_PROXY_FLAGS_NONE, NULL,
+               ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
+               NULL, &error);
+       if (proxy == NULL) {
+               _E("failed to create new proxy, error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       param = g_variant_new("(s)", event_name);
+
+       value = g_dbus_proxy_call_sync(proxy, "GetTrustedPeerList", param,
+               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (error != NULL) {
+               _E("proxy call sync error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_2;
+       }
+
+       g_variant_get(value, "(ias)", &result, &iter);
+
+       _D("result(%d)", result);
+
+       if (result == 1) {
+               ret = ES_R_OK;
+               while (g_variant_iter_loop(iter, "s", &str)) {
+                       dest_name = strdup((char *)str);
+                       if (dest_name) {
+                               _D("dest name(%s)", str);
+                               *dest_list = g_list_append(*dest_list, dest_name);
+                       } else {
+                               _E("out of memory");
+                               ret = ES_R_ENOMEM;
+                               break;
+                       }
+               }
+       }
+       g_variant_iter_free(iter);
+
+out_2:
+       g_variant_unref(value);
+out_1:
+       if (conn) {
+               g_object_unref(conn);
+       }
+
+       return ret;
+}
+
+#ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE
+static int __eventsystem_request_earlier_data(const char *event_name,
+               eventsystem_cb callback, void *user_data)
+{
+       int ret = 0;
+       GDBusConnection *conn = NULL;
+       GError *error = NULL;
+       GDBusProxy *proxy = NULL;
+       GVariant *param = NULL;
+       gint result = 0;
+       bundle_raw *raw = NULL;
+       int len = 0;
+
+       if (!_initialized) {
+               __initialize();
+       }
+
+       if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
+               _E("getting gdbus-connetion error");
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       proxy = g_dbus_proxy_new_sync(conn,
+               G_DBUS_PROXY_FLAGS_NONE, NULL,
+               ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
+               NULL, &error);
+
+       if (proxy == NULL) {
+               _E("failed to create new proxy, error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_1;
+       }
+
+       param = g_variant_new("(s)", event_name);
+       GVariant *value = g_dbus_proxy_call_sync(proxy, "GetEarlierData", param,
+               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (error != NULL) {
+               _E("proxy call sync error(%s)", error->message);
+               g_error_free(error);
+               ret = ES_R_ERROR;
+               goto out_2;
+       }
+
+       g_variant_get(value, "(iis)", &result, &len, &raw);
+       g_variant_unref(value);
+
+       _D("result(%d), len(%d)", result, len);
+
+       if (!result && raw && len > 0) {
+               callback(event_name, raw, len, user_data);
+               bundle_free_encoded_rawdata(&raw);
+       }
+
+       ret = ES_R_OK;
+
+out_2:
+       g_variant_unref(value);
+out_1:
+       if (conn) {
+               g_object_unref(conn);
+       }
+
+       return ret;
+}
+#endif
+
+int eventsystem_register_application_event(const char *event_name, unsigned int *reg_id,
+               int *event_type, eventsystem_cb callback, void *user_data)
+{
+       eventmap_s *em;
+       char *interface_name = NULL;
+       char *object_path = NULL;
+       char *member_name = NULL;
+       char *sender_name = NULL;
+       GDBusSignalCallback filter;
+       GBusType bus_type;
+       guint  subscription_id  = 0;
+       int ret = 0;
+       GDBusConnection *conn = NULL;
+
+       if (!_initialized) {
+               __initialize();
+       }
+
+       if (__check_eventname_validation_system((char *)event_name)) {
+               if (__eventsystem_check_privilege_validation(event_name) != ES_R_OK) {
+                       _E("invalid privilege(%s)", event_name);
+                       return ES_R_ENOTPERMITTED;
+               }
+               *event_type = ES_TYPE_SYSTEM;
+       } else if (__check_eventname_validation_user((char *)event_name)) {
+               *event_type = ES_TYPE_USER;
+       } else {
+               *event_type = ES_TYPE_UNKNOWN;
+               _E("unknown type event(%s)", event_name);
+               return ES_R_EINVAL;
+       }
+
+       if (*event_type == ES_TYPE_SYSTEM) {
+               interface_name = strdup(SYS_EVENT_NAME_PREFIX);
+               if (interface_name == NULL) {
+                       _E("out of memory");
+                       return ES_R_ENOMEM;
+               }
+               if (!g_dbus_is_interface_name(interface_name)) {
+                       _E("invalid interface_name(%s)", interface_name);
+                       FREE_AND_NULL(interface_name);
+                       return ES_R_EINVAL;
+               }
+               member_name = __get_member_name_from_eventname((char *)event_name);
+               if (member_name == NULL) {
+                       _E("member_name is NULL(%s)", event_name);
+                       FREE_AND_NULL(interface_name);
+                       return ES_R_ERROR;
+               }
+               if (!g_dbus_is_member_name(member_name)) {
+                       _E("Invalid member_name(%s)", member_name);
+                       FREE_AND_NULL(interface_name);
+                       FREE_AND_NULL(member_name);
+                       return ES_R_ERROR;
+               }
+               filter = __eventsystem_filter_sysevent_for_application;
+               bus_type = G_BUS_TYPE_SYSTEM;
+       } else {
+               interface_name = __get_encoded_interface_name((char *)event_name);
+               if (!interface_name) {
+                       _E("interface_name is NULL");
+                       return ES_R_ERROR;
+               }
+               if (!g_dbus_is_interface_name(interface_name)) {
+                       _E("invalid interface_name(%s)", interface_name);
+                       FREE_AND_NULL(interface_name);
+                       return ES_R_EINVAL;
+               }
+               member_name = strdup(EVENT_SYSTEM_MEMBER);
+               if (!member_name) {
+                       _E("out_of_memory");
+                       FREE_AND_NULL(interface_name);
+                       return ES_R_ERROR;
+               }
+               filter = __eventsystem_filter_userevent_for_application;
+               bus_type = G_BUS_TYPE_SESSION;
+       }
+
+       object_path = __get_object_path(interface_name);
+       if (!object_path) {
+               _E("failed get object_path");
+               FREE_AND_NULL(interface_name);
+               FREE_AND_NULL(member_name);
+               return ES_R_ERROR;
+       }
+       sender_name = NULL;
+
+       _D("interface_name(%s), object_path(%s)", interface_name, object_path);
+       _D(" member_name(%s), sender_name(%s), type(%d), bus_type(%d)",
+               member_name, sender_name, *event_type, bus_type);
+
+       if (__get_gdbus_shared_connection(&conn, bus_type, *event_type) < 0) {
+               _E("getting gdbus-connetion error");
+               FREE_AND_NULL(interface_name);
+               FREE_AND_NULL(object_path);
+               FREE_AND_NULL(member_name);
+               return ES_R_ERROR;
+       }
+
+#ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE
+       __eventsystem_request_earlier_data(event_name, callback, user_data);
+#endif
+
+       subscription_id = g_dbus_connection_signal_subscribe(conn,
+               sender_name, /* sender */
+               interface_name,
+               member_name, /* member */
+               object_path, /* object_path */
+               NULL, /* arg0 */
+               G_DBUS_SIGNAL_FLAGS_NONE,
+               filter,
+               user_data,
+               NULL); /* user_data_free_func */
+
+       _D("event_name(%s), subscription_id(%d)", event_name, subscription_id);
+
+       if (subscription_id != 0) {
+               em = calloc(1, sizeof(eventmap_s));
+               if (!em) {
+                       _E("memory alloc failed");
+                       ret = ES_R_ENOMEM;
+               } else {
+                       em->interface_name = strdup(interface_name);
+                       em->member_name = strdup(member_name);
+                       em->event_name = strdup(event_name);
+                       em->es_cb = callback;
+                       em->bus_type = bus_type;
+                       em->reg_id = subscription_id;
+                       em->event_type = *event_type;
+
+                       if (!em->interface_name || !em->member_name ||
+                               !em->event_name) {
+                               _E("out_of_memory");
+                               FREE_AND_NULL(em->interface_name);
+                               FREE_AND_NULL(em->member_name);
+                               FREE_AND_NULL(em->event_name);
+                               FREE_AND_NULL(em);
+                               ret = ES_R_ENOMEM;
+                       } else {
+                               system_event_list =
+                                       g_list_append(system_event_list, em);
+                               *reg_id = subscription_id;
+
+                               ret = ES_R_OK;
+
+                               if (em->bus_type == G_BUS_TYPE_SESSION &&
+                                        em->event_type == ES_TYPE_USER) {
+                                       if (s_info.own_name_session_bus == NULL) {
+                                               _E("session bus is not ready");
+                                               ret = ES_R_ERROR;
+                                       } else {
+                                               if (__eventsystem_setup_trusted_peer(event_name,
+                                                       s_info.own_name_session_bus) < 0) {
+                                                       _E("failed to setup trusted peer");
+                                                       ret = ES_R_ERROR;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       } else {
+               _E("dbus subscribe: error(%d)", subscription_id);
+               ret = ES_R_ERROR;
+       }
+
+       FREE_AND_NULL(interface_name);
+       FREE_AND_NULL(object_path);
+       FREE_AND_NULL(member_name);
+       if (conn) {
+               g_object_unref(conn);
+       }
+
+       return ret;
+}
+
+int eventsystem_unregister_application_event(unsigned int reg_id)
+{
+       eventmap_s em;
+       eventmap_s *em_data = NULL;
+       GBusType bus_type;
+       GList *cb_list = NULL;
+       GDBusConnection *conn = NULL;
+       eventsystem_event_type evt_type;
+
+       retvm_if(reg_id == 0, ES_R_EINVAL, "Invalid argument : reg_id");
+
+       if (!_initialized) {
+               __initialize();
+       }
+
+       em.reg_id = reg_id;
+       cb_list = g_list_find_custom(system_event_list, &em,
+               (GCompareFunc)__event_compare_reg_id_cb);
+       if (cb_list) {
+               em_data = (eventmap_s *)cb_list->data;
+
+               bus_type = em_data->bus_type;
+               evt_type = em_data->event_type;
+
+               _D("unsubscribe: reg_id(%d), bus_type(%d)", reg_id, bus_type);
+
+               if (__get_gdbus_shared_connection(&conn, bus_type, evt_type) < 0) {
+                       _E("getting gdbus-connetion error");
+                       return ES_R_ERROR;
+               }
+               g_dbus_connection_signal_unsubscribe(conn, reg_id);
+
+               system_event_list = g_list_remove(system_event_list, cb_list->data);
+
+               FREE_AND_NULL(em_data->interface_name);
+               FREE_AND_NULL(em_data->member_name);
+               FREE_AND_NULL(em_data->event_name);
+               FREE_AND_NULL(em_data);
+               g_object_unref(conn);
+       } else {
+               _E("not found matched item");
+               return ES_R_ERROR;
+       }
+
+       return ES_R_OK;
+}
+
+int eventsystem_application_finalize(void)
+{
+       gpointer key, value;
+
+       _D("release all resouces");
+
+       if (system_event_list) {
+               g_list_free(system_event_list);
+       }
+
+       if (check_tbl) {
+               GHashTableIter iter;
+
+               g_hash_table_iter_init(&iter, check_tbl);
+
+               while (g_hash_table_iter_next(&iter, &key, &value)) {
+                       char *val_item = (char *)value;
+                       if (val_item) {
+                               free(val_item);
+                       } else {
+                               _E("check_tbl, val_item is NULL");
+                       }
+                       g_hash_table_iter_remove(&iter);
+               }
+               g_hash_table_unref(check_tbl);
+       }
+
+       if (filter_tbl) {
+               GHashTableIter iter;
+
+               g_hash_table_iter_init(&iter, filter_tbl);
+
+               while (g_hash_table_iter_next(&iter, &key, &value)) {
+                       char *key_item = (char *)key;
+                       if (key_item) {
+                               free(key_item);
+                       } else {
+                               _E("filter_tbl, key_item is NULL");
+                       }
+                       char *val_item = (char *)value;
+                       if (val_item) {
+                               free(val_item);
+                       } else {
+                               _E("filter_tbl, val_item is NULL");
+                       }
+                       g_hash_table_iter_remove(&iter);
+               }
+               g_hash_table_unref(filter_tbl);
+       }
+
+       FREE_AND_NULL(s_info.own_name_system_bus);
+       FREE_AND_NULL(s_info.own_name_session_bus);
+
+       return 0;
+}