From e6179aeed5e7bce0bf024a335c38442c64e7de22 Mon Sep 17 00:00:00 2001 From: Pawel Kaczmarek Date: Mon, 2 Feb 2015 13:18:00 +0100 Subject: [PATCH] [Sound] Initial implementation of Sound module [Verification] console.log(typeof tizen.sound); should return object Change-Id: Icf72d5644238b76e3e4d1316a9c2524865aaf84a Signed-off-by: Pawel Kaczmarek --- src/sound/sound.gyp | 28 +++++++ src/sound/sound_api.js | 125 +++++++++++++++++++++++++++++++ src/sound/sound_extension.cc | 25 +++++++ src/sound/sound_extension.h | 19 +++++ src/sound/sound_instance.cc | 141 +++++++++++++++++++++++++++++++++++ src/sound/sound_instance.h | 31 ++++++++ src/tizen-wrt.gyp | 1 + 7 files changed, 370 insertions(+) create mode 100644 src/sound/sound.gyp create mode 100644 src/sound/sound_api.js create mode 100644 src/sound/sound_extension.cc create mode 100644 src/sound/sound_extension.h create mode 100644 src/sound/sound_instance.cc create mode 100644 src/sound/sound_instance.h diff --git a/src/sound/sound.gyp b/src/sound/sound.gyp new file mode 100644 index 00000000..c1e48554 --- /dev/null +++ b/src/sound/sound.gyp @@ -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 index 00000000..9693fa59 --- /dev/null +++ b/src/sound/sound_api.js @@ -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 index 00000000..d7a40919 --- /dev/null +++ b/src/sound/sound_extension.cc @@ -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 index 00000000..8bcea5d8 --- /dev/null +++ b/src/sound/sound_extension.h @@ -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 index 00000000..cd0d2931 --- /dev/null +++ b/src/sound/sound_instance.cc @@ -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 + +#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(); + + // 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(args.get("callbackId").get()); + + // 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(args.get("callbackId").get()); + + // 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 index 00000000..d35f0141 --- /dev/null +++ b/src/sound/sound_instance.h @@ -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 diff --git a/src/tizen-wrt.gyp b/src/tizen-wrt.gyp index d7c97ffb..1a320e3c 100644 --- a/src/tizen-wrt.gyp +++ b/src/tizen-wrt.gyp @@ -37,6 +37,7 @@ 'systeminfo/systeminfo.gyp:*', #'radio/radio.gyp:*', 'secureelement/secureelement.gyp:*', + 'sound/sound.gyp:*', 'notification/notification.gyp:*', ], }, -- 2.34.1