-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement incremental port configuration update
- Loading branch information
1 parent
8941cc0
commit 0273978
Showing
15 changed files
with
658 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "config_cache.h" | ||
|
||
using namespace swss; | ||
|
||
ConfigCache::ConfigCache(ConfigChangeCb configChangeCb): | ||
mConfigChangeCb(configChangeCb) | ||
{} | ||
|
||
void ConfigCache::config(const std::string& key, const std::string& field, const std::string& value) | ||
{ | ||
auto iter = mConfigData.find(key); | ||
if (iter == mConfigData.end()) | ||
{ | ||
mConfigData.emplace(key, ConfigEntry({{field, value}})); | ||
mConfigChangeCb(key, field, "", value); | ||
} | ||
else | ||
{ | ||
auto entry_iter = iter->second.find(field); | ||
if (entry_iter == iter->second.end()) | ||
{ | ||
iter->second.emplace(field, value); | ||
mConfigChangeCb(key, field, "", value); | ||
} | ||
else | ||
{ | ||
if (value != entry_iter->second) | ||
{ | ||
mConfigChangeCb(key, field, entry_iter->second, value); | ||
entry_iter->second = value; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void ConfigCache::applyDefault(const std::string& key, const ConfigEntry &defaultConfig) | ||
{ | ||
auto &entry = mConfigData[key]; | ||
for (auto &fv : defaultConfig) | ||
{ | ||
auto iter = entry.find(fv.first); | ||
if (iter == entry.end()) | ||
{ | ||
entry.emplace(fv.first, fv.second); | ||
mConfigChangeCb(key, fv.first, "", fv.second); | ||
} | ||
} | ||
} | ||
|
||
bool ConfigCache::exist(const std::string& key) const | ||
{ | ||
return mConfigData.find(key) != mConfigData.end(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
#include <map> | ||
#include <string> | ||
#include <functional> | ||
|
||
namespace swss { | ||
|
||
typedef std::function<void(const std::string&, const std::string&, const std::string&, const std::string &)> ConfigChangeCb; | ||
typedef std::map<std::string, std::string> ConfigEntry; | ||
typedef std::map<std::string, ConfigEntry> ConfigData; | ||
|
||
class ConfigCache | ||
{ | ||
public: | ||
|
||
ConfigCache(ConfigChangeCb configChangeCb); | ||
|
||
void config(const std::string& key, const std::string& field, const std::string& value); | ||
void applyDefault(const std::string& key, const ConfigEntry &defaultConfig); | ||
bool exist(const std::string& key) const; | ||
void remove(const std::string &key) { mConfigData.erase(key); } | ||
private: | ||
ConfigData mConfigData; | ||
ConfigChangeCb mConfigChangeCb; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.