Merge branch 'tizen' into mediaserver
authorLuc Yriarte <luc.yriarte@intel.com>
Tue, 30 Jul 2013 07:28:38 +0000 (09:28 +0200)
committerLuc Yriarte <luc.yriarte@intel.com>
Tue, 30 Jul 2013 07:28:38 +0000 (09:28 +0200)
.gbs.conf [deleted file]
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
src/Vehicle/Vehicle.idl

diff --git a/.gbs.conf b/.gbs.conf
deleted file mode 100644 (file)
index 1b88822..0000000
--- a/.gbs.conf
+++ /dev/null
@@ -1,3 +0,0 @@
-[general]
-upstream_branch = tizen
-upstream_tag = ${upstreamversion}
index a18f706..b2655fa 100644 (file)
@@ -1,2 +1,8 @@
+* Mon Jul 29 2013 <kevron.m.rees@intel.com>
+- added supported() call
+- fix for callback garbage collection
+- cleaned up code
+- sr to tizen
+
 * Fri Jul 19 15:09:00 PST 2013 - <kevron.m.rees@intel.com>
 - initial add of changelog
index 4294405..1a56c93 100644 (file)
@@ -1,6 +1,6 @@
 Name:       wrt-plugins-ivi
 Summary:    JavaScript plugins for WebRuntime for IVI
-Version:    0.2.0
+Version:    0.3.0
 Release:    1
 Group:      Development/Libraries
 License:    Apache License, Version 2.0
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..8109e50 100644 (file)
@@ -209,7 +209,7 @@ GDBusProxy* VehicleMaster::automotiveManager()
 std::string VehicleMaster::findProperty(std::string objectName)
 {
        GDBusProxy* managerProxy = automotiveManager();
-       
+
        GError *error = nullptr;
        
        GVariant* objectPath = g_dbus_proxy_call_sync(managerProxy, "findProperty", g_variant_new("(s)", objectName.c_str()), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
@@ -219,24 +219,24 @@ std::string VehicleMaster::findProperty(std::string objectName)
                LoggerE("Could not find property");
                return ""; 
        }
-       
+
        if(error)
        {
                LoggerD("error calling findProperty "<< error->message);
                g_error_free(error);
                return "";
        }
-       
+
        LoggerD("returned object path: " << g_variant_get_type_string(objectPath));
-       
+
        gchar * objP;
        g_variant_get(objectPath,"(o)", &objP);
-       
+
        LoggerD("findProperty() returned object path: " <<objP);
-       
+
        g_object_unref(managerProxy);
        g_variant_unref(objectPath);    
-       
+
        return objP;
        
 }
@@ -244,9 +244,9 @@ std::string VehicleMaster::findProperty(std::string objectName)
 void VehicleMaster::onSignalReceived(std::string objectName, std::map<std::string, GVariant*> propertyMap)
 {
        LoggerD("Entered");
-       
+
        std::stringstream json;
-               
+
        json<<"{";
 
        for(auto itr = propertyMap.begin(); itr != propertyMap.end(); itr++)
@@ -270,15 +270,15 @@ void VehicleMaster::onSignalReceived(std::string objectName, std::map<std::strin
        LoggerD("get json: " << json.str().c_str());
 
        JSStringRef jsonString = JSStringCreateWithUTF8CString(json.str().c_str());
-               
+
        std::list<VehicleSubscribeCB> cbs = objectToFunctionListMap[objectName];
-       
+
        if(!cbs.size())
        {
                LoggerD("No callbacks for this signal.  aborting");
                return;
        }
-       
+
        auto cbitr = cbs.begin();
        
        JSValueRef value =  JSValueMakeFromJSONString((*cbitr).context, jsonString);
@@ -290,7 +290,7 @@ void VehicleMaster::onSignalReceived(std::string objectName, std::map<std::strin
        }
 
        const JSValueRef arguments[1] = { value };
-       
+
        try{
        for(auto itr = cbs.begin(); itr != cbs.end(); itr++)
        {
@@ -306,5 +306,27 @@ void VehicleMaster::onSignalReceived(std::string objectName, std::map<std::strin
        }
 }
 
+GVariant* VehicleMaster::listObjects()
+{
+       LoggerD("Entered");
+
+       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;
+       }
+
+       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:
index 42c4b99..8430e2c 100644 (file)
@@ -54,18 +54,16 @@ callback SupportedPropertiesCallback = void (sequence<DOMString> properties);
 interface Vehicle  { 
 
        /**  
-        *  \brief returns supported properties  
-        *  \arg VehiclePropertyCallback successCallback function to be called when method has completed successfully  
-        *  \arg VehiclePropertyErrorCallback errorCallback this function is called when an error has occured.
+        *  \brief returns supported object types
         **/
-       getSupported(SupportedPropertiesCallback successCallback, optional VehiclePropertyErrorCallback errorCallback);
+       sequence<DOMString> supported();
 
        /**  
-        *  \brief fetch the current value for 'property'.  
-        *  \arg DOMString property is the requested property to be retrieved.
-        *  \returns object representing the requested 'property'
+        *  \brief fetch the current value for 'objectType'.  
+        *  \arg DOMString objectType is the requested property to be retrieved.
+        *  \returns object representing the requested 'objectType'
         **/
-       any get(DOMString property);  
+       any get(DOMString objectType);  
 
        /** \brief subscribe to the given property and get callbacks when it changes
         *  \arg DOMString property property to set