insert edbus server routine 05/13705/5
authorjy910.yun <jy910.yun@samsung.com>
Wed, 19 Jun 2013 12:40:07 +0000 (21:40 +0900)
committerKrzysztof Sasiak <k.sasiak@samsung.com>
Tue, 24 Dec 2013 13:29:55 +0000 (14:29 +0100)
Change-Id: Idcd667900ea73a594d1ad7b907221ebb8edb32c4
Signed-off-by: Krzysztof Sasiak <k.sasiak@samsung.com>
CMakeLists.txt
packaging/system-server.spec
src/core/edbus-handler.c
src/core/edbus-handler.h
src/core/main.c
src/core/sig-handler.c
src/core/sysnoti.c

index d412314..61ca672 100755 (executable)
@@ -37,10 +37,7 @@ SET(DEVICED_SRCS
 SET(DEVICED_HEADERS
        src/deviced/dd-battery.h)
 
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src)
-
-# libdeviced
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/deviced)
 
 SET(MOVINAND_FORMAT scripts/movi_format.sh)
 
index bb5a7ae..c1df839 100755 (executable)
@@ -25,7 +25,7 @@ BuildRequires:  pkgconfig(usbutils)
 BuildRequires:  pkgconfig(udev)
 BuildRequires:  pkgconfig(device-node)
 BuildRequires:  pkgconfig(libsmack)
-BuildRequires: gettext
+BuildRequires:  gettext
 BuildRequires:  pkgconfig(libsystemd-daemon)
 %{?systemd_requires}
 Requires(preun): /usr/bin/systemctl
index 6d0c82e..7537a22 100644 (file)
 /*
- * deviced
+ *  deviced
  *
- * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2010 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Licensed under the Apache License, Version 2.0 (the License);
+ * 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
+ * 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 <stdbool.h>
 #include "core/log.h"
 #include "core/data.h"
-#include "core/edbus-handler.h"
-#include "core/common.h"
+#include "edbus-handler.h"
 
 #define EDBUS_INIT_RETRY_COUNT 5
 
-#define DBUS_REPLY_TIMEOUT     (120 * 1000)
-#define RETRY_MAX 5
-
 struct edbus_list{
        char *signal_name;
        E_DBus_Signal_Handler *handler;
 };
 
-static struct edbus_object {
-       const char *path;
-       const char *interface;
-       E_DBus_Object *obj;
-       E_DBus_Interface *iface;
-} edbus_objects[] = {
-       /* Add new object & interface here*/
-};
-
 static Eina_List *edbus_handler_list;
 static int edbus_init_val;
-static DBusConnection *conn;
 static E_DBus_Connection *edbus_conn;
 static DBusPendingCall *edbus_request_name;
-
-static int register_edbus_interface(struct edbus_object *object)
-{
-       int ret;
-
-       if (!object) {
-               _E("object is invalid value!");
-               return -1;
-       }
-
-       object->obj = e_dbus_object_add(edbus_conn, object->path, NULL);
-       if (!object->obj) {
-               _E("fail to add edbus obj");
-               return -1;
-       }
-
-       object->iface = e_dbus_interface_new(object->interface);
-       if (!object->iface) {
-               _E("fail to add edbus interface");
-               return -1;
-       }
-
-       e_dbus_object_interface_attach(object->obj, object->iface);
-
-       return 0;
-}
-
-E_DBus_Interface *get_edbus_interface(const char *path)
-{
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(edbus_objects); i++)
-               if (!strcmp(path, edbus_objects[i].path))
-                       return edbus_objects[i].iface;
-
-       return NULL;
-}
-
-pid_t get_edbus_sender_pid(DBusMessage *msg)
-{
-       const char *sender;
-       DBusMessage *send_msg;
-       DBusPendingCall *pending;
-       DBusMessageIter iter;
-       int ret;
-       pid_t pid;
-
-       if (!msg) {
-               _E("invalid argument!");
-               return -1;
-       }
-
-       sender = dbus_message_get_sender(msg);
-       if (!sender) {
-               _E("invalid sender!");
-               return -1;
-       }
-
-       send_msg = dbus_message_new_method_call(DBUS_SERVICE_DBUS,
-                                   DBUS_PATH_DBUS,
-                                   DBUS_INTERFACE_DBUS,
-                                   "GetConnectionUnixProcessID");
-       if (!send_msg) {
-               _E("invalid send msg!");
-               return -1;
-       }
-
-       ret = dbus_message_append_args(send_msg, DBUS_TYPE_STRING,
-                                   &sender, DBUS_TYPE_INVALID);
-       if (!ret) {
-               _E("fail to append args!");
-               dbus_message_unref(send_msg);
-               return -1;
-       }
-
-       pending = e_dbus_message_send(edbus_conn, send_msg, NULL, -1, NULL);
-       if (!pending) {
-               _E("pending is null!");
-               dbus_message_unref(send_msg);
-               return -1;
-       }
-
-       dbus_message_unref(send_msg);
-
-       /* block until reply is received */
-       dbus_pending_call_block(pending);
-
-       msg = dbus_pending_call_steal_reply(pending);
-       dbus_pending_call_unref(pending);
-       if (!msg) {
-               _E("reply msg is null!");
-               return -1;
-       }
-
-       dbus_message_iter_init(msg, &iter);
-       dbus_message_iter_get_basic(&iter, &pid);
-       dbus_message_unref(msg);
-
-       return pid;
-}
-
 static void unregister_edbus_signal_handle(void)
 {
        Eina_List *tmp;
@@ -164,37 +49,38 @@ static void unregister_edbus_signal_handle(void)
        }
 }
 
