2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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;
70 struct DBObjectCompare
72 bool operator()(DBObject const & lhs, DBObject & rhs) const
87 template <> struct hash<DBObject>
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;
117 PlaybackShared(AbstractRoutingEngine* re, std::string u, uint playbackMult)
118 :routingEngine(re),uuid(u),playBackMultiplier(playbackMult),stop(false) {}
121 for(auto itr = playbackQueue.begin(); itr != playbackQueue.end(); itr++)
126 playbackQueue.clear();
129 AbstractRoutingEngine* routingEngine;
130 std::list<DBObject> playbackQueue;
131 uint playBackMultiplier;
136 PROPERTYTYPEBASIC(DatabaseLogging, bool)
137 PROPERTYTYPEBASIC(DatabasePlayback, bool)
138 PROPERTYTYPE(DatabaseFile, DatabaseFileType, StringPropertyType, std::string)
140 class DatabaseSink : public AmbPluginImpl
144 DatabaseSink(AbstractRoutingEngine* engine, map<string, string> config, AbstractSource &parent);
146 virtual void supportedChanged(const PropertyList & supportedProperties);
147 virtual void propertyChanged(AbstractPropertyType *value);
148 const std::string uuid() const;
153 virtual void getRangePropertyAsync(AsyncRangePropertyReply *reply);
154 virtual AsyncPropertyReply * setProperty(const AsyncSetPropertyRequest & request);
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 setDatabaseFileName(std::string filename);
169 PropertyList mSubscriptions;
171 std::unique_ptr<std::thread> thread;
172 std::string tablename;
173 std::string tablecreate;
174 PropertyList propertiesToSubscribeTo;
175 PlaybackShared* playbackShared;
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