20 #ifndef DATABASESINK_H
21 #define DATABASESINK_H
23 #include "abstractsink.h"
24 #include "abstractsource.h"
26 #include <asyncqueue.hpp>
27 #include "listplusplus.h"
28 #include "ambpluginimpl.h"
35 #include <condition_variable>
36 #include <unordered_map>
38 const std::string DatabaseLogging =
"DatabaseLogging";
39 const std::string DatabasePlayback =
"DatabasePlayback";
40 const std::string DatabaseFile =
"DatabaseFile";
44 DBObject(): zone(0), time(0), sequence(0), quit(
false) {}
55 bool operator == (
const DBObject & other)
const
57 return (key == other.key && source == other.source && zone == other.zone &&
58 value == other.value && sequence == other.sequence && time == other.time);
61 bool operator != (
const DBObject & other)
63 return (*
this == other) ==
false;
89 size_t operator()(
const DBObject & x)
const
91 return x.key.length() * x.value.length() + x.time;
110 amb::Queue<DBObject, amb::DBObjectCompare> queue;
118 :routingEngine(re),uuid(u),playBackMultiplier(playbackMult),stop(
false) {}
121 for(
auto itr = playbackQueue.begin(); itr != playbackQueue.end(); itr++)
126 playbackQueue.clear();
130 std::list<DBObject> playbackQueue;
131 uint playBackMultiplier;
136 PROPERTYTYPEBASIC(DatabaseLogging,
bool)
137 PROPERTYTYPEBASIC(DatabasePlayback,
bool)
146 virtual void supportedChanged(
const PropertyList & supportedProperties);
148 const std::string uuid()
const;
155 virtual void subscribeToPropertyChanges(VehicleProperty::Property
property);
156 virtual void unsubscribeToPropertyChanges(VehicleProperty::Property property);
157 int supportedOperations()
const {
return AbstractSource::GetRanged | AbstractSource::Get | AbstractSource::Set;}
164 void startPlayback();
166 void updateForNewDbFilename();
169 PropertyList mSubscriptions;
171 std::unique_ptr<std::thread> thread;
172 std::string tablename;
173 std::string tablecreate;
174 PropertyList propertiesToSubscribeTo;
176 uint playbackMultiplier;
177 std::shared_ptr<AbstractPropertyType> playback;
178 std::shared_ptr<AbstractPropertyType> databaseName;
179 std::shared_ptr<AbstractPropertyType> databaseLogging;
182 #endif // DATABASESINK_H