1 #include "databasesink.h"
3 DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std::string> config)
4 :AbstractSink(engine,config)
7 shared->db->init("storage","data","CREATE TABLE IF NOT EXISTS vehicledata (key TEXT, value BLOB, time REAL, source TEXT");
9 auto cb = [](gpointer data)
11 Shared *shared = (Shared*)data;
15 DBObject* obj = shared->queue.pop();
22 DictionaryList<string> dict;
24 NameValuePair<string> one("key", obj->key);
25 NameValuePair<string> two("value", obj->value);
26 NameValuePair<string> three("source", obj->source);
27 NameValuePair<string> four("time", boost::lexical_cast<string>(obj->time));
28 NameValuePair<string> five("sequence", boost::lexical_cast<string>(obj->sequence));
32 dict.push_back(three);
36 shared->db->insert(dict);
44 thread = g_thread_new("dbthread", cb, shared);
48 DatabaseSink::~DatabaseSink()
54 PropertyList DatabaseSink::subscriptions()
60 void DatabaseSink::supportedChanged(PropertyList supportedProperties)
66 void DatabaseSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, std::string uuid)
68 DBObject* obj = new DBObject;
70 obj->value = value->toString();
72 obj->time = value->timestamp;
73 obj->sequence = value->sequence;
77 std::string DatabaseSink::uuid()
79 return "9f88156e-cb92-4472-8775-9c08addf50d3";