Seperate file for each devices 64/22664/1
authorjy910.yun <jy910.yun@samsung.com>
Mon, 2 Sep 2013 03:42:13 +0000 (12:42 +0900)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Mon, 9 Jun 2014 12:04:57 +0000 (14:04 +0200)
if some device does not support in our system anymore,
we can just remove one file for device we want to delete.
do not combine between each other device code

Signed-off-by: jy910.yun <jy910.yun@samsung.com>
Signed-off-by: Maciej Wereski <m.wereski@partner.samsung.com>
Change-Id: I8e70f1cf6a4b1115704c718ab1f919390bafd075

28 files changed:
src/battery/lowbat-handler.c
src/bs/bs.c
src/control/control.c
src/core/core.c
src/core/device-change-handler.c
src/core/device-notifier.c
src/core/devices.c
src/core/devices.h
src/core/edbus-handler.c
src/core/edbus-handler.h
src/core/main.c
src/core/noti.c
src/core/predefine.c
src/core/sig-handler.c
src/core/sysnoti.c
src/cpu/cpu-handler.c
src/display/core.c
src/display/core.h
src/haptic/haptic.c
src/led/led.c
src/mmc/mmc-handler.c
src/mmc/mmc-handler.h
src/power/power-handler.c
src/proc/lowmem-handler.c
src/proc/pmon-handler.c
src/proc/proc-handler.c
src/ta/ta-handler.c
src/time/time-handler.c

index ef66019..c14859c 100644 (file)
@@ -32,6 +32,7 @@
 #include "core/data.h"
 #include "core/devices.h"
 #include "core/device-handler.h"
+#include "core/common.h"
 #include "device-node.h"
 #include "display/setting.h"
 
@@ -498,6 +499,10 @@ static void lowbat_init(void *data)
        vconf_notify_key_changed(VCONFKEY_PM_STATE, (void *)wakeup_cb, NULL);
 }
 
-const struct device_ops lowbat_device_ops = {
-       .init = lowbat_init,
+static const struct device_ops lowbat_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "lowbat",
+       .init     = lowbat_init,
 };
+
+DEVICE_OPS_REGISTER(&lowbat_device_ops)
index 3eafbfa..45c8605 100644 (file)
@@ -447,6 +447,10 @@ static void bs_init(void *data)
        }
 }
 
-const struct device_ops bs_device_ops = {
-       .init = bs_init,
+static const struct device_ops bs_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "bs",
+       .init     = bs_init,
 };
+
+DEVICE_OPS_REGISTER(&bs_device_ops)
index 1fe97d7..3b68e13 100644 (file)
@@ -26,6 +26,7 @@
 #include "core/log.h"
 #include "core/common.h"
 #include "core/devices.h"
+#include "mmc/mmc-handler.h"
 
 static const struct control_device {
        const int id;
@@ -78,7 +79,10 @@ static void control_init(void *data)
        action_entry_add_internal(CONTROL_HANDLER_NAME, control_handler, NULL, NULL);
 }
 
-const struct device_ops control_device_ops = {
-       .init = control_init,
+static const struct device_ops control_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "control",
+       .init     = control_init,
 };
 
+DEVICE_OPS_REGISTER(&control_device_ops)
index d62c533..1e685de 100644 (file)
@@ -23,6 +23,7 @@
 #include "predefine.h"
 #include "core.h"
 #include "devices.h"
+#include "common.h"
 
 enum ss_core_cmd_type {
        SS_CORE_ACT_RUN,
@@ -170,6 +171,10 @@ static void core_init(void *data)
                _E("fail pipe control fd init");
 }
 
-const struct device_ops core_device_ops = {
-       .init = core_init,
+static const struct device_ops core_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "core",
+       .init     = core_init,
 };
+
+DEVICE_OPS_REGISTER(&core_device_ops)
index be2b597..12ce566 100644 (file)
@@ -998,7 +998,11 @@ static void device_change_exit(void *data)
 
 }
 
-const struct device_ops change_device_ops = {
-       .init = device_change_init,
-       .exit = device_change_exit,
+static const struct device_ops change_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "device change",
+       .init     = device_change_init,
+       .exit     = device_change_exit,
 };
+
+DEVICE_OPS_REGISTER(&change_device_ops)
index b6c8a49..677649b 100644 (file)
@@ -23,6 +23,7 @@
 #include "devices.h"
 #include "device-notifier.h"
 #include "list.h"
+#include "common.h"
 
 struct device_notifier {
        enum device_notifier_type status;
@@ -116,7 +117,10 @@ static void device_notifier_exit(void *data)
        _I("all deleted!");
 }
 
-const struct device_ops notifier_device_ops = {
+static const struct device_ops notifier_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name = "notifier",
        .exit = device_notifier_exit,
 };
 
+DEVICE_OPS_REGISTER(&notifier_device_ops)
index e6711ee..9cf130a 100644 (file)
 #include <stdio.h>
 
 #include "log.h"
-#include "devices.h"
+#include "list.h"
 #include "common.h"
+#include "devices.h"
+
+static dd_list *dev_head;
+
+void add_device(const struct device_ops *dev)
+{
+       if (dev->priority == DEVICE_PRIORITY_HIGH)
+               DD_LIST_PREPEND(dev_head, dev);
+       else
+               DD_LIST_APPEND(dev_head, dev);
+}
 
-static const struct device_ops *devices[] = {
-       /* The below devices have init dependency with other module */
-       &edbus_device_ops,
-       &display_device_ops,
-       /* The below devices don't have any init dependency */
-       &sysnoti_device_ops,
-       &noti_device_ops,
-       &control_device_ops,
-       &core_device_ops,
-       &signal_device_ops,
-       &predefine_device_ops,
-       &lowmem_device_ops,
-       &lowbat_device_ops,
-       &change_device_ops,
-       &power_device_ops,
-       &bs_device_ops,
-       &process_device_ops,
-       &time_device_ops,
-       &cpu_device_ops,
-       &usb_device_ops,
-       &ta_device_ops,
-       &pmon_device_ops,
-       &mmc_device_ops,
-       &haptic_device_ops,
-       &led_device_ops,
-       &vibrator_device_ops,
-       &notifier_device_ops,
-};
+void remove_device(const struct device_ops *dev)
+{
+       DD_LIST_REMOVE(dev_head, dev);
+}
 
 void devices_init(void *data)
 {
-       int i;
-       int size;
+       dd_list *elem;
        const struct device_ops *dev;
 
-       size = ARRAY_SIZE(devices);
-       for(i = 0; i < size; ++i) {
-               dev = devices[i];
+       DD_LIST_FOREACH(dev_head, elem, dev) {
+               _D("[%s] initialize", dev->name);
                if (dev->init)
                        dev->init(data);
        }
@@ -68,13 +53,11 @@ void devices_init(void *data)
 
 void devices_exit(void *data)
 {
-       int i;
-       int size;
+       dd_list *elem;
        const struct device_ops *dev;
 
-       size = ARRAY_SIZE(devices);
-       for(i = 0; i < size; ++i) {
-               dev = devices[i];
+       DD_LIST_FOREACH(dev_head, elem, dev) {
+               _D("[%s] deinitialize", dev->name);
                if (dev->exit)
                        dev->exit(data);
        }
index 32cc7be..cc120f1 100644 (file)
 #define __DEVICES_H__
 
 #include <errno.h>
+#include "common.h"
+
+enum device_priority {
+       DEVICE_PRIORITY_NORMAL = 0,
+       DEVICE_PRIORITY_HIGH,
+};
 
 struct device_ops {
+       enum device_priority priority;
+       char *name;
        void (*init) (void *data);
        void (*exit) (void *data);
        int (*start) (void);
@@ -64,29 +72,17 @@ static inline int device_get_status(const struct device_ops *dev)
        return -EINVAL;
 }
 
-extern const struct device_ops edbus_device_ops;
-extern const struct device_ops display_device_ops;
-extern const struct device_ops sysnoti_device_ops;
-extern const struct device_ops noti_device_ops;
-extern const struct device_ops control_device_ops;
-extern const struct device_ops core_device_ops;
-extern const struct device_ops signal_device_ops;
-extern const struct device_ops predefine_device_ops;
-extern const struct device_ops lowmem_device_ops;
-extern const struct device_ops lowbat_device_ops;
-extern const struct device_ops change_device_ops;
-extern const struct device_ops power_device_ops;
-extern const struct device_ops bs_device_ops;
-extern const struct device_ops process_device_ops;
-extern const struct device_ops time_device_ops;
-extern const struct device_ops cpu_device_ops;
-extern const struct device_ops usb_device_ops;
-extern const struct device_ops ta_device_ops;
-extern const struct device_ops pmon_device_ops;
-extern const struct device_ops mmc_device_ops;
-extern const struct device_ops haptic_device_ops;
-extern const struct device_ops led_device_ops;
-extern const struct device_ops vibrator_device_ops;
-extern const struct device_ops notifier_device_ops;
+#define DEVICE_OPS_REGISTER(dev)       \
+static void __CONSTRUCTOR__ module_init(void)  \
+{      \
+       add_device(dev);        \
+}      \
+static void __DESTRUCTOR__ module_exit(void)   \
+{      \
+       remove_device(dev);     \
+}
+
+void add_device(const struct device_ops *dev);
+void remove_device(const struct device_ops *dev);
 
 #endif
index 8a937a3..657cfb0 100644 (file)
@@ -21,7 +21,6 @@
 #include "core/data.h"
 #include "core/edbus-handler.h"
 #include "core/common.h"
-#include "core/devices.h"
 #include "core/device-notifier.h"
 #include "core/list.h"
 
@@ -367,7 +366,7 @@ static void unregister_edbus_watch_all(void)
        }
 }
 
-static void edbus_init(void *data)
+void edbus_init(void *data)
 {
        int retry = EDBUS_INIT_RETRY_COUNT;
        int i, r;
@@ -421,15 +420,10 @@ err_dbus_shutdown:
        return;
 }
 
-static void edbus_exit(void *data)
+void edbus_exit(void *data)
 {
        unregister_edbus_signal_handle();
        unregister_edbus_watch_all();
        e_dbus_connection_close(edbus_conn);
        e_dbus_shutdown();
 }
-
-const struct device_ops edbus_device_ops = {
-       .init = edbus_init,
-       .exit = edbus_exit,
-};
index 533ce25..2266c46 100644 (file)
@@ -81,4 +81,7 @@ pid_t get_edbus_sender_pid(DBusMessage *msg);
 int broadcast_edbus_signal(const char *path, const char *interface,
                const char *name, int type, void *value);
 
+void edbus_init(void *data);
+void edbus_exit(void *data);
+
 #endif /* __SS_EDBUS_HANDLE_H__ */
index 307f987..5a9022f 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "log.h"
 #include "data.h"
+#include "edbus-handler.h"
 #include "devices.h"
 
 #define SS_PIDFILE_PATH                "/var/run/.system_server.pid"
@@ -60,6 +61,7 @@ static int system_main(int argc, char **argv)
        struct ss_main_data ad;
 
        init_ad(&ad);
+       edbus_init(&ad);
        devices_init(&ad);
        signal(SIGTERM, sig_quit);
        signal(SIGUSR1, sig_usr1);
@@ -67,6 +69,7 @@ static int system_main(int argc, char **argv)
        ecore_main_loop_begin();
 
        devices_exit(&ad);
+       edbus_exit(&ad);
        ecore_shutdown();
        return 0;
 }
index dca7679..6845a18 100644 (file)
@@ -21,6 +21,7 @@
 #include "log.h"
 #include "data.h"
 #include "devices.h"
+#include "common.h"
 
 static int noti_fd;
 
@@ -75,7 +76,11 @@ static void noti_exit(void *data)
        heynoti_close(noti_fd);
 }
 
-const struct device_ops noti_device_ops = {
-       .init = noti_init,
-       .exit = noti_exit,
+static const struct device_ops noti_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "noti",
+       .init     = noti_init,
+       .exit     = noti_exit,
 };
+
+DEVICE_OPS_REGISTER(&noti_device_ops)
index 8778a05..b25f23f 100644 (file)
@@ -189,6 +189,10 @@ static void predefine_init(void *data)
        action_entry_load_from_sodir();
 }
 
-const struct device_ops predefine_device_ops = {
-       .init = predefine_init,
+static const struct device_ops predefine_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "predefine",
+       .init     = predefine_init,
 };
+
+DEVICE_OPS_REGISTER(&predefine_device_ops)
index 12d299d..34f78d5 100644 (file)
@@ -26,6 +26,7 @@
 #include "edbus-handler.h"
 #include "display/poll.h"
 #include "devices.h"
+#include "common.h"
 
 static struct sigaction sig_child_old_act;
 static struct sigaction sig_pipe_old_act;
@@ -68,6 +69,10 @@ static void signal_init(void *data)
        sigaction(SIGPIPE, &sig_act, &sig_pipe_old_act);
 }
 
-const struct device_ops signal_device_ops = {
-       .init = signal_init,
+static const struct device_ops signal_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "signal",
+       .init     = signal_init,
 };
+
+DEVICE_OPS_REGISTER(&signal_device_ops)
index 3e855c1..1fc56ca 100644 (file)
@@ -328,6 +328,10 @@ static void sysnoti_init(void *data)
        ad->sysnoti_fd = __sysnoti_start();
 }
 
-const struct device_ops sysnoti_device_ops = {
+static const struct device_ops sysnoti_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "sysnoti",
        .init = sysnoti_init,
 };
+
+DEVICE_OPS_REGISTER(&sysnoti_device_ops)
index 9a2a54f..379ca00 100644 (file)
@@ -429,6 +429,10 @@ static void cpu_init(void *data)
        vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU, (void *)power_saving_cpu_cb, NULL);
 }
 
-const struct device_ops cpu_device_ops = {
-       .init = cpu_init,
+static const struct device_ops cpu_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "cpu",
+       .init     = cpu_init,
 };
+
+DEVICE_OPS_REGISTER(&cpu_device_ops)
index 39760a3..7883472 100644 (file)
@@ -50,6 +50,7 @@
 #include "core/device-notifier.h"
 #include "core/udev.h"
 #include "core/list.h"
+#include "core/common.h"
 
 #define USB_CON_PIDFILE                        "/var/run/.system_server.pid"
 #define PM_STATE_LOG_FILE              "/var/log/pm_state.log"
@@ -1687,11 +1688,15 @@ static int display_status(void)
 }
 
 const struct device_ops display_device_ops = {
+       .priority = DEVICE_PRIORITY_HIGH,
+       .name     = "display",
        .init = display_init,
        .exit = display_exit,
        .status = display_status,
 };
 
+DEVICE_OPS_REGISTER(&display_device_ops)
+
 /**
  * @}
  */
index cf78365..efd24ea 100644 (file)
@@ -107,6 +107,8 @@ int (*pm_init_extention) (void *data);              /**< extention init function */
 void (*pm_exit_extention) (void);              /**< extention exit function */
 int check_processes(enum state_t prohibit_state);
 
+extern const struct device_ops display_device_ops;
+
 /**
  * @}
  */
index bdaebf6..4925e75 100644 (file)
@@ -508,7 +508,11 @@ static void haptic_exit(void *data)
        release_module();
 }
 
-const struct device_ops haptic_device_ops = {
-       .init = haptic_init,
-       .exit = haptic_exit,
+static const struct device_ops haptic_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "haptic",
+       .init     = haptic_init,
+       .exit     = haptic_exit,
 };
+
+DEVICE_OPS_REGISTER(&haptic_device_ops)
index e627561..efbea59 100644 (file)
@@ -69,6 +69,10 @@ static void led_init(void *data)
        action_entry_add_internal(PREDEF_LED, predefine_action, NULL, NULL);
 }
 
-const struct device_ops led_device_ops = {
+static const struct device_ops led_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "led",
        .init = led_init,
 };
+
+DEVICE_OPS_REGISTER(&led_device_ops)
index f8eb472..03c4162 100644 (file)
@@ -832,7 +832,11 @@ static int mmc_stop(void)
 }
 
 const struct device_ops mmc_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "mmc",
        .init = mmc_init,
        .start = mmc_start,
        .stop = mmc_stop,
 };
+
+DEVICE_OPS_REGISTER(&mmc_device_ops)
index 960df73..82804a0 100644 (file)
@@ -78,4 +78,6 @@ struct mmc_filesystem_info {
 int mount_fs(char *path, const char *fs_name, const char *mount_data);
 int register_mmc_handler(const char *name, struct mmc_filesystem_ops filesystem_type);
 
+extern const struct device_ops mmc_device_ops;
+
 #endif /* __MMC_HANDLER_H__ */
index 6f43137..7485b58 100755 (executable)
@@ -50,6 +50,7 @@
 #include "proc/proc-handler.h"
 #include "display/poll.h"
 #include "display/setting.h"
+#include "display/core.h"
 
 #define SIGNAL_NAME_POWEROFF_POPUP     "poweroffpopup"
 
@@ -572,6 +573,10 @@ static void power_init(void *data)
                    (void *)lcd_control_edbus_signal_handler);
 }
 
-const struct device_ops power_device_ops = {
+static const struct device_ops power_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "power",
        .init = power_init,
 };
+
+DEVICE_OPS_REGISTER(&power_device_ops)
index a93c68d..e070e6c 100644 (file)
@@ -546,6 +546,10 @@ static void lowmem_init(void *data)
        }
 }
 
-const struct device_ops lowmem_device_ops = {
-       .init = lowmem_init,
+static const struct device_ops lowmem_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "lowmem",
+       .init     = lowmem_init,
 };
+
+DEVICE_OPS_REGISTER(&lowmem_device_ops)
index e3324d9..d10d82b 100644 (file)
@@ -266,6 +266,10 @@ static void pmon_init(void *data)
        }
 }
 
-const struct device_ops pmon_device_ops = {
-       .init = pmon_init,
+static const struct device_ops pmon_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "pmon",
+       .init     = pmon_init,
 };
+
+DEVICE_OPS_REGISTER(&pmon_device_ops)
index f0a4c1b..bb45b35 100644 (file)
@@ -278,6 +278,10 @@ static void process_init(void *data)
        action_entry_add_internal(PROCESS_GROUP_SET, set_process_group_action, NULL, NULL);
 }
 
-const struct device_ops process_device_ops = {
+static const struct device_ops process_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "process",
        .init = process_init,
 };
+
+DEVICE_OPS_REGISTER(&process_device_ops)
index 927dafb..4e779da 100644 (file)
@@ -24,6 +24,7 @@
 #include "core/data.h"
 #include "core/devices.h"
 #include "display/poll.h"
+#include "core/common.h"
 
 #define RETRY  3
 
@@ -54,6 +55,10 @@ static void ta_init(void *data)
                vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, val);
 }
 
-const struct device_ops ta_device_ops = {
-       .init = ta_init,
+static const struct device_ops ta_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "ta",
+       .init     = ta_init,
 };
+
+DEVICE_OPS_REGISTER(&ta_device_ops)
index c5ed441..5b0acfd 100644 (file)
@@ -276,6 +276,10 @@ static void time_init(void *data)
        }
 }
 
-const struct device_ops time_device_ops = {
-       .init = time_init,
+static const struct device_ops time_device_ops = {
+       .priority = DEVICE_PRIORITY_NORMAL,
+       .name     = "time",
+       .init     = time_init,
 };
+
+DEVICE_OPS_REGISTER(&time_device_ops)