{ "supported", JSVehicle::supported, kJSPropertyAttributeNone },
{ "set", JSVehicle::set, kJSPropertyAttributeNone },
{ "getHistory", JSVehicle::getHistory, kJSPropertyAttributeNone },
+ { "listZones", JSVehicle::listZones, kJSPropertyAttributeNone },
{ 0, 0, 0 }
};
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;
+}
+
}
}
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.
*/
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