From aa3831d2a578342084f211858ab1795a203c2d68 Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Tue, 5 Nov 2013 11:38:26 -0800 Subject: [PATCH] added listZones method to vehicle Change-Id: Iea7597257cc9ab79fa0ff4a167d7b84feb2cf65f --- packaging/wrt-plugins-ivi.changes | 3 +++ packaging/wrt-plugins-ivi.spec | 2 +- src/Vehicle/JSVehicle.cpp | 42 +++++++++++++++++++++++++++++++++++++++ src/Vehicle/JSVehicle.h | 7 +++++++ src/Vehicle/Vehicle.cpp | 26 +++++++++++++++++++++++- src/Vehicle/Vehicle.h | 2 ++ 6 files changed, 80 insertions(+), 2 deletions(-) diff --git a/packaging/wrt-plugins-ivi.changes b/packaging/wrt-plugins-ivi.changes index 4a41b79..95c25ab 100644 --- a/packaging/wrt-plugins-ivi.changes +++ b/packaging/wrt-plugins-ivi.changes @@ -1,3 +1,6 @@ +* Tue Nov 05 2013 +- added vehicle.listZones to get zones for a given data type + * Mon Oct 28 2013 - Added locale plugin diff --git a/packaging/wrt-plugins-ivi.spec b/packaging/wrt-plugins-ivi.spec index b7f3d07..f5041d1 100644 --- a/packaging/wrt-plugins-ivi.spec +++ b/packaging/wrt-plugins-ivi.spec @@ -1,6 +1,6 @@ Name: wrt-plugins-ivi Summary: JavaScript plugins for WebRuntime for IVI -Version: 0.10.0 +Version: 0.11.0 Release: 1 Group: Development/Libraries License: Apache-2.0 diff --git a/src/Vehicle/JSVehicle.cpp b/src/Vehicle/JSVehicle.cpp index 512f9f7..1bef667 100644 --- a/src/Vehicle/JSVehicle.cpp +++ b/src/Vehicle/JSVehicle.cpp @@ -51,6 +51,7 @@ JSStaticFunction JSVehicle::m_function[] = { { "supported", JSVehicle::supported, kJSPropertyAttributeNone }, { "set", JSVehicle::set, kJSPropertyAttributeNone }, { "getHistory", JSVehicle::getHistory, kJSPropertyAttributeNone }, + { "listZones", JSVehicle::listZones, kJSPropertyAttributeNone }, { 0, 0, 0 } }; @@ -404,5 +405,46 @@ JSValueRef JSVehicle::getHistory(JSContextRef context, return JSValueMakeUndefined(context); } +JSValueRef JSVehicle::listZones(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LoggerD("Entered"); + VehiclePrivObject* privateObject = static_cast(JSObjectGetPrivate(thisObject)); + if (NULL == privateObject) + { + LoggerE("private object is null"); + } + + VehiclePtr vehicle(privateObject->getObject()); + + ArgumentValidator validator(context, argumentCount, arguments); + + std::string objectName = validator.toString(0); + + GVariant * value = vehicle->listZones(objectName); + + if(!value) + return JSValueMakeUndefined(context); + + gsize size; + std::string script; + std::string valStr = json_gvariant_serialize_data(value,&size); + + LoggerD("array: " << valStr); + + script = "return " + valStr; + + JSStringRef scriptJS = JSStringCreateWithUTF8CString(script.c_str()); + JSObjectRef fn = JSObjectMakeFunction(context, NULL, 0, NULL, scriptJS, NULL, 1, NULL); + JSValueRef result = JSObjectCallAsFunction(context, fn, NULL, 0, NULL, NULL); + JSStringRelease(scriptJS); + + return result; +} + } } diff --git a/src/Vehicle/JSVehicle.h b/src/Vehicle/JSVehicle.h index 89d437a..74cabd8 100644 --- a/src/Vehicle/JSVehicle.h +++ b/src/Vehicle/JSVehicle.h @@ -74,6 +74,13 @@ private: const JSValueRef arguments[], JSValueRef* exception); + static JSValueRef listZones(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + /** * This structure contains properties and callbacks that define a type of object. */ diff --git a/src/Vehicle/Vehicle.cpp b/src/Vehicle/Vehicle.cpp index 354f8b7..a17d940 100644 --- a/src/Vehicle/Vehicle.cpp +++ b/src/Vehicle/Vehicle.cpp @@ -644,5 +644,29 @@ void VehicleMaster::getHistory(std::string objectName, int zone, double begin, d g_dbus_proxy_call(proxy, "GetHistory", g_variant_new("(dd)", begin, end), G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback)cb, data); } +GVariant* VehicleMaster::listZones(std::string objectName) +{ + LoggerD("Entered"); + + GDBusProxy* managerProxy = automotiveManager(); + + GError *error = nullptr; + + GVariant* supportedList = g_dbus_proxy_call_sync(managerProxy, "ZonesForObjectName", g_variant_new("s",objectName.c_str()), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + + if(error) + { + LoggerD("error calling listZones "<< error->message); + g_error_free(error); + + if(supportedList) + g_variant_unref(supportedList); + + return NULL; + } + + return supportedList; +} + +} } -} \ No newline at end of file diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index e787b74..e2698f6 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -81,6 +81,8 @@ public: void getHistory(std::string objectName, int zone, double begin, double end, JSObjectRef successCallback, JSObjectRef errorCallback, JSContextRef context); + GVariant* listZones(std::string objectName); + private: /// methods: GDBusProxy* automotiveManager(); -- 2.7.4