[Notification] LED implementation
authorRafal Galka <r.galka@samsung.com>
Wed, 25 Mar 2015 10:16:42 +0000 (11:16 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Fri, 3 Apr 2015 09:00:04 +0000 (18:00 +0900)
Change-Id: I69788dbf129c40ce0e1f08d13f7474c0b7017762

src/notification/notification.gyp
src/notification/notification_api.js
src/notification/notification_instance.cc
src/notification/notification_instance.h
src/notification/notification_manager.cc
src/notification/notification_manager.h

index 2d7e10d0cbe0f3c122f75e0b1cc1b3d3cf1ea351..9c219a8c2e9524921b5a1a140476395a5847e2a0 100755 (executable)
@@ -24,7 +24,8 @@
         ['tizen == 1', {
           'variables': {
             'packages': [
-              'notification'
+              'notification',
+              'capi-system-device',
             ]
           },
         }],
index 7283424857e623e9f4b8b3ebaf3d38741bdf07b8..1b42396c3d239a082d607417a32816e27be069cd 100644 (file)
@@ -9,6 +9,27 @@ var validator_ = utils_.validator;
 var types_ = validator_.Types;
 var native_ = new xwalk.utils.NativeManager(extension);
 
+function convertColorToInt(rgbaColor) {
+  var color = rgbaColor.length === 7 ? rgbaColor + 'ff' : rgbaColor;
+  var isLengthOk = color.length === 9;
+  var isHash = color.substr(0, 1) === '#';
+  var hex = '0123456789abcdefABCDEF';
+  var isHex = true;
+  var c = color.replace('#', '');
+
+  for (var i = 0; i < c.length; i++) {
+    if (hex.indexOf(c[i]) < 0) {
+      isHex = false;
+    }
+  }
+
+  if (!isLengthOk || !isHash || !isHex) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR, 'invalid value');
+  }
+
+  return parseInt('0x' + c);
+}
+
 var EditManager = function() {
   this.canEdit = false;
 };
@@ -39,6 +60,11 @@ var NotificationProgressType = {
   BYTE: 'BYTE'
 };
 
+var LEDCustomFlags = {
+  LED_CUSTOM_DUTY_ON: 'LED_CUSTOM_DUTY_ON',
+  LED_CUSTOM_DEFAULT: 'LED_CUSTOM_DEFAULT'
+};
+
 function NotificationManager() {}
 
 
@@ -168,6 +194,46 @@ NotificationManager.prototype.getAll = function() {
   return notifications;
 };
 
+/**
+ * Plays the custom effect of the service LED that is located to the front of a device.
+ *
+ * @param timeOn Number
+ * @param timeOff Number
+ * @param color String
+ * @param flags Array
+ */
+NotificationManager.prototype.playLEDCustomEffect = function(timeOn, timeOff, color, flags) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'timeOn', type: types_.LONG},
+    {name: 'timeOff', type: types_.LONG},
+    {name: 'color', type: types_.STRING},
+    {name: 'flags', type: types_.ARRAY, values: types_.STRING}
+  ]);
+
+  for (var i = 0; i < args.flags.length; ++i) {
+    if (Object.keys(LEDCustomFlags).indexOf(args.flags[i]) < 0) {
+      throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'invalid value');
+    }
+  }
+
+  args.color = convertColorToInt(args.color);
+  var result = native_.callSync('NotificationManager_playLEDCustomEffect', args);
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+};
+
+/**
+ * Stops the custom effect of the service LED that is located to the front of a device.
+ */
+NotificationManager.prototype.stopLEDCustomEffect = function() {
+  var result = native_.callSync('NotificationManager_stopLEDCustomEffect');
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+};
+
+
 function NotificationInitDict(data) {
   var _iconPath = null;
   var _soundPath = null;
index 3fa58c58aae3acf23a294ba68279e36efece6c06..01790d1adcbd8e6c06e1fc2e4eb242d07c2cdf3e 100644 (file)
@@ -33,6 +33,10 @@ NotificationInstance::NotificationInstance() {
   REGISTER_SYNC("NotificationManager_getAll", NotificationManagerGetAll);
   REGISTER_SYNC("NotificationManager_post", NotificationManagerPost);
   REGISTER_SYNC("NotificationManager_removeAll", NotificationManagerRemoveAll);
+  REGISTER_SYNC("NotificationManager_playLEDCustomEffect",
+      NotificationManagerPlayLEDCustomEffect);
+  REGISTER_SYNC("NotificationManager_stopLEDCustomEffect",
+      NotificationManagerStopLEDCustomEffect);
 #undef REGISTER_SYNC
 
   manager_ = NotificationManager::GetInstance();
@@ -126,6 +130,28 @@ void NotificationInstance::NotificationManagerGetAll(
     ReportError(status, &out);
 }
 
+void NotificationInstance::NotificationManagerPlayLEDCustomEffect(
+    const picojson::value& args, picojson::object& out) {
+
+  PlatformResult status = manager_->PlayLEDCustomEffect(args.get<picojson::object>());
+
+  if (status.IsSuccess())
+    ReportSuccess(out);
+  else
+    ReportError(status, &out);
+}
+
+void NotificationInstance::NotificationManagerStopLEDCustomEffect(
+    const picojson::value& /*args*/, picojson::object& out) {
+
+  PlatformResult status = manager_->StopLEDCustomEffect();
+
+  if (status.IsSuccess())
+    ReportSuccess(out);
+  else
+    ReportError(status, &out);
+}
+
 #undef CHECK_EXIST
 
 }  // namespace notification
index 958e7941018027d916831aba5dd6ef3525289dc6..425668e23f30ef9a60ac10d36794cf8fc7216d23 100644 (file)
@@ -31,6 +31,11 @@ class NotificationInstance : public common::ParsedInstance {
                               picojson::object& out);
   void NotificationManagerGetAll(const picojson::value& args,
                                  picojson::object& out);
+
+  void NotificationManagerPlayLEDCustomEffect(const picojson::value& args,
+                                              picojson::object& out);
+  void NotificationManagerStopLEDCustomEffect(const picojson::value& args,
+                                              picojson::object& out);
 };
 
 }  // namespace notification
