16#include <boost/scoped_ptr.hpp> 
   41    asiolink::IntervalTimer interval_timer_;
 
   61    TimerInfo(
const asiolink::IOServicePtr& io_service,
 
   65        : interval_timer_(io_service),
 
   66          user_callback_(user_callback),
 
   68          scheduling_mode_(mode) { };
 
  148    void setup(
const std::string& timer_name);
 
  155    void cancel(
const std::string& timer_name);
 
  173    void registerTimerInternal(
const std::string& timer_name,
 
  186    void unregisterTimerInternal(
const std::string& timer_name);
 
  192    void unregisterTimersInternal();
 
  206    void setupInternal(
const std::string& timer_name);
 
  213    void cancelInternal(
const std::string& timer_name);
 
  219    void timerCallback(
const std::string& timer_name);
 
  229    boost::scoped_ptr<std::mutex> mutex_;
 
 
  233    registered_timers_(), mutex_(new std::mutex) {
 
 
  242    io_service_ = io_service;
 
 
  251        std::lock_guard<std::mutex> lock(*mutex_);
 
  252        registerTimerInternal(timer_name, callback, interval, scheduling_mode);
 
  254        registerTimerInternal(timer_name, callback, interval, scheduling_mode);
 
 
  259TimerMgrImpl::registerTimerInternal(
const std::string& timer_name,
 
  264    if (timer_name.empty()) {
 
  269    if (registered_timers_.find(timer_name) != registered_timers_.end()) {
 
  271                  << timer_name << 
"'");
 
  277    TimerInfoPtr timer_info(
new TimerInfo(io_service_, callback,
 
  278                                          interval, scheduling_mode));
 
  281    registered_timers_.insert(std::pair<std::string, TimerInfoPtr>(timer_name,
 
  288        std::lock_guard<std::mutex> lock(*mutex_);
 
  289        unregisterTimerInternal(timer_name);
 
  291        unregisterTimerInternal(timer_name);
 
 
  296TimerMgrImpl::unregisterTimerInternal(
const std::string& timer_name) {
 
  298    TimerInfoMap::iterator timer_info_it = registered_timers_.find(timer_name);
 
  301    if (timer_info_it == registered_timers_.end()) {
 
  303                  << timer_name << 
"'");
 
  307    cancelInternal(timer_name);
 
  310    registered_timers_.erase(timer_info_it);
 
  316        std::lock_guard<std::mutex> lock(*mutex_);
 
  317        unregisterTimersInternal();
 
  319        unregisterTimersInternal();
 
 
  324TimerMgrImpl::unregisterTimersInternal() {
 
  334    TimerInfoMap registered_timers_copy(registered_timers_);
 
  337    for (
auto const& timer_info_it : registered_timers_copy) {
 
  338        unregisterTimerInternal(timer_info_it.first);
 
  345        std::lock_guard<std::mutex> lock(*mutex_);
 
  346        return (registered_timers_.find(timer_name) != registered_timers_.end());
 
  348        return (registered_timers_.find(timer_name) != registered_timers_.end());
 
 
  355        std::lock_guard<std::mutex> lock(*mutex_);
 
  356        return (registered_timers_.size());
 
  358        return (registered_timers_.size());
 
 
  365        std::lock_guard<std::mutex> lock(*mutex_);
 
  366        setupInternal(timer_name);
 
  368        setupInternal(timer_name);
 
 
  373TimerMgrImpl::setupInternal(
const std::string& timer_name) {
 
  375   TimerInfoMap::const_iterator timer_info_it = registered_timers_.find(timer_name);
 
  376   if (timer_info_it == registered_timers_.end()) {
 
  378                 "no such timer registered");
 
  386   timer_info->interval_timer_.setup(
cb, timer_info->interval_,
 
  387                                     timer_info->scheduling_mode_);
 
  393        std::lock_guard<std::mutex> lock(*mutex_);
 
  394        cancelInternal(timer_name);
 
  396        cancelInternal(timer_name);
 
 
  401TimerMgrImpl::cancelInternal(
const std::string& timer_name) {
 
  403    TimerInfoMap::const_iterator timer_info_it = registered_timers_.find(timer_name);
 
  404    if (timer_info_it == registered_timers_.end()) {
 
  406                  "no such timer registered");
 
  409    timer_info_it->second->interval_timer_.cancel();
 
  413TimerMgrImpl::timerCallback(
const std::string& timer_name) {
 
  415    TimerInfoMap::iterator timer_info_it = registered_timers_.find(timer_name);
 
  416    if (timer_info_it != registered_timers_.end()) {
 
  423            .arg(timer_info_it->first);
 
  425        std::string error_string;
 
  427            timer_info_it->second->user_callback_();
 
  429        } 
catch (
const std::exception& ex){
 
  430            error_string = ex.what();
 
  433            error_string = 
"unknown reason";
 
  437        if (!error_string.empty()) {
 
  439                .arg(timer_info_it->first)
 
  456    impl_->unregisterTimers();
 
 
  470    impl_->registerTimer(timer_name, callback, interval, scheduling_mode);
 
 
  480    impl_->unregisterTimer(timer_name);
 
 
  489    impl_->unregisterTimers();
 
 
  494    return (impl_->isTimerRegistered(timer_name));
 
 
  499    return (impl_->timersCount());
 
 
  509    impl_->setup(timer_name);
 
 
  519    impl_->cancel(timer_name);
 
 
  524    impl_->setIOService(io_service);
 
 
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
The IOService class is a wrapper for the ASIO io_context class.
std::function< void()> Callback
Mode
Defines possible timer modes used to setup a timer.
Implementation of the TimerMgr.
void unregisterTimers()
Unregisters all timers.
size_t timersCount() const
Returns the number of registered timers.
void cancel(const std::string &timer_name)
Cancels the execution of the interval timer.
void registerTimer(const std::string &timer_name, const asiolink::IntervalTimer::Callback &callback, const long interval, const asiolink::IntervalTimer::Mode &scheduling_mode)
Registers new timer in the TimerMgr.
void unregisterTimer(const std::string &timer_name)
Unregisters specified timer.
void setup(const std::string &timer_name)
Schedules the execution of the interval timer.
void setIOService(const IOServicePtr &io_service)
Sets IO service to be used by the Timer Manager.
TimerMgrImpl()
Constructor.
bool isTimerRegistered(const std::string &timer_name)
Checks if the timer with a specified name has been registered.
bool isTimerRegistered(const std::string &timer_name)
Checks if the timer with a specified name has been registered.
void setIOService(const asiolink::IOServicePtr &io_service)
Sets IO service to be used by the Timer Manager.
void setup(const std::string &timer_name)
Schedules the execution of the interval timer.
size_t timersCount() const
Returns the number of registered timers.
void unregisterTimers()
Unregisters all timers.
void cancel(const std::string &timer_name)
Cancels the execution of the interval timer.
void registerTimer(const std::string &timer_name, const asiolink::IntervalTimer::Callback &callback, const long interval, const asiolink::IntervalTimer::Mode &scheduling_mode)
Registers new timer in the TimerMgr.
void unregisterTimer(const std::string &timer_name)
Unregisters specified timer.
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
boost::shared_ptr< TimerMgr > TimerMgrPtr
Type definition of the shared pointer to TimerMgr.
const isc::log::MessageID DHCPSRV_TIMERMGR_UNREGISTER_ALL_TIMERS
std::map< std::string, TimerInfoPtr > TimerInfoMap
A type definition for the map holding timers configuration.
const isc::log::MessageID DHCPSRV_TIMERMGR_STOP_TIMER
const isc::log::MessageID DHCPSRV_TIMERMGR_RUN_TIMER_OPERATION
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
const isc::log::MessageID DHCPSRV_TIMERMGR_START_TIMER
const isc::log::MessageID DHCPSRV_TIMERMGR_UNREGISTER_TIMER
boost::shared_ptr< TimerInfo > TimerInfoPtr
A type definition for the pointer to TimerInfo structure.
const isc::log::MessageID DHCPSRV_TIMERMGR_REGISTER_TIMER
const isc::log::MessageID DHCPSRV_TIMERMGR_CALLBACK_FAILED
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
Defines the logger used by the top-level component of kea-lfc.