[Sound] Initial implementation of Sound module
authorPawel Kaczmarek <p.kaczmarek3@samsung.com>
Mon, 2 Feb 2015 12:18:00 +0000 (13:18 +0100)
committerRafal Galka <r.galka@samsung.com>
Mon, 2 Feb 2015 13:28:27 +0000 (22:28 +0900)
[Verification]
console.log(typeof tizen.sound);
should return object

Change-Id: Icf72d5644238b76e3e4d1316a9c2524865aaf84a
Signed-off-by: Pawel Kaczmarek <p.kaczmarek3@samsung.com>
src/sound/sound.gyp [new file with mode: 0644]
src/sound/sound_api.js [new file with mode: 0644]
src/sound/sound_extension.cc [new file with mode: 0644]
src/sound/sound_extension.h [new file with mode: 0644]
src/sound/sound_instance.cc [new file with mode: 0644]
src/sound/sound_instance.h [new file with mode: 0644]
src/tizen-wrt.gyp

diff --git a/src/sound/sound.gyp b/src/sound/sound.gyp
new file mode 100644 (file)
index 0000000..c1e4855
--- /dev/null
@@ -0,0 +1,28 @@
+{
+  'includes':[
+    '../common/common.gypi',
+  ],
+  'targets': [
+    {
+      'target_name': 'tizen_sound',
+      'type': 'loadable_module',
+      'variables': {
+        'packages': [
+          'icu-i18n',
+        ],
+      },
+      'sources': [
+        'sound_api.js',
+        'sound_extension.cc',
+        'sound_extension.h',
+        'sound_instance.cc',
+        'sound_instance.h',
+      ],
+      'conditions': [
+        [ 'tizen == 1', {
+            'variables': { 'packages': ['vconf'] },
+        }],
+      ],
+    },
+  ],
+}
diff --git a/src/sound/sound_api.js b/src/sound/sound_api.js
new file mode 100644 (file)
index 0000000..9693fa5
--- /dev/null
@@ -0,0 +1,125 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+
+var utils_ = xwalk.utils;
+var type_ = utils_.type;
+var converter_ = utils_.converter;
+var validator_ = utils_.validator;
+var types_ = validator_.Types;
+var native_ = new xwalk.utils.NativeManager(extension);
+
+
+var SoundType = {
+  SYSTEM: 'SYSTEM',
+  NOTIFICATION: 'NOTIFICATION',
+  ALARM: 'ALARM',
+  MEDIA: 'MEDIA',
+  VOICE: 'VOICE',
+  RINGTONE: 'RINGTONE'
+};
+
+var SoundModeType = {
+  SOUND: 'SOUND',
+  VIBRATE: 'VIBRATE',
+  MUTE: 'MUTE'
+};
+
+
+function SoundManager() {}
+
+SoundManager.prototype.getSoundMode = function() {
+  var result = native_.callSync('SoundManager_getSoundMode');
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  return native_.getResultObject(result);
+};
+
+SoundManager.prototype.setVolume = function(type, volume) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'type', type: types_.ENUM, values: Object.keys(SoundType)},
+    {name: 'volume', type: types_.DOUBLE}
+  ]);
+
+  var result = native_.callSync('SoundManager_setVolume', args);
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  return native_.getResultObject(result);
+};
+
+SoundManager.prototype.getVolume = function(type) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'type', type: types_.ENUM, values: Object.keys(SoundType)}
+  ]);
+
+  var result = native_.callSync('SoundManager_getVolume', args);
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  return native_.getResultObject(result);
+};
+
+SoundManager.prototype.setSoundModeChangeListener = function(callback) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'callback', type: types_.FUNCTION}
+  ]);
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+      return;
+    }
+
+    var _result = native_.getResultObject(result);
+
+    native_.callIfPossible(args.successCallback);
+  };
+
+  native_.call('SoundManager_setSoundModeChangeListener', args, callback);
+};
+
+SoundManager.prototype.unsetSoundModeChangeListener = function() {
+  var result = native_.callSync('SoundManager_unsetSoundModeChangeListener');
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  return native_.getResultObject(result);
+};
+
+SoundManager.prototype.setVolumeChangeListener = function(callback) {
+  var args = validator_.validateArgs(arguments, [
+    {name: 'callback', type: types_.FUNCTION}
+  ]);
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+      return;
+    }
+
+    var _result = native_.getResultObject(result);
+
+    native_.callIfPossible(args.successCallback);
+  };
+
+  native_.call('SoundManager_setVolumeChangeListener', args, callback);
+};
+
+SoundManager.prototype.unsetVolumeChangeListener = function() {
+  var result = native_.callSync('SoundManager_unsetVolumeChangeListener');
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  return native_.getResultObject(result);
+};
+
+
+exports = new SoundManager();
diff --git a/src/sound/sound_extension.cc b/src/sound/sound_extension.cc
new file mode 100644 (file)
index 0000000..d7a4091
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sound/sound_extension.h"
+
+#include "sound/sound_instance.h"
+
+// This will be generated from sound_api.js
+extern const char kSource_sound_api[];
+
+common::Extension* CreateExtension() {
+  return new SoundExtension;
+}
+
+SoundExtension::SoundExtension() {
+  SetExtensionName("tizen.sound");
+  SetJavaScriptAPI(kSource_sound_api);
+}
+
+SoundExtension::~SoundExtension() {}
+
+common::Instance* SoundExtension::CreateInstance() {
+  return new extension::sound::SoundInstance;
+}
\ No newline at end of file
diff --git a/src/sound/sound_extension.h b/src/sound/sound_extension.h
new file mode 100644 (file)
index 0000000..8bcea5d
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SOUND_SOUND_EXTENSION_H_
+#define SOUND_SOUND_EXTENSION_H_
+
+#include "common/extension.h"
+
+class SoundExtension : public common::Extension {
+ public:
+  SoundExtension();
+  virtual ~SoundExtension();
+
+ private:
+  virtual common::Instance* CreateInstance();
+};
+
+#endif // SOUND_SOUND_EXTENSION_H_
diff --git a/src/sound/sound_instance.cc b/src/sound/sound_instance.cc
new file mode 100644 (file)
index 0000000..cd0d293
--- /dev/null
@@ -0,0 +1,141 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sound/sound_instance.h"
+
+#include <functional>
+
+#include "common/picojson.h"
+#include "common/logger.h"
+#include "common/platform_exception.h"
+
+namespace extension {
+namespace sound {
+
+namespace {
+// The privileges that required in Sound API
+const std::string kPrivilegeSound = "";
+
+} // namespace
+
+using namespace common;
+using namespace extension::sound;
+
+SoundInstance::SoundInstance() {
+  using namespace std::placeholders;
+  #define REGISTER_SYNC(c,x) \
+    RegisterSyncHandler(c, std::bind(&SoundInstance::x, this, _1, _2));
+  REGISTER_SYNC("SoundManager_setVolume", SoundManagerSetVolume);
+  REGISTER_SYNC("SoundManager_unsetSoundModeChangeListener", SoundManagerUnsetSoundModeChangeListener);
+  REGISTER_SYNC("SoundManager_getVolume", SoundManagerGetVolume);
+  REGISTER_SYNC("SoundManager_unsetVolumeChangeListener", SoundManagerUnsetVolumeChangeListener);
+  REGISTER_SYNC("SoundManager_setSoundModeChangeListener", SoundManagerSetSoundModeChangeListener);
+  REGISTER_SYNC("SoundManager_setVolumeChangeListener", SoundManagerSetVolumeChangeListener);
+  REGISTER_SYNC("SoundManager_getSoundMode", SoundManagerGetSoundMode);
+  #undef REGISTER_SYNC
+}
+
+SoundInstance::~SoundInstance() {
+}
+
+
+
+#define CHECK_EXIST(args, name, out) \
+    if (!args.contains(name)) {\
+      ReportError(TypeMismatchException(name" is required argument"), out);\
+      return;\
+    }
+
+
+void SoundInstance::SoundManagerGetSoundMode(const picojson::value& args, picojson::object& out) {
+
+
+  // implement it
+
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void SoundInstance::SoundManagerSetVolume(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "volume", out)
+
+  double volume = args.get("volume").get<double>();
+
+  // implement it
+
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void SoundInstance::SoundManagerGetVolume(const picojson::value& args, picojson::object& out) {
+
+
+  // implement it
+
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void SoundInstance::SoundManagerSetSoundModeChangeListener(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "callbackId", out)
+
+  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+
+  // implement it
+
+  // call ReplyAsync in later (Asynchronously)
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void SoundInstance::SoundManagerUnsetSoundModeChangeListener(const picojson::value& args, picojson::object& out) {
+
+
+  // implement it
+
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void SoundInstance::SoundManagerSetVolumeChangeListener(const picojson::value& args, picojson::object& out) {
+  CHECK_EXIST(args, "callbackId", out)
+
+  int callbackId = static_cast<int>(args.get("callbackId").get<double>());
+
+  // implement it
+
+  // call ReplyAsync in later (Asynchronously)
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+void SoundInstance::SoundManagerUnsetVolumeChangeListener(const picojson::value& args, picojson::object& out) {
+
+
+  // implement it
+
+
+  // if success
+  // ReportSuccess(out);
+  // if error
+  // ReportError(out);
+}
+
+
+#undef CHECK_EXIST
+
+} // namespace sound
+} // namespace extension
\ No newline at end of file
diff --git a/src/sound/sound_instance.h b/src/sound/sound_instance.h
new file mode 100644 (file)
index 0000000..d35f014
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SOUND_SOUND_INSTANCE_H_
+#define SOUND_SOUND_INSTANCE_H_
+
+#include "common/extension.h"
+
+namespace extension {
+namespace sound {
+
+class SoundInstance : public common::ParsedInstance {
+ public:
+  SoundInstance();
+  virtual ~SoundInstance();
+
+ private:
+  void SoundManagerSetVolume(const picojson::value& args, picojson::object& out);
+  void SoundManagerUnsetSoundModeChangeListener(const picojson::value& args, picojson::object& out);
+  void SoundManagerGetVolume(const picojson::value& args, picojson::object& out);
+  void SoundManagerUnsetVolumeChangeListener(const picojson::value& args, picojson::object& out);
+  void SoundManagerSetSoundModeChangeListener(const picojson::value& args, picojson::object& out);
+  void SoundManagerSetVolumeChangeListener(const picojson::value& args, picojson::object& out);
+  void SoundManagerGetSoundMode(const picojson::value& args, picojson::object& out);
+};
+
+} // namespace sound
+} // namespace extension
+
+#endif // SOUND_SOUND_INSTANCE_H_
\ No newline at end of file
index d7c97ffb7fc5e76cde634e0d7f73b9df8d0949a9..1a320e3c768df32a4825f202a2d2374a0f98ccc2 100644 (file)
@@ -37,6 +37,7 @@
               'systeminfo/systeminfo.gyp:*',
               #'radio/radio.gyp:*',
               'secureelement/secureelement.gyp:*',
+              'sound/sound.gyp:*',
               'notification/notification.gyp:*',
             ],
           },