switched to list, added helper methods for type inspection, use map for updated messages
This commit is contained in:
@@ -17,7 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "datahandler.h"
|
#include "datahandler.h"
|
||||||
#include <vector>
|
#include <list>
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
#ifdef HAVE_MQTT
|
#ifdef HAVE_MQTT
|
||||||
# include "mqtthandler.h"
|
# include "mqtthandler.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -48,7 +51,7 @@ const struct argp_child* datahandler_getargs()
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool datahandler_register(BusHandler* busHandler, vector<DataHandler*>& handlers)
|
bool datahandler_register(BusHandler* busHandler, list<DataHandler*>& handlers)
|
||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
#ifdef HAVE_MQTT
|
#ifdef HAVE_MQTT
|
||||||
@@ -64,5 +67,5 @@ bool datahandler_register(BusHandler* busHandler, vector<DataHandler*>& handlers
|
|||||||
|
|
||||||
void DataSink::notifyUpdate(Message* message)
|
void DataSink::notifyUpdate(Message* message)
|
||||||
{
|
{
|
||||||
m_updatedMessages.push_back(message);
|
m_updatedMessages[message]++;
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-7
@@ -22,9 +22,6 @@
|
|||||||
#include "bushandler.h"
|
#include "bushandler.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include <argp.h>
|
#include <argp.h>
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** @file datahandler.h
|
/** @file datahandler.h
|
||||||
* Classes and functions for implementing and registering generic data sinks
|
* 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.
|
* Registration function that is called once during initialization.
|
||||||
* @param busHandler the @a BusHandler instance.
|
* @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.
|
* @return true if registration was successful.
|
||||||
*/
|
*/
|
||||||
bool datahandler_register(BusHandler* busHandler, vector<DataHandler*>& handlers);
|
bool datahandler_register(BusHandler* busHandler, list<DataHandler*>& handlers);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,6 +69,18 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void start() = 0;
|
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);
|
virtual void notifyUpdate(Message* message);
|
||||||
|
|
||||||
|
// @copydoc
|
||||||
|
virtual bool isDataSink() { return true; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/** a queue of updated @p Message instances. */
|
/** a map of updated @p Message instances. */
|
||||||
deque<Message*> m_updatedMessages;
|
map<Message*, int> m_updatedMessages;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -125,6 +137,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual ~DataSource() {}
|
virtual ~DataSource() {}
|
||||||
|
|
||||||
|
// @copydoc
|
||||||
|
virtual bool isDataSource() { return true; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/** the @a BusHandler instance. */
|
/** the @a BusHandler instance. */
|
||||||
|
|||||||
Reference in New Issue
Block a user