fixed up athe setSupported issue.
authorKevron Rees <tripzero.kev@gmail.com>
Wed, 17 Jul 2013 19:27:38 +0000 (12:27 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Wed, 17 Jul 2013 19:27:38 +0000 (12:27 -0700)
ambd/core.cpp
ambd/glibmainloop.cpp
plugins/examplesink.cpp

index 59ad1af..8e96bb5 100644 (file)
@@ -201,31 +201,12 @@ std::list<std::string> Core::sourcesForProperty(VehicleProperty::Property proper
        return l;
 }
 
-struct UserData{
-       AbstractSink* sink;
-       PropertyList list;
-};
-
 void Core::registerSink(AbstractSink *self)
 {
        if(!ListPlusPlus<AbstractSink*>(&mSinks).contains(self))
        {
                mSinks.push_back(self);
        }
-
-       auto cb = [](gpointer userdata) {
-               UserData* foo = (UserData*)userdata;
-               foo->sink->supportedChanged(foo->list);
-
-               delete foo;
-               return (int)0;
-       };
-
-       UserData* foo = new UserData;
-       foo->sink = self;
-       foo->list = mMasterPropertyList;
-
-       g_timeout_add(0, (GSourceFunc) cb, foo);
 }
 
 void Core::unregisterSink(AbstractSink *self)
index cb23f93..ca8c194 100644 (file)
@@ -17,5 +17,6 @@ GlibMainLoop::~GlibMainLoop()
 int GlibMainLoop::exec()
 {
        g_main_loop_run(mainLoop);
+       return 1;
 }
 
index 8fdcfdc..95c8773 100644 (file)
@@ -20,6 +20,7 @@
 #include "examplesink.h"
 #include "abstractroutingengine.h"
 #include "debugout.h"
+#include "listplusplus.h"
 
 #include <glib.h>
 
@@ -33,9 +34,10 @@ ExampleSink::ExampleSink(AbstractRoutingEngine* engine, map<string, string> conf
 {
        routingEngine->subscribeToProperty(VehicleProperty::EngineSpeed, this);
        routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
+       routingEngine->subscribeToProperty(VehicleProperty::Latitude, this);
+       routingEngine->subscribeToProperty(VehicleProperty::Longitude, this);
 
-//     supportedChanged(routingEngine->supported());
-
+       supportedChanged(engine->supported());
 }
 
 
@@ -46,102 +48,116 @@ PropertyList ExampleSink::subscriptions()
 
 void ExampleSink::supportedChanged(PropertyList supportedProperties)
 {
-       printf("Support changed!\n");
-       routingEngine->subscribeToProperty(VehicleProperty::EngineSpeed, this);
-       routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
-       routingEngine->subscribeToProperty(VehicleProperty::Latitude, this);
-       routingEngine->subscribeToProperty(VehicleProperty::Longitude, this);
+       DebugOut()<<"Support changed!"<<endl;
 
-       AsyncPropertyRequest velocityRequest;
-       velocityRequest.property = VehicleProperty::VehicleSpeed;
-       velocityRequest.completed = [](AsyncPropertyReply* reply)
+       if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::VehicleSpeed))
        {
-               if(!reply->success)
-                       DebugOut(DebugOut::Error)<<"Velocity Async request failed ("<<reply->error<<")"<<endl;
-               else
-                       DebugOut(0)<<"Velocity Async request completed: "<<reply->value->toString()<<endl;
-               delete reply;
-       };
+               AsyncPropertyRequest velocityRequest;
+               velocityRequest.property = VehicleProperty::VehicleSpeed;
+               velocityRequest.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                               DebugOut(DebugOut::Error)<<"Velocity Async request failed ("<<reply->error<<")"<<endl;
+                       else
+                               DebugOut(0)<<"Velocity Async request completed: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       routingEngine->getPropertyAsync(velocityRequest);
+               routingEngine->getPropertyAsync(velocityRequest);
+       }
 