-int register_edbus_signal_handler(const char *path, const char *interface,
-               const char *name, E_DBus_Signal_Cb cb)
+int register_edbus_signal_handler(char *signal_name, E_DBus_Signal_Cb cb)
 {
        Eina_List *tmp;
        struct edbus_list *entry;
        E_DBus_Signal_Handler *handler;
 
        EINA_LIST_FOREACH(edbus_handler_list, tmp, entry) {
-               if (entry != NULL && strncmp(entry->signal_name, name, strlen(name)) == 0)
+               if (entry != NULL && strncmp(entry->signal_name, signal_name, strlen(signal_name)) == 0)
                        return -1;
        }
 
-       handler = e_dbus_signal_handler_add(edbus_conn, NULL, path,
-                               interface, name, cb, NULL);
+       handler = e_dbus_signal_handler_add(edbus_conn, NULL, OBJECT_PATH,
+                               INTERFACE_NAME, signal_name, cb, NULL);
 
        if (!handler) {
-               _E("fail to add edbus handler");
+               _D("fail to add edbus handler");
                return -1;
        }
 
+       _D("add edbus service: %s", signal_name);
+
        entry = malloc(sizeof(struct edbus_list));
 
        if (!entry) {
-               _E("Malloc failed");
+               _D("Malloc failed");
                return -1;
        }
 
-       entry->signal_name = strndup(name, strlen(name));
+       entry->signal_name = strndup(signal_name, strlen(signal_name));
 
        if (!entry->signal_name) {
-               _E("Malloc failed");
+               _D("Malloc failed");
                free(entry);
                return -1;
        }
@@ -202,7 +88,7 @@ int register_edbus_signal_handler(const char *path, const char *interface,
        entry->handler = handler;
        edbus_handler_list = eina_list_prepend(edbus_handler_list, entry);
        if (!edbus_handler_list) {
-               _E("eina_list_prepend failed");
+               _D("eina_list_prepend failed");
                free(entry->signal_name);
                free(entry);
                return -1;
@@ -210,192 +96,35 @@ int register_edbus_signal_handler(const char *path, const char *interface,
        return 0;
 }
 
-static int append_variant(DBusMessageIter *iter, const char *sig, char *param[])
+void edbus_fini(void)
 {
-       char *ch;
-       int i;
-       int int_type;
-       uint64_t int64_type;
-       DBusMessageIter arr;
-       struct dbus_byte *byte;
-
-       if (!sig || !param)
-               return 0;
-
-       for (ch = (char*)sig, i = 0; *ch != '\0'; ++i, ++ch) {
-               switch (*ch) {
-               case 'i':
-                       int_type = atoi(param[i]);
-                       dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &int_type);
-                       break;
-               case 'u':
-                       int_type = strtoul(param[i], NULL, 10);
-                       dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &int_type);
-                       break;
-               case 't':
-                       int64_type = atoll(param[i]);
-                       dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT64, &int64_type);
-                       break;
-               case 's':
-                       dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &param[i]);
-                       break;
-               case 'a':
-                       ++i, ++ch;
-                       switch (*ch) {
-                       case 'y':
-                               dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &arr);
-                               byte = (struct dbus_byte*)param[i];
-                               dbus_message_iter_append_fixed_array(&arr, DBUS_TYPE_BYTE, &(byte->data), byte->size);
-                               dbus_message_iter_close_container(iter, &arr);
-                               break;
-                       default:
-                               break;
-                       }
-                       break;
-               default:
-                       return -EINVAL;
-               }
-       }
-
-       return 0;
-}
-
-int broadcast_edbus_signal(const char *path, const char *interface,
-               const char *name, const char *sig, char *param[])
-{
-       DBusMessage *msg;
-       DBusMessageIter iter;
-       int r;
-
-       msg = dbus_message_new_signal(path, interface, name);
-       if (!msg) {
-               _E("fail to allocate new %s.%s signal", interface, name);
-               return -EPERM;
-       }
-
-       dbus_message_iter_init_append(msg, &iter);
-       r = append_variant(&iter, sig, param);
-       if (r < 0) {
-               _E("append_variant error(%d)", r);
-               return -EPERM;
-       }
-
-       e_dbus_message_send(edbus_conn, msg, NULL, -1, NULL);
-
-       dbus_message_unref(msg);
-       return 0;
-}
-
-DBusMessage *send_edbus_method_sync(const char *dest, const char *path,
-               const char *interface, const char *method,
-               const char *sig, char *param[])
-{
-       DBusConnection *conn;
-       DBusMessage *msg;
-       DBusMessageIter iter;
-       DBusMessage *reply;
-       DBusError err;
-       int i, r;
-
-       conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-       if (!conn) {
-               _E("dbus_bus_get error");
-               return NULL;
-       }
-
-       msg = dbus_message_new_method_call(dest, path, interface, method);
-       if (!msg) {
-               _E("dbus_message_new_method_call(%s:%s-%s)", path, interface, method);
-               return NULL;
-       }
-
-       dbus_message_iter_init_append(msg, &iter);
-       r = append_variant(&iter, sig, param);
-       if (r < 0) {
-               _E("append_variant error(%d)", r);
-               dbus_message_unref(msg);
-               return NULL;
-       }
-
-       for (i = 0; i < RETRY_MAX; ++i) {
-               dbus_error_init(&err);
-
-               reply = dbus_connection_send_with_reply_and_block(conn, msg, DBUS_REPLY_TIMEOUT, &err);
-               if (reply)
-                       break;
-
-               if (dbus_error_is_set(&err)) {
-                       _E("dbus_connection_send error(%s:%s) : retry..%d", err.name, err.message, i);
-                       dbus_error_free(&err);
-               }
-       }
-
-       dbus_message_unref(msg);
-       return reply;
-}
-
-int register_edbus_method(const char *path, const struct edbus_method *edbus_methods, int size)
-{
-       E_DBus_Interface *iface;
-       int ret;
-       int i;
-
-       iface = get_edbus_interface(path);
-
-       if (!iface) {
-               _E("fail to get edbus interface!");
-               return -ENODEV;
-       }
-
-       for (i = 0; i < size; i++) {
-               ret = e_dbus_interface_method_add(iface,
-                                   edbus_methods[i].member,
-                                   edbus_methods[i].signature,
-                                   edbus_methods[i].reply_signature,
-                                   edbus_methods[i].func);
-               if (!ret) {
-                       _E("fail to add method %s!", edbus_methods[i].member);
-                       return -EINVAL;
-               }
-       }
-
-       return 0;
+       unregister_edbus_signal_handle();
+       e_dbus_connection_close(edbus_conn);
+       e_dbus_shutdown();
 }
 
