diff options
author | Kevron Rees <kevron.m.rees@intel.com> | 2015-01-14 15:03:09 -0800 |
---|---|---|
committer | Kevron Rees <kevron.m.rees@intel.com> | 2015-01-26 13:15:56 -0800 |
commit | c2fa34a7cfb95b6aa272bdbbb9bb9893ea0b4a37 (patch) | |
tree | fdd7172c0976996367eda2efbee5085f0525a80b | |
parent | f66e7a8bf29b6fe290815084331b459bf47351a6 (diff) | |
download | automotive-message-broker-c2fa34a7cfb95b6aa272bdbbb9bb9893ea0b4a37.tar.gz |
Store system time in db, not steady time
-rw-r--r-- | plugins/database/databasesink.cpp | 10 | ||||
-rw-r--r-- | plugins/database/databasesink.h | 2 |
2 files changed, 7 insertions, 5 deletions
diff --git a/plugins/database/databasesink.cpp b/plugins/database/databasesink.cpp index b18ca2c6..57d57073 100644 --- a/plugins/database/databasesink.cpp +++ b/plugins/database/databasesink.cpp @@ -30,10 +30,10 @@ static void * cbFunc(Shared* shared) vector<DictionaryList<string> > insertList; + double startTime = amb::currentTime(); + while(1) { - usleep(timeout*1000); - DBObject obj = shared->queue.pop(); if( obj.quit ) @@ -47,7 +47,7 @@ static void * cbFunc(Shared* shared) NameValuePair<string> two("value", obj.value); NameValuePair<string> three("source", obj.source); NameValuePair<string> zone("zone", boost::lexical_cast<string>(obj.zone)); - NameValuePair<string> four("time", boost::lexical_cast<string>(obj.time)); + NameValuePair<string> four("time", boost::lexical_cast<string>(amb::Timestamp::instance()->epochTime(obj.time))); NameValuePair<string> five("sequence", boost::lexical_cast<string>(obj.sequence)); NameValuePair<string> six("tripId", shared->tripId); @@ -61,8 +61,10 @@ static void * cbFunc(Shared* shared) insertList.push_back(dict); - if(insertList.size() >= bufferLength) + if(insertList.size() >= bufferLength && amb::currentTime() - startTime >= timeout / 1000) { + startTime = amb::currentTime(); + shared->db->exec("BEGIN IMMEDIATE TRANSACTION"); for(int i=0; i< insertList.size(); i++) { diff --git a/plugins/database/databasesink.h b/plugins/database/databasesink.h index 459ec928..a382043a 100644 --- a/plugins/database/databasesink.h +++ b/plugins/database/databasesink.h @@ -97,7 +97,7 @@ class Shared { public: Shared() - :queue(true) + :queue(true, true) { db = new BaseDB; } |