-       AsyncPropertyRequest vinRequest;
-       vinRequest.property = VehicleProperty::VIN;
-       vinRequest.completed = [](AsyncPropertyReply* reply)
+       if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::VIN))
        {
-               if(!reply->success)
-                       DebugOut(DebugOut::Error)<<"VIN Async request failed ("<<reply->error<<")"<<endl;
-               else
-                       DebugOut(0)<<"VIN Async request completed: "<<reply->value->toString()<<endl;
-               delete reply;
-       };
-
-       routingEngine->getPropertyAsync(vinRequest);
+               AsyncPropertyRequest vinRequest;
+               vinRequest.property = VehicleProperty::VIN;
+               vinRequest.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                               DebugOut(DebugOut::Error)<<"VIN Async request failed ("<<reply->error<<")"<<endl;
+                       else
+                               DebugOut(0)<<"VIN Async request completed: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       AsyncPropertyRequest wmiRequest;
-       wmiRequest.property = VehicleProperty::WMI;
-       wmiRequest.completed = [](AsyncPropertyReply* reply)
+               routingEngine->getPropertyAsync(vinRequest);
+       }
+       if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::WMI))
        {
-               if(!reply->success)
-                       DebugOut(DebugOut::Error)<<"WMI Async request failed ("<<reply->error<<")"<<endl;
-               else
-               DebugOut(1)<<"WMI Async request completed: "<<reply->value->toString()<<endl;
-               delete reply;
-       };
-
-       routingEngine->getPropertyAsync(wmiRequest);
+               AsyncPropertyRequest wmiRequest;
+               wmiRequest.property = VehicleProperty::WMI;
+               wmiRequest.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                               DebugOut(DebugOut::Error)<<"WMI Async request failed ("<<reply->error<<")"<<endl;
+                       else
+                               DebugOut(1)<<"WMI Async request completed: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       AsyncPropertyRequest batteryVoltageRequest;
-       batteryVoltageRequest.property = VehicleProperty::BatteryVoltage;
-       batteryVoltageRequest.completed = [](AsyncPropertyReply* reply)
+               routingEngine->getPropertyAsync(wmiRequest);
+       }
+       if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::BatteryVoltage))
        {
-               if(!reply->success)
-                       DebugOut(DebugOut::Error)<<"BatteryVoltage Async request failed ("<<reply->error<<")"<<endl;
-               else
-                       DebugOut(1)<<"BatteryVoltage Async request completed: "<<reply->value->toString()<<endl;
-               delete reply;
-       };
-
-       routingEngine->getPropertyAsync(batteryVoltageRequest);
+               AsyncPropertyRequest batteryVoltageRequest;
+               batteryVoltageRequest.property = VehicleProperty::BatteryVoltage;
+               batteryVoltageRequest.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                               DebugOut(DebugOut::Error)<<"BatteryVoltage Async request failed ("<<reply->error<<")"<<endl;
+                       else
+                               DebugOut(1)<<"BatteryVoltage Async request completed: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       AsyncPropertyRequest doorsPerRowRequest;
-       doorsPerRowRequest.property = VehicleProperty::DoorsPerRow;
-       doorsPerRowRequest.completed = [](AsyncPropertyReply* reply)
+               routingEngine->getPropertyAsync(batteryVoltageRequest);
+       }
+       if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::DoorsPerRow))
        {
-               if(!reply->success)
-                       DebugOut(DebugOut::Error)<<"Doors per row Async request failed ("<<reply->error<<")"<<endl;
-               else
-                       DebugOut(1)<<"Doors per row: "<<reply->value->toString()<<endl;
-               delete reply;
-       };
+               AsyncPropertyRequest doorsPerRowRequest;
+               doorsPerRowRequest.property = VehicleProperty::DoorsPerRow;
+               doorsPerRowRequest.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                               DebugOut(DebugOut::Error)<<"Doors per row Async request failed ("<<reply->error<<")"<<endl;
+                       else
+                               DebugOut(1)<<"Doors per row: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       routingEngine->getPropertyAsync(doorsPerRowRequest);
+               routingEngine->getPropertyAsync(doorsPerRowRequest);
+       }
 
-       AsyncPropertyRequest airbagStatus;
-       airbagStatus.property = VehicleProperty::AirbagStatus;
-       airbagStatus.completed = [](AsyncPropertyReply* reply)
+       if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::AirbagStatus))
        {
-               if(!reply->success)
-                       DebugOut(DebugOut::Error)<<"Airbag Async request failed ("<<reply->error<<")"<<endl;
-               else
-                       DebugOut(1)<<"Airbag Status: "<<reply->value->toString()<<endl;
-               delete reply;
-       };
+               AsyncPropertyRequest airbagStatus;
+               airbagStatus.property = VehicleProperty::AirbagStatus;
+               airbagStatus.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                               DebugOut(DebugOut::Error)<<"Airbag Async request failed ("<<reply->error<<")"<<endl;
+                       else
+                               DebugOut(1)<<"Airbag Status: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       routingEngine->getPropertyAsync(airbagStatus);
+               routingEngine->getPropertyAsync(airbagStatus);
+       }
 
-       AsyncPropertyRequest exteriorBrightness;
-       exteriorBrightness.property = VehicleProperty::ExteriorBrightness;
-       exteriorBrightness.completed = [](AsyncPropertyReply* reply)
+       if(ListPlusPlus<VehicleProperty::Property>(&supportedProperties).contains(VehicleProperty::ExteriorBrightness))
        {
-               if(!reply->success)
-                       DebugOut(DebugOut::Error)<<"Exterior Brightness Async request failed ("<<reply->error<<")"<<endl;
-               else
-                       DebugOut(1)<<"Exterior Brightness: "<<reply->value->toString()<<endl;
-               delete reply;
-       };
+               AsyncPropertyRequest exteriorBrightness;
+               exteriorBrightness.property = VehicleProperty::ExteriorBrightness;
+               exteriorBrightness.completed = [](AsyncPropertyReply* reply)
+               {
+                       if(!reply->success)
+                               DebugOut(DebugOut::Error)<<"Exterior Brightness Async request failed ("<<reply->error<<")"<<endl;
+                       else
+                               DebugOut(1)<<"Exterior Brightness: "<<reply->value->toString()<<endl;
+                       delete reply;
+               };
 
-       routingEngine->getPropertyAsync(exteriorBrightness);
+               routingEngine->getPropertyAsync(exteriorBrightness);
+       }
 
        auto getRangedCb = [](gpointer data)
        {