initial working plugin
authorKevron Rees <kevron_m_rees@linux.intel.com>
Tue, 9 Jul 2013 20:49:37 +0000 (13:49 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Tue, 9 Jul 2013 20:49:37 +0000 (13:49 -0700)
src/Vehicle/JSVehicle.cpp
src/Vehicle/Vehicle.cpp

index 40bf34d..22a23de 100644 (file)
@@ -102,7 +102,7 @@ JSValueRef JSVehicle::get(JSContextRef context,
                const JSValueRef arguments[],
                JSValueRef* exception)
 {
-       LoggerD("Entered ");
+       LoggerD("Entered awesome");
        //Try {
                VehiclePrivObject* privateObject = static_cast<VehiclePrivObject*>(JSObjectGetPrivate(thisObject));
                if (NULL == privateObject)
@@ -111,16 +111,24 @@ JSValueRef JSVehicle::get(JSContextRef context,
                        //return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
                }
 
+               LoggerD("Validating arguments: " << argumentCount);
+               
                ArgumentValidator validator(context, argumentCount, arguments);
                std::string property = validator.toString(0);
+               
+               LoggerD("property to get: " << property);
 
                VehiclePtr vehicle(privateObject->getObject());
 
                std::list<AbstractPropertyType*> properties = vehicle->get(property);
 
+               LoggerD("properties in dbus object: "<<properties.size());
+               
                std::stringstream json;
 
 
+               
+               
                json<<"{";
 
                for(auto itr = properties.begin(); itr != properties.end(); itr++)
@@ -136,8 +144,12 @@ JSValueRef JSVehicle::get(JSContextRef context,
                json << "}";
 
                Converter converter(context);
+               
+               LoggerD("get json: " << json.str().c_str());
 
-               return converter.toJSValueRef(json.str());
+               JSStringRef jsonString = converter.toJSStringRef(json.str());
+               
+               return JSValueMakeFromJSONString(context, jsonString);
 
 
        /*} Catch (PlatformException) {
index b154bd9..2890a93 100644 (file)
@@ -2,6 +2,7 @@
 #include <gio/gio.h>
 #include <stdexcept>
 #include <list>
+#include <Logger.h>
 
 #include <Commons/ThreadPool.h>
 
@@ -19,12 +20,17 @@ using namespace WrtDeviceApis::Commons;
 VehicleMaster::VehicleMaster()
 :EventRequestReceiver<EventVehiclePropertyChanged>(ThreadEnum::APPLICATION_THREAD)
 {
+       VehicleProperty::factory();
 }
 
 
 
 std::list<AbstractPropertyType *> VehicleMaster::get(std::string property)
 {
+       LoggerD("Entered");
+       
+       std::list<AbstractPropertyType*> returnValue;
+       
        GError* error = NULL;
        GDBusProxy* managerProxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
                                                                                                                         "org.automotive.message.broker",
@@ -35,19 +41,37 @@ std::list<AbstractPropertyType *> VehicleMaster::get(std::string property)
 
        if(error)
        {
-               throw std::runtime_error("could not get automotive message broker Manager interface");
+               LoggerE("could not get automotive message broker Manager interface");
+               return returnValue;
        }
 
-
+       LoggerD("calling findProperty() with " <<property);
+       
        GVariant* objectPath = g_dbus_proxy_call_sync(managerProxy, "findProperty", g_variant_new("(s)", property.c_str()), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
 
-       const char* objP = g_variant_get_string(objectPath, NULL);
+       LoggerD("returned object path: " << g_variant_get_type_string(objectPath));
+       
+       gchar * objP;
+       g_variant_get(objectPath,"(o)", &objP);
+       
+       LoggerD("findProperty() returned object path: " <<objP);
+       
+       if(error)
+       {
+               LoggerD("error calling findProperty "<< error->message);
+               return returnValue;
+       }
+       
+       std::string objPStr = objP;
 
-       if(std::string(objP) == "")
+       if(objPStr == "")
        {
-               throw std::runtime_error("could not find property "+ property);
+               LoggerD("could not find property " << property);
+               return returnValue;
        }
 
+       LoggerD("Getting properties interface");
+       
        GDBusProxy* propertiesProxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
                                                                                                                                 "org.automotive.message.broker",
                                                                                                                                 objP,
@@ -60,20 +84,25 @@ std::list<AbstractPropertyType *> VehicleMaster::get(std::string property)
 
        if(error)
        {
-               throw std::runtime_error("failed to call GetAll on interface " + interfaceName);
+               LoggerD("failed to call GetAll on interface " << interfaceName);
+               return returnValue;
        }
 
        GVariantIter* iter;
        char* key;
        GVariant *value;
 
-       std::list<AbstractPropertyType*> returnValue;
-
        g_variant_get(propertyMap,"(a{sv})",&iter);
 
        while(g_variant_iter_next(iter,"{sv}", &key, &value))
        {
+               LoggerD("getting property for key: " << key);
                AbstractPropertyType* val = VehicleProperty::getPropertyTypeForPropertyNameValue(key);
+               if(!val)
+               {
+                       LoggerD("Error creating abstractpropertytype for key");
+                       return returnValue;
+               }
                val->fromVariant(value);
                returnValue.push_back(val);
        }