index e18d97726cbe674f3eedc95a120d2d7f842aa57a..ffd1c3b0b4e3f7d1f92d159871da01cf55f1c226 100644 (file)
@@ -4,8 +4,9 @@
 
 #include "notification/notification_manager.h"
 
-#include <notification_internal.h>
 #include <app_control_internal.h>
+#include <device/led.h>
+#include <notification_internal.h>
 
 #include "common/converter.h"
 #include "common/logger.h"
@@ -140,5 +141,46 @@ PlatformResult NotificationManager::GetAll(picojson::array& out) {
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
+PlatformResult NotificationManager::PlayLEDCustomEffect(
+    const picojson::object& args) {
+  LOGGER(DEBUG) << "entered";
+
+  int timeOn = FromJson<double>(args, "timeOn");
+  int timeOff = FromJson<double>(args, "timeOff");
+  unsigned int color = FromJson<double>(args, "color");
+
+  auto& flags = FromJson<picojson::array>(args, "flags");
+  unsigned int platformFlags = 0;
+  for (auto flag : flags) {
+    std::string flagStr = JsonCast<std::string>(flag);
+    if (flagStr == "LED_CUSTOM_DEFAULT")
+      platformFlags |= LED_CUSTOM_DEFAULT;
+    else if (flagStr == "LED_CUSTOM_DUTY_ON")
+      platformFlags |= LED_CUSTOM_DUTY_ON;
+  }
+
+  int ret;
+  ret = device_led_play_custom(timeOn, timeOff, color, platformFlags);
+  if (ret != DEVICE_ERROR_NONE) {
+    LOGGER(ERROR) << "Cannot play LED custom effect: " << ret;
+    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot play LED custom effect");
+  }
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult NotificationManager::StopLEDCustomEffect() {
+  LOGGER(DEBUG) << "entered";
+
+  int ret = DEVICE_ERROR_NONE;
+  ret = device_led_stop_custom();
+  if (ret != DEVICE_ERROR_NONE) {
+    LOGGER(ERROR) << "Cannot stop LED custom effect: " << ret;
+    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot stop LED custom effect");
+  }
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
 }  // namespace notification
 }  // namespace extension
index 9d977e85123b235d0bb8dbd0248e2d722ea6e92a..53bf043853ba9e2d9fc7004bcac10fc48f4bcce5 100644 (file)
@@ -26,6 +26,9 @@ class NotificationManager {
                              picojson::object& out);
   common::PlatformResult GetAll(picojson::array& out);
 
+  common::PlatformResult PlayLEDCustomEffect(const picojson::object& args);
+  common::PlatformResult StopLEDCustomEffect();
+
  private:
   NotificationManager();
   virtual ~NotificationManager();