reorganized how custom properties are laid out
authorKevron Rees <kevron_m_rees@linux.intel.com>
Fri, 11 Jan 2013 21:58:52 +0000 (13:58 -0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Fri, 11 Jan 2013 21:58:52 +0000 (13:58 -0800)
plugins/dbus/abstractdbusinterface.cpp
plugins/dbus/custompropertyinterface.cpp
plugins/dbus/custompropertyinterface.h
plugins/dbus/dbusinterfacemanager.cpp
plugins/obd2plugin/obd2source.cpp

index aad3fd2..1272057 100644 (file)
@@ -88,9 +88,18 @@ void AbstractDBusInterface::registerObject()
        }
 
        GDBusInterfaceInfo* mInterfaceInfo = g_dbus_node_info_lookup_interface(introspection, mInterfaceName.c_str());
-       
-       const GDBusInterfaceVTable vtable = { NULL, AbstractDBusInterface::getProperty, AbstractDBusInterface::setProperty };
-       
+
+       auto fakeMethodCb = [](GDBusConnection *connection,
+                       const gchar *sender,
+                       const gchar *object_path,
+                       const gchar *interface_name,
+                       const gchar *method_name,
+                       GVariant *parameters,
+                       GDBusMethodInvocation *invocation,
+                       gpointer user_data) { };
+
+       const GDBusInterfaceVTable vtable = { fakeMethodCb, AbstractDBusInterface::getProperty, AbstractDBusInterface::setProperty };
+
        regId = g_dbus_connection_register_object(mConnection, mObjectPath.c_str(), mInterfaceInfo, &vtable, NULL, NULL, &error);
        
        if(error) throw -1;
@@ -139,7 +148,6 @@ void AbstractDBusInterface::startRegistration()
 
 GVariant* AbstractDBusInterface::getProperty(GDBusConnection* connection, const gchar* sender, const gchar* objectPath, const gchar* interfaceName, const gchar* propertyName, GError** error, gpointer userData)
 {
-       *error = NULL;
        if(interfaceMap.count(interfaceName))
        {
                GVariant* value = interfaceMap[interfaceName]->getProperty(propertyName);
index ceeb9fd..f449176 100644 (file)
@@ -1,15 +1,15 @@
 #include "custompropertyinterface.h"
 #include "vehicleproperty.h"
 #include "varianttype.h"
+#include "listplusplus.h"
 
-CustomPropertyInterface::CustomPropertyInterface(AbstractRoutingEngine *re, GDBusConnection *connection)
-       :DBusSink("org.automotive.custom","/org/automotive/custom", re, connection, map<string, string>())
+CustomPropertyInterface::CustomPropertyInterface(VehicleProperty::Property prop, AbstractRoutingEngine *re, GDBusConnection *connection)
+       :DBusSink("org.automotive."+prop,"/org/automotive/custom/"+prop, re, connection, map<string, string>())
 {
        PropertyList list = VehicleProperty::customProperties();
-       for (auto itr = list.begin(); itr != list.end(); itr++)
-       {
-               VehicleProperty::Property prop = *itr;
 
+       if(ListPlusPlus<VehicleProperty::Property>(&list).contains(prop))
+       {
                propertyDBusMap[prop] = new VariantType(re, prop, VariantType::ReadWrite, this);
        }
 
index c6a8207..d58823c 100644 (file)
@@ -6,7 +6,7 @@
 class CustomPropertyInterface: DBusSink
 {
 public:
-       CustomPropertyInterface(AbstractRoutingEngine* re, GDBusConnection* connection);
+       CustomPropertyInterface(VehicleProperty::Property, AbstractRoutingEngine* re, GDBusConnection* connection);
 };
 
 
index f33aacb..fb4107f 100644 (file)
@@ -52,7 +52,16 @@ on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_d
        ConstructProperty(HornProperty);
        ConstructProperty(FuelProperty);
        ConstructProperty(EngineOilProperty);
-       ConstructProperty(CustomPropertyInterface);
+
+       PropertyList list = VehicleProperty::customProperties();
+
+       for (auto itr = list.begin(); itr != list.end(); itr++)
+       {
+               VehicleProperty::Property prop = *itr;
+
+               new CustomPropertyInterface(prop,iface->re,connection);
+       }
+
 
 }
 
index ad6b0c2..f959f79 100644 (file)
@@ -918,7 +918,30 @@ void OBD2Source::getPropertyAsync(AsyncPropertyReply *reply)
 AsyncPropertyReply *OBD2Source::setProperty(AsyncSetPropertyRequest request )
 {
        AsyncPropertyReply* reply = new AsyncPropertyReply (request);
-       reply->success = false;
+
+       if(request.property == Obd2Connected)
+       {
+               if(request.value->value<bool>() == true)
+               {
+                       CommandRequest *req = new CommandRequest();
+                       req->req = "connectifnot";
+                       g_async_queue_push(commandQueue,req);
+               }
+               else
+               {
+                       CommandRequest *req = new CommandRequest();
+                       req->req = "disconnect";
+                       g_async_queue_push(commandQueue,req);
+               }
+
+               reply->success = true;
+       }
+
+       else
+       {
+               reply->success = false;
+       }
+
        try
        {
                reply->completed(reply);