summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author <philippe colliot>2016-03-18 17:57:41 +0100
committer <philippe colliot>2016-03-18 17:57:41 +0100
commit9cc597d1dc2252695baa9ca6bf46aa7ebc6707d3 (patch)
treeb8c72d9b14b67825b91658a66f8c89aec21ec063
parent2658eef26ffcabfeee9450bb5fef8c52c618447b (diff)
downloadpoi-service-9cc597d1dc2252695baa9ca6bf46aa7ebc6707d3.tar.gz
Keep on working on W3C POC, still issue with DBus signal
-rw-r--r--test/navigation/w3c/socket-based-poc/README.md7
-rw-r--r--test/navigation/w3c/socket-based-poc/navigation-settings-language-and-units.html42
-rw-r--r--test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreConfigurationWrapper.cpp272
-rw-r--r--test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreConfigurationWrapper.hpp (renamed from test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreWrapper.hpp)15
-rw-r--r--test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreWrapper.cpp266
-rw-r--r--test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/POIServiceWrapper.cpp23
-rw-r--r--test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/PositioningWrapper.cpp23
-rw-r--r--test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/binding.gyp4
-rw-r--r--test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/dbus-proxies/NavigationCoreProxy.cpp21
-rw-r--r--test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/dbus-proxies/NavigationCoreProxy.hpp16
-rw-r--r--test/navigation/w3c/socket-based-poc/server.js43
11 files changed, 394 insertions, 338 deletions
diff --git a/test/navigation/w3c/socket-based-poc/README.md b/test/navigation/w3c/socket-based-poc/README.md
index 1e86d9d..fafae64 100644
--- a/test/navigation/w3c/socket-based-poc/README.md
+++ b/test/navigation/w3c/socket-based-poc/README.md
@@ -1,7 +1,12 @@
Preliminary code for testing the implementation of a set of navigation Web API based on GENIVI API
Technology used: nodejs
-To get nodejs:
+To get a given version of nodejs (e.g. 0.12):
+curl -sL https://deb.nodesource.com/setup_0.12 | sudo -E bash
+sudo apt-get install -y nodejs
+NB: not supported by my trusty :-(
+
+For the time being, version is v0.10.25:
sudo apt-get install nodejs npm
npm install -g node-gyp
diff --git a/test/navigation/w3c/socket-based-poc/navigation-settings-language-and-units.html b/test/navigation/w3c/socket-based-poc/navigation-settings-language-and-units.html
index 822381b..d474200 100644
--- a/test/navigation/w3c/socket-based-poc/navigation-settings-language-and-units.html
+++ b/test/navigation/w3c/socket-based-poc/navigation-settings-language-and-units.html
@@ -58,13 +58,20 @@ socket.on('navigationcore_answer', function(message) {
} else {
if(message.request === 'getUnitsOfMeasurement')
{
- alert('Message received from the server : ' +message.answer.length+ message.answer[0].key+ message.answer[0].value);
- }
+ getUnitsOfMeasurementReturn(message.answer);
+ }
}
}
}
})
+socket.on('navigationcore_signal', function(message) {
+ if(message.signal === 'configurationChanged')
+ {
+ configurationChanged(message.data);
+ }
+})
+
<!-- initialization -->
var today=new Date();
document.getElementById("start_time").innerHTML=today;
@@ -86,7 +93,7 @@ getUnitsOfMeasurement();
getLocale();
-<!-- middleware abstraction layer -->
+<!-- getters -->
function getVersion() {
socket.emit('navigationcore_request', {interface: 'NavigationCoreConfiguration', method: 'getVersion', parameters: []});
}
@@ -122,21 +129,23 @@ function getSupportedLocalesReturn(answer) {
function getUnitsOfMeasurement() {
socket.emit('navigationcore_request', {interface: 'NavigationCoreConfiguration', method: 'getUnitsOfMeasurement', parameters: []});
}
-
-function configurationChanged(changedSettings) {
-getLocale();
+function getUnitsOfMeasurementReturn(answer) {
}
+<!-- setters -->
function setLocale(button) {
- var data = {
- property : 'Locale',
- languageCode : supportedLocales[button.value].languageCode,
- countryCode : supportedLocales[button.value].countryCode,
- scriptCode : supportedLocales[button.value].scriptCode,
- callBack : configurationChanged()
- };
-
- socket.emit('navigationcore_request', {interface: 'NavigationCoreConfiguration', method: 'setProperty', parameters: data});
+ var data = {
+ property : 'Locale',
+ languageCode : supportedLocales[button.value].languageCode,
+ countryCode : supportedLocales[button.value].countryCode,
+ scriptCode : supportedLocales[button.value].scriptCode
+ };
+ socket.emit('navigationcore_request', {interface: 'NavigationCoreConfiguration', method: 'setProperty', parameters: data});
+}
+
+<!-- signals -->
+function configurationChanged(changedSettings) {
+ getLocale();
}
<!-- some other functions -->
@@ -151,7 +160,6 @@ function addLocaleListButtons( div, num_buttons ) {
newdiv.innerHTML = buttons;
div.appendChild(newdiv);
}
-
function enhanceLocaleButton(id) {
for ( var i=0; i<supportedLocales.length; i++ ) {
document.getElementById(supportedLocales[i].countryCode).style.width = "104px";
@@ -160,7 +168,6 @@ function enhanceLocaleButton(id) {
document.getElementById(id).style.width = "124px";
document.getElementById(id).style.height = "76px";
}
-
function addLocale(language, country,script,flag) {
supportedLocales.push({
languageCode: language,
@@ -169,6 +176,7 @@ function addLocale(language, country,script,flag) {
flagUrl: flag,
});
}
+
</script>
</body>
</html>
diff --git a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreConfigurationWrapper.cpp b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreConfigurationWrapper.cpp
new file mode 100644
index 0000000..811431b
--- /dev/null
+++ b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreConfigurationWrapper.cpp
@@ -0,0 +1,272 @@
+/**
+* @licence app begin@
+* SPDX-License-Identifier: MPL-2.0
+*
+* \copyright Copyright (C) 2016, PCA Peugeot Citroen
+*
+* \file main.cpp
+*
+* \brief This file is part of the Navigation Web API proof of concept.
+*
+* \author Philippe Colliot <philippe.colliot@mpsa.com>
+*
+* \version 0.1
+*
+* This Source Code Form is subject to the terms of the
+* Mozilla Public License (MPL), v. 2.0.
+* If a copy of the MPL was not distributed with this file,
+* You can obtain one at http://mozilla.org/MPL/2.0/.
+*
+* For further information see http://www.genivi.org/.
+*
+* List of changes:
+* <date>, <name>, <description of change>
+*
+* @licence end@
+*/
+#include <node.h>
+
+#include "NavigationCoreConfigurationWrapper.hpp"
+
+
+v8::Persistent<v8::FunctionTemplate> NavigationCoreConfigurationWrapper::constructor;
+v8::Persistent<v8::Function> NavigationCoreConfigurationWrapper::callbackConfigurationChanged;
+
+void NavigationCoreConfigurationWrapper::ConfigurationChanged(const std::vector< int32_t >& changedSettings) {
+ v8::HandleScope scope;
+
+ const unsigned argc = changedSettings.size();
+ v8::Local<v8::Value> argv[argc];
+ for(unsigned i=0;i<changedSettings.size();i++)
+ {
+ argv[i]=v8::Int32::New(changedSettings.at(i));
+ }
+
+ callbackConfigurationChanged->Call(v8::Context::GetCurrent()->Global(), argc, argv);
+}
+
+void NavigationCoreConfigurationWrapper::Init(v8::Handle<v8::Object> target) {
+ v8::HandleScope scope;
+
+ v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(New);
+ v8::Local<v8::String> name = v8::String::NewSymbol("NavigationCoreConfigurationWrapper");
+
+ constructor = v8::Persistent<v8::FunctionTemplate>::New(tpl);
+ // ObjectWrap uses the first internal field to store the wrapped pointer.
+ constructor->InstanceTemplate()->SetInternalFieldCount(1);
+ constructor->SetClassName(name);
+
+ // Add all prototype methods, getters and setters here.
+ NODE_SET_PROTOTYPE_METHOD(constructor, "getVersion", GetVersion);
+ NODE_SET_PROTOTYPE_METHOD(constructor, "getSupportedLocales", GetSupportedLocales);
+ NODE_SET_PROTOTYPE_METHOD(constructor, "getProperty", GetProperty);
+ NODE_SET_PROTOTYPE_METHOD(constructor, "setProperty", SetProperty);
+ NODE_SET_PROTOTYPE_METHOD(constructor, "getUnitsOfMeasurement", GetUnitsOfMeasurement);
+ NODE_SET_PROTOTYPE_METHOD(constructor, "setConfigurationChangedListener", SetConfigurationChangedListener);
+
+ // This has to be last, otherwise the properties won't show up on the
+ // object in JavaScript.
+ target->Set(name, constructor->GetFunction());
+}
+
+NavigationCoreConfigurationWrapper::NavigationCoreConfigurationWrapper() {
+}
+
+NavigationCoreConfigurationWrapper::~NavigationCoreConfigurationWrapper() {
+}
+
+v8::Handle<v8::Value> NavigationCoreConfigurationWrapper::New(const v8::Arguments& args) {
+ v8::HandleScope scope;
+
+ if (!args.IsConstructCall()) {
+ return v8::ThrowException(v8::Exception::TypeError(
+ v8::String::New("Use the new operator to create instances of this object."))
+ );
+ }
+ // Creates a new instance object of this type and wraps it.
+ NavigationCoreConfigurationWrapper* obj = new NavigationCoreConfigurationWrapper();
+
+ NavigationCoreProxy* proxy = new NavigationCoreProxy(obj);
+
+ obj->mp_navigationCoreProxy = proxy;
+ obj->Wrap(args.This());
+
+ return args.This();
+}
+
+v8::Handle<v8::Value> NavigationCoreConfigurationWrapper::GetProperty(const v8::Arguments& args) {
+ v8::HandleScope scope; //to properly clean up v8 handles
+
+ if (args.Length() < 1) {
+ return v8::ThrowException(
+ v8::Exception::TypeError(v8::String::New("getProperty requires at least 1 argument"))
+ );
+ }
+ v8::String::Utf8Value str(args[0]->ToString());
+ std::string propertyName = std::string(*str);
+
+ if(propertyName == "Locale") {
+ // Retrieves the pointer to the wrapped object instance.
+ NavigationCoreConfigurationWrapper* obj = ObjectWrap::Unwrap<NavigationCoreConfigurationWrapper>(args.This());
+
+ v8::Local<v8::Object> ret = v8::Object::New();
+ Locale localeValue;
+ obj->mp_navigationCoreProxy->mp_navigationCoreConfigurationProxy->GetLocale(localeValue.languageCode,localeValue.countryCode,localeValue.scriptCode);
+ ret->Set( 0, v8::String::New(propertyName.c_str()) );
+ ret->Set( 1, v8::String::New(localeValue.languageCode.c_str()) );
+ ret->Set( 2, v8::String::New(localeValue.countryCode.c_str()) );
+ ret->Set( 3, v8::String::New(localeValue.scriptCode.c_str()) );
+ return scope.Close(ret);
+ }
+ else
+ {
+ if(propertyName == "TimeFormat") {
+ // Retrieves the pointer to the wrapped object instance.
+ NavigationCoreConfigurationWrapper* obj = ObjectWrap::Unwrap<NavigationCoreConfigurationWrapper>(args.This());
+
+ v8::Local<v8::Object> ret = v8::Object::New();
+
+ return scope.Close(ret);
+ }
+ else
+ {
+ if(propertyName == "CoordinatesFormat") {
+ // Retrieves the pointer to the wrapped object instance.
+ NavigationCoreConfigurationWrapper* obj = ObjectWrap::Unwrap<NavigationCoreConfigurationWrapper>(args.This());
+
+ v8::Local<v8::Object> ret = v8::Object::New();
+
+ return scope.Close(ret);
+ }
+ }
+ }
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> NavigationCoreConfigurationWrapper::SetProperty(const v8::Arguments& args)
+{
+ v8::HandleScope scope; //to properly clean up v8 handles
+
+ if (args.Length() < 1) {
+ return v8::ThrowException(
+ v8::Exception::TypeError(v8::String::New("setProperty requires at least 1 argument"))
+ );
+ }
+ v8::Handle<v8::Object> property_obj = v8::Handle<v8::Object>::Cast(args[0]);
+
+ v8::Handle<v8::Value> property = property_obj->Get(v8::String::New("property"));
+
+ v8::String::Utf8Value str(property->ToString());
+
+ if(std::string(*str) == "Locale")
+ {
+ Locale localeValue;
+ v8::Handle<v8::Value> languageCodeValue = property_obj->Get(v8::String::New("languageCode"));
+ v8::String::Utf8Value languageCode(languageCodeValue->ToString());
+ localeValue.languageCode = std::string(*languageCode);
+ v8::Handle<v8::Value> countryCodeValue = property_obj->Get(v8::String::New("countryCode"));
+ v8::String::Utf8Value countryCode(countryCodeValue->ToString());
+ localeValue.countryCode = std::string(*countryCode);
+ v8::Handle<v8::Value> scriptCodeValue = property_obj->Get(v8::String::New("scriptCode"));
+ v8::String::Utf8Value scriptCode(scriptCodeValue->ToString());
+ localeValue.scriptCode = std::string(*scriptCode);
+
+ // Retrieves the pointer to the wrapped object instance.
+ NavigationCoreConfigurationWrapper* obj = ObjectWrap::Unwrap<NavigationCoreConfigurationWrapper>(args.This());
+ obj->mp_navigationCoreProxy->mp_navigationCoreConfigurationProxy->SetLocale(localeValue.languageCode,localeValue.countryCode,localeValue.scriptCode);
+ }
+
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> NavigationCoreConfigurationWrapper::GetVersion(const v8::Arguments& args) {
+ v8::HandleScope scope; //to properly clean up v8 handles
+
+ // Retrieves the pointer to the wrapped object instance.
+ NavigationCoreConfigurationWrapper* obj = ObjectWrap::Unwrap<NavigationCoreConfigurationWrapper>(args.This());
+
+ ::DBus::Struct< uint16_t, uint16_t, uint16_t, std::string > DBus_version = obj->mp_navigationCoreProxy->mp_navigationCoreConfigurationProxy->GetVersion();
+
+ v8::Local<v8::Object> ret = v8::Object::New();
+ ret->Set( 0, v8::Int32::New(DBus_version._1) );
+ ret->Set( 1, v8::Int32::New(DBus_version._2) );
+ ret->Set( 2, v8::Int32::New(DBus_version._3) );
+ ret->Set( 3, v8::String::New(DBus_version._4.c_str()) );
+
+ return scope.Close(ret);
+}
+
+v8::Handle<v8::Value> NavigationCoreConfigurationWrapper::GetSupportedLocales(const v8::Arguments& args) {
+ v8::HandleScope scope; //to properly clean up v8 handles
+
+ // Retrieves the pointer to the wrapped object instance.
+ NavigationCoreConfigurationWrapper* obj = ObjectWrap::Unwrap<NavigationCoreConfigurationWrapper>(args.This());
+
+ std::vector< ::DBus::Struct< std::string, std::string, std::string > > localeList = obj->mp_navigationCoreProxy->mp_navigationCoreConfigurationProxy->GetSupportedLocales();
+
+ v8::Local<v8::Array> ret = v8::Array::New();
+ for (unsigned i=0;i<localeList.size();i++)
+ {
+ v8::Local<v8::Object> data = v8::Object::New();
+ data->Set( 0, v8::String::New(localeList.at(i)._1.c_str()) );
+ data->Set( 1, v8::String::New(localeList.at(i)._2.c_str()) );
+ data->Set( 2, v8::String::New(localeList.at(i)._3.c_str()) );
+ ret->Set(ret->Length(), data);
+ }
+
+ return scope.Close(ret);
+}
+
+v8::Handle<v8::Value> NavigationCoreConfigurationWrapper::GetUnitsOfMeasurement(const v8::Arguments& args)
+{
+ v8::HandleScope scope; //to properly clean up v8 handles
+
+ // Retrieves the pointer to the wrapped object instance.
+ NavigationCoreConfigurationWrapper* obj = ObjectWrap::Unwrap<NavigationCoreConfigurationWrapper>(args.This());
+
+ NavigationCoreConfigurationProxy::UnitsOfMeasurement unitsOfMeasurement = obj->mp_navigationCoreProxy->mp_navigationCoreConfigurationProxy->GetUnitsOfMeasurement();
+
+ v8::Local<v8::Array> ret = v8::Array::New();
+ for (NavigationCoreConfigurationProxy::UnitsOfMeasurement::iterator iter = unitsOfMeasurement.begin(); iter != unitsOfMeasurement.end(); iter++) {
+ v8::Local<v8::Object> data = v8::Object::New();
+ NavigationCoreConfigurationProxy::UnitsOfMeasurementValueStruct unitsOfMeasurement;
+ unitsOfMeasurement = iter->second;
+ data->Set(v8::String::New("key"), v8::Int32::New(iter->first));
+ switch (unitsOfMeasurement.type) {
+ case NavigationCoreConfigurationProxy::intValue:
+ data->Set(v8::String::New("value"), v8::Int32::New(unitsOfMeasurement.value.intValue));
+ break;
+ case NavigationCoreConfigurationProxy::doubleValue:
+ default:
+ data->Set(v8::String::New("value"), v8::Number::New(unitsOfMeasurement.value.doubleValue));
+ break;
+ }
+ ret->Set(ret->Length(), data);
+ }
+ return scope.Close(ret);
+}
+
+v8::Handle<v8::Value> NavigationCoreConfigurationWrapper::SetConfigurationChangedListener(const v8::Arguments& args)
+{
+ v8::HandleScope scope; //to properly clean up v8 handles
+
+ if (!args[0]->IsFunction()) {
+ return v8::ThrowException(
+ v8::Exception::TypeError(v8::String::New("SetConfigurationChangedListener requires a function as parameter"))
+ );
+ }
+
+ v8::Persistent<v8::Function> callback(v8::Local<v8::Function>::Cast(args[0]));
+ callbackConfigurationChanged = callback;
+
+ v8::Local<v8::Object> ret = v8::Object::New();
+ ret->Set( 0, v8::Boolean::New(callbackConfigurationChanged->IsFunction()) );
+
+ return scope.Close(ret);
+}
+
+void RegisterModule(v8::Handle<v8::Object> target) {
+ NavigationCoreConfigurationWrapper::Init(target);
+}
+
+NODE_MODULE(NavigationCoreConfigurationWrapper, RegisterModule);
diff --git a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreWrapper.hpp b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreConfigurationWrapper.hpp
index af08bee..e8cf65a 100644
--- a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreWrapper.hpp
+++ b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreConfigurationWrapper.hpp
@@ -43,14 +43,17 @@
// header file.
// using namespace v8;
-class NavigationCoreWrapper : public node::ObjectWrap {
+class NavigationCoreConfigurationWrapper : public node::ObjectWrap {
+ friend void NavigationCoreProxy::ConfigurationChanged(const std::vector< int32_t >& changedSettings);
+
public:
static v8::Persistent<v8::FunctionTemplate> constructor;
static void Init(v8::Handle<v8::Object> target);
+ static v8::Persistent<v8::Function> callbackConfigurationChanged;
protected:
- NavigationCoreWrapper();
- ~NavigationCoreWrapper();
+ NavigationCoreConfigurationWrapper();
+ ~NavigationCoreConfigurationWrapper();
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> GetVersion(const v8::Arguments& args);
@@ -60,11 +63,11 @@ protected:
static v8::Handle<v8::Value> GetProperty(const v8::Arguments& args);
static v8::Handle<v8::Value> SetProperty(const v8::Arguments& args);
- static void ConfigurationChanged(const v8::Handle<v8::Function> &callback, const v8::Handle<v8::Array>& array);
+ static v8::Handle<v8::Value> SetConfigurationChangedListener(const v8::Arguments& args);
+ static void ConfigurationChanged(const std::vector<int32_t> &changedSettings);
private:
-
- NavigationCoreProxy* mp_proxy;
+ NavigationCoreProxy* mp_navigationCoreProxy;
};
#endif
diff --git a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreWrapper.cpp b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreWrapper.cpp
deleted file mode 100644
index e48d522..0000000
--- a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreWrapper.cpp
+++ /dev/null
@@ -1,266 +0,0 @@
-/**
-* @licence app begin@
-* SPDX-License-Identifier: MPL-2.0
-*
-* \copyright Copyright (C) 2016, PCA Peugeot Citroen
-*
-* \file main.cpp
-*
-* \brief This file is part of the Navigation Web API proof of concept.
-*
-* \author Philippe Colliot <philippe.colliot@mpsa.com>
-*
-* \version 0.1
-*
-* This Source Code Form is subject to the terms of the
-* Mozilla Public License (MPL), v. 2.0.
-* If a copy of the MPL was not distributed with this file,
-* You can obtain one at http://mozilla.org/MPL/2.0/.
-*
-* For further information see http://www.genivi.org/.
-*
-* List of changes:
-* <date>, <name>, <description of change>
-*
-* @licence end@
-*/
-#include <node.h>
-
-#include "NavigationCoreWrapper.hpp"
-
-using namespace v8;
-using namespace std;
-
-
-Persistent<FunctionTemplate> NavigationCoreWrapper::constructor;
-
-void NavigationCoreWrapper::ConfigurationChanged(const Handle<Function>& callback, const Handle<Array>& array) {
- HandleScope scope;
- // In case the operation succeeded, convention is to pass null as the
- // first argument before the result arguments.
- const unsigned argc = array->Length() + 1;
- Local<Value> argv[argc];
- argv[0] = Local<Value>::New(Null());
-
- String::Utf8Value str(argv[argc]->ToString());
-
- // Note: When calling this in an asynchronous function that just returned
- // from the threadpool, you have to wrap this in a v8::TryCatch.
- // You can also pass another handle as the "this" parameter.
- callback->Call(Context::GetCurrent()->Global(), argc, argv);
-}
-
-void NavigationCoreWrapper::Init(Handle<Object> target) {
- HandleScope scope;
-
- Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
- Local<String> name = String::NewSymbol("NavigationCoreWrapper");
-
- constructor = Persistent<FunctionTemplate>::New(tpl);
- // ObjectWrap uses the first internal field to store the wrapped pointer.
- constructor->InstanceTemplate()->SetInternalFieldCount(1);
- constructor->SetClassName(name);
-
- // Add all prototype methods, getters and setters here.
- NODE_SET_PROTOTYPE_METHOD(constructor, "getVersion", GetVersion);
- NODE_SET_PROTOTYPE_METHOD(constructor, "getSupportedLocales", GetSupportedLocales);
- NODE_SET_PROTOTYPE_METHOD(constructor, "getProperty", GetProperty);
- NODE_SET_PROTOTYPE_METHOD(constructor, "setProperty", SetProperty);
- NODE_SET_PROTOTYPE_METHOD(constructor, "getUnitsOfMeasurement", GetUnitsOfMeasurement);
-
- // This has to be last, otherwise the properties won't show up on the
- // object in JavaScript.
- target->Set(name, constructor->GetFunction());
-}
-
-NavigationCoreWrapper::NavigationCoreWrapper() {
-}
-
-NavigationCoreWrapper::~NavigationCoreWrapper() {
-}
-
-Handle<Value> NavigationCoreWrapper::New(const Arguments& args) {
- HandleScope scope;
-
- if (!args.IsConstructCall()) {
- return ThrowException(Exception::TypeError(
- String::New("Use the new operator to create instances of this object."))
- );
- }
- NavigationCoreProxy* proxy = new NavigationCoreProxy();
-
- // Creates a new instance object of this type and wraps it.
- NavigationCoreWrapper* obj = new NavigationCoreWrapper();
- obj->mp_proxy = proxy;
- obj->Wrap(args.This());
-
- return args.This();
-}
-
-Handle<Value> NavigationCoreWrapper::GetProperty(const Arguments& args) {
- HandleScope scope; //to properly clean up v8 handles
-
- if (args.Length() < 1) {
- return ThrowException(
- Exception::TypeError(String::New("getProperty requires at least 1 argument"))
- );
- }
- String::Utf8Value str(args[0]->ToString());
- string propertyName = std::string(*str);
-
- if(propertyName == "Locale") {
- // Retrieves the pointer to the wrapped object instance.
- NavigationCoreWrapper* obj = ObjectWrap::Unwrap<NavigationCoreWrapper>(args.This());
-
- Local<Object> ret = Object::New();
- Locale localeValue;
- obj->mp_proxy->mp_configurationProxy->GetLocale(localeValue.languageCode,localeValue.countryCode,localeValue.scriptCode);
- ret->Set( 0, String::New(propertyName.c_str()) );
- ret->Set( 1, String::New(localeValue.languageCode.c_str()) );
- ret->Set( 2, String::New(localeValue.countryCode.c_str()) );
- ret->Set( 3, String::New(localeValue.scriptCode.c_str()) );
- return scope.Close(ret);
- }
- else
- {
- if(propertyName == "TimeFormat") {
- // Retrieves the pointer to the wrapped object instance.
- NavigationCoreWrapper* obj = ObjectWrap::Unwrap<NavigationCoreWrapper>(args.This());
-
- Local<Object> ret = Object::New();
-
- return scope.Close(ret);
- }
- else
- {
- if(propertyName == "CoordinatesFormat") {
- // Retrieves the pointer to the wrapped object instance.
- NavigationCoreWrapper* obj = ObjectWrap::Unwrap<NavigationCoreWrapper>(args.This());
-
- Local<Object> ret = Object::New();
-
- return scope.Close(ret);
- }
- }
- }
- return Undefined();
-}
-
-Handle<Value> NavigationCoreWrapper::SetProperty(const Arguments& args)
-{
- HandleScope scope; //to properly clean up v8 handles
-
- if (args.Length() < 1) {
- return ThrowException(
- Exception::TypeError(String::New("setProperty requires at least 1 argument"))
- );
- }
- Handle<Object> property_obj = Handle<Object>::Cast(args[0]);
-
- Handle<Value> property = property_obj->Get(String::New("property"));
-
- String::Utf8Value str(property->ToString());
-
- if(std::string(*str) == "Locale")
- {
- Locale localeValue;
- Handle<Value> languageCodeValue = property_obj->Get(String::New("languageCode"));
- String::Utf8Value languageCode(languageCodeValue->ToString());
- localeValue.languageCode = std::string(*languageCode);
- Handle<Value> countryCodeValue = property_obj->Get(String::New("countryCode"));
- String::Utf8Value countryCode(countryCodeValue->ToString());
- localeValue.countryCode = std::string(*countryCode);
- Handle<Value> scriptCodeValue = property_obj->Get(String::New("scriptCode"));
- String::Utf8Value scriptCode(scriptCodeValue->ToString());
- localeValue.scriptCode = std::string(*scriptCode);
-
- // Retrieves the pointer to the wrapped object instance.
- NavigationCoreWrapper* obj = ObjectWrap::Unwrap<NavigationCoreWrapper>(args.This());
- obj->mp_proxy->mp_configurationProxy->SetLocale(localeValue.languageCode,localeValue.countryCode,localeValue.scriptCode);
-
- Handle<Value> callBackValue = property_obj->Get(String::New("callBack"));
-
- if (callBackValue->IsFunction()) { //callback used
- Handle<Function> callBackFunction = Handle<Function>::Cast(callBackValue);
- Handle<Array> array = Array::New(1);
- Local<String> v = String::New("LOCALE");
- array->Set(0, v);
- ConfigurationChanged(callBackFunction,array);
- }
- }
-
- return Undefined();
-}
-
-Handle<Value> NavigationCoreWrapper::GetVersion(const Arguments& args) {
- HandleScope scope; //to properly clean up v8 handles
-
- // Retrieves the pointer to the wrapped object instance.
- NavigationCoreWrapper* obj = ObjectWrap::Unwrap<NavigationCoreWrapper>(args.This());
-
- ::DBus::Struct< uint16_t, uint16_t, uint16_t, std::string > DBus_version = obj->mp_proxy->mp_configurationProxy->GetVersion();
-
- Local<Object> ret = Object::New();
- ret->Set( 0, Int32::New(DBus_version._1) );
- ret->Set( 1, Int32::New(DBus_version._2) );
- ret->Set( 2, Int32::New(DBus_version._3) );
- ret->Set( 3, String::New(DBus_version._4.c_str()) );
-
- return scope.Close(ret);
-}
-
-Handle<Value> NavigationCoreWrapper::GetSupportedLocales(const Arguments& args) {
- HandleScope scope; //to properly clean up v8 handles
-
- // Retrieves the pointer to the wrapped object instance.
- NavigationCoreWrapper* obj = ObjectWrap::Unwrap<NavigationCoreWrapper>(args.This());
-
- std::vector< ::DBus::Struct< std::string, std::string, std::string > > localeList = obj->mp_proxy->mp_configurationProxy->GetSupportedLocales();
-
- Local<Array> ret = Array::New();
- for (unsigned i=0;i<localeList.size();i++)
- {
- Local<Object> data = Object::New();
- data->Set( 0, String::New(localeList.at(i)._1.c_str()) );
- data->Set( 1, String::New(localeList.at(i)._2.c_str()) );
- data->Set( 2, String::New(localeList.at(i)._3.c_str()) );
- ret->Set(ret->Length(), data);
- }
-
- return scope.Close(ret);
-}
-
-Handle<Value> NavigationCoreWrapper::GetUnitsOfMeasurement(const Arguments& args)
-{
- HandleScope scope; //to properly clean up v8 handles
-
- // Retrieves the pointer to the wrapped object instance.
- NavigationCoreWrapper* obj = ObjectWrap::Unwrap<NavigationCoreWrapper>(args.This());
-
- NavigationCoreConfigurationProxy::UnitsOfMeasurement unitsOfMeasurement = obj->mp_proxy->mp_configurationProxy->GetUnitsOfMeasurement();
-
- Local<Array> ret = Array::New();
- for (NavigationCoreConfigurationProxy::UnitsOfMeasurement::iterator iter = unitsOfMeasurement.begin(); iter != unitsOfMeasurement.end(); iter++) {
- Local<Object> data = Object::New();
- NavigationCoreConfigurationProxy::UnitsOfMeasurementValueStruct unitsOfMeasurement;
- unitsOfMeasurement = iter->second;
- data->Set(String::New("key"), Int32::New(iter->first));
- switch (unitsOfMeasurement.type) {
- case NavigationCoreConfigurationProxy::intValue:
- data->Set(String::New("value"), Int32::New(unitsOfMeasurement.value.intValue));
- break;
- case NavigationCoreConfigurationProxy::doubleValue:
- default:
- data->Set(String::New("value"), Number::New(unitsOfMeasurement.value.doubleValue));
- break;
- }
- ret->Set(ret->Length(), data);
- }
- return scope.Close(ret);
-}
-
-void RegisterModule(Handle<Object> target) {
- NavigationCoreWrapper::Init(target);
-}
-
-NODE_MODULE(NavigationCoreWrapper, RegisterModule);
diff --git a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/POIServiceWrapper.cpp b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/POIServiceWrapper.cpp
index 776f17f..a11cfa6 100644
--- a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/POIServiceWrapper.cpp
+++ b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/POIServiceWrapper.cpp
@@ -28,20 +28,19 @@
#include "POIServiceWrapper.hpp"
-using namespace v8;
using namespace std;
-Persistent<FunctionTemplate> POIServiceWrapper::constructor;
+v8::Persistent<v8::FunctionTemplate> POIServiceWrapper::constructor;
-void POIServiceWrapper::Init(Handle<Object> target) {
- HandleScope scope;
+void POIServiceWrapper::Init(v8::Handle<v8::Object> target) {
+ v8::HandleScope scope;
- Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
- Local<String> name = String::NewSymbol("POIServiceWrapper");
+ v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(New);
+ v8::Local<v8::String> name = v8::String::NewSymbol("POIServiceWrapper");
- constructor = Persistent<FunctionTemplate>::New(tpl);
+ constructor = v8::Persistent<v8::FunctionTemplate>::New(tpl);
// ObjectWrap uses the first internal field to store the wrapped pointer.
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(name);
@@ -59,12 +58,12 @@ POIServiceWrapper::POIServiceWrapper() {
POIServiceWrapper::~POIServiceWrapper() {
}
-Handle<Value> POIServiceWrapper::New(const Arguments& args) {
- HandleScope scope;
+v8::Handle<v8::Value> POIServiceWrapper::New(const v8::Arguments& args) {
+ v8::HandleScope scope;
if (!args.IsConstructCall()) {
- return ThrowException(Exception::TypeError(
- String::New("Use the new operator to create instances of this object."))
+ return v8::ThrowException(v8::Exception::TypeError(
+ v8::String::New("Use the new operator to create instances of this object."))
);
}
POIServiceProxy* proxy = new POIServiceProxy();
@@ -77,7 +76,7 @@ Handle<Value> POIServiceWrapper::New(const Arguments& args) {
return args.This();
}
-void RegisterModule(Handle<Object> target) {
+void RegisterModule(v8::Handle<v8::Object> target) {
POIServiceWrapper::Init(target);
}
diff --git a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/PositioningWrapper.cpp b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/PositioningWrapper.cpp
index a4c163e..3b95352 100644
--- a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/PositioningWrapper.cpp
+++ b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/PositioningWrapper.cpp
@@ -28,20 +28,19 @@
#include "PositioningWrapper.hpp"
-using namespace v8;
using namespace std;
-Persistent<FunctionTemplate> PositioningWrapper::constructor;
+v8::Persistent<v8::FunctionTemplate> PositioningWrapper::constructor;
-void PositioningWrapper::Init(Handle<Object> target) {
- HandleScope scope;
+void PositioningWrapper::Init(v8::Handle<v8::Object> target) {
+ v8::HandleScope scope;
- Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
- Local<String> name = String::NewSymbol("PositioningWrapper");
+ v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(New);
+ v8::Local<v8::String> name = v8::String::NewSymbol("PositioningWrapper");
- constructor = Persistent<FunctionTemplate>::New(tpl);
+ constructor = v8::Persistent<v8::FunctionTemplate>::New(tpl);
// ObjectWrap uses the first internal field to store the wrapped pointer.
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(name);
@@ -59,12 +58,12 @@ PositioningWrapper::PositioningWrapper() {
PositioningWrapper::~PositioningWrapper() {
}
-Handle<Value> PositioningWrapper::New(const Arguments& args) {
- HandleScope scope;
+v8::Handle<v8::Value> PositioningWrapper::New(const v8::Arguments& args) {
+ v8::HandleScope scope;
if (!args.IsConstructCall()) {
- return ThrowException(Exception::TypeError(
- String::New("Use the new operator to create instances of this object."))
+ return v8::ThrowException(v8::Exception::TypeError(
+ v8::String::New("Use the new operator to create instances of this object."))
);
}
PositioningProxy* proxy = new PositioningProxy();
@@ -77,7 +76,7 @@ Handle<Value> PositioningWrapper::New(const Arguments& args) {
return args.This();
}
-void RegisterModule(Handle<Object> target) {
+void RegisterModule(v8::Handle<v8::Object> target) {
PositioningWrapper::Init(target);
}
diff --git a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/binding.gyp b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/binding.gyp
index 24d8eb5..061368f 100644
--- a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/binding.gyp
+++ b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/binding.gyp
@@ -10,9 +10,9 @@
'libraries': ['-ldbus-c++-1 -ldbus-1 -ldbus-c++-glib-1', '-L/usr/lib/i386-linux-gnu/']
},
{
- 'target_name': 'NavigationCoreWrapper',
+ 'target_name': 'NavigationCoreConfigurationWrapper',
'dependencies': [ 'NavigationCoreProxy' ],
- 'sources': [ './NavigationCoreWrapper.cpp' ],
+ 'sources': [ './NavigationCoreConfigurationWrapper.cpp' ],
'include_dirs': ['./','./dbus-proxies','/usr/include/dbus-c++-1/','/usr/include/glib-2.0/','/usr/lib/i386-linux-gnu/glib-2.0/include/'],
'cflags_cc': ['-Wall', '-std=gnu++11', '-fexceptions'],
'libraries': ['-ldbus-c++-1 -ldbus-1 -ldbus-c++-glib-1', '-L/usr/lib/i386-linux-gnu/']
diff --git a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/dbus-proxies/NavigationCoreProxy.cpp b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/dbus-proxies/NavigationCoreProxy.cpp
index 7e3501e..8f9f1ff 100644
--- a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/dbus-proxies/NavigationCoreProxy.cpp
+++ b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/dbus-proxies/NavigationCoreProxy.cpp
@@ -27,6 +27,7 @@
#include <node.h>
#include "NavigationCoreProxy.hpp"
+#include "../NavigationCoreConfigurationWrapper.hpp"
using namespace v8;
using namespace std;
@@ -34,11 +35,14 @@ using namespace std;
static DBus::Glib::BusDispatcher *dispatcher;
static DBus::Connection *connection;
-NavigationCoreConfigurationProxy::NavigationCoreConfigurationProxy(DBus::Connection &connection)
+NavigationCoreConfigurationProxy::NavigationCoreConfigurationProxy(DBus::Connection &connection, NavigationCoreProxy *navigationCoreProxy)
: DBus::ObjectProxy(connection,
"/org/genivi/navigationcore",
"org.genivi.navigationcore.Configuration")
{
+ printf("NavigationCoreConfigurationProxy\n");
+
+ mp_navigationCoreProxy = navigationCoreProxy;
UnitsOfMeasurementValueStruct value {intValue,METER};
@@ -47,7 +51,8 @@ NavigationCoreConfigurationProxy::NavigationCoreConfigurationProxy(DBus::Connect
void NavigationCoreConfigurationProxy::ConfigurationChanged(const std::vector< int32_t >& changedSettings)
{
-
+ printf("ConfigurationChanged\n");
+ mp_navigationCoreProxy->ConfigurationChanged(changedSettings);
}
NavigationCoreConfigurationProxy::UnitsOfMeasurement NavigationCoreConfigurationProxy::GetUnitsOfMeasurement()
@@ -55,19 +60,25 @@ NavigationCoreConfigurationProxy::UnitsOfMeasurement NavigationCoreConfiguration
return m_units_of_measurement;
}
-NavigationCoreProxy::NavigationCoreProxy()
+NavigationCoreProxy::NavigationCoreProxy(NavigationCoreConfigurationWrapper *navigationCoreConfigurationWrapper)
{
dispatcher = new DBus::Glib::BusDispatcher();
DBus::default_dispatcher = dispatcher;
dispatcher->attach(NULL);
connection = new DBus::Connection(DBus::Connection::SessionBus());
connection->setup(dispatcher);
- mp_configurationProxy = new NavigationCoreConfigurationProxy(*connection);
+ mp_navigationCoreConfigurationWrapper = navigationCoreConfigurationWrapper;
+ mp_navigationCoreConfigurationProxy = new NavigationCoreConfigurationProxy(*connection,this);
}
NavigationCoreProxy::~NavigationCoreProxy()
{
- delete mp_configurationProxy;
+ delete mp_navigationCoreConfigurationProxy;
delete connection;
delete dispatcher;
}
+
+void NavigationCoreProxy::ConfigurationChanged(const std::vector< int32_t >& changedSettings)
+{
+ mp_navigationCoreConfigurationWrapper->ConfigurationChanged(changedSettings);
+}
diff --git a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/dbus-proxies/NavigationCoreProxy.hpp b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/dbus-proxies/NavigationCoreProxy.hpp
index 321c29a..6582d02 100644
--- a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/dbus-proxies/NavigationCoreProxy.hpp
+++ b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/dbus-proxies/NavigationCoreProxy.hpp
@@ -41,7 +41,9 @@
// header file.
// using namespace v8;
+
class Locale {
+
public:
Locale() {
languageCode = "eng";
@@ -59,10 +61,12 @@ public:
std::string scriptCode;
};
+class NavigationCoreProxy;
class NavigationCoreConfigurationProxy
: public org::genivi::navigationcore::Configuration_proxy,
public DBus::ObjectProxy
{
+
public:
union UnitsOfMeasurementValue {
@@ -95,21 +99,27 @@ public:
typedef std::map<UnitsOfMeasurementAttribute,UnitsOfMeasurementValueStruct > UnitsOfMeasurement;
- NavigationCoreConfigurationProxy(DBus::Connection &connection);
+ NavigationCoreConfigurationProxy(DBus::Connection &connection,NavigationCoreProxy* navigationCoreProxy);
void ConfigurationChanged(const std::vector< int32_t >& changedSettings);
UnitsOfMeasurement GetUnitsOfMeasurement();
private:
+ NavigationCoreProxy* mp_navigationCoreProxy;
UnitsOfMeasurement m_units_of_measurement;
};
+class NavigationCoreConfigurationWrapper;
class NavigationCoreProxy
{
+
public:
- NavigationCoreProxy();
+ NavigationCoreProxy(NavigationCoreConfigurationWrapper *navigationCoreConfigurationWrapper);
~NavigationCoreProxy();
+ NavigationCoreConfigurationProxy* mp_navigationCoreConfigurationProxy;
+ void ConfigurationChanged(const std::vector< int32_t >& changedSettings);
- NavigationCoreConfigurationProxy* mp_configurationProxy;
+private:
+ NavigationCoreConfigurationWrapper* mp_navigationCoreConfigurationWrapper;
};
#endif
diff --git a/test/navigation/w3c/socket-based-poc/server.js b/test/navigation/w3c/socket-based-poc/server.js
index 02d7391..4716ae5 100644
--- a/test/navigation/w3c/socket-based-poc/server.js
+++ b/test/navigation/w3c/socket-based-poc/server.js
@@ -34,6 +34,7 @@ var fs = require('fs');
var path = require('path');
var webidl2 = require('webidl2');
var escodegen = require('escodegen');
+var events = require('events');
// Parse the web idl files
var file = fs.readFileSync("./NavigationCoreConfiguration.widl");
@@ -42,10 +43,16 @@ var tree = webidl2.parse(file.toString());
//console.log(escodegen.generate(tree));
// Requirements of LBS add-on modules
-var navigationCoreConfigurationWrapper = require(resource.generatedNodejsModulePath+'/NavigationCoreWrapper');
+var navigationCoreConfigurationWrapper = require(resource.generatedNodejsModulePath+'/NavigationCoreConfigurationWrapper');
// Create instances
-var i_navigationCoreConfiguration = new navigationCoreConfigurationWrapper.NavigationCoreWrapper();
+var i_navigationCoreConfigurationWrapper = new navigationCoreConfigurationWrapper.NavigationCoreConfigurationWrapper();
+
+// Connect signals
+function configurationChanged(changedSettings) {
+ console.log('configurationChanged: ' + changedSettings);
+}
+var data = i_navigationCoreConfigurationWrapper.setConfigurationChangedListener(configurationChanged);
// Create and init server
var port = 8080;
@@ -84,22 +91,30 @@ server.listen(port);
// Load socket.io
var io = require('socket.io').listen(server);
+var toto;
// On connection
io.sockets.on('connection', function (socket) {
console.log('Client connected');
-
+toto = socket;
socket.on('navigationcore_request', function (message) {
- if (message.method in i_navigationCoreConfiguration && typeof i_navigationCoreConfiguration[message.method] === "function") {
- console.log('Message received: Interface-->' + message.interface +' Method-->', message.method +' Parameters-->' + message.parameters);
- var data = i_navigationCoreConfiguration[message.method](message.parameters);
- if(data) {
- socket.emit('navigationcore_answer', {request: message.method, answer: data});
- }
- }
- else {
- console.log("Could not find " + message.method + " function");
- socket.emit('feedback', "Could not find " + message.method + " function");
- }
+ switch(message.interface) {
+ case "NavigationCoreConfiguration":
+ console.log('Message received: Interface-->' + message.interface +' Method-->', message.method +' Parameters-->' + message.parameters);
+ if (message.method in i_navigationCoreConfigurationWrapper && typeof i_navigationCoreConfigurationWrapper[message.method] === "function") {
+ var data = i_navigationCoreConfigurationWrapper[message.method](message.parameters);
+ if(data) {
+ socket.emit('navigationcore_answer', {request: message.method, answer: data});
+ }
+ }
+ else {
+ console.log("Could not find " + message.method + " function");
+ socket.emit('feedback', "Could not find " + message.method + " function");
+ }
+ break;
+ default:
+ console.log("Could not find " + message.interface);
+ socket.emit('feedback', "Could not find " + message.interface);
+ }
});
});