From: Pawel Kaczmarek Date: Mon, 2 Feb 2015 15:56:19 +0000 (+0100) Subject: [NetworkBearerSelection] Initial implementation X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~497 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=433ee663fc11d5eb9665ba5a49deaea792244131;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [NetworkBearerSelection] Initial implementation [Verification] console.log(typeof tizen.networkbearerselection); should return object Change-Id: I33110f8ebc94d8990d0a1fad713679080d22eac2 Signed-off-by: Pawel Kaczmarek --- diff --git a/src/networkbearerselection/networkbearerselection.gyp b/src/networkbearerselection/networkbearerselection.gyp new file mode 100644 index 00000000..54b2c480 --- /dev/null +++ b/src/networkbearerselection/networkbearerselection.gyp @@ -0,0 +1,28 @@ +{ + 'includes':[ + '../common/common.gypi', + ], + 'targets': [ + { + 'target_name': 'tizen_networkbearerselection', + 'type': 'loadable_module', + 'variables': { + 'packages': [ + 'icu-i18n', + ], + }, + 'sources': [ + 'networkbearerselection_api.js', + 'networkbearerselection_extension.cc', + 'networkbearerselection_extension.h', + 'networkbearerselection_instance.cc', + 'networkbearerselection_instance.h', + ], + 'conditions': [ + [ 'tizen == 1', { + 'variables': { 'packages': ['vconf'] }, + }], + ], + }, + ], +} diff --git a/src/networkbearerselection/networkbearerselection_api.js b/src/networkbearerselection/networkbearerselection_api.js new file mode 100644 index 00000000..ca40ce42 --- /dev/null +++ b/src/networkbearerselection/networkbearerselection_api.js @@ -0,0 +1,66 @@ +// 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 NetworkType = { + CELLULAR: 'CELLULAR', + UNKNOWN: 'UNKNOWN' +}; + + +function NetworkBearerSelection() {} + +NetworkBearerSelection.prototype.requestRouteToHost = function(networkType, domainName, successCallback, errorCallback) { + var args = validator_.validateArgs(arguments, [ + {name: 'networkType', type: types_.ENUM, values: Object.keys(NetworkType)}, + {name: 'domainName', type: types_.STRING}, + {name: 'successCallback', type: types_.LISTENER, values: ['onsuccess', 'ondisconnected']}, + {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} + ]); + + 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('NetworkBearerSelection_requestRouteToHost', args, callback); +}; + +NetworkBearerSelection.prototype.releaseRouteToHost = function(networkType, domainName, successCallback, errorCallback) { + var args = validator_.validateArgs(arguments, [ + {name: 'networkType', type: types_.ENUM, values: Object.keys(NetworkType)}, + {name: 'domainName', type: types_.STRING}, + {name: 'successCallback', type: types_.FUNCTION}, + {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} + ]); + + 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('NetworkBearerSelection_releaseRouteToHost', args, callback); +}; + + +exports = new NetworkBearerSelection(); diff --git a/src/networkbearerselection/networkbearerselection_extension.cc b/src/networkbearerselection/networkbearerselection_extension.cc new file mode 100644 index 00000000..ddc1e383 --- /dev/null +++ b/src/networkbearerselection/networkbearerselection_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 "networkbearerselection/networkbearerselection_extension.h" + +#include "networkbearerselection/networkbearerselection_instance.h" + +// This will be generated from networkbearerselection_api.js +extern const char kSource_networkbearerselection_api[]; + +common::Extension* CreateExtension() { + return new NetworkBearerSelectionExtension; +} + +NetworkBearerSelectionExtension::NetworkBearerSelectionExtension() { + SetExtensionName("tizen.networkbearerselection"); + SetJavaScriptAPI(kSource_networkbearerselection_api); +} + +NetworkBearerSelectionExtension::~NetworkBearerSelectionExtension() {} + +common::Instance* NetworkBearerSelectionExtension::CreateInstance() { + return new extension::networkbearerselection::NetworkBearerSelectionInstance; +} diff --git a/src/networkbearerselection/networkbearerselection_extension.h b/src/networkbearerselection/networkbearerselection_extension.h new file mode 100644 index 00000000..73011a75 --- /dev/null +++ b/src/networkbearerselection/networkbearerselection_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 NETWORKBEARERSELECTION_NETWORKBEARERSELECTION_EXTENSION_H_ +#define NETWORKBEARERSELECTION_NETWORKBEARERSELECTION_EXTENSION_H_ + +#include "common/extension.h" + +class NetworkBearerSelectionExtension : public common::Extension { + public: + NetworkBearerSelectionExtension(); + virtual ~NetworkBearerSelectionExtension(); + + private: + virtual common::Instance* CreateInstance(); +}; + +#endif // NETWORKBEARERSELECTION_NETWORKBEARERSELECTION_EXTENSION_H_ diff --git a/src/networkbearerselection/networkbearerselection_instance.cc b/src/networkbearerselection/networkbearerselection_instance.cc new file mode 100644 index 00000000..9d5d4cfc --- /dev/null +++ b/src/networkbearerselection/networkbearerselection_instance.cc @@ -0,0 +1,113 @@ +// 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 "networkbearerselection/networkbearerselection_instance.h" + +#include + +#include "common/picojson.h" +#include "common/logger.h" +#include "common/platform_exception.h" + +namespace extension { +namespace networkbearerselection { + +namespace { +// The privileges that required in NetworkBearerSelection API +const std::string kPrivilegeNetworkBearerSelection = ""; + +} // namespace + +using namespace common; +using namespace extension::networkbearerselection; + +NetworkBearerSelectionInstance::NetworkBearerSelectionInstance() { + using namespace std::placeholders; + #define REGISTER_SYNC(c,x) \ + RegisterSyncHandler(c, std::bind(&NetworkBearerSelectionInstance::x, this, _1, _2)); + REGISTER_SYNC("NetworkBearerSelection_requestRouteToHost", NetworkBearerSelectionRequestRouteToHost); + REGISTER_SYNC("NetworkBearerSelection_releaseRouteToHost", NetworkBearerSelectionReleaseRouteToHost); + #undef REGISTER_SYNC +} + +NetworkBearerSelectionInstance::~NetworkBearerSelectionInstance() { +} + + +enum NetworkBearerSelectionCallbacks { + NetworkBearerSelectionRequestRouteToHostCallback, + NetworkBearerSelectionReleaseRouteToHostCallback +}; + +static void ReplyAsync(NetworkBearerSelectionInstance* instance, NetworkBearerSelectionCallbacks cbfunc, + int callbackId, bool isSuccess, picojson::object& param) { + param["callbackId"] = picojson::value(static_cast(callbackId)); + param["status"] = picojson::value(isSuccess ? "success" : "error"); + + // insert result for async callback to param + switch(cbfunc) { + case NetworkBearerSelectionRequestRouteToHostCallback: { + // do something... + break; + } + case NetworkBearerSelectionReleaseRouteToHostCallback: { + // do something... + break; + } + default: { + LoggerE("Invalid Callback Type"); + return; + } + } + + picojson::value result = picojson::value(param); + + instance->PostMessage(result.serialize().c_str()); +} + +#define CHECK_EXIST(args, name, out) \ + if (!args.contains(name)) {\ + ReportError(TypeMismatchException(name" is required argument"), out);\ + return;\ + } + + +void NetworkBearerSelectionInstance::NetworkBearerSelectionRequestRouteToHost(const picojson::value& args, picojson::object& out) { + CHECK_EXIST(args, "callbackId", out) + CHECK_EXIST(args, "domainName", out) + + int callbackId = static_cast(args.get("callbackId").get()); + const std::string& domainName = args.get("domainName").get(); + + // implement it + + // call ReplyAsync in later (Asynchronously) + + // if success + // ReportSuccess(out); + // if error + // ReportError(out); +} +void NetworkBearerSelectionInstance::NetworkBearerSelectionReleaseRouteToHost(const picojson::value& args, picojson::object& out) { + CHECK_EXIST(args, "callbackId", out) + CHECK_EXIST(args, "domainName", out) + + int callbackId = static_cast(args.get("callbackId").get()); + const std::string& domainName = args.get("domainName").get(); + + // implement it + + // call ReplyAsync in later (Asynchronously) + + // if success + // ReportSuccess(out); + // if error + // ReportError(out); +} + + +#undef CHECK_EXIST + +} // namespace networkbearerselection +} // namespace extension diff --git a/src/networkbearerselection/networkbearerselection_instance.h b/src/networkbearerselection/networkbearerselection_instance.h new file mode 100644 index 00000000..4aa27494 --- /dev/null +++ b/src/networkbearerselection/networkbearerselection_instance.h @@ -0,0 +1,26 @@ +// 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 NETWORKBEARERSELECTION_NETWORKBEARERSELECTION_INSTANCE_H_ +#define NETWORKBEARERSELECTION_NETWORKBEARERSELECTION_INSTANCE_H_ + +#include "common/extension.h" + +namespace extension { +namespace networkbearerselection { + +class NetworkBearerSelectionInstance : public common::ParsedInstance { + public: + NetworkBearerSelectionInstance(); + virtual ~NetworkBearerSelectionInstance(); + + private: + void NetworkBearerSelectionRequestRouteToHost(const picojson::value& args, picojson::object& out); + void NetworkBearerSelectionReleaseRouteToHost(const picojson::value& args, picojson::object& out); +}; + +} // namespace networkbearerselection +} // namespace extension + +#endif // NETWORKBEARERSELECTION_NETWORKBEARERSELECTION_INSTANCE_H_ diff --git a/src/tizen-wrt.gyp b/src/tizen-wrt.gyp index 1a320e3c..72d4d0f5 100644 --- a/src/tizen-wrt.gyp +++ b/src/tizen-wrt.gyp @@ -31,6 +31,7 @@ 'datacontrol/datacontrol.gyp:*', 'datasync/datasync.gyp:*', 'messaging/messaging.gyp:*', + 'networkbearerselection/networkbearerselection.gyp:*', 'nfc/nfc.gyp:*', 'power/power.gyp:*', 'bookmark/bookmark.gyp:*',