13 using contrail_rapidjson::Document;
 
   14 using contrail_rapidjson::Value;
 
   20 #define FLAG_DEBUG(args...) if (process::debug_) LOG(DEBUG, ##args) 
   21 #define FLAG_WARN(args...) if (process::debug_) LOG(WARN, ##args) 
   22 #define FLAG_ERROR(args...) if (process::debug_) LOG(ERROR, ##args) 
   33 Flag::Flag(FlagManager *manager, 
const string &name,
 
   34            const string &description, 
bool enabled,
 
   37       description_(description),
 
   39       context_infos_(context_infos),
 
   46     manager_->Register(
this);
 
   51       description_(flag.description_),
 
   52       enabled_(flag.enabled_),
 
   53       context_infos_(flag.context_infos_),
 
   54       flag_state_cb_(callback),
 
   55       manager_(flag.manager_)
 
   92   return !(*
this == rhs);
 
  105     : flag_manager_(manager),
 
  106       flag_uve_cb_(flag_uve_cb) {
 
  158     : flag_manager_(manager) {
 
  170     if ( d.Parse<0>(build_info.c_str()).HasParseError() ) {
 
  173         const Value &v = d[
"build-info"];
 
  174         version_ = v[0][
"build-version"].GetString();
 
  186                             const string &
version, 
bool enabled,
 
  196             " does not match with module version " << 
version_ <<
 
  247     bool changed = 
false;
 
  251     tbb::mutex::scoped_lock lock(
mutex_);
 
  260         FLAG_DEBUG(
"Flag " << name << 
"Already Present\n");
 
  262              << 
" Version: " << old_cfg.
version()
 
  263              << 
" Enabled: " << 
string(old_cfg.
enabled() ? 
"True " : 
"False ")
 
  267         for (c_itr = c_vec.begin(); c_itr != c_vec.end(); ++c_itr) {
 
  269                        << 
" Value: " << c_itr->value);
 
  272         if (old_cfg != flag_cfg) {
 
  275             fmap_itr->second = flag_cfg;
 
  277             FLAG_DEBUG(
"No change in flag " << name << 
" configuration\n");
 
  284         FLAG_DEBUG(
"New flag configured. Name: " << name);
 
  285         flag_map_.insert(make_pair(name, flag_cfg));
 
  289       << 
" Version: " << flag_cfg.
version()
 
  290       << 
" Enabled: " << 
string(flag_cfg.
enabled() ? 
"True " : 
"False ")
 
  294     for (c_itr = c_vec.begin(); c_itr != c_vec.end(); ++c_itr) {
 
  296                    << 
" Value: " << c_itr->value);
 
  309         pair <int_map_itr, int_map_itr> ret;
 
  311         for (
int_map_itr it = ret.first; it != ret.second; ++it) {
 
  313             Flag *f = it->second;
 
  330     pair <int_map_itr, int_map_itr> ret;
 
  332     for (
int_map_itr it = ret.first; it != ret.second; ++it) {
 
  333         Flag *f = it->second;
 
  359     FLAG_DEBUG(
"Checking if flag with name: " << name
 
  360                << 
" is enabled for context");
 
  361     for (c_itr = c_vec.begin(); c_itr != c_vec.end(); ++c_itr) {
 
  363                    << 
" Value: " << c_itr->value);
 
  384         if (c_vec.empty() && !f_vec.empty()) {
 
  387         for (c_itr = c_vec.begin(); c_itr != c_vec.end(); ++c_itr) {
 
  388             f_itr = find(f_vec.begin(), f_vec.end(), *c_itr);
 
  389             if (f_itr == f_vec.end()) {
 
  401         result = default_state;
 
  404     FLAG_DEBUG(
"Flag enabled: " << 
string(result ? 
"True" : 
"False"));
 
  413     tbb::mutex::scoped_lock lock(
mutex_);
 
  415     string name = flag->
name();
 
  417     FLAG_DEBUG(
"Module interested in flag. Name: " << name <<
 
  418                " \nAdding to InterestMap");
 
  428                    " already present in FlagMap");
 
  438     itr = 
int_map_.insert(make_pair(name, flag));
 
  442     pair <int_map_itr, int_map_itr> ret;
 
  443     const string name = flag->
name();
 
  446     FLAG_DEBUG(
"Module not interested in flag. Name: " << name <<
 
  447                " \nRemoving from InterestMap");
 
  449     tbb::mutex::scoped_lock lock(
mutex_);
 
  452     while (it != ret.second) {
 
  453         if (it->second == flag) {
 
  463     pair <int_map_const_itr, int_map_const_itr> ret;
 
  465     tbb::mutex::scoped_lock lock(
mutex_);
 
  469         if (it->second == flag) {
 
  493             flag_infos.push_back(flag_cfg);
 
  501     tbb::mutex::scoped_lock lock(
mutex_);
 
FlagManager * flag_manager_
FlagConfigManager(FlagManager *manager)
void Unset(const std::string &name)
static FlagConfigManager * GetInstance()
static std::string version_
static boost::scoped_ptr< FlagConfigManager > instance_
static void Initialize(const string &build_info)
void Set(const std::string &name, const std::string &version_info, bool enabled, FlagState::Type state, ContextVec &context_infos)
const FlagState::Type & state() const
const std::string & name() const
const std::string & version() const
const ContextVec & context_infos() const
bool IsRegistered(const Flag *flag) const
size_t GetIntMapCount() const
std::map< std::string, FlagConfig >::iterator flag_map_itr
std::multimap< std::string, Flag * >::iterator int_map_itr
size_t GetFlagMapCount() const
void Register(Flag *flag)
void Set(const std::string &name, const std::string &version, bool enabled, FlagState::Type state, ContextVec &context_infos)
static FlagManager * GetInstance()
FlagConfigVec GetFlagInfosUnlocked() const
std::multimap< std::string, Flag * >::const_iterator int_map_const_itr
void Unregister(const Flag *flag)
bool IsFlagEnabled(const std::string &name, bool default_state, const ContextVec &c_vec) const
void Unset(const std::string &name)
static boost::scoped_ptr< FlagManager > instance_
FlagConfigVec GetFlagInfos() const
std::map< std::string, FlagConfig >::const_iterator flag_map_citr
FlagConfigVec GetFlagInfos(bool lock) const
boost::function< void(void)> FlagUveCb
static void CreateInstance(FlagManager *mgr, FlagUveCb send_uve_cb)
static boost::scoped_ptr< FlagUveManager > instance_
FlagManager * flag_manager_
FlagUveManager(FlagManager *manager, FlagUveCb send_uve_cb)
static FlagUveManager * GetInstance()
const ContextVec & context_infos() const
bool operator!=(const Flag &rhs) const
bool operator==(const Flag &rhs) const
const std::string & name() const
boost::function< void()> FlagStateCb
ContextVec context_infos_
void set_enabled(const bool val)
const bool enabled() const
FlagStateCb flag_state_cb_
#define FLAG_WARN(args...)
#define FLAG_DEBUG(args...)
std::vector< FlagConfig > FlagConfigVec
std::vector< FlagContext >::const_iterator context_iterator
std::vector< FlagContext > ContextVec
static std::string ToString(Type state)