fixed how sinks are cleaned up. sinks were not being cleaned up properly before
authorKevron Rees <tripzero.kev@gmail.com>
Sat, 4 May 2013 19:38:36 +0000 (12:38 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Sat, 4 May 2013 19:38:36 +0000 (12:38 -0700)
ambd/core.cpp
ambd/core.h
ambd/glibmainloop.cpp
ambd/main.cpp
ambd/pluginloader.cpp
lib/abstractroutingengine.cpp
lib/abstractroutingengine.h
lib/abstractsink.cpp
plugins/database/databasesink.cpp
plugins/database/databasesink.h

index bb7ee7b..703e35d 100644 (file)
@@ -50,7 +50,11 @@ Core::Core()
 
 Core::~Core()
 {
-
+       for(auto itr = mSinks.begin(); itr != mSinks.end(); itr++)
+       {
+               AbstractSink* sink = *itr;
+               delete sink;
+       }
 }
 
 
index 7ad4ad0..bbbee72 100644 (file)
@@ -49,7 +49,6 @@ public:
        void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self);
        PropertyList supported() { return mMasterPropertyList; }
     
-protected: 
        ~Core();
        
 private:
index b568cf2..cb23f93 100644 (file)
@@ -11,7 +11,7 @@ GlibMainLoop::GlibMainLoop(int argc, char **argv)
 GlibMainLoop::~GlibMainLoop()
 {
        g_main_loop_quit(mainLoop);
-       exit(0);
+       //exit(0);
 }
 
 int GlibMainLoop::exec()
index b2dadd7..7a4c70c 100644 (file)
@@ -131,7 +131,9 @@ int main(int argc, char **argv)
 
        VehicleProperty::factory();
        
-       PluginLoader loader(config, new Core(), argc, argv);
+       Core routingEngine;
+
+       PluginLoader loader(config, &routingEngine , argc, argv);
        
        if(!loader.sources().size())
        {
index b02914a..4e191be 100644 (file)
@@ -209,15 +209,6 @@ PluginLoader::PluginLoader(string configFile, AbstractRoutingEngine* re, int arg
 
 PluginLoader::~PluginLoader()
 {
-       for(auto itr = mSinks.begin(); itr != mSinks.end(); itr++)
-       {
-               delete *itr;
-       }
-
-       for(auto itr = mSources.begin(); itr != mSources.end(); itr++)
-       {
-               delete *itr;
-       }
 }
 
 SinkList PluginLoader::sinks()
index 44c324a..f6623fe 100644 (file)
@@ -19,3 +19,8 @@
 
 #include "abstractroutingengine.h"
 
+
+
+AbstractRoutingEngine::~AbstractRoutingEngine()
+{
+}
index f372bef..c3bf267 100644 (file)
@@ -151,6 +151,8 @@ public:
 class AbstractRoutingEngine
 {
 public:
+       virtual ~AbstractRoutingEngine();
+
        virtual void setSupported(PropertyList supported, AbstractSource* source) = 0;
        virtual void updateSupported(PropertyList added, PropertyList removed) = 0;
        virtual void updateProperty(VehicleProperty::Property property, AbstractPropertyType* value, std::string uuid) = 0;
@@ -164,7 +166,6 @@ public:
        virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
        virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
        virtual PropertyList supported() = 0;
-
 };
 
 #endif // ABSTRACTROUTINGENGINE_H
index a8ec558..82de77f 100644 (file)
@@ -28,7 +28,7 @@ AbstractSink::AbstractSink(AbstractRoutingEngine* engine, map<string, string> co
 
 AbstractSink::~AbstractSink()
 {
-       routingEngine->unregisterSink(this);
+       //routingEngine->unregisterSink(this);
 }
 
 void AbstractSink::setConfiguration(map<string, string> config)
index fa28f2b..5c5291c 100644 (file)
@@ -126,7 +126,7 @@ DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std::
 
        if(config.find("databaseFile") != config.end())
        {
-               databaseName = config["databaseFile"];
+               setDatabaseFileName(config["databaseFile"]);
        }
 
        if(config.find("properties") != config.end())
@@ -143,30 +143,11 @@ DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std::
        mSupported.push_back(DatabaseLoggingProperty);
        mSupported.push_back(DatabasePlaybackProperty);
 
-       /// get supported:
-
-       initDb();
-
-       vector<vector<string> > supportedStr = shared->db->select("SELECT DISTINCT key FROM "+tablename);
-
-       for(int i=0; i < supportedStr.size(); i++)
-       {
-               if(!ListPlusPlus<VehicleProperty::Property>(&mSupported).contains(supportedStr[i][0]))
-                       mSupported.push_back(supportedStr[i][0]);
-       }
-
-       delete shared;
-       shared = NULL;
-
        routingEngine->setSupported(supported(), this);
 
        if(config.find("startOnLoad")!= config.end())
        {
-               AsyncSetPropertyRequest request;
-               request.property = DatabaseLoggingProperty;
-               request.value = new DatabaseLoggingType(true);
-
-               setProperty(request);
+               setLogging(true);
        }
 
        if(config.find("playbackMultiplier")!= config.end())
@@ -176,11 +157,7 @@ DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std::
 
        if(config.find("playbackOnLoad")!= config.end())
        {
-               AsyncSetPropertyRequest request;
-               request.property = DatabasePlaybackProperty;
-               request.value = new DatabasePlaybackType(true);
-
-               setProperty(request);
+               setPlayback(true);
        }
 
 
@@ -362,6 +339,26 @@ void DatabaseSink::setLogging(bool b)
        setProperty(request);
 }
 
+void DatabaseSink::setDatabaseFileName(string filename)
+{
+       databaseName = filename;
+
+       initDb();
+
+       vector<vector<string> > supportedStr = shared->db->select("SELECT DISTINCT key FROM "+tablename);
+
+       for(int i=0; i < supportedStr.size(); i++)
+       {
+               if(!ListPlusPlus<VehicleProperty::Property>(&mSupported).contains(supportedStr[i][0]))
+                       mSupported.push_back(supportedStr[i][0]);
+       }
+
+       delete shared;
+       shared = NULL;
+
+       routingEngine->setSupported(mSupported, this);
+}
+
 void DatabaseSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, std::string uuid)
 {
        if(!shared)
index 6e22259..f28a20b 100644 (file)
@@ -167,6 +167,7 @@ private: //methods:
        void initDb();
        void setPlayback(bool v);
        void setLogging(bool b);
+       void setDatabaseFileName(std::string filename);
 
 private:
        PropertyList mSubscriptions;