--- /dev/null
+/*
+ * deviced
+ *
+ * Copyright (c) 2012 - 2016 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+
+#include <stdio.h>
+#include <errno.h>
+#include <assert.h>
+#include <device-node.h>
+#include <Ecore.h>
+#include <vconf.h>
+#include <hw/led.h>
+
+#include "core/log.h"
+#include "core/common.h"
+#include "core/edbus-handler.h"
+#include "core/devices.h"
+#include "core/device-notifier.h"
+
+/* enum values defined in capi-system-device */
+typedef enum {
+ LED_CUSTOM_DUTY_ON = 1 << 0, /**< blink LED */
+ LED_CUSTOM_DEFAULT = (LED_CUSTOM_DUTY_ON), /**< Default flag */
+} led_custom_flags;
+
+struct led_device *rgb_dev;
+
+static int rgb_play(struct led_state *state)
+{
+ if (!rgb_dev) {
+ _E("There is NO HAL");
+ return -ENODEV;
+ }
+
+ if (!rgb_dev->set_state) {
+ _E("LED HAL does not support set_state()");
+ return -ENOTSUP;
+ }
+
+ return rgb_dev->set_state(state);
+}
+
+static DBusMessage *edbus_playcustom(E_DBus_Object *obj, DBusMessage *msg)
+{
+ int ret;
+ int on, off;
+ unsigned int color, flags;
+ struct led_state state;
+ pid_t pid;
+
+ ret = dbus_message_get_args(msg, NULL,
+ DBUS_TYPE_INT32, &on,
+ DBUS_TYPE_INT32, &off,
+ DBUS_TYPE_UINT32, &color,
+ DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID);
+ if (!ret) {
+ _I("there is no message");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ pid = get_edbus_sender_pid(msg);
+
+ _I("pid %d led play custom %d, %d, %x", pid, on, off, color);
+
+ state.color = color;
+ state.duty_on = on;
+ state.duty_off = off;
+ if (flags & LED_CUSTOM_DUTY_ON)
+ state.type = LED_TYPE_BLINK;
+ else
+ state.type = LED_TYPE_MANUAL;
+
+ ret = rgb_play(&state);
+ if (ret < 0)
+ _E("Failed to play LED notification (%d)", ret);
+
+out:
+ return make_reply_message(msg, ret);
+}
+
+static DBusMessage *edbus_stopcustom(E_DBus_Object *obj, DBusMessage *msg)
+{
+ struct led_state state = { 0, };
+ int ret;
+ pid_t pid;
+
+ pid = get_edbus_sender_pid(msg);
+
+ _I("pid %d led stop custom", pid);
+
+ ret = rgb_play(&state);
+ if (ret < 0)
+ _E("Failed to play LED notification (%d)", ret);
+
+ return make_reply_message(msg, ret);
+}
+
+static const struct edbus_method edbus_methods[] = {
+ { "playcustom", "iiuu", "i", edbus_playcustom },
+ { "stopcustom", NULL, "i", edbus_stopcustom },
+ /* Add methods here */
+};
+
+static void rgb_init(void *data)
+{
+ int ret;
+
+ /* init dbus interface */
+ ret = register_edbus_interface_and_method(DEVICED_PATH_LED,
+ DEVICED_INTERFACE_LED,
+ edbus_methods, ARRAY_SIZE(edbus_methods));
+ if (ret < 0)
+ _E("fail to init edbus interface and method(%d)", ret);
+}
+
+static int rgb_probe(void *data)
+{
+ struct hw_info *info;
+ int ret;
+
+ if (rgb_dev)
+ return 0;
+
+ ret = hw_get_info(LED_HARDWARE_DEVICE_ID,
+ (const struct hw_info **)&info);
+ if (ret < 0) {
+ _E("There is no LED HAL");
+ return -ENOTSUP;
+ }
+
+ if (!info->open) {
+ _E("Failed to open led device; open(NULL)");
+ return -ENODEV;
+ }
+
+ ret = info->open(info, LED_ID_NOTIFICATION, (struct hw_common **)&rgb_dev);
+ if (ret < 0) {
+ _E("Failed to get LED NOTIFICATION device structure (%d)", ret);
+ return ret;
+ }
+
+ _I("LED NOTIFICATION device structure load success");
+ return 0;
+}
+
+static const struct device_ops rgbled_device_ops = {
+ .name = "rgbled",
+ .probe = rgb_probe,
+ .init = rgb_init,
+};
+
+DEVICE_OPS_REGISTER(&rgbled_device_ops)