initial sequence and timestamp support
[profile/ivi/automotive-message-broker.git] / plugins / database / databasesink.cpp
1 #include "databasesink.h"
2
3 DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std::string> config)
4         :AbstractSink(engine,config)
5 {
6         shared = new Shared;
7         shared->db->init("storage","data","CREATE TABLE IF NOT EXISTS vehicledata (key TEXT, value BLOB, time REAL, source TEXT");
8
9         auto cb = [](gpointer data)
10         {
11                 Shared *shared = (Shared*)data;
12
13                 while(1)
14                 {
15                         DBObject* obj = shared->queue.pop();
16
17                         if( obj->quit )
18                         {
19                                 break;
20                         }
21
22                         DictionaryList<string> dict;
23
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));
29
30                         dict.push_back(one);
31                         dict.push_back(two);
32                         dict.push_back(three);
33                         dict.push_back(four);
34                         dict.push_back(five);
35
36                         shared->db->insert(dict);
37                         delete obj;
38                 }
39
40                 void* ret = NULL;
41                 return ret;
42         };
43
44         thread = g_thread_new("dbthread", cb, shared);
45
46 }
47
48 DatabaseSink::~DatabaseSink()
49 {
50
51 }
52
53
54 PropertyList DatabaseSink::subscriptions()
55 {
56
57 }
58
59
60 void DatabaseSink::supportedChanged(PropertyList supportedProperties)
61 {
62
63 }
64
65
66 void DatabaseSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, std::string uuid, double timestamp, uint32_t sequence)
67 {
68         DBObject* obj = new DBObject;
69         obj->key = property;
70         obj->value = value->toString();
71         obj->source = uuid;
72 }
73
74
75 std::string DatabaseSink::uuid()
76 {
77         return "9f88156e-cb92-4472-8775-9c08addf50d3";
78 }