added vin and wmi support to dbus
authorKevron Rees <kevron_m_rees@linux.intel.com>
Tue, 29 Jan 2013 20:44:31 +0000 (12:44 -0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Tue, 29 Jan 2013 21:25:00 +0000 (13:25 -0800)
plugins/dbus/CMakeLists.txt
plugins/dbus/basicproperty.h
plugins/dbus/dbusinterfacemanager.cpp
plugins/dbus/dbusplugin.h
plugins/dbus/properties.h
plugins/dbus/varianttype.cpp
plugins/dbus/vehicleinfo.cpp [new file with mode: 0644]
plugins/dbus/vehicleinfo.h [new file with mode: 0644]
plugins/obd2plugin/obd2source.cpp

index 5cd1ff8..d8c6432 100644 (file)
@@ -3,8 +3,8 @@ include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs})
 
 pkg_check_modules(gio REQUIRED gio-2.0)
 
-set(dbussinkplugin_headers dbusplugin.h abstractproperty.h abstractdbusinterface.h dbusinterfacemanager.h basicproperty.h properties.h varianttype.h custompropertyinterface.h environmentproperties.h)
-set(dbussinkplugin_sources dbusplugin.cpp abstractproperty.cpp abstractdbusinterface.cpp dbusinterfacemanager.cpp basicproperty.cpp properties.cpp varianttype.cpp custompropertyinterface.cpp environmentproperties.cpp)
+set(dbussinkplugin_headers dbusplugin.h abstractproperty.h abstractdbusinterface.h dbusinterfacemanager.h basicproperty.h properties.h varianttype.h custompropertyinterface.h environmentproperties.h vehicleinfo.h)
+set(dbussinkplugin_sources dbusplugin.cpp abstractproperty.cpp abstractdbusinterface.cpp dbusinterfacemanager.cpp basicproperty.cpp properties.cpp varianttype.cpp custompropertyinterface.cpp environmentproperties.cpp vehicleinfo.cpp)
 
 add_library(dbussinkplugin MODULE ${dbussinkplugin_sources})
 set_target_properties(dbussinkplugin PROPERTIES PREFIX "")
index ba83f20..42dca27 100644 (file)
 #include "abstractproperty.h"
 #include "vehicleproperty.h"
 #include "abstractroutingengine.h"
+#include <functional>
 
 template <typename T>
 class BasicProperty: public AbstractProperty
 {
 public:
        BasicProperty(AbstractRoutingEngine* re, string ambPropertyName, string propertyName, string signature, Access access, AbstractDBusInterface *interface)
-               :AbstractProperty(propertyName, signature, access, interface)
+               :AbstractProperty(propertyName, signature, access, interface), routingEngine(re)
        {
                mAmbPropertyName = ambPropertyName;
+               //set default value:
+               AbstractProperty::setValue(VehicleProperty::getPropertyTypeForPropertyNameValue(ambPropertyName));
+
+               using namespace std::placeholders;
+
+               AsyncPropertyRequest request;
+               request.property = ambPropertyName;
+               request.completed = std::bind(&BasicProperty<T>::asyncReply,this,_1);
+               routingEngine->getPropertyAsync(request);
+
+       }
+
+       void asyncReply(AsyncPropertyReply* reply)
+       {
+               if(reply->success)
+                       AbstractProperty::setValue(reply->value);
+
+               delete reply;
        }
 
        void setValue(T val)
@@ -75,4 +94,63 @@ private:
        AbstractRoutingEngine* routingEngine;
 };
 
+
+class StringDBusProperty: public AbstractProperty
+{
+public:
+
+       StringDBusProperty(AbstractRoutingEngine* re, string ambPropertyName, string propertyName, string signature, Access access, AbstractDBusInterface *interface)
+               :AbstractProperty(propertyName, signature, access, interface), routingEngine(re), mAmbPropertyName(ambPropertyName)
+       {
+               //set default value:
+               AbstractProperty::setValue(VehicleProperty::getPropertyTypeForPropertyNameValue(ambPropertyName));
+
+               AsyncPropertyRequest request;
+               request.property = ambPropertyName;
+               request.completed = [this](AsyncPropertyReply* reply)
+               {
+                       AbstractProperty::setValue(reply->value);
+
+                       delete reply;
+               };
+
+               routingEngine->getPropertyAsync(request);
+       }
+
+       void setValue(std::string val)
+       {
+               AbstractProperty::setValue<std::string>(val);
+       }
+
+       virtual GVariant* toGVariant()
+       {
+               return g_variant_new(signature().c_str(), value()->toString().c_str());
+       }
+
+       virtual void fromGVariant(GVariant *value)
+       {
+               char *val;
+               g_variant_get(value,signature().c_str(), &val);
+
+               AbstractPropertyType* apt = VehicleProperty::getPropertyTypeForPropertyNameValue(mAmbPropertyName,val);
+
+               AsyncSetPropertyRequest request;
+               request.property = mAmbPropertyName;
+               request.value = apt;
+               request.completed = [apt](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success) {
+                               //TODO: throw DBus exception
+                       }
+                       delete apt;
+               };
+
+               routingEngine->setProperty(request);
+       }
+
+private:
+       VehicleProperty::Property mAmbPropertyName;
+       AbstractRoutingEngine* routingEngine;
+};
+
 #endif
index 1467b01..8df3a47 100644 (file)
@@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 #include "properties.h"
 #include "custompropertyinterface.h"
 #include "environmentproperties.h"
+#include "vehicleinfo.h"
 
 #define ConstructProperty(property) \
        new property(iface->re, connection);
@@ -53,6 +54,7 @@ on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_d
        ConstructProperty(FuelProperty);
        ConstructProperty(EngineOilProperty);
        ConstructProperty(ExteriorBrightnessProperty);
+       ConstructProperty(VehicleId);
 
        PropertyList list = VehicleProperty::customProperties();
 
index 103cfaa..ab9acac 100644 (file)
@@ -24,6 +24,7 @@
 #include "abstractdbusinterface.h"
 #include "basicproperty.h"
 #include <map>
+#include <type_traits>
 
 typedef std::map<VehicleProperty::Property, AbstractProperty*> PropertyDBusMap;
 
@@ -43,14 +44,11 @@ protected:
                propertyDBusMap[property] = new BasicProperty<T>(routingEngine, property, propertyName, signature, access, this);
        }
 
-       /*virtual void setProperty(VehicleProperty::Property name, AbstractPropertyType* value)
+
+       void wantPropertyString(VehicleProperty::Property property, std::string propertyName, std::string signature, AbstractProperty::Access access)
        {
-               AsyncSetPropertyRequest request;
-               request.property = name;
-               request.value = value;
-               request.completed = [](AsyncPropertyReply* reply) { delete reply; };
-               routingEngine->setProperty(request);
-       }*/
+               propertyDBusMap[property] = new StringDBusProperty(routingEngine, property, propertyName, signature, access, this);
+       }
 
        PropertyDBusMap propertyDBusMap;
 private:
index f43b0c3..6ea677c 100644 (file)
@@ -55,10 +55,10 @@ public:
        TirePressureProperty(AbstractRoutingEngine* re, GDBusConnection* connection)
                :DBusSink("org.automotive.tirePressure","/org/automotive/maintainance/tirePressure", re, connection, map<string, string>())
        {
-               wantProperty<uint16_t>(VehicleProperty::TirePressureLeftFront,"LeftFront", "q", AbstractProperty::Read);
-               wantProperty<uint16_t>(VehicleProperty::TirePressureRightFront,"RightFront", "q", AbstractProperty::Read);
-               wantProperty<uint16_t>(VehicleProperty::TirePressureLeftRear,"LeftRear", "q", AbstractProperty::Read);
-               wantProperty<uint16_t>(VehicleProperty::TirePressureRightRear,"RightRear", "q", AbstractProperty::Read);
+               wantProperty<double>(VehicleProperty::TirePressureLeftFront,"LeftFront", "d", AbstractProperty::Read);
+               wantProperty<double>(VehicleProperty::TirePressureRightFront,"RightFront", "d", AbstractProperty::Read);
+               wantProperty<double>(VehicleProperty::TirePressureLeftRear,"LeftRear", "d", AbstractProperty::Read);
+               wantProperty<double>(VehicleProperty::TirePressureRightRear,"RightRear", "d", AbstractProperty::Read);
                supportedChanged(re->supported());
        }
 };
@@ -69,7 +69,7 @@ public:
        VehiclePowerModeProperty(AbstractRoutingEngine* re, GDBusConnection* connection)
                :DBusSink("org.automotive.vehiclePowerMode","/org/automotive/runningstatus/vehiclePowerMode", re, connection, map<string, string>())
        {
-               wantProperty<uint16_t>(VehicleProperty::VehiclePowerMode, "VehiclePowerMode","b",AbstractProperty::Read);
+               wantProperty<Power::PowerModes>(VehicleProperty::VehiclePowerMode, "VehiclePowerMode","b",AbstractProperty::Read);
                supportedChanged(re->supported());
        }
 };
@@ -110,7 +110,7 @@ public:
                                                                                                                  "ShiftPosition", "y", AbstractProperty::Read);
                wantProperty<Transmission::TransmissionPositions>(VehicleProperty::TransmissionGearPosition,
                                                                                                                  "GearPosition", "y", AbstractProperty::Read);
-               wantProperty<Transmission::TransmissionPositions>(VehicleProperty::TransmissionMode,
+               wantProperty<Transmission::Mode>(VehicleProperty::TransmissionMode,
                                                                                                                  "Mode", "y", AbstractProperty::Read);
 
                supportedChanged(re->supported());
@@ -123,10 +123,10 @@ public:
        TireTemperatureProperty(AbstractRoutingEngine* re, GDBusConnection* connection)
                :DBusSink("org.automotive.tireTemperature","/org/automotive/maintainance/tireTemperature", re, connection, map<string, string>())
        {
-               wantProperty<uint16_t>(VehicleProperty::TireTemperatureLeftFront,"LeftFront", "i", AbstractProperty::Read);
-               wantProperty<uint16_t>(VehicleProperty::TireTemperatureRightFront,"RightFront", "i", AbstractProperty::Read);
-               wantProperty<uint16_t>(VehicleProperty::TireTemperatureLeftRear,"LeftRear", "i", AbstractProperty::Read);
-               wantProperty<uint16_t>(VehicleProperty::TireTemperatureRightRear,"RightRear", "i", AbstractProperty::Read);
+               wantProperty<double>(VehicleProperty::TireTemperatureLeftFront,"LeftFront", "d", AbstractProperty::Read);
+               wantProperty<double>(VehicleProperty::TireTemperatureRightFront,"RightFront", "d", AbstractProperty::Read);
+               wantProperty<double>(VehicleProperty::TireTemperatureLeftRear,"LeftRear", "d", AbstractProperty::Read);
+               wantProperty<double>(VehicleProperty::TireTemperatureRightRear,"RightRear", "d", AbstractProperty::Read);
                supportedChanged(re->supported());
        }
 };
@@ -218,7 +218,7 @@ public:
                        :DBusSink("org.automotive.engineOil", "/org/automotive/runningstatus/engineOil", re, connection, map<string, string>())
        {
                wantProperty<uint16_t>(VehicleProperty::EngineOilRemaining, "Remaining", "y", AbstractProperty::Read);
-               wantProperty<uint16_t>(VehicleProperty::EngineOilTemperature, "Temperature", "y", AbstractProperty::Read);
+               wantProperty<int>(VehicleProperty::EngineOilTemperature, "Temperature", "i", AbstractProperty::Read);
                wantProperty<uint16_t>(VehicleProperty::EngineOilPressure, "Pressure", "y", AbstractProperty::Read);
                supportedChanged(re->supported());
        }
index 6cd4bba..935abe4 100644 (file)
@@ -4,14 +4,15 @@
 VariantType::VariantType(AbstractRoutingEngine* re, std::string signature, std::string propertyName,  Access access, AbstractDBusInterface *interface)
        :AbstractProperty(propertyName, signature, access, interface),routingEngine(re)
 {
+       //set default value:
+       setValue(VehicleProperty::getPropertyTypeForPropertyNameValue(propertyName));
+
        AsyncPropertyRequest request;
        request.property = mPropertyName;
 
-       VariantType* foo = this;
-
-       request.completed = [foo](AsyncPropertyReply* reply)
+       request.completed = [this](AsyncPropertyReply* reply)
        {
-               foo->setValue(reply->value);
+               setValue(reply->value);
        };
 
        re->getPropertyAsync(request);
diff --git a/plugins/dbus/vehicleinfo.cpp b/plugins/dbus/vehicleinfo.cpp
new file mode 100644 (file)
index 0000000..693fa55
--- /dev/null
@@ -0,0 +1 @@
+#include "vehicleinfo.h"
diff --git a/plugins/dbus/vehicleinfo.h b/plugins/dbus/vehicleinfo.h
new file mode 100644 (file)
index 0000000..17264f1
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef _VEHICLEINFO_H_
+#define _VEHICLEINFO_H_
+
+
+#include "dbusplugin.h"
+#include "abstractdbusinterface.h"
+#include "abstractroutingengine.h"
+
+
+class VehicleId: public DBusSink
+{
+public:
+       VehicleId(AbstractRoutingEngine* re, GDBusConnection* connection)
+               :DBusSink("org.automotive.vehicleId","/org/automotive/vehicleinfo/vehicleId", re, connection, map<string, string>())
+       {
+               wantPropertyString(VehicleProperty::WMI, "WMI", "s", AbstractProperty::Read);
+               wantPropertyString(VehicleProperty::VIN, "VIN", "s", AbstractProperty::Read);
+
+               supportedChanged(re->supported());
+       }
+};
+
+
+#endif
index c2d8355..613c742 100644 (file)
@@ -502,7 +502,13 @@ void OBD2Source::setConfiguration(map<string, string> config)
 OBD2Source::OBD2Source(AbstractRoutingEngine *re, map<string, string> config)
        : AbstractSource(re, config)
 {
-       VehicleProperty::registerProperty(Obd2Connected,[](){ return new Obd2ConnectType(false); });
+       bool success = VehicleProperty::registerProperty(Obd2Connected,[](){ return new Obd2ConnectType(false); });
+
+       if(!success)
+       {
+               ///ERROR!
+       }
+
        clientConnected = false;
        m_re = re;