-void edbus_init(void *data)
+void edbus_init(void)
 {
        int retry = EDBUS_INIT_RETRY_COUNT;
-       int i, ret;
 
        while (--retry) {
                edbus_init_val = e_dbus_init();
                if (edbus_init_val)
                        break;
                if (!retry) {
-                       _E("fail to init edbus");
+                       _D("fail to init edbus");
                        return;
                }
        }
 
        retry = EDBUS_INIT_RETRY_COUNT;
        while (--retry) {
-               conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-               if (conn)
-                       break;
-               if (!retry) {
-                       _E("fail to get dbus");
-                       goto out1;
-               }
-       }
-
-       retry = EDBUS_INIT_RETRY_COUNT;
-       while (--retry) {
-               edbus_conn = e_dbus_connection_setup(conn);
+               edbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
                if (edbus_conn)
                        break;
                if (!retry) {
-                       _E("fail to get edbus");
-                       goto out2;
+                       _D("fail to get edbus");
+                       goto err_dbus_shutdown;
                }
        }
 
@@ -405,33 +134,17 @@ void edbus_init(void *data)
                if (edbus_request_name)
                        break;
                if (!retry) {
-                       _E("fail to request edbus name");
-                       goto out3;
-               }
-       }
-
-       for (i = 0; i < ARRAY_SIZE(edbus_objects); i++) {
-               ret = register_edbus_interface(&edbus_objects[i]);
-               if (ret < 0) {
-                       _E("fail to add obj & interface for %s",
-                                   edbus_objects[i].interface);
-                       return;
+                       _D("fail to request edbus name");
+                       goto err_dbus_close;
                }
-               _D("add new obj for %s", edbus_objects[i].interface);
        }
+       _D("start edbus service");
        return;
 
-out3:
+err_dbus_close:
        e_dbus_connection_close(edbus_conn);
-out2:
-       dbus_connection_set_exit_on_disconnect(conn, FALSE);
-out1:
+err_dbus_shutdown:
        e_dbus_shutdown();
+       return;
 }
 
-void edbus_exit(void *data)
-{
-       unregister_edbus_signal_handle();
-       e_dbus_connection_close(edbus_conn);
-       e_dbus_shutdown();
-}
index 1e6c0db..ea40f0f 100644 (file)
@@ -1,20 +1,21 @@
 /*
- * deviced
+ *  deviced
  *
- * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2010 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Licensed under the Apache License, Version 2.0 (the License);
+ * 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
+ * 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 __EDBUS_HANDLE_H__
 #define OBJECT_PATH            "/Org/Tizen/System/DeviceD"
 #define INTERFACE_NAME         BUS_NAME
 
-struct dbus_byte {
-       char *data;
-       int size;
-};
-
-struct edbus_method {
-       const char *member;
-       const char *signature;
-       const char *reply_signature;
-       E_DBus_Method_Cb func;
-};
-
-int register_edbus_method(const char *path, const struct edbus_method *edbus_methods, int size);
-int register_edbus_signal_handler(const char *path, const char *interface,
-               const char *name, E_DBus_Signal_Cb cb);
-E_DBus_Interface *get_edbus_interface(const char *path);
-pid_t get_edbus_sender_pid(DBusMessage *msg);
-int broadcast_edbus_signal(const char *path, const char *interface,
-               const char *name, const char *sig, char *param[]);
-DBusMessage *send_edbus_method_sync(const char *dest, const char *path,
-               const char *interface, const char *method,
-               const char *sig, char *param[]);
-
-void edbus_init(void *data);
-void edbus_exit(void *data);
+void edbus_init(void);
+void edbus_fini(void);
+int register_edbus_signal_handler(char *signal_name, E_DBus_Signal_Cb cb);
 
-#endif /* __EDBUS_HANDLE_H__ */
+#endif /* __SS_EDBUS_HANDLE_H__ */
index ae84823..cd8abe4 100644 (file)
@@ -19,7 +19,6 @@
 #include <fcntl.h>
 #include <heynoti.h>
 #include <sys/reboot.h>
-
 #include "log.h"
 #include "core.h"
 #include "sig-handler.h"
@@ -101,7 +100,7 @@ static int system_main(int argc, char **argv)
                fini(&ad);
                return 0;
        }
-
+       edbus_init();
        system_server_init(&ad);
        signal(SIGTERM, sig_quit);
 
@@ -112,6 +111,7 @@ static int system_main(int argc, char **argv)
        ecore_main_loop_begin();
 
        fini(&ad);
+       edbus_fini();
        ecore_shutdown();
 
        return 0;
index cb8bf96..1d8a92e 100644 (file)
@@ -18,7 +18,9 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <vconf.h>
 #include "core.h"
+#include "edbus-handler.h"
 
 #define _E(format, args...) do { \
        char buf[255];\
@@ -32,6 +34,8 @@
        write(1, buf, strlen(buf));\
 } while (0);
 
+#define SIGNAL_NAME_POWEROFF_POPUP     "poweroffpopup"
+
 static struct sigaction sig_child_old_act;
 static struct sigaction sig_pipe_old_act;
 
@@ -56,7 +60,38 @@ static void sig_pipe_handler(int signo, siginfo_t *info, void *data)
 
 }
 
-void ss_signal_init()
+static void poweroff_popup_edbus_signal_handler(void *data, DBusMessage *msg)
+{
+       DBusError err;
+       char *str;
+       int val = 0;
+
+       if (dbus_message_is_signal(msg, INTERFACE_NAME, SIGNAL_NAME_POWEROFF_POPUP) == 0) {
+               _D("there is no power off popup signal");
+               return;
+       }
+
+       dbus_error_init(&err);
+
+       if (dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID) == 0) {
+               _D("there is no message");
+               return;
+       }
+
+       if (strncmp(str, PREDEF_PWROFF_POPUP, strlen(PREDEF_PWROFF_POPUP)) == 0)
+               val = VCONFKEY_SYSMAN_POWER_OFF_POPUP;
+       else if (strncmp(str, PREDEF_POWEROFF, strlen(PREDEF_POWEROFF)) == 0)
+               val = VCONFKEY_SYSMAN_POWER_OFF_DIRECT;
+       else if (strncmp(str, PREDEF_POWEROFF, strlen(PREDEF_REBOOT)) == 0)
+               val = VCONFKEY_SYSMAN_POWER_OFF_RESTART;
+       if (val == 0) {
+               _D("not supported message : %s", str);
+               return;
+       }
+       vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, val);
+}
+
+void ss_signal_init(void)
 {
        struct sigaction sig_act;
 
@@ -71,4 +106,5 @@ void ss_signal_init()
        sig_act.sa_flags = SA_SIGINFO;
        sigemptyset(&sig_act.sa_mask);
        sigaction(SIGPIPE, &sig_act, &sig_pipe_old_act);
+       register_edbus_signal_handler(SIGNAL_NAME_POWEROFF_POPUP, (void *)poweroff_popup_edbus_signal_handler);
 }
index e6e3699..778e314 100755 (executable)
@@ -45,7 +45,6 @@ static int __sysnoti_stop(int fd);
 
 static void print_sysnoti_msg(const char *title, struct sysnoti *msg)
 {
-       int i;
        char exe_name[PATH_MAX];
 
        if (sysman_get_cmdline_name(msg->pid, exe_name, PATH_MAX) < 0)