From cae6bb1a790a50fa59a4fdbbfe4a22530c1c07b3 Mon Sep 17 00:00:00 2001 From: Pawel Andruszkiewicz Date: Thu, 7 Apr 2016 14:43:50 +0200 Subject: [PATCH] [NetworkInformation] Code structure changed to match cordova architecture. Change-Id: I0bd584511e991e1f9a59abb4f998f111f336998d Signed-off-by: Pawel Andruszkiewicz --- src/cordova-api.gyp | 1 - src/lib/cordova_plugins.js | 13 +++++ .../tizen/Connection.js | 49 +++++++++++++++++++ .../tizen/NetworkStatus.js} | 38 -------------- .../cordova_networkinformation.gyp | 25 ---------- .../cordova_networkinformation_extension.cc | 39 --------------- .../cordova_networkinformation_extension.h | 36 -------------- 7 files changed, 62 insertions(+), 139 deletions(-) create mode 100644 src/lib/plugins/cordova-plugin-network-information/tizen/Connection.js rename src/{networkinformation/cordova_networkinformation_api.js => lib/plugins/cordova-plugin-network-information/tizen/NetworkStatus.js} (69%) delete mode 100644 src/networkinformation/cordova_networkinformation.gyp delete mode 100644 src/networkinformation/cordova_networkinformation_extension.cc delete mode 100644 src/networkinformation/cordova_networkinformation_extension.h diff --git a/src/cordova-api.gyp b/src/cordova-api.gyp index af8643b..1fc74b9 100644 --- a/src/cordova-api.gyp +++ b/src/cordova-api.gyp @@ -11,7 +11,6 @@ 'cordova/cordova.gyp:*', 'file/cordova_file.gyp:*', 'globalization/cordova_globalization.gyp:*', - 'networkinformation/cordova_networkinformation.gyp:*', ], }, ], # end targets diff --git a/src/lib/cordova_plugins.js b/src/lib/cordova_plugins.js index 9d4303a..ebf0716 100644 --- a/src/lib/cordova_plugins.js +++ b/src/lib/cordova_plugins.js @@ -239,6 +239,19 @@ module.exports = [ "Connection" ] }, + { + "file": "plugins/cordova-plugin-network-information/tizen/NetworkStatus.js", + "id": "cordova-plugin-network-information.tizen.NetworkStatus", + "runs": true + }, + { + "file": "plugins/cordova-plugin-network-information/tizen/Connection.js", + "id": "cordova-plugin-network-information.tizen.Connection", + "clobbers": [ + "navigator.connection", + "navigator.network.connection" + ] + }, { "file": "plugins/cordova-plugin-globalization/www/GlobalizationError.js", "id": "cordova-plugin-globalization.GlobalizationError", diff --git a/src/lib/plugins/cordova-plugin-network-information/tizen/Connection.js b/src/lib/plugins/cordova-plugin-network-information/tizen/Connection.js new file mode 100644 index 0000000..e775328 --- /dev/null +++ b/src/lib/plugins/cordova-plugin-network-information/tizen/Connection.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TODO: remove when added to public cordova repository -> begin +var plugin_name_type = 'cordova-plugin-network-information.tizen.Connection'; + +cordova.define(plugin_name_type, function(require, exports, module) { +//TODO: remove -> end + +var exec = require('cordova/exec'); + +function NetworkConnection() { + this.type = Connection.UNKNOWN; + var that = this; + function successCallback(info) { + that.type = info; + } + + function errorCallback() { + that.type = Connection.UNKNOWN; + } + + function getType() { + exec(successCallback, errorCallback, 'NetworkStatus', 'getConnectionInfo', []); + } + + document.addEventListener('offline', getType); + document.addEventListener('online', getType); +} +var me = new NetworkConnection(); + +module.exports = me; + +//TODO: remove when added to public cordova repository -> begin +}); +// TODO: remove -> end diff --git a/src/networkinformation/cordova_networkinformation_api.js b/src/lib/plugins/cordova-plugin-network-information/tizen/NetworkStatus.js similarity index 69% rename from src/networkinformation/cordova_networkinformation_api.js rename to src/lib/plugins/cordova-plugin-network-information/tizen/NetworkStatus.js index bb013d2..c03af58 100644 --- a/src/networkinformation/cordova_networkinformation_api.js +++ b/src/lib/plugins/cordova-plugin-network-information/tizen/NetworkStatus.js @@ -90,42 +90,4 @@ console.log('Loaded cordova.networkinformation API'); // TODO: remove when added to public cordova repository -> begin }); - -var plugin_name_type = 'cordova-plugin-network-information.tizen.NetworkStatus.type'; - -cordova.define(plugin_name_type, function(require, exports, module) { //TODO: remove -> end - -var exec = require('cordova/exec'); - -function NetworkConnection() { - this.type = Connection.UNKNOWN; - var that = this; - function successCallback(info) { - that.type = info; - } - - function errorCallback() { - that.type = Connection.UNKNOWN; - } - - function getType() { - exec(successCallback, errorCallback, 'NetworkStatus', 'getConnectionInfo', []); - } - - document.addEventListener('offline', getType); - document.addEventListener('online', getType); -} -var me = new NetworkConnection(); - -module.exports = me; - -//TODO: remove when added to public cordova repository -> begin -}); - -exports = function(require) { - require('cordova-tizen').addPlugin('cordova-plugin-network-information.network', plugin_name, 'runs'); - require('cordova-tizen').addPlugin('cordova-plugin-network-information.network', plugin_name_type, 'clobbers', 'navigator.connection'); - require('cordova-tizen').addPlugin('cordova-plugin-network-information.network', plugin_name_type, 'clobbers', 'navigator.network.connection'); -}; -// TODO: remove -> end diff --git a/src/networkinformation/cordova_networkinformation.gyp b/src/networkinformation/cordova_networkinformation.gyp deleted file mode 100644 index e22a8d1..0000000 --- a/src/networkinformation/cordova_networkinformation.gyp +++ /dev/null @@ -1,25 +0,0 @@ -{ - 'includes':[ - '/usr/include/webapi-plugins/src/common/common.gypi', - ], - 'targets': [ - { - 'target_name': 'tizen_cordova_networkinformation', - 'type': 'loadable_module', - 'sources': [ - 'cordova_networkinformation_api.js', - 'cordova_networkinformation_extension.cc', - 'cordova_networkinformation_extension.h', - ], - 'include_dirs': [ - '../', - '<(SHARED_INTERMEDIATE_DIR)', - ], - 'variables': { - 'packages': [ - 'webapi-plugins', - ], - }, - }, - ], -} diff --git a/src/networkinformation/cordova_networkinformation_extension.cc b/src/networkinformation/cordova_networkinformation_extension.cc deleted file mode 100644 index fdcec2e..0000000 --- a/src/networkinformation/cordova_networkinformation_extension.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "networkinformation/cordova_networkinformation_extension.h" - -// This will be generated from cordova_networkinformation_api.js -extern const char kSource_cordova_networkinformation_api[]; - -common::Extension* CreateExtension() { - return new extension::cordova::networkinformation::CordovaNetworkInformationExtension(); -} - -namespace extension { -namespace cordova { -namespace networkinformation { - -CordovaNetworkInformationExtension::CordovaNetworkInformationExtension() { - SetExtensionName("tizen.cordova.networkinformation"); - SetJavaScriptAPI(kSource_cordova_networkinformation_api); -} - -CordovaNetworkInformationExtension::~CordovaNetworkInformationExtension() {} - -} // networkinformation -} // cordova -} // extension diff --git a/src/networkinformation/cordova_networkinformation_extension.h b/src/networkinformation/cordova_networkinformation_extension.h deleted file mode 100644 index 3168b57..0000000 --- a/src/networkinformation/cordova_networkinformation_extension.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NETWORKINFORMATION_CORDOVA_NETWORKINFORMATION_EXTENSION_H_ -#define NETWORKINFORMATION_CORDOVA_NETWORKINFORMATION_EXTENSION_H_ - -#include - -namespace extension { -namespace cordova { -namespace networkinformation { - -class CordovaNetworkInformationExtension : public common::Extension { - public: - CordovaNetworkInformationExtension(); - virtual ~CordovaNetworkInformationExtension(); -}; - -} // networkinformation -} // cordova -} // extension - -#endif // NETWORKINFORMATION_CORDOVA_NETWORKINFORMATION_EXTENSION_H_ -- 2.34.1