JSStaticFunction JSVehicle::m_function[] = {
{ "get", JSVehicle::get, kJSPropertyAttributeNone },
{ "subscribe", JSVehicle::subscribe, kJSPropertyAttributeNone },
+ { "supported", JSVehicle::supported, kJSPropertyAttributeNone },
{ 0, 0, 0 }
};
if (NULL == privateObject)
{
LoggerE("private object is null");
- //return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+ return JSValueMakeUndefined(context);
}
LoggerD("Validating arguments: " << argumentCount);
std::stringstream json;
+ if(!properties.size())
+ return JSValueMakeUndefined(context);
+
json<<"{";
for(auto itr = properties.begin(); itr != properties.end(); itr++)
// successCallback
JSObjectRef successCallback = validator.toFunction(1, true);
+
+ JSValueProtect(context, successCallback);
// errorCallback
//JSObjectRef errorCallback = validator.toFunction(2, true);
return JSValueMakeUndefined(context);
}
+JSValueRef JSVehicle::supported(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");
+ //return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+ }
+
+ VehiclePtr vehicle(privateObject->getObject());
+
+ GVariant * value = vehicle->listObjects();
+
+ 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;
+}
+
}
}
}
}
+GVariant* VehicleMaster::listObjects()
+{
+ LoggerD("Entered");
+
+ //std::list<std::string> supportedObjects;
+
+ GDBusProxy* managerProxy = automotiveManager();
+
+ GError *error = nullptr;
+
+ GVariant* supportedList = g_dbus_proxy_call_sync(managerProxy, "list", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+ if(error)
+ {
+ LoggerD("error calling list "<< error->message);
+ g_error_free(error);
+ g_object_unref(managerProxy);
+ return NULL;
+ }
+
+
+ /*GVariant *value;
+ GVariantIter iter;
+
+ g_variant_get(supportedList,"(as)",&iter);
+
+ while(g_variant_iter_next(iter,"(s)", &key, &value))
+ {
+ supportedObjects.push_back(g_variant_get_string(value);
+ g_variant_unref(value);
+ }
+*/
+ g_object_unref(managerProxy);
+ return supportedList;
+}
+
}
}
\ No newline at end of file