added listZones method to vehicle 24/11824/3
authorKevron Rees <kevron.m.rees@intel.com>
Tue, 5 Nov 2013 19:38:26 +0000 (11:38 -0800)
committerKevron Rees <kevron.m.rees@intel.com>
Thu, 7 Nov 2013 18:47:42 +0000 (10:47 -0800)
Change-Id: Iea7597257cc9ab79fa0ff4a167d7b84feb2cf65f

packaging/wrt-plugins-ivi.changes
packaging/wrt-plugins-ivi.spec
src/Vehicle/JSVehicle.cpp
src/Vehicle/JSVehicle.h
src/Vehicle/Vehicle.cpp
src/Vehicle/Vehicle.h

index 4a41b79..95c25ab 100644 (file)
@@ -1,3 +1,6 @@
+* Tue Nov 05 2013 <kevron.m.rees@intel.com>
+- added vehicle.listZones to get zones for a given data type
+
 * Mon Oct 28 2013 <kevron.m.rees@intel.com>
 - Added locale plugin
 
index b7f3d07..f5041d1 100644 (file)
@@ -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
index 512f9f7..1bef667 100644 (file)
@@ -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<VehiclePrivObject*>(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;
+}
+
 }
 }
index 89d437a..74cabd8 100644 (file)
@@ -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.
                 */
index 354f8b7..a17d940 100644 (file)
@@ -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
index e787b74..e2698f6 100644 (file)
@@ -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();