change to example and dbus plugins
authorKevron Rees <tripzero.kev@gmail.com>
Sun, 27 Apr 2014 19:32:41 +0000 (12:32 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Sun, 27 Apr 2014 19:32:41 +0000 (12:32 -0700)
Example plugin was change to reflect best-practices.  Allocating properties for every change should be avoided.  Dbus plugin caching when not registered is now disabled.  This improved performance by about 40%.

plugins/dbus/dbusplugin.cpp
plugins/exampleplugin.cpp
plugins/exampleplugin.h

index 5835cef..0dcf8bd 100644 (file)
@@ -69,6 +69,9 @@ void DBusSink::supportedChanged(const PropertyList &supportedProperties)
 
 void DBusSink::propertyChanged(AbstractPropertyType *value)
 {
+       if(!isRegistered())
+               return;
+
        VehicleProperty::Property property = value->name;
 
        if(propertyDBusMap.find(property) == propertyDBusMap.end() || value->zone != zoneFilter)
index 6ad6622..737605e 100644 (file)
@@ -33,9 +33,11 @@ uint16_t accelerationX = 0;
 Transmission::TransmissionPositions transmissionShiftPostion = Transmission::Neutral;
 uint16_t steeringWheelAngle=0;
 uint16_t throttlePos = 0;
-uint16_t engineCoolant = 40;
+int engineCoolant = 40;
 bool machineGun = false;
 
+const char* id = "6dd4268a-c605-4a06-9034-59c1e8344c8e";
+
 static gboolean timeoutCallback(gpointer data)
 {
        ExampleSourcePlugin* src = (ExampleSourcePlugin*)data;
@@ -113,7 +115,7 @@ extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<str
 
 const string ExampleSourcePlugin::uuid()
 {
-       return "6dd4268a-c605-4a06-9034-59c1e8344c8e";
+       return id;
 }
 
 
@@ -363,15 +365,15 @@ void ExampleSourcePlugin::randomizeProperties()
        DebugOut()<<"setting velocity to: "<<velocity<<endl;
        DebugOut()<<"setting enginespeed to: "<<engineSpeed<<endl;
        
-       VehicleProperty::VehicleSpeedType vel(velocity);
-       VehicleProperty::EngineSpeedType es(engineSpeed);
-       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);
+       vel.setValue(velocity);
+       es.setValue(engineSpeed);
+       ac.setValue(accelerationX);
+       swa.setValue(steeringWheelAngle);
+       tsp.setValue(transmissionShiftPostion);
+       tgp.setValue(transmissionShiftPostion);
+       tp.setValue(throttlePos);
+       ec.setValue(engineCoolant);
+       mgt.setValue(machineGun);
 
        machineGun = !machineGun;
 
index 42108cf..fd2769e 100644 (file)
@@ -64,6 +64,16 @@ private:
        PropertyList mSupported;
        uint16_t velocity;
        uint16_t engineSpeed;
+
+       VehicleProperty::VehicleSpeedType vel;
+       VehicleProperty::EngineSpeedType es;
+       VehicleProperty::AccelerationXType ac;
+       VehicleProperty::SteeringWheelAngleType swa;
+       VehicleProperty::TransmissionShiftPositionType tsp;
+       VehicleProperty::TransmissionGearPositionType tgp;
+       VehicleProperty::ThrottlePositionType tp;
+       VehicleProperty::EngineCoolantTemperatureType ec;
+       VehicleProperty::MachineGunTurretStatusType mgt;
 };
 
 #endif // EXAMPLEPLUGIN_H