fixed issue with complex objects only firing the last property and dropping all others
authorKevron Rees <kevron.m.rees@intel.com>
Thu, 20 Mar 2014 23:11:54 +0000 (16:11 -0700)
committerKevron Rees <kevron.m.rees@intel.com>
Thu, 20 Mar 2014 23:11:54 +0000 (16:11 -0700)
plugins/dbus/dbussignaller.h
plugins/exampleplugin.cpp
plugins/gpsnmea/gpsnmea.cpp

index b5ddcd4..27b5575 100644 (file)
@@ -2,12 +2,55 @@
 #define _DBUSSIGNALLER_H_
 
 #include <gio/gio.h>
-#include <map>
+#include <unordered_set>
 #include <string>
 
 #include "debugout.h"
 #include "abstractproperty.h"
 
+class DBusSignal;
+
+namespace std {
+  template <>
+  struct hash<DBusSignal>
+  {
+       typedef DBusSignal   argument_type;
+       typedef std::size_t  result_type;
+
+       result_type operator()(const DBusSignal & t) const
+       {
+         std::size_t val { 0 };
+         return val;
+       }
+  };
+}
+
+class DBusSignal
+{
+public:
+       DBusSignal():connection(nullptr), property(nullptr){}
+       DBusSignal(GDBusConnection* conn, std::string objPath, std::string iface, std::string sigName, AbstractProperty* var)
+               : connection(conn), objectPath(objPath), interface(iface), signalName(sigName), property(var)
+       {
+
+       }
+
+       bool operator == (const DBusSignal &other) const
+       {
+               return connection == other.connection &&
+                               objectPath == other.objectPath &&
+                               interface == other.interface &&
+                               signalName == other.signalName &&
+                               property == other.property;
+       }
+
+       GDBusConnection* connection;
+       std::string objectPath;
+       std::string interface;
+       std::string signalName;
+       AbstractProperty* property;
+};
+
 class DBusSignaller
 {
 public:
@@ -23,26 +66,9 @@ public:
        {
                DBusSignal signal(conn, objPath, iface, sigName, prop);
 
-               queue[objPath] = signal;
+               queue.insert(signal);
        }
 
-       class DBusSignal
-       {
-       public:
-               DBusSignal():connection(nullptr), property(nullptr){}
-               DBusSignal(GDBusConnection* conn, std::string objPath, std::string iface, std::string sigName, AbstractProperty* var)
-                       : connection(conn), objectPath(objPath), interface(iface), signalName(sigName), property(var)
-               {
-
-               }
-
-               GDBusConnection* connection;
-               std::string objectPath;
-               std::string interface;
-               std::string signalName;
-               AbstractProperty* property;
-       };
-
 private:
 
        DBusSignaller() { }
@@ -51,12 +77,12 @@ private:
        {
                g_timeout_add(timeout,[](gpointer userData)
                {
-                       std::map<std::string, DBusSignal> *q = static_cast<std::map<std::string, DBusSignal>*>(userData);
-                       std::map<std::string, DBusSignal> queue = *q;
+                       std::unordered_set<DBusSignal> *q = static_cast<std::unordered_set< DBusSignal>*>(userData);
+                       std::unordered_set<DBusSignal> queue = *q;
 
-                       for(auto sig : queue)
+                       for(auto s : queue)
                        {
-                               DBusSignal signal = sig.second;
+                               DBusSignal signal = s;
 
                                GError* error = nullptr;
 
@@ -76,14 +102,14 @@ private:
 
                                g_dbus_connection_emit_signal(signal.connection, NULL, signal.objectPath.c_str(), "org.freedesktop.DBus.Properties", signal.signalName.c_str(), g_variant_new("(sa{sv}as)",
                                                                                                                                                                                                                                                                                                                                         signal.interface.c_str(),
-                                                                                                                                                                                                                                                                                                                                        &builder, NULL), &error);
+                                                                                                                                                                                                                                                                                                                &builder, NULL), &error);
 
                                if(error)
                                {
                                        DebugOut(DebugOut::Error)<<error->message<<std::endl;
                                }
 
-                               queue.erase(signal.objectPath);
+                               queue.erase(signal);
 
                        }
 
@@ -94,7 +120,7 @@ private:
                },&queue);
        }
 
-       std::map<std::string, DBusSignal> queue;
+       std::unordered_set<DBusSignal> queue;
 
        static DBusSignaller * singleton;
 };
index e862b01..5bb86dd 100644 (file)
@@ -63,6 +63,7 @@ ExampleSourcePlugin::ExampleSourcePlugin(AbstractRoutingEngine* re, map<string,
        addPropertySupport(VehicleProperty::VehicleSpeed, Zone::None);
        addPropertySupport(VehicleProperty::AccelerationX, Zone::None);
        addPropertySupport(VehicleProperty::TransmissionShiftPosition, Zone::None);
+       addPropertySupport(VehicleProperty::TransmissionGearPosition, Zone::None);
        addPropertySupport(VehicleProperty::SteeringWheelAngle, Zone::None);
        addPropertySupport(VehicleProperty::ThrottlePosition, Zone::None);
        addPropertySupport(VehicleProperty::EngineCoolantTemperature, Zone::None);
@@ -368,6 +369,7 @@ void ExampleSourcePlugin::randomizeProperties()
        VehicleProperty::AccelerationXType ac(accelerationX);
        VehicleProperty::SteeringWheelAngleType swa(steeringWheelAngle);
        VehicleProperty::TransmissionShiftPositionType tsp(transmissionShiftPostion);
+       VehicleProperty::TransmissionGearPositionType tgp(transmissionShiftPostion);
        VehicleProperty::ThrottlePositionType tp(throttlePos);
        VehicleProperty::EngineCoolantTemperatureType ec(engineCoolant);
        VehicleProperty::MachineGunTurretStatusType mgt(machineGun);
@@ -381,6 +383,7 @@ void ExampleSourcePlugin::randomizeProperties()
        routingEngine->updateProperty(&tsp, uuid());
        routingEngine->updateProperty(&tp, uuid());
        routingEngine->updateProperty(&ec, uuid());
+       routingEngine->updateProperty(&tgp, uuid());
 
 }
 
index e4c9502..4ecdeed 100644 (file)
@@ -276,8 +276,6 @@ void Location::parseSpeed(string spd)
 {
        try
        {
-
-
                double s = boost::lexical_cast<double>(spd);
 
                ///to kph: