getRanged works with database sink 36/2536/1
authorKevron Rees <tripzero.kev@gmail.com>
Sun, 2 Dec 2012 03:29:42 +0000 (19:29 -0800)
committerKevron Rees <tripzero.kev@gmail.com>
Sun, 2 Dec 2012 03:29:42 +0000 (19:29 -0800)
lib/debugout.h
plugins/database/databasesink.cpp
plugins/database/databasesink.h
plugins/examplesink.cpp

index c8eb7fb..40cbb9b 100644 (file)
@@ -36,7 +36,7 @@ public:
        {
                ostream out(buf);
 
-               out.precision(5);
+               out.precision(15);
 
                if(mDebugLevel <= debugThreshhold)
                         out<<message<<" ";
@@ -47,7 +47,7 @@ public:
        {
                ostream out(buf);
 
-               out.precision(5);
+               out.precision(15);
 
                if(mDebugLevel <= debugThreshhold)
                         out<<endl;
index 742f5ac..eb4a0a5 100644 (file)
@@ -136,10 +136,38 @@ void DatabaseSink::getRangePropertyAsync(AsyncRangePropertyReply *reply)
 
        std::vector<std::vector<string>> data = db->select(query.str());
 
+       std::list<AbstractPropertyType*> cleanup;
+
        for(auto i=0;i<data.size();i++)
        {
-               for(auto n=0;n<data[i].size();n++)
-                       cout<<"Data: "<<data[i][n]<<endl;
+               if(data[i].size() != 5)
+                       continue;
+
+               DBObject dbobj;
+               dbobj.key = data[i][0];
+               dbobj.value = data[i][1];
+               dbobj.source = data[i][2];
+               dbobj.time = boost::lexical_cast<double>(data[i][3]);
+               dbobj.sequence = boost::lexical_cast<double>(data[i][4]);
+
+               AbstractPropertyType* property = VehicleProperty::getPropertyTypeForPropertyNameValue(dbobj.key,dbobj.value);
+               if(property)
+               {
+                       property->timestamp = dbobj.time;
+                       property->sequence = dbobj.sequence;
+
+                       reply->values.push_back(property);
+                       cleanup.push_back(property);
+               }
+       }
+
+       reply->success = true;
+       reply->completed(reply);
+
+       /// reply is owned by the requester of this call.  we own the data:
+       for(auto itr = cleanup.begin(); itr != cleanup.end(); itr++)
+       {
+               delete *itr;
        }
 
        delete db;
index 2cdf208..e759141 100644 (file)
@@ -99,6 +99,10 @@ public:
        {
                db = new BaseDB;
        }
+       ~Shared()
+       {
+               delete db;
+       }
 
        BaseDB * db;
        Queue<DBObject*> queue;
index e0e7bf7..f00f33f 100644 (file)
@@ -68,7 +68,8 @@ ExampleSink::ExampleSink(AbstractRoutingEngine* engine, map<string, string> conf
                std::list<AbstractPropertyType*> values = reply->values;
                for(auto itr = values.begin(); itr != values.end(); itr++)
                {
-                       DebugOut(0)<<"Velocity value from last week: "<<(*itr)->toString()<<" time: "<<(*itr)->timestamp<<endl;
+                       auto val = *itr;
+                       DebugOut(0)<<"Velocity value from past: "<<val->toString()<<" time: "<<val->timestamp<<endl;
                }
        };