Skip to content
This repository has been archived by the owner on Jan 16, 2020. It is now read-only.

Commit

Permalink
FOGL-2297 Update DeltaMap when configuration changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkRiddoch committed Jan 11, 2019
1 parent 6e2e957 commit 2b52fdd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion delta_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void DeltaFilter::ingest(vector<Reading *> *readings, vector<Reading *>& out)
it != readings->end(); it++)
{
Reading *reading = *it;
lock_guard<mutex> guard(m_configMutex); // Protect against reconfiguration
// Find this asset in the map of values we hold
DeltaMap::iterator deltaIt = m_state.find(reading->getAssetName());
if (deltaIt == m_state.end())
Expand Down Expand Up @@ -243,8 +244,13 @@ struct timeval now, res;
void
DeltaFilter::reconfigure(const string& newConfig)
{
lock_guard<mutex> guard(m_configMutex);
setConfig(newConfig);
handleConfig(m_config);
handleConfig(m_config);
for (DeltaMap::iterator it = m_state.begin(); it != m_state.end(); ++it)
{
it->second->reconfigure(m_tolerance, m_rate);
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions include/delta_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <string>
#include <vector>
#include <regex>
#include <mutex>

/**
* A FogLAMP filter that is used to filter out duplicate data in the readings stream.
Expand All @@ -39,6 +40,11 @@ class DeltaFilter : public FogLampFilter {
~DeltaData();
bool evaluate(Reading *);
const std::string& getAssetName() { return m_lastSent->getAssetName(); };
void reconfigure(double tolerance, struct timeval rate)
{
m_tolerance = tolerance;
m_rate = rate;
};
private:
Reading *m_lastSent;
struct timeval m_lastSentTime;
Expand All @@ -50,6 +56,7 @@ class DeltaFilter : public FogLampFilter {
DeltaMap m_state;
double m_tolerance;
struct timeval m_rate;
std::mutex m_configMutex;
};


Expand Down

0 comments on commit 2b52fdd

Please sign in to comment.