Add new APIs that control multiple LEDs 48/169048/18
authorlokilee73 <changjoo.lee@samsung.com>
Fri, 2 Feb 2018 05:06:31 +0000 (14:06 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Tue, 6 Feb 2018 01:11:18 +0000 (10:11 +0900)
Change-Id: I6c1e0bc0b54a910ddb7ec371a24765552b07d6ff
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
Signed-off-by: Hyotaek Shim <hyotaek.shim@samsung.com>
include/battery.h [changed mode: 0755->0644]
include/device.h [changed mode: 0755->0644]
include/display.h [changed mode: 0755->0644]
include/led-internal.h [new file with mode: 0644]
include/power.h [changed mode: 0755->0644]
src/common.c
src/dbus.c
src/dbus.h
src/led.c [changed mode: 0644->0755]

old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index d2e31da..38d5326
@@ -11,7 +11,7 @@
  * 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. 
+ * limitations under the License.
  */
 
 
@@ -70,14 +70,14 @@ int device_get_display_numbers(int* device_number);
 int device_get_brightness(int display_index, int *brightness);
 
 /**
- * @brief Sets the display brightness value. 
+ * @brief Sets the display brightness value.
  *
  * @param[in] display_index    The index of the display, it be greater than or equal to 0 and less than \n
  *                          the number of displays returned by device_get_display_numbers().\n
  *                          The index zero is always assigned to the main display.
  * @param[in] brightness       The new brightness value to set \n
  *                                                     The maximum value can be represented by device_get_max_brightness()
- * 
+ *
  * @return 0 on success, otherwise a negative error value.
  * @retval #DEVICE_ERROR_NONE                          Successful
  * @retval #DEVICE_ERROR_INVALID_PARAMETER  Invalid parameter
@@ -92,7 +92,7 @@ int device_get_brightness(int display_index, int *brightness);
 int device_set_brightness(int display_index, int brightness);
 
 /**
- * @brief Gets the maximum brightness value that can be set. 
+ * @brief Gets the maximum brightness value that can be set.
  *
  * @param[in] display_index    The index of the display, it be greater than or equal to 0 and less than \n
  *                          the number of displays returned by device_get_display_numbers().\n
old mode 100755 (executable)
new mode 100644 (file)
diff --git a/include/led-internal.h b/include/led-internal.h
new file mode 100644 (file)
index 0000000..7d2e016
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2014 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 __TIZEN_SYSTEM_LED_INTERNAL_H__
+#define __TIZEN_SYSTEM_LED_INTERNAL_H__
+
+
+#include "device-error.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @brief Gets the total number of LEDs in the device.
+ * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/led
+ * @remarks This API is related to the following feature: %http://tizen.org/feature/led
+ * @param[out] Number of LEDs
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #DEVICE_ERROR_NONE Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
+ * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device
+ */
+int device_multi_led_get_number(int *num_of_leds);
+
+/**
+ * @brief Plays multiple LEDs at the same time.
+ * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/led
+ * @remarks This API is related to the following feature: %http://tizen.org/feature/led
+ * @remarks The array size must be the same as the number of LEDs, which is obtained by device_multi_led_get_number().
+ * @param[in] led[] Indicate LEDs to be controlled
+ * @param[in] color[] The Color values \n
+ *                    The first byte means opaque, and the other 3 bytes mean RGB values
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #DEVICE_ERROR_NONE Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
+ * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device
+ */
+int device_multi_led_play_custom(bool led[], unsigned int color[]);
+
+/**
+ * @brief Stops multiple LEDs at the same time.
+ * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/led
+ * @remarks This API is related to the following feature: %http://tizen.org/feature/led
+ * @remarks The array size must be the same as the number of LEDs, which is obtained by device_multi_led_get_number().
+ * @param[in] led[] Indicate LEDs to be controlled
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #DEVICE_ERROR_NONE Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
+ * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device
+ */
+int device_multi_led_stop_custom(bool led[]);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif  // __TIZEN_SYSTEM_LED_INTERNAL_H__
old mode 100755 (executable)
new mode 100644 (file)
index 63481dc..c6fd0a1 100644 (file)
@@ -160,4 +160,4 @@ tizen_profile_t _get_tizen_profile()
        free(profileName);
 
        return profile;
-}
\ No newline at end of file
+}
index e49e71b..4f84fcc 100644 (file)
@@ -294,6 +294,63 @@ int dbus_method_sync(const char *dest, const char *path,
        return result;
 }
 
+int dbus_method_sync_var(const char *dest, const char *path,
+               const char *interface, const char *method, GVariant *var)
+{
+       GDBusProxy *proxy;
+       GError *err = NULL;
+       GVariant *output;
+       int result;
+
+#if !GLIB_CHECK_VERSION(2, 35, 0)
+       g_type_init();
+#endif
+
+       pthread_mutex_lock(&dmutex);
+       proxy = get_proxy_from_proxy_pool(dest, path, interface, &err);
+       if (!proxy) {
+//LCOV_EXCL_START System Error
+               pthread_mutex_unlock(&dmutex);
+               _E("fail to get proxy from proxy pool : %s-%s (%d-%s)",
+                               interface, method, err->code, err->message);
+               result = g_dbus_error_to_errno(err->code);
+               g_clear_error(&err);
+               return result;
+//LCOV_EXCL_STOP
+       }
+
+       output = g_dbus_proxy_call_sync(proxy,
+                       method,                       /* method name */
+                       var, /* parameters */
+                       G_DBUS_CALL_FLAGS_NONE,
+                       DBUS_REPLY_TIMEOUT,           /* timeout */
+                       NULL,                         /* GCancellable */
+                       &err);
+       pthread_mutex_unlock(&dmutex);
+
+       if (!output) {
+//LCOV_EXCL_START System Error
+               if (!err) {
+                       _E("g_dbus_proxy_call_sync error : %s-%s",
+                                       interface, method);
+                       return -EPERM;
+               }
+               _E("g_dbus_proxy_call_sync error : %s-%s (%d-%s)",
+                               interface, method, err->code, err->message);
+               result = g_dbus_error_to_errno(err->code);
+               g_clear_error(&err);
+               return result;
+//LCOV_EXCL_STOP
+       }
+
+       /* get output value */
+       g_variant_get(output, "(i)", &result);
+
+       g_variant_unref(output);
+
+       return result;
+}
+
 int dbus_method_sync_with_reply(const char *dest,
                const char *path, const char *interface,
                const char *method, const char *sig,
index 11d13ce..c502284 100644 (file)
@@ -70,6 +70,8 @@ int dbus_method_sync_with_reply(const char *dest,
                const char *path, const char *interface,
                const char *method, const char *sig,
                char *param[], GVariant **info);
+int dbus_method_sync_var(const char *dest, const char *path,
+       const char *iface, const char *method, GVariant *var);
 
 /**
  * If result is NULL, err is set.
old mode 100644 (file)
new mode 100755 (executable)
index bb388e7..43d8e07
--- a/src/led.c
+++ b/src/led.c
 #include <system_info.h>
 
 #include "led.h"
+#include "led-internal.h"
 #include "common.h"
 #include "dbus.h"
 
 #define METHOD_GET_MAX_BRIGHTNESS      "GetMaxBrightness"
 #define METHOD_GET_BRIGHTNESS          "GetBrightness"
 #define METHOD_SET_BRIGHTNESS          "SetBrightness"
-#define METHOD_PLAY_CUSTOM     "playcustom"
-#define METHOD_STOP_CUSTOM     "stopcustom"
+#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_STOP_CUSTOM             "stopcustom"
 
 #define FRONT_LED_FEATURE              "tizen.org/feature/led"
 #define CAMERA_LED_FEATURE             "tizen.org/feature/camera.back.flash"
 
 static bool support_front_led;
 static bool support_camera_led;
+static int number_of_devices;
 
 static void __CONSTRUCTOR__ init(void)
 {
@@ -170,3 +175,75 @@ int device_led_stop_custom(void)
 
        return DEVICE_ERROR_NONE;
 }
+
+int device_multi_led_get_number(int *num_of_leds)
+{
+       int ret;
+
+       if (!support_front_led)
+               return DEVICE_ERROR_NOT_SUPPORTED;
+
+       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
+
+       *num_of_leds = ret;
+       number_of_devices = ret;
+       return DEVICE_ERROR_NONE;
+}
+
+int device_multi_led_play_custom(bool led[], unsigned int color[])
+{
+       GVariantBuilder *builder = NULL;
+       GVariant *var = NULL;
+       int i;
+
+       if (!support_front_led)
+               return DEVICE_ERROR_NOT_SUPPORTED;
+
+       if (led == NULL || color == NULL)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a(bu)"));
+       for (i = 0; i < number_of_devices; i++)
+               g_variant_builder_add(builder, "(bu)", led[i], color[i]);
+
+       var = g_variant_new("(a(bu))", builder);
+       g_variant_builder_unref(builder);
+
+       return dbus_method_sync_var(DEVICED_BUS_NAME, DEVICED_PATH_LED,
+                               DEVICED_INTERFACE_LED, METHOD_MULTI_PLAY_CUSTOM, var);
+
+}
+
+int device_multi_led_stop_custom(bool led[])
+{
+       GVariantBuilder *builder = NULL;
+       GVariant *var = NULL;
+       int ret, i;
+
+       if (!support_front_led)
+               return DEVICE_ERROR_NOT_SUPPORTED;
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("ab"));
+       for (i = 0 ; i < number_of_devices; i++)
+               g_variant_builder_add(builder, "b", led[i]);
+
+       var = g_variant_new("(ab)", builder);
+       g_variant_builder_unref(builder);
+
+       ret = dbus_method_sync_var(DEVICED_BUS_NAME,
+               DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
+               METHOD_MULTI_STOP_CUSTOM, var);
+       //LCOV_EXCL_START System Error
+       if (ret < 0)
+               return errno_to_device_error(ret);
+       //LCOV_EXCL_STOP
+
+       return DEVICE_ERROR_NONE;
+}