From: Kevron Rees Date: Mon, 29 Jul 2013 22:20:37 +0000 (-0700) Subject: added supported call and may have fixed callback garbage collecting issue X-Git-Tag: submit/tizen/20130729.222823~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F72%2F6072%2F1;p=profile%2Fivi%2Fwrt-plugins-ivi.git added supported call and may have fixed callback garbage collecting issue --- diff --git a/src/Vehicle/JSVehicle.cpp b/src/Vehicle/JSVehicle.cpp index a2c3659..394e979 100644 --- a/src/Vehicle/JSVehicle.cpp +++ b/src/Vehicle/JSVehicle.cpp @@ -43,6 +43,7 @@ JSClassDefinition JSVehicle::m_classInfo = { JSStaticFunction JSVehicle::m_function[] = { { "get", JSVehicle::get, kJSPropertyAttributeNone }, { "subscribe", JSVehicle::subscribe, kJSPropertyAttributeNone }, + { "supported", JSVehicle::supported, kJSPropertyAttributeNone }, { 0, 0, 0 } }; @@ -109,7 +110,7 @@ JSValueRef JSVehicle::get(JSContextRef context, 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); @@ -127,6 +128,9 @@ JSValueRef JSVehicle::get(JSContextRef context, std::stringstream json; + if(!properties.size()) + return JSValueMakeUndefined(context); + json<<"{"; for(auto itr = properties.begin(); itr != properties.end(); itr++) @@ -192,6 +196,8 @@ JSValueRef JSVehicle::subscribe(JSContextRef context, // successCallback JSObjectRef successCallback = validator.toFunction(1, true); + + JSValueProtect(context, successCallback); // errorCallback //JSObjectRef errorCallback = validator.toFunction(2, true); @@ -201,5 +207,40 @@ JSValueRef JSVehicle::subscribe(JSContextRef context, 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(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; +} + } } diff --git a/src/Vehicle/JSVehicle.h b/src/Vehicle/JSVehicle.h index 04d9f36..8992f8b 100644 --- a/src/Vehicle/JSVehicle.h +++ b/src/Vehicle/JSVehicle.h @@ -52,6 +52,13 @@ private: size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); + + static JSValueRef supported(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 783d4cb..be10960 100644 --- a/src/Vehicle/Vehicle.cpp +++ b/src/Vehicle/Vehicle.cpp @@ -306,5 +306,41 @@ void VehicleMaster::onSignalReceived(std::string objectName, std::map 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 diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index 9009fe9..2dc200f 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -33,6 +33,8 @@ public: void subscribe(std::string objectName, JSObjectRef successCallback, JSContextRef context); + GVariant* listObjects(); + void onSignalReceived(std::string objectName, std::map propertyMap); private: /// methods: