fixed up database get ranged issues
authorKevron Rees <tripzero.kev@gmail.com>
Thu, 16 May 2013 03:13:50 +0000 (20:13 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Thu, 16 May 2013 03:13:50 +0000 (20:13 -0700)
examples/databaseconfig
examples/storage
plugins/database/databasesink.cpp
plugins/examplesink.cpp

index ceee3d2..f2430e0 100644 (file)
@@ -9,8 +9,9 @@
                {
                        "name" : "Database",
                        "path" : "/usr/lib/automotive-message-broker/databasesinkplugin.so",
-                       "properties" : "{ 'properties' : ['VehicleSpeed'] }",
-                       "startOnLoad" : "true"
+                       "properties" : "{ 'properties' : ['VehicleSpeed','EngineSpeed'] }",
+                       "startOnLoad" : "true",
+                       "bufferLength" : "1"
                },
                {
                        "name" : "Example Sink",
index 65bd8a3..171b84a 100644 (file)
Binary files a/examples/storage and b/examples/storage differ
index 5c5291c..93195b3 100644 (file)
@@ -2,6 +2,8 @@
 #include "abstractroutingengine.h"
 #include "listplusplus.h"
 
+int bufferLength = 100;
+
 extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map<string, string> config)
 {
        return new DatabaseSinkManager(routingengine, config);
@@ -44,7 +46,7 @@ void * cbFunc(gpointer data)
 
                insertList.push_back(dict);
 
-               if(insertList.size() > 100)
+               if(insertList.size() > bufferLength)
                {
                        shared->db->exec("BEGIN IMMEDIATE TRANSACTION");
                        for(int i=0; i< insertList.size(); i++)
@@ -129,6 +131,11 @@ DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std::
                setDatabaseFileName(config["databaseFile"]);
        }
 
+       if(config.find("bufferLength") != config.end())
+       {
+               bufferLength = atoi(config["bufferLength"].c_str());
+       }
+
        if(config.find("properties") != config.end())
        {
                parseConfig();
@@ -364,6 +371,12 @@ void DatabaseSink::propertyChanged(VehicleProperty::Property property, AbstractP
        if(!shared)
                return;
 
+       if(!ListPlusPlus<VehicleProperty::Property>(&mSupported).contains(property))
+       {
+               mSupported.push_back(property);
+               routingEngine->setSupported(mSupported, this);
+       }
+
        DBObject* obj = new DBObject;
        obj->key = property;
        obj->value = value->toString();
@@ -426,7 +439,7 @@ void DatabaseSink::getRangePropertyAsync(AsyncRangePropertyReply *reply)
        ostringstream query;
        query.precision(15);
 
-       query<<"SELECT * from "<<tablename<<" WHERE ";
+       query<<"SELECT * from "<<tablename<<" WHERE key='"<<reply->property<<"' AND";
 
        if(reply->timeBegin && reply->timeEnd)
        {
index 333fa67..51e3535 100644 (file)
@@ -158,7 +158,7 @@ void ExampleSink::supportedChanged(PropertyList supportedProperties)
                        for(auto itr = values.begin(); itr != values.end(); itr++)
                        {
                                auto val = *itr;
-                               DebugOut(1)<<"Velocity value from past: "<<val->toString()<<" time: "<<val->timestamp<<endl;
+                               DebugOut(1)<<"Value from past: ("<<val->name<<"): "<<val->toString()<<" time: "<<val->timestamp<<endl;
                        }
 
                        delete reply;