* 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.
*/
#include <stdbool.h>
#include <errno.h>
#include <system_info.h>
+#include <libsyscommon/dbus-system.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_LED_CONTROL "multi_led_control"
+#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 = -1;
static void __CONSTRUCTOR__ init(void)
{
int device_flash_get_max_brightness(int *max_brightness)
{
- int ret;
+ int ret, val;
if (!support_camera_led)
return DEVICE_ERROR_NOT_SUPPORTED;
if (!max_brightness)
return DEVICE_ERROR_INVALID_PARAMETER;
- ret = dbus_method_sync(DEVICED_BUS_NAME,
+ ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME,
DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
- METHOD_GET_MAX_BRIGHTNESS, NULL, NULL);
+ METHOD_GET_MAX_BRIGHTNESS, NULL, &val);
if (ret < 0)
- return errno_to_device_error(ret);
+ return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
- *max_brightness = ret;
+ *max_brightness = val;
return DEVICE_ERROR_NONE;
}
int device_flash_get_brightness(int *brightness)
{
- int ret;
+ int ret, val;
if (!support_camera_led)
return DEVICE_ERROR_NOT_SUPPORTED;
if (!brightness)
return DEVICE_ERROR_INVALID_PARAMETER;
- ret = dbus_method_sync(DEVICED_BUS_NAME,
+ ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME,
DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
- METHOD_GET_BRIGHTNESS, NULL, NULL);
+ METHOD_GET_BRIGHTNESS, NULL, &val);
if (ret < 0)
- return errno_to_device_error(ret);
+ return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
- *brightness = ret;
+ *brightness = val;
return DEVICE_ERROR_NONE;
}
int device_flash_set_brightness(int brightness)
{
- char *arr[2];
- char buf_val[32];
- char buf_noti[32];
int max, ret;
if (!support_camera_led)
if (brightness < 0 || brightness > max)
return DEVICE_ERROR_INVALID_PARAMETER;
- snprintf(buf_val, sizeof(buf_val), "%d", brightness);
- arr[0] = buf_val;
- snprintf(buf_noti, sizeof(buf_noti), "%d", 0);
- arr[1] = buf_noti;
-
- ret = dbus_method_sync(DEVICED_BUS_NAME,
+ /* if camera API preempt a flash device, it will return -EBUSY error. */
+ ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME,
DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
- METHOD_SET_BRIGHTNESS, "ii", arr);
+ METHOD_SET_BRIGHTNESS, g_variant_new("(ii)", brightness, 0), NULL);
if (ret < 0)
- return errno_to_device_error(ret);
+ return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
return DEVICE_ERROR_NONE;
}
int device_led_play_custom(int on, int off, unsigned int color, unsigned int flags)
{
- char *arr[4];
- char str_on[32], str_off[32];
- char str_color[32], str_flags[32];
int ret;
if (!support_front_led)
if (on < 0 || off < 0)
return DEVICE_ERROR_INVALID_PARAMETER;
- snprintf(str_on, sizeof(str_on), "%d", on);
- arr[0] = str_on;
- snprintf(str_off, sizeof(str_off), "%d", off);
- arr[1] = str_off;
- snprintf(str_color, sizeof(str_color), "%lu", (long unsigned int)color);
- arr[2] = str_color;
- snprintf(str_flags, sizeof(str_flags), "%lu", (long unsigned int)flags);
- arr[3] = str_flags;
-
- ret = dbus_method_sync(DEVICED_BUS_NAME,
+ ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME,
DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
- METHOD_PLAY_CUSTOM, "iiuu", arr);
+ METHOD_PLAY_CUSTOM, g_variant_new("(iiuu)", on, off, (unsigned int)color, (unsigned int)flags), NULL);
+//LCOV_EXCL_START System Error
if (ret < 0)
return errno_to_device_error(ret);
+//LCOV_EXCL_STOP
return DEVICE_ERROR_NONE;
}
if (!support_front_led)
return DEVICE_ERROR_NOT_SUPPORTED;
- ret = dbus_method_sync(DEVICED_BUS_NAME,
+ ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME,
DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
METHOD_STOP_CUSTOM, NULL, NULL);
+//LCOV_EXCL_START System Error
if (ret < 0)
return errno_to_device_error(ret);
+//LCOV_EXCL_STOP
+
+ return DEVICE_ERROR_NONE;
+}
+
+//LCOV_EXCL_START Not tested API
+int device_multi_led_get_number(int *num_of_leds)
+{
+ int ret, val;
+
+ if (!support_front_led)
+ return DEVICE_ERROR_NOT_SUPPORTED;
+
+ if (!num_of_leds)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ if (number_of_devices < 0) {
+ ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME,
+ DEVICED_PATH_LED, DEVICED_INTERFACE_LED,
+ METHOD_GET_LED_NUMBER, NULL, &val);
+ if (ret < 0)
+ return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
+ number_of_devices = val;
+ }
+
+ *num_of_leds = number_of_devices;
+
+ return DEVICE_ERROR_NONE;
+}
+//LCOV_EXCL_STOP
+
+//LCOV_EXCL_START Not tested API
+int device_multi_led_control(unsigned int color[])
+{
+ GVariantBuilder *builder = NULL;
+ GVariant *var = NULL;
+ int i, ret;
+
+ if (!support_front_led)
+ return DEVICE_ERROR_NOT_SUPPORTED;
+
+ 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]);
+
+ var = g_variant_new("(au)", builder);
+ g_variant_builder_unref(builder);
+
+ ret = dbus_handle_method_sync_var(DEVICED_BUS_NAME, DEVICED_PATH_LED,
+ DEVICED_INTERFACE_LED, METHOD_MULTI_LED_CONTROL, var, NULL);
+ if (ret < 0)
+ return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error
return DEVICE_ERROR_NONE;
}
+//LCOV_EXCL_STOP