pmqos: Move registration of booting-done callback to probe 51/117151/5
authorWook Song <wook16.song@samsung.com>
Fri, 3 Mar 2017 01:15:52 +0000 (10:15 +0900)
committerWook Song <wook16.song@samsung.com>
Fri, 10 Mar 2017 07:26:43 +0000 (16:26 +0900)
This patch moves the registration of a callback for the booting-done
event from the pmqos_init() function to the pmqos_probe() function,
which is newly added. This booting-done callback is renamed to
pmqos_init_done and slightly modified.

Change-Id: If8b1de698ab03257b5fd67081cad1101c06e47d7
Signed-off-by: Wook Song <wook16.song@samsung.com>
Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com>
src/pmqos/pmqos.c

index baaf748..1ade574 100644 (file)
@@ -418,17 +418,21 @@ static const struct edbus_method edbus_methods[] = {
        { "UltraPowerSaving",     "i",    "i", dbus_pmqos_handler },
 };
 
-static int booting_done(void *data, void *user_data)
+static int pmqos_init_done(void *data, void *user_data)
 {
-       static int done;
        struct edbus_method *methods = NULL;
+       int booting_done;
        int ret, size;
 
-       if (data == NULL)
-               goto out;
-       done = (int)data;
-       if (!done)
-               goto out;
+       /*
+        * As a callback function for the booting-done event, it is notified
+        * with the result of the booting_finished() function by using the
+        * first argument, void *data. When it is successfully booted up, 1 is
+        * passed with the first argument.
+        */
+       booting_done = (int)data;
+       if (!booting_done)
+               return -EINVAL;
 
        /* register edbus methods */
        ret = register_edbus_method(PASS_PATH_PMQOS, edbus_methods,
@@ -449,13 +453,13 @@ static int booting_done(void *data, void *user_data)
                free(methods);
        }
 
-out:
-       return done;
+       return ret;
 }
 
 static void pmqos_init(void *data)
 {
-       register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done, NULL);
+       /* This is the case of daemon creation: DO NOTHING */
+       return;
 }
 
 static void pmqos_free(void)
@@ -480,14 +484,40 @@ static void pmqos_free(void)
 
 static void pmqos_exit(void *data)
 {
-       unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
+       unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, pmqos_init_done);
        pmqos_free();
 }
 
+/*
+ * pmqos_probe - Probe PMQOS
+ *
+ * @data: the data passed from pass_main(), currently NULL
+ */
+static int pmqos_probe(void *data)
+{
+       int ret = 0;
+
+       /*
+        * Register a notifier for the booting-done event. The actual
+        * initialization of the daemon is performed by this notifier after
+        * booting is completely done.
+        */
+       ret = register_notifier(DEVICE_NOTIFIER_BOOTING_DONE,
+                       pmqos_init_done, NULL);
+       if (ret < 0) {
+               _E("cannot register a callback function \
+                               for the booting-done event (%d)\n", ret);
+               return ret;
+       }
+
+       return ret;
+}
+
 static const struct device_ops pmqos_device_ops = {
-       .name     = "pmqos",
-       .init     = pmqos_init,
-       .exit     = pmqos_exit,
+       .name   = "pmqos",
+       .probe  = pmqos_probe,
+       .init   = pmqos_init,
+       .exit   = pmqos_exit,
 };
 
 DEVICE_OPS_REGISTER(&pmqos_device_ops)