Skip to content

Commit

Permalink
Added support for message topic in sink and filter plugins. Plugin pr…
Browse files Browse the repository at this point in the history
…otocol version 4
  • Loading branch information
pbosetti committed Jul 15, 2024
1 parent 7ffbdb4 commit 056810b
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/common.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef COMMON_HPP
#define COMMON_HPP

#define PLUGIN_PROTOCOL_VERSION 4

/*!
* @file common.hpp
* @brief Common definitions for the pugg library
Expand Down
5 changes: 3 additions & 2 deletions src/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ class Filter {
* data was loaded successfully, and false otherwise.
*
* @param data The input data
* @param topic The topic of the data
* @return True if the data was loaded successfully, and false otherwise
*/
virtual return_type load_data(Tin const &data) = 0;
virtual return_type load_data(Tin const &data, std::string topic = "") = 0;

/*!
* Processes the input data
Expand Down Expand Up @@ -124,7 +125,7 @@ class Filter {
/*!
* Returns the plugin protocol version.
*/
static const int version = 3;
static const int version = PLUGIN_PROTOCOL_VERSION;

/*!
* Returns the plugin server name.
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/echoj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using json = nlohmann::json;
class Echo : public Filter<json, json> {
public:
string kind() override { return PLUGIN_NAME; }
return_type load_data(json const &d) override {
return_type load_data(json const &d, string topic = "") override {
_data = d;
return return_type::success;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/running_avg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RunningAverage : public Filter<json, json> {
// We expect to have a dictionary of values in the input, and we feed them
// into a map of double-ended queues (deques) to keep track of the last N
// values for each key.
return_type load_data(json const &input) override {
return_type load_data(json const &input, string topic = "") override {
if (input[_params["field"]].is_object() == false) {
return return_type::error;
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/to_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ using json = nlohmann::json;
class ToConsole : public Sink<json> {
public:
string kind() override { return PLUGIN_NAME; }
return_type load_data(json const &d) override {
return_type load_data(json const &d, string topic = "") override {
_data = d;
cout << "Data: " << _data << endl;
cout << "[" << topic << "] Data: " << _data << endl;
return return_type::success;
}

Expand Down
5 changes: 3 additions & 2 deletions src/sink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ class Sink {
* data was loaded successfully, and false otherwise.
*
* @param data The input data
* @param topic The topic of the data
* @return True if the data was loaded successfully, and false otherwise
*/
virtual return_type load_data(Tin const &data) = 0;
virtual return_type load_data(Tin const &data, std::string topic = "") = 0;

/*!
* Sets the parameters
Expand Down Expand Up @@ -112,7 +113,7 @@ class Sink {
/*!
* Returns the plugin protocol version.
*/
static const int version = 3;
static const int version = PLUGIN_PROTOCOL_VERSION;

/*!
* Returns the plugin server name.
Expand Down
2 changes: 1 addition & 1 deletion src/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Source {
bool dummy;


static const int version = 3;
static const int version = PLUGIN_PROTOCOL_VERSION;

/*!
* Returns the plugin server name.
Expand Down

0 comments on commit 056810b

Please sign in to comment.