[NetworkBearerSelection] Initial implementation
authorPawel Kaczmarek <p.kaczmarek3@samsung.com>
Mon, 2 Feb 2015 15:56:19 +0000 (16:56 +0100)
committerRafal Galka <r.galka@samsung.com>
Tue, 3 Feb 2015 09:45:21 +0000 (18:45 +0900)
[Verification]
console.log(typeof tizen.networkbearerselection);
should return object

Change-Id: I33110f8ebc94d8990d0a1fad713679080d22eac2
Signed-off-by: Pawel Kaczmarek <p.kaczmarek3@samsung.com>
src/networkbearerselection/networkbearerselection.gyp [new file with mode: 0644]
src/networkbearerselection/networkbearerselection_api.js [new file with mode: 0644]
src/networkbearerselection/networkbearerselection_extension.cc [new file with mode: 0644]
src/networkbearerselection/networkbearerselection_extension.h [new file with mode: 0644]
src/networkbearerselection/networkbearerselection_instance.cc [new file with mode: 0644]
src/networkbearerselection/networkbearerselection_instance.h [new file with mode: 0644]
src/tizen-wrt.gyp

diff --git a/src/networkbearerselection/networkbearerselection.gyp b/src/networkbearerselection/networkbearerselection.gyp
new file mode 100644 (file)
index 0000000..54b2c48
--- /dev/null
@@ -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 (file)
index 0000000..ca40ce4
--- /dev/null
@@ -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 (file)
index 0000000..ddc1e38
--- /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 "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 (file)
index 0000000..73011a7
--- /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 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 (file)
index 0000000..9d5d4cf
--- /dev/null
@@ -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 <functional>
+
+#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<double>(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<int>(args.get("callbackId").get<double>());
+  const std::string& domainName = args.get("domainName").get<std::string>();
+
+  // 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<int>(args.get("callbackId").get<double>());
+  const std::string& domainName = args.get("domainName").get<std::string>();
+
+  // 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 (file)
index 0000000..4aa2749
--- /dev/null
@@ -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_
index 1a320e3c768df32a4825f202a2d2374a0f98ccc2..72d4d0f5a3636caad3d05983b062c99f8788fa1e 100644 (file)
@@ -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:*',