diff options
author | <philippe colliot> | 2016-03-08 17:39:26 +0100 |
---|---|---|
committer | <philippe colliot> | 2016-03-08 17:39:26 +0100 |
commit | af9921122b0799c19634792131a152a6db6dbfa3 (patch) | |
tree | d3751a2ec0084c9abf95800558ed4a0e53652e25 | |
parent | 69f9de871a7d45952806e81b7b8baba6f3808a7e (diff) | |
download | poi-service-af9921122b0799c19634792131a152a6db6dbfa3.tar.gz |
Push preliminary work for W3C POC, based on nodejs and HTML
20 files changed, 921 insertions, 7 deletions
diff --git a/api/franca/navigation/NavigationTypes.fidl b/api/franca/navigation/NavigationTypes.fidl index a4800c2..1a51aa8 100755 --- a/api/franca/navigation/NavigationTypes.fidl +++ b/api/franca/navigation/NavigationTypes.fidl @@ -58,7 +58,6 @@ typeCollection NavigationTypes { /* enumerations */
-// for the time being, no use of inheritance (extends) for the enumerations, to be implemented later
enumeration BasicEnum {
INVALID = 0
}
diff --git a/api/franca/navigation/mapviewer/MapViewerConfiguration.fidl b/api/franca/navigation/mapviewer/MapViewerConfiguration.fidl index bc22502..66c8d01 100644 --- a/api/franca/navigation/mapviewer/MapViewerConfiguration.fidl +++ b/api/franca/navigation/mapviewer/MapViewerConfiguration.fidl @@ -11,7 +11,7 @@ import org.genivi.navigation.NavigationTypes.* from "../NavigationTypes.fidl" <** @description : This interface offers methods that implement the map viewer configuration functionality of a navigation system.**> -interface MapViewerConfiguration { +interface Configuration { version { major 0 minor 1 diff --git a/api/franca/navigation/navigationcore/NavigationCoreConfiguration.fidl b/api/franca/navigation/navigationcore/NavigationCoreConfiguration.fidl index 1ca1ac9..73caead 100644 --- a/api/franca/navigation/navigationcore/NavigationCoreConfiguration.fidl +++ b/api/franca/navigation/navigationcore/NavigationCoreConfiguration.fidl @@ -11,7 +11,7 @@ import org.genivi.navigation.NavigationTypes.* from "../NavigationTypes.fidl" <** @description : This interface offers methods that implement the navigation core configuration functionality of a navigation system.**> -interface NavigationCoreConfiguration { +interface Configuration { version { major 0 minor 1 @@ -146,7 +146,7 @@ interface NavigationCoreConfiguration { <** @description : Get the supported set of coordinates format .**> method getSupportedCoordinatesFormat { out { - <** @description : array[struct(languageCode,countryCode,scriptCode)]**> + <** @description : array[coordinatesFormat]**> CoordinatesFormat[] coordinatesFormatList } } @@ -155,7 +155,7 @@ interface NavigationCoreConfiguration { method setUnitsOfMeasurement { in { <** @description : unitsOfMeasurementList = array[unitsOfMeasurement]**> - UnitsOfMeasurement unitsOfMeasurementList + UnitsOfMeasurement[] unitsOfMeasurementList } } @@ -163,7 +163,7 @@ interface NavigationCoreConfiguration { method getUnitsOfMeasurement { out { <** @description : unitsOfMeasurementList = array[unitsOfMeasurement]**> - UnitsOfMeasurement unitsOfMeasurementList + UnitsOfMeasurement[] unitsOfMeasurementList } } @@ -171,7 +171,7 @@ interface NavigationCoreConfiguration { method getSupportedUnitsOfMeasurement { out { <** @description : unitsOfMeasurementList = array[unitsOfMeasurement]**> - UnitsOfMeasurement unitsOfMeasurementList + UnitsOfMeasurement[] unitsOfMeasurementList } } diff --git a/test/navigation/w3c/socket-based-poc/.gitignore b/test/navigation/w3c/socket-based-poc/.gitignore new file mode 100644 index 0000000..61344f5 --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/.gitignore @@ -0,0 +1,5 @@ +node_modules +~ +build +*.tgz +*.user
\ No newline at end of file diff --git a/test/navigation/w3c/socket-based-poc/NavigationCoreConfiguration.widl b/test/navigation/w3c/socket-based-poc/NavigationCoreConfiguration.widl new file mode 100644 index 0000000..a8f5c2d --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/NavigationCoreConfiguration.widl @@ -0,0 +1,79 @@ +enum Settings { + "INVALID", + "UNITS_OF_MEASUREMENT", + "LOCALE", + "TIME_FORMAT", + "COORDINATES_FORMAT" +}; + +enum UnitsOfMeasurementAttribute { + "INVALID", + "LENGTH" +}; + +interface UnitsOfMeasurementValue { + attribute (long or double) value; +}; + +interface UnitsOfMeasurement { + maplike<UnitsOfMeasurementAttribute, UnitsOfMeasurementValue>; +}; + +enum Units { + "METER", + "MILE", + "KM", + "YARD", + "FOOT" +}; + +enum TimeFormat { + "INVALID", + "TWELVEH", + "TWENTYFOURH" +}; + +enum CoordinatesFormat { + "INVALID", + "DEGREES", + "MINUTES", + "SECONDS" +}; + +[Constructor(unsigned short versionMajor, unsigned short versionMinor, unsigned short versionMicro, DOMString date)] +interface Version { + readonly attribute unsigned short versionMajor; + readonly attribute unsigned short versionMinor; + readonly attribute unsigned short versionMicro; + readonly attribute DOMString date; +}; + +[Constructor(DOMString languageCode, DOMString countryCode, DOMString scriptCode)] +interface Locale { + attribute DOMString languageCode; + attribute DOMString countryCode; + attribute DOMString scriptCode; +}; + +dictionary navigationCoreConfigurationOptions { + Version version; + Locale locale; + TimeFormat format; + CoordinatesFormat coordinatesFormat; + any unitsOfMeasurementList; +}; + +callback interface configurationChangedEventListener { + void handleEvent(any changedSettings); +}; + +[Constructor, Constructor(Node navigationCoreConfigurationNode, navigationCoreConfigurationOptions opts)] +interface NavigationCoreConfiguration { + Promise<any> setProperty(DOMString propertyName, any newValue); + Promise<any> getProperty(DOMString propertyName); + any getSupportedLocales(); + any getSupportedTimeFormats(); + any getSupportedUnitsOfMeasurement(); + void addEventListener(DOMString type, configurationChangedEventListener configurationChanged); +}; + diff --git a/test/navigation/w3c/socket-based-poc/README.md b/test/navigation/w3c/socket-based-poc/README.md new file mode 100644 index 0000000..d7c16ed --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/README.md @@ -0,0 +1,25 @@ +Preliminary code for testing the implementation of a set of navigation Web API based on GENIVI API +Technology used: nodejs + +To get nodejs: +sudo apt-get install nodejs npm + +To build the module in C++ and install the module localy for nodejs: +cd ./node-cpp-lbs-modules +npm build . +npm pack +cd .. +npm install node-cpp-lbs-modules/node-cpp-based-modules-0.1.0.tgz + +To test: +Intall additional modules for nodejs: +npm install http url fs path webidl2 escodegen + +Run the server: + +node server.js + +In your browser: + +http://localhost:8080/index.html + diff --git a/test/navigation/w3c/socket-based-poc/images/french-flag.png b/test/navigation/w3c/socket-based-poc/images/french-flag.png Binary files differnew file mode 100644 index 0000000..7355870 --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/images/french-flag.png diff --git a/test/navigation/w3c/socket-based-poc/images/german-flag.png b/test/navigation/w3c/socket-based-poc/images/german-flag.png Binary files differnew file mode 100644 index 0000000..f8f785d --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/images/german-flag.png diff --git a/test/navigation/w3c/socket-based-poc/images/japanese-flag.png b/test/navigation/w3c/socket-based-poc/images/japanese-flag.png Binary files differnew file mode 100644 index 0000000..69c1e4e --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/images/japanese-flag.png diff --git a/test/navigation/w3c/socket-based-poc/images/usa-flag.png b/test/navigation/w3c/socket-based-poc/images/usa-flag.png Binary files differnew file mode 100644 index 0000000..69c30d1 --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/images/usa-flag.png diff --git a/test/navigation/w3c/socket-based-poc/index.html b/test/navigation/w3c/socket-based-poc/index.html new file mode 100644 index 0000000..822381b --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/index.html @@ -0,0 +1,174 @@ +<!DOCTYPE html> +<html lang="en"> +<head> +<meta charset="utf-8" /> +<title>Test page for GENIVI Web API (draft)</title> +<link rel="stylesheet" href="style-sheets/stylesheet.css"> +<!-- to be fixed, use relative paths --> +<script type="text/javascript" src="./node_modules/socket.io/node_modules/socket.io-client/socket.io.js"></script> +<script type="text/javascript" src="./node_modules/webidl2/lib/webidl2.js"></script> +</head> +<body> +<header> +<h1>Test of the NavigationCoreConfiguration interface</h1> +<p id="start_time"></p> +<p id="version"></p> +</header> + +<nav> +TBD +</nav> + +<section> +<p id="locale"></p> +</section> + +<section> +<div id="localeSection"> +</div> +</section> + +<footer> +Copyright © PCA Peugeot Citroen +</footer> + +<script type="text/javascript"> + +<!-- socket management --> +var socket = io.connect('http://localhost:8080'); +socket.on('feedback', function(message) { + alert('Message received from the server : ' + message); +}) + +socket.on('navigationcore_answer', function(message) { + if(message.request === 'getVersion') + { + getVersionReturn(message.answer); + } else { + if(message.request === 'getProperty') + { + if(message.answer[0] === 'Locale') + { + getLocaleReturn(message.answer); + } + } else { + if(message.request === 'getSupportedLocales') + { + getSupportedLocalesReturn(message.answer); + } else { + if(message.request === 'getUnitsOfMeasurement') + { + alert('Message received from the server : ' +message.answer.length+ message.answer[0].key+ message.answer[0].value); + } + } + } + } +}) + +<!-- initialization --> +var today=new Date(); +document.getElementById("start_time").innerHTML=today; + +getVersion(); + +var supportedLocales=[]; +addLocale("eng","USA", "Latn","./images/usa-flag.png"); +addLocale("deu","DEU", "Latn","./images/german-flag.png"); +addLocale("fra","FRA", "Latn","./images/french-flag.png"); +addLocale("jpn","JPN", "Hrkt","./images/japanese-flag.png"); + +var div = document.getElementById("localeSection"); +addLocaleListButtons(div,supportedLocales.length); + +getSupportedLocales(); + +getUnitsOfMeasurement(); + +getLocale(); + +<!-- middleware abstraction layer --> +function getVersion() { + socket.emit('navigationcore_request', {interface: 'NavigationCoreConfiguration', method: 'getVersion', parameters: []}); +} +function getVersionReturn(answer) { + document.getElementById("version").innerHTML=answer[3]; +} +function getLocale() { + socket.emit('navigationcore_request', {interface: 'NavigationCoreConfiguration', method: 'getProperty', parameters: ['Locale']}); +} +function getLocaleReturn(answer) { + enhanceLocaleButton(answer[2]); +} +function getSupportedLocales() { + socket.emit('navigationcore_request', {interface: 'NavigationCoreConfiguration', method: 'getSupportedLocales', parameters: []}); +} +function getSupportedLocalesReturn(answer) { + for ( var i=0; i<supportedLocales.length; i++ ) { + document.getElementById(supportedLocales[i].countryCode).disabled = true; + document.getElementById(supportedLocales[i].countryCode).style.opacity= 0.5; + } + + for ( var i=0; i<answer.length; i++ ) { + for ( var j=0; j<supportedLocales.length; j++ ) { + if(supportedLocales[j].countryCode === answer[i][1]) + { + document.getElementById(supportedLocales[j].countryCode).disabled = false; + document.getElementById(supportedLocales[j].countryCode).style.opacity= 1; + break; + } + } + } +} +function getUnitsOfMeasurement() { + socket.emit('navigationcore_request', {interface: 'NavigationCoreConfiguration', method: 'getUnitsOfMeasurement', parameters: []}); +} + +function configurationChanged(changedSettings) { +getLocale(); +} + +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}); +} + +<!-- some other functions --> +function addLocaleListButtons( div, num_buttons ) { + var buttons=""; + for ( var i=0; i<num_buttons; i++ ) { + buttons += '<input type="button" id="'+supportedLocales[i].countryCode+'" style="cursor:pointer; background: url('+supportedLocales[i].flagUrl+'); width:104px; height:64px; background-size: 100%; opacity: 0.5; no-repeat" onclick="setLocale(this)" class="localeListButtons" value="'+i+'" disabled></input><br></br>'; + } + var newdiv = document.createElement('div'); + var divIdName = 'localeList'; + newdiv.setAttribute('id',divIdName); + 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"; + document.getElementById(supportedLocales[i].countryCode).style.height = "64px"; + } + document.getElementById(id).style.width = "124px"; + document.getElementById(id).style.height = "76px"; +} + +function addLocale(language, country,script,flag) { + supportedLocales.push({ + languageCode: language, + countryCode: country, + scriptCode: script, + flagUrl: flag, + }); +} +</script> +</body> +</html> diff --git a/test/navigation/w3c/socket-based-poc/js/resource.js b/test/navigation/w3c/socket-based-poc/js/resource.js new file mode 100644 index 0000000..452e3e8 --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/js/resource.js @@ -0,0 +1,33 @@ +/** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2013-2014, PCA Peugeot Citroen +* +* \file resource.js.in +* +* \brief This file is part of the navigation hmi. +* +* \author Philippe Colliot <philippe.colliot@mpsa.com> +* +* \version 1.0 +* +* 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@ +*/ +var generatedNodejsModulePath="node-cpp-based-modules/build/Release/"; +var iconPath = "images"; +var constantPath = "."; +exports.generatedNodejsModulePath = generatedNodejsModulePath; +exports.iconPath = iconPath; +exports.constantPath = constantPath; + diff --git a/test/navigation/w3c/socket-based-poc/js/resource.js.in b/test/navigation/w3c/socket-based-poc/js/resource.js.in new file mode 100644 index 0000000..1864885 --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/js/resource.js.in @@ -0,0 +1,33 @@ +/** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2013-2014, PCA Peugeot Citroen +* +* \file resource.js.in +* +* \brief This file is part of the navigation hmi. +* +* \author Philippe Colliot <philippe.colliot@mpsa.com> +* +* \version 1.0 +* +* 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@ +*/ +var generatedNodejsModulePath="@GENERATED_NODEJS_MODULE_PATH@"; +var iconPath = "@ICON_PATH@"; +var constantPath = "@CONSTANT_PATH@"; +exports.generatedNodejsModulePath = generatedNodejsModulePath; +exports.iconPath = iconPath; +exports.constantPath = constantPath; + diff --git a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/CMakeLists.txt b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/CMakeLists.txt new file mode 100644 index 0000000..dbb03d0 --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/CMakeLists.txt @@ -0,0 +1,13 @@ +project(socket-based-web-poc) +cmake_minimum_required(VERSION 2.8) +aux_source_directory(. SRC_LIST) +include_directories( + ./ + /usr/include/nodejs/src/ +) + +add_executable(${PROJECT_NAME} ${SRC_LIST}) +set(npm 'npm build .') +execute_process( + COMMAND ${npm} +) diff --git a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreConfiguration.cpp b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreConfiguration.cpp new file mode 100644 index 0000000..1e6081a --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreConfiguration.cpp @@ -0,0 +1,234 @@ +#include <node.h> + +#include "NavigationCoreConfiguration.hpp" + +using namespace v8; +using namespace std; +using namespace org::genivi::navigationcore; + +Persistent<FunctionTemplate> NavigationCoreConfiguration::constructor; + +void NavigationCoreConfiguration::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 NavigationCoreConfiguration::Init(Handle<Object> target) { + HandleScope scope; + + Local<FunctionTemplate> tpl = FunctionTemplate::New(New); + Local<String> name = String::NewSymbol("NavigationCoreConfiguration"); + + 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()); +} + +NavigationCoreConfiguration::NavigationCoreConfiguration() : ObjectWrap() {} + +Handle<Value> NavigationCoreConfiguration::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.")) + ); + } + + // Creates a new instance object of this type and wraps it. + NavigationCoreConfiguration* obj = new NavigationCoreConfiguration(); + obj->Wrap(args.This()); + + return args.This(); +} + +Handle<Value> NavigationCoreConfiguration::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. + NavigationCoreConfiguration* obj = ObjectWrap::Unwrap<NavigationCoreConfiguration>(args.This()); + + Local<Object> ret = Object::New(); + + Locale localeValue = obj->m_proxy.GetLocale(); + 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. + NavigationCoreConfiguration* obj = ObjectWrap::Unwrap<NavigationCoreConfiguration>(args.This()); + + Local<Object> ret = Object::New(); + + return scope.Close(ret); + } + else + { + if(propertyName == "CoordinatesFormat") { + // Retrieves the pointer to the wrapped object instance. + NavigationCoreConfiguration* obj = ObjectWrap::Unwrap<NavigationCoreConfiguration>(args.This()); + + Local<Object> ret = Object::New(); + + return scope.Close(ret); + } + } + } + return Undefined(); +} + +Handle<Value> NavigationCoreConfiguration::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. + NavigationCoreConfiguration* obj = ObjectWrap::Unwrap<NavigationCoreConfiguration>(args.This()); + obj->m_proxy.SetLocale(localeValue); + + 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> NavigationCoreConfiguration::GetVersion(const Arguments& args) { + HandleScope scope; //to properly clean up v8 handles + + // Retrieves the pointer to the wrapped object instance. + NavigationCoreConfiguration* obj = ObjectWrap::Unwrap<NavigationCoreConfiguration>(args.This()); + + Version version = obj->m_proxy.GetVersion(); + + Local<Object> ret = Object::New(); + ret->Set( 0, Int32::New(version.versionMajor) ); + ret->Set( 1, Int32::New(version.versionMinor) ); + ret->Set( 2, Int32::New(version.versionMicro) ); + ret->Set( 3, String::New(version.date.c_str()) ); + + return scope.Close(ret); +} + +Handle<Value> NavigationCoreConfiguration::GetSupportedLocales(const Arguments& args) { + HandleScope scope; //to properly clean up v8 handles + + // Retrieves the pointer to the wrapped object instance. + NavigationCoreConfiguration* obj = ObjectWrap::Unwrap<NavigationCoreConfiguration>(args.This()); + + std::vector<Locale > localeList = obj->m_proxy.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).languageCode.c_str()) ); + data->Set( 1, String::New(localeList.at(i).countryCode.c_str()) ); + data->Set( 2, String::New(localeList.at(i).scriptCode.c_str()) ); + ret->Set(ret->Length(), data); + } + + return scope.Close(ret); +} + +Handle<Value> NavigationCoreConfiguration::GetUnitsOfMeasurement(const Arguments& args) +{ + HandleScope scope; //to properly clean up v8 handles + + // Retrieves the pointer to the wrapped object instance. + NavigationCoreConfiguration* obj = ObjectWrap::Unwrap<NavigationCoreConfiguration>(args.This()); + + Configuration_proxy::UnitsOfMeasurement unitsOfMeasurement = obj->m_proxy.GetUnitsOfMeasurement(); + + Local<Array> ret = Array::New(); + for (Configuration_proxy::UnitsOfMeasurement::iterator iter = unitsOfMeasurement.begin(); iter != unitsOfMeasurement.end(); iter++) { + Local<Object> data = Object::New(); + Configuration_proxy::UnitsOfMeasurementValueStruct unitsOfMeasurement; + unitsOfMeasurement = iter->second; + data->Set(String::New("key"), Int32::New(iter->first)); + switch (unitsOfMeasurement.type) { + case Configuration_proxy::intValue: + data->Set(String::New("value"), Int32::New(unitsOfMeasurement.value.intValue)); + break; + case Configuration_proxy::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) { + NavigationCoreConfiguration::Init(target); +} + +NODE_MODULE(NavigationCoreConfiguration, RegisterModule); diff --git a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreConfiguration.hpp b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreConfiguration.hpp new file mode 100644 index 0000000..1e294cb --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/NavigationCoreConfiguration.hpp @@ -0,0 +1,158 @@ +#ifndef NAVIGATIONCORECONFIGURATION_HPP +#define NAVIGATIONCORECONFIGURATION_HPP + +#include <node.h> +#include <node_buffer.h> + +#include <string> +#include <vector> +#include <map> + +// Do not include this line. It's generally frowned upon to use namespaces +// in header files as it may cause issues with other code that includes your +// header file. +// using namespace v8; + +class Version { +public: + Version() { + versionMajor = 1; + versionMinor = 0; + versionMicro = 0; + date = "19:02:2016"; + } + uint16_t versionMajor; + uint16_t versionMinor; + uint16_t versionMicro; + std::string date; +}; + +class Locale { +public: + Locale() { + languageCode = "eng"; + countryCode = "USA"; + scriptCode = "Latn"; + } + Locale(std::string language, std::string country, std::string script) { + languageCode = language; + countryCode = country; + scriptCode = script; + } + + std::string languageCode; + std::string countryCode; + std::string scriptCode; +}; + + +namespace org { +namespace genivi { +namespace navigationcore { + +class Configuration_proxy +{ +public: + + union UnitsOfMeasurementValue { + int32_t intValue; + double doubleValue; + }; + + enum UnitsOfMeasurementValueType { + intValue=0, + doubleValue=1 + }; + + typedef struct { + UnitsOfMeasurementValueType type; + UnitsOfMeasurementValue value; + } UnitsOfMeasurementValueStruct; + + enum UnitsOfMeasurementAttribute { + INVALID, + LENGTH=1 + }; + + enum Units { + METER = 50, + MILE = 51, + KM = 52, + YARD = 53, + FOOT = 54 + }; + + typedef std::map<UnitsOfMeasurementAttribute,UnitsOfMeasurementValueStruct > UnitsOfMeasurement; + + Configuration_proxy() + { + Locale en_US { "eng","USA", "Latn" }; + Locale de_DE { "deu","DEU", "Latn" }; + Locale fr_FR { "fra","FRA", "Latn" }; + Locale jp_JP { "jpn","JPN", "Hrkt" }; + m_locale_list.push_back(en_US); + m_locale_list.push_back(de_DE); + m_locale_list.push_back(fr_FR); +// m_locale_list.push_back(jp_JP); //For the test Japanese is not supported + + UnitsOfMeasurementValueStruct value {intValue,METER}; + + m_units_of_measurement[LENGTH] = value; + } + + Version GetVersion() + { + return m_version; + } + + Locale GetLocale() + { + return m_locale; + } + std::vector<Locale > GetSupportedLocales() + { + return m_locale_list; + } + + void SetLocale(Locale& locale) + { + m_locale = locale; + } + + UnitsOfMeasurement GetUnitsOfMeasurement() + { + return m_units_of_measurement; + } + +public: +private: + Version m_version; + Locale m_locale; + std::vector<Locale > m_locale_list; + UnitsOfMeasurement m_units_of_measurement; +}; +} } } + +class NavigationCoreConfiguration : public node::ObjectWrap { +public: + static v8::Persistent<v8::FunctionTemplate> constructor; + static void Init(v8::Handle<v8::Object> target); + +protected: + NavigationCoreConfiguration(); + + static v8::Handle<v8::Value> New(const v8::Arguments& args); + static v8::Handle<v8::Value> GetVersion(const v8::Arguments& args); + static v8::Handle<v8::Value> GetSupportedLocales(const v8::Arguments& args); + static v8::Handle<v8::Value> GetUnitsOfMeasurement(const v8::Arguments& args); + + 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); + + // Your own object variables here + org::genivi::navigationcore::Configuration_proxy m_proxy; +}; + +#endif 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 new file mode 100644 index 0000000..b2b78ef --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/binding.gyp @@ -0,0 +1,12 @@ +{ + "targets": [ + { + "target_name": "NavigationCoreConfiguration", + "sources": [ "./NavigationCoreConfiguration.cpp" ], + "include_dirs": ["./"], + "cflags_cc": ["-Wall", "-std=gnu++11", "-fexceptions"] + } + ] + + +} diff --git a/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/package.json b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/package.json new file mode 100644 index 0000000..6064421 --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/node-cpp-lbs-modules/package.json @@ -0,0 +1,19 @@ +{ + "name": "node-cpp-based-modules", + "version": "0.1.0", + "description": "C++ modules used by the for POC Web APIs, GENIVI/W3C cooperation", + "keywords": [ + "npm", + "GENIVI", + "W3C", + "LBS-EG" + ], + "author": "Philippe Colliot <philippe.colliot@mpsa.com>", + "contributors": [""], + "main": "./build/Release/NavigationCoreConfiguration", + "license": "MPL V.2.0", + "devDependencies": { + "chai": "~3.5.0", + "mocha": "~2.4.5" + } +} diff --git a/test/navigation/w3c/socket-based-poc/server.js b/test/navigation/w3c/socket-based-poc/server.js new file mode 100644 index 0000000..8d5fa3b --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/server.js @@ -0,0 +1,82 @@ +// Requirement of external JS files +var resource = require('./js/resource.js'); + +// Requirements of nodejs modules +var http = require('http'); +var url = require('url'); +var fs = require('fs'); +var path = require('path'); +var webidl2 = require('webidl2'); +var escodegen = require('escodegen'); + +// Parse the web idl files +var file = fs.readFileSync("./NavigationCoreConfiguration.widl"); +var tree = webidl2.parse(file.toString()); +//console.log(tree); +//console.log(escodegen.generate(tree)); + +// Requirements of LBS add-on modules +var navigationCoreConfiguration = require(resource.generatedNodejsModulePath+'/NavigationCoreConfiguration'); + +// Create instances +var i_navigationCoreConfiguration = new navigationCoreConfiguration.NavigationCoreConfiguration(); + +// Create and init server +var port = 8080; +var hostname = '127.0.0.1'; +var server = http.createServer(function(req, res) { + var page = url.parse(req.url).pathname; + var full_path = path.join(process.cwd(),page); + // Check if page exists (for the moment only index.html) + fs.exists(full_path,function(exists){ + if(!exists){ + res.writeHeader(404, {"Content-Type": "text/plain"}); + res.write("404 Not Found\n"); + res.end(); + } + else{ + fs.readFile(full_path, "binary", function(err, file) { + if(err) { + res.writeHeader(500, {"Content-Type": "text/plain"}); + res.write(err + "\n"); + res.end(); + + } + else{ + res.writeHeader(200); + res.write(file, "binary"); + res.end(); + } + }); + } + }); +}); + +// Launch server +server.listen(port); + +// Load socket.io +var io = require('socket.io').listen(server); + +// On connection +io.sockets.on('connection', function (socket) { +console.log('Client connected'); + +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"); + } +}); +}); + +// Log info +console.log('Server listening at: %s', server.address().port); + diff --git a/test/navigation/w3c/socket-based-poc/style-sheets/stylesheet.css b/test/navigation/w3c/socket-based-poc/style-sheets/stylesheet.css new file mode 100644 index 0000000..40f27b1 --- /dev/null +++ b/test/navigation/w3c/socket-based-poc/style-sheets/stylesheet.css @@ -0,0 +1,48 @@ +body { + width: 800px; + height: 480px; + max-width: 800px; + max-height: 480px; + margin: 0; + padding: 0; + background-color: lightblue; +} +header { + color:white; + text-align:center; + padding:5px; +} +nav { + line-height:30px; + background-color:#eeeeee; + height:300px; + width:100px; + float:left; + padding:5px; +} +section { + width:350px; + float:left; + padding:10px; +} +footer { + background-color:black; + color:white; + clear:both; + text-align:center; + padding:5px; +} +h1 { + color: navy; + margin-left: 20px; +} + +p { + font-family: verdana; + color: grey; +} + +localeListButtons { + color: yellow; +} + |