added supported call and may have fixed callback garbage collecting issue 72/6072/1
authorKevron Rees <kevron_m_rees@linux.intel.com>
Mon, 29 Jul 2013 22:20:37 +0000 (15:20 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Mon, 29 Jul 2013 22:20:37 +0000 (15:20 -0700)
src/Vehicle/JSVehicle.cpp
src/Vehicle/JSVehicle.h
src/Vehicle/Vehicle.cpp
src/Vehicle/Vehicle.h

index a2c3659..394e979 100644 (file)
@@ -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<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;
+}
+
 }
 }
index 04d9f36..8992f8b 100644 (file)
@@ -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.
index 783d4cb..be10960 100644 (file)
@@ -306,5 +306,41 @@ void VehicleMaster::onSignalReceived(std::string objectName, std::map<std::strin
        }
 }
 
+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
index 9009fe9..2dc200f 100644 (file)
@@ -33,6 +33,8 @@ public:
        
        void subscribe(std::string objectName, JSObjectRef successCallback, JSContextRef context);
        
+       GVariant* listObjects();
+       
        void onSignalReceived(std::string objectName, std::map<std::string, GVariant*> propertyMap);
        
 private: /// methods: