Browse Source

adding put methods for callbacks

Now, you can also use
mrmc::settings::Callbacks::instance()->put()
to add a new callback from some other code.
main
gereon 12 years ago
parent
commit
89d93d87d4
  1. 7
      src/utility/settings.cpp
  2. 42
      src/utility/settings.h

7
src/utility/settings.cpp

@ -77,6 +77,7 @@ Settings::Settings(const int argc, const char* argv[], const char* filename)
//! Finalize parsed options, check for specified requirements //! Finalize parsed options, check for specified requirements
bpo::notify(this->vm); bpo::notify(this->vm);
mrmc::settings::Callbacks::instance()->disabled = true;
LOG4CPLUS_DEBUG(logger, "Finished loading config."); LOG4CPLUS_DEBUG(logger, "Finished loading config.");
} }
catch (bpo::reading_file e) catch (bpo::reading_file e)
@ -134,7 +135,7 @@ void Settings::initDescriptions()
/* /*
* Get Callbacks object, then iterate over and call all register callbacks. * Get Callbacks object, then iterate over and call all register callbacks.
*/ */
Callbacks* cb = mrmc::settings::Callbacks::getInstance();
Callbacks* cb = mrmc::settings::Callbacks::instance();
while (cb->registerList.size() > 0) while (cb->registerList.size() > 0)
{ {
CallbackType type = cb->registerList.front().first; CallbackType type = cb->registerList.front().first;
@ -184,7 +185,7 @@ void Settings::firstRun(const int argc, const char* argv[], const char* filename
/* /*
* Call intermediate callbacks. * Call intermediate callbacks.
*/ */
Callbacks* cb = mrmc::settings::Callbacks::getInstance();
Callbacks* cb = mrmc::settings::Callbacks::instance();
while (cb->intermediateList.size() > 0) while (cb->intermediateList.size() > 0)
{ {
CallbackType type = cb->intermediateList.front().first; CallbackType type = cb->intermediateList.front().first;
@ -242,7 +243,7 @@ void Settings::secondRun(const int argc, const char* argv[], const char* filenam
/* /*
* Call checker callbacks. * Call checker callbacks.
*/ */
Callbacks* cb = mrmc::settings::Callbacks::getInstance();
Callbacks* cb = mrmc::settings::Callbacks::instance();
while (cb->checkerList.size() > 0) while (cb->checkerList.size() > 0)
{ {
CheckerCallback fptr = cb->checkerList.front(); CheckerCallback fptr = cb->checkerList.front();

42
src/utility/settings.h

@ -240,26 +240,48 @@ namespace settings {
*/ */
class Callbacks class Callbacks
{ {
public:
inline void put(const CallbackType type, const RegisterCallback ptr)
{
if (this->disabled) throw mrmc::exceptions::InvalidSettings();
this->registerList.push_back(std::pair<CallbackType, RegisterCallback>(type, ptr));
}
inline void put(const CallbackType type, const IntermediateCallback ptr)
{
if (this->disabled) throw mrmc::exceptions::InvalidSettings();
this->intermediateList.push_back(std::pair<CallbackType, IntermediateCallback>(type, ptr));
}
inline void put(const CheckerCallback ptr)
{
if (this->disabled) throw mrmc::exceptions::InvalidSettings();
this->checkerList.push_back(ptr);
}
private: private:
/*! /*!
* @brief Stores register callbacks.
* @brief Stores register callbacks.
*/ */
std::list<std::pair<CallbackType, RegisterCallback>> registerList; std::list<std::pair<CallbackType, RegisterCallback>> registerList;
/*! /*!
* @brief Stores intermediate callbacks.
* @brief Stores intermediate callbacks.
*/ */
std::list<std::pair<CallbackType, IntermediateCallback>> intermediateList; std::list<std::pair<CallbackType, IntermediateCallback>> intermediateList;
/*! /*!
* @brief Stores check callbacks.
* @brief Stores check callbacks.
*/ */
std::list<CheckerCallback> checkerList; std::list<CheckerCallback> checkerList;
/*!
* @brief Stores if we already loaded the settings.
*/
bool disabled;
/*! /*!
* @brief Private constructor. * @brief Private constructor.
*/ */
Callbacks() {}
Callbacks() : disabled(false) {}
/*! /*!
* @brief Private copy constructor. * @brief Private copy constructor.
*/ */
@ -273,10 +295,10 @@ namespace settings {
* @brief Returns current instance to create singleton. * @brief Returns current instance to create singleton.
* @return current instance * @return current instance
*/ */
inline static Callbacks* getInstance()
inline static Callbacks* instance()
{ {
static Callbacks instance;
return &instance;
static Callbacks inst;
return &inst;
} }
/*! /*!
@ -321,7 +343,7 @@ namespace settings {
*/ */
Register(const CallbackType type, const RegisterCallback ptr) Register(const CallbackType type, const RegisterCallback ptr)
{ {
mrmc::settings::Callbacks::getInstance()->registerList.push_back(std::pair<CallbackType, RegisterCallback>(type, ptr));
mrmc::settings::Callbacks::instance()->put(type, ptr);
} }
/*! /*!
@ -342,7 +364,7 @@ namespace settings {
*/ */
Register(const CallbackType type, const IntermediateCallback ptr) Register(const CallbackType type, const IntermediateCallback ptr)
{ {
mrmc::settings::Callbacks::getInstance()->intermediateList.push_back(std::pair<CallbackType, IntermediateCallback>(type, ptr));
mrmc::settings::Callbacks::instance()->put(type, ptr);
} }
/*! /*!
@ -362,7 +384,7 @@ namespace settings {
*/ */
Register(const CheckerCallback ptr) Register(const CheckerCallback ptr)
{ {
mrmc::settings::Callbacks::getInstance()->checkerList.push_back(ptr);
mrmc::settings::Callbacks::instance()->put(ptr);
} }
}; };

Loading…
Cancel
Save