Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

blackberry.connection implementation - not tested yet

  • Loading branch information...
commit bec9959e435ff1463fcf4029a31bf53b3d4d3487 1 parent 6273eb6
@rwmtse rwmtse authored
View
3  .jshintrc
@@ -27,7 +27,8 @@
"screen",
"setInterval", "clearInterval", "setTimeout", "clearTimeout",
"require", "Node",
- "qnx", "chrome", "NamedNodeMap"
+ "qnx", "chrome", "NamedNodeMap",
+ "JNEXT"
],
"node" : true,
View
38 ext/blackberry.connection/client.js
@@ -0,0 +1,38 @@
+/*
+* Copyright 2012 Research In Motion Limited.
+*
+* 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.
+*/
+var _self = {},
+ _ID = "blackberry.connection";
+
+Object.defineProperty(_self, "type", {
+ get: function () {
+ return window.webworks.execSync(_ID, "type");
+ }
+});
+
+/*
+ * Define constants for type constants
+ */
+window.webworks.defineReadOnlyField(_self, "UNKNOWN", 0);
+window.webworks.defineReadOnlyField(_self, "ETHERNET", 1);
+window.webworks.defineReadOnlyField(_self, "WIFI", 2);
+window.webworks.defineReadOnlyField(_self, "BLUETOOTH_DUN", 3);
+window.webworks.defineReadOnlyField(_self, "USB", 4);
+window.webworks.defineReadOnlyField(_self, "VPN", 5);
+window.webworks.defineReadOnlyField(_self, "BB", 6);
+window.webworks.defineReadOnlyField(_self, "CELLULAR", 7);
+window.webworks.defineReadOnlyField(_self, "NONE", 8);
+
+module.exports = _self;
View
59 ext/blackberry.connection/index.js
@@ -0,0 +1,59 @@
+/*
+* Copyright 2012 Research In Motion Limited.
+*
+* 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.
+*/
+var connection;
+
+module.exports = {
+ type: function (success, fail, args) {
+ success(connection.getType());
+ }
+};
+
+///////////////////////////////////////////////////////////////////
+// JavaScript wrapper for JNEXT plugin
+///////////////////////////////////////////////////////////////////
+
+JNEXT.Connection = function ()
+{
+ var self = this;
+
+ self.getType = function () {
+ var val = JNEXT.invoke(self.m_id, "getType");
+ return val;
+ };
+
+ self.getId = function () {
+ return self.m_id;
+ };
+
+ self.init = function ()
+ {
+ if (!JNEXT.require("connection")) {
+ return false;
+ }
+
+ self.m_id = JNEXT.createObject("connection.Connection");
+
+ if (self.m_id === "") {
+ return false;
+ }
+ };
+
+ self.m_id = "";
+
+ self.init();
+};
+
+connection = new JNEXT.Connection();
View
82 ext/blackberry.connection/native/connection_bps.cpp
@@ -0,0 +1,82 @@
+/*
+* Copyright 2012 Research In Motion Limited.
+*
+* 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 "connection_bps.h"
+
+ConnectionBPS::ConnectionBPS()
+{
+ bps_initialize();
+}
+
+ConnectionBPS::~ConnectionBPS()
+{
+
+}
+
+ConnectionTypes ConnectionBPS::GetConnectionType()
+{
+ bool available;
+ char* interface;
+ netstatus_interface_details_t* details;
+ netstatus_interface_type_t type;
+ int status;
+ ConnectionTypes returnType;
+
+ netstatus_get_availability(&available);
+
+ if (available) {
+ netstatus_get_default_interface(&interface);
+ status = netstatus_get_interface_details(interface, &details);
+
+ if (status == BPS_SUCCESS) {
+ type = netstatus_interface_get_type(details);
+
+ switch (type) {
+ case NETSTATUS_INTERFACE_TYPE_UNKNOWN:
+ returnType = UNKNOWN;
+ break;
+ case NETSTATUS_INTERFACE_TYPE_WIRED:
+ returnType = ETHERNET;
+ break;
+ case NETSTATUS_INTERFACE_TYPE_WIFI:
+ returnType = WIFI;
+ break;
+ case NETSTATUS_INTERFACE_TYPE_BLUETOOTH_DUN:
+ returnType = BLUETOOTH_DUN;
+ break;
+ case NETSTATUS_INTERFACE_TYPE_USB:
+ returnType = USB;
+ break;
+ case NETSTATUS_INTERFACE_TYPE_VPN:
+ returnType = VPN;
+ break;
+ case NETSTATUS_INTERFACE_TYPE_BB:
+ returnType = BB;
+ break;
+ case NETSTATUS_INTERFACE_TYPE_CELLULAR:
+ returnType = CELLULAR;
+ break;
+ };
+
+ netstatus_free_interface_details(&details);
+ }
+ } else {
+ returnType = NONE;
+ }
+
+ return returnType;
@jengee Collaborator
jengee added a note

Right now it looks like it returns only 1 connection type. What happens if the device has more than 1 connection type on? Will it return all of them? Will it return the 1 that the device is mainly using? What's the precedence?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+}
+
+
View
41 ext/blackberry.connection/native/connection_bps.h
@@ -0,0 +1,41 @@
+/*
+* Copyright 2012 Research In Motion Limited.
+*
+* 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 <bps/bps.h>
+#include <bps/netstatus.h>
+
+#ifndef CONNECTION_BPS_H_
+#define CONNECTION_BPS_H_
+
+enum ConnectionTypes {
+ UNKNOWN = 0,
+ ETHERNET = 1,
+ WIFI = 2,
+ BLUETOOTH_DUN = 3,
+ USB = 4,
+ VPN = 5,
+ BB = 6,
+ CELLULAR = 7,
+ NONE = 8
+};
+
+class ConnectionBPS {
+public:
+ ConnectionBPS();
+ ~ConnectionBPS();
+ ConnectionTypes GetConnectionType();
+};
+
+#endif /* CONNECTION_BPS_H_ */
View
53 ext/blackberry.connection/native/connection_js.cpp
@@ -0,0 +1,53 @@
+/*
+* Copyright 2012 Research In Motion Limited.
+*
+* 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 "connection_js.h"
+
+Connection::Connection(const std::string& id) : m_id(id)
+{
+
+}
+
+char* onGetObjList()
+{
+ static char name[] = "Connection";
+ return name;
+}
+
+JSExt* onCreateObject(const std::string& className, const std::string& id)
+{
+ if (className != "Connection") {
+ return NULL;
+ }
+
+ return new Connection(id);
+}
+
+std::string Connection::InvokeMethod(const std::string& command)
+{
+ int index = command.find_first_of(" ");
+
+ string strCommand = command.substr(0, index);
+ string jsonObject = command.substr(index + 1, command.length());
+ string returnValue;
+
+ if (strCommand == "getType") {
+ ConnectionBPS *connection = new ConnectionBPS();
+ itoa(connection->GetConnectionType(), returnValue.c_str(), 10);
+ }
+
+ return returnValue;
+}
+
View
33 ext/blackberry.connection/native/connection_js.h
@@ -0,0 +1,33 @@
+/*
+* Copyright 2012 Research In Motion Limited.
+*
+* 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 "../common/plugin.h"
+#include <string>
+
+#ifndef CONNECTION_JS_H_
+#define CONNECTION_JS_H_
+
+class Connection : public JSExt
+{
+public:
+ Connection(const std::string& id);
+ virtual ~Connection() {}
+ virtual std::String InvokeMethod(const std::string& command);
+ virtual bool CanDelete() { return true; }
+private:
+ std::string m_id;
+};
+
+#endif /* CONNECTION_JS_H_ */
Please sign in to comment.
Something went wrong with that request. Please try again.