From beb6b6ca9757aa690f2878619d34c2e3acd2e093 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 8 Jan 2017 09:34:58 +0100 Subject: [PATCH] switched to list, added helper methods for type inspection, use map for updated messages --- src/ebusd/datahandler.cpp | 9 ++++++--- src/ebusd/datahandler.h | 29 ++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/ebusd/datahandler.cpp b/src/ebusd/datahandler.cpp index 70052304..e2e67834 100644 --- a/src/ebusd/datahandler.cpp +++ b/src/ebusd/datahandler.cpp @@ -17,7 +17,10 @@ */ #include "datahandler.h" -#include +#include +#ifdef HAVE_CONFIG_H +# include +#endif #ifdef HAVE_MQTT # include "mqtthandler.h" #endif @@ -48,7 +51,7 @@ const struct argp_child* datahandler_getargs() return NULL; } -bool datahandler_register(BusHandler* busHandler, vector& handlers) +bool datahandler_register(BusHandler* busHandler, list& handlers) { bool success = true; #ifdef HAVE_MQTT @@ -64,5 +67,5 @@ bool datahandler_register(BusHandler* busHandler, vector& handlers void DataSink::notifyUpdate(Message* message) { - m_updatedMessages.push_back(message); + m_updatedMessages[message]++; } diff --git a/src/ebusd/datahandler.h b/src/ebusd/datahandler.h index d8d3b938..8eb6eed7 100644 --- a/src/ebusd/datahandler.h +++ b/src/ebusd/datahandler.h @@ -22,9 +22,6 @@ #include "bushandler.h" #include "message.h" #include -#ifdef HAVE_CONFIG_H -# include -#endif /** @file datahandler.h * Classes and functions for implementing and registering generic data sinks @@ -45,10 +42,10 @@ const struct argp_child* datahandler_getargs(); /** * Registration function that is called once during initialization. * @param busHandler the @a BusHandler instance. - * @param handlers the @a vector to which new @a DataHandler instances shall be added. + * @param handlers the @a list to which new @a DataHandler instances shall be added. * @return true if registration was successful. */ -bool datahandler_register(BusHandler* busHandler, vector& handlers); +bool datahandler_register(BusHandler* busHandler, list& handlers); /** @@ -72,6 +69,18 @@ public: */ virtual void start() = 0; + /** + * Return whether this is a @a DataSink instance. + * @return whether this is a @a DataSink instance. + */ + virtual bool isDataSink() { return false; } + + /** + * Return whether this is a @a DataSource instance. + * @return whether this is a @a DataSource instance. + */ + virtual bool isDataSource() { return false; } + }; @@ -98,10 +107,13 @@ public: */ virtual void notifyUpdate(Message* message); + // @copydoc + virtual bool isDataSink() { return true; } + protected: - /** a queue of updated @p Message instances. */ - deque m_updatedMessages; + /** a map of updated @p Message instances. */ + map m_updatedMessages; }; @@ -125,6 +137,9 @@ public: */ virtual ~DataSource() {} + // @copydoc + virtual bool isDataSource() { return true; } + protected: /** the @a BusHandler instance. */