Apply some changes to support multi leds 81/189481/4
authorlokilee73 <changjoo.lee@samsung.com>
Tue, 18 Sep 2018 06:15:44 +0000 (15:15 +0900)
committerlokilee73 <changjoo.lee@samsung.com>
Wed, 19 Sep 2018 06:44:27 +0000 (15:44 +0900)
1. Change the name of device_multi_led_play_custom() to device_multi_led_control()
2. Add device_multi_led_get_number() in device_multi_led_control()

Change-Id: I5ac5b5e01fc583080c17ff8733dd4dac818d4f5a
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
src/led.c

index bc4596f..f3b4f5b 100755 (executable)
--- a/src/led.c
+++ b/src/led.c
@@ -30,8 +30,7 @@
 #define METHOD_SET_BRIGHTNESS          "SetBrightness"
 #define METHOD_PLAY_CUSTOM             "playcustom"
 #define METHOD_GET_LED_NUMBER          "GetNumOfLeds"
-#define METHOD_MULTI_PLAY_CUSTOM       "multi_playcustom"
-#define METHOD_MULTI_STOP_CUSTOM       "multi_stopcustom"
+#define METHOD_MULTI_LED_CONTROL       "multi_led_control"
 #define METHOD_STOP_CUSTOM             "stopcustom"
 
 #define FRONT_LED_FEATURE              "tizen.org/feature/led"
@@ -39,7 +38,7 @@
 
 static bool support_front_led;
 static bool support_camera_led;
-static int number_of_devices;
+static int number_of_devices = -1;
 
 static void __CONSTRUCTOR__ init(void)
 {
@@ -188,22 +187,25 @@ int device_multi_led_get_number(int *num_of_leds)
        if (!num_of_leds)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
-       ret = dbus_method_sync(DEVICED_BUS_NAME,
-                       DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
-                       METHOD_GET_LED_NUMBER, NULL, NULL);
-       if (ret < 0)
-               return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
+       if (number_of_devices < 0) {
+               ret = dbus_method_sync(DEVICED_BUS_NAME,
+                               DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
+                               METHOD_GET_LED_NUMBER, NULL, NULL);
+               if (ret < 0)
+                       return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
+               number_of_devices = ret;
+       }
+
+       *num_of_leds = number_of_devices;
 
-       *num_of_leds = ret;
-       number_of_devices = ret;
        return DEVICE_ERROR_NONE;
 }
 
-int device_multi_led_play_custom(unsigned int color[])
+int device_multi_led_control(unsigned int color[])
 {
        GVariantBuilder *builder = NULL;
        GVariant *var = NULL;
-       int i;
+       int i, ret;
 
        if (!support_front_led)
                return DEVICE_ERROR_NOT_SUPPORTED;
@@ -211,6 +213,12 @@ int device_multi_led_play_custom(unsigned int color[])
        if (color == NULL)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
+       if (number_of_devices < 0) {
+               ret = device_multi_led_get_number(&number_of_devices);
+               if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error
+                       return ret;
+       }
+
        builder = g_variant_builder_new(G_VARIANT_TYPE("au"));
        for (i = 0; i < number_of_devices; i++)
                g_variant_builder_add(builder, "u", color[i]);
@@ -219,6 +227,6 @@ int device_multi_led_play_custom(unsigned int color[])
        g_variant_builder_unref(builder);
 
        return dbus_method_sync_var(DEVICED_BUS_NAME, DEVICED_PATH_LED,
-                               DEVICED_INTERFACE_LED, METHOD_MULTI_PLAY_CUSTOM, var);
+                               DEVICED_INTERFACE_LED, METHOD_MULTI_LED_CONTROL, var);
 }
 //LCOV_EXCL_STOP