Line data Source code
1 : /* 2 : * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef __AGENT_CONFIG_STALE_CLEANER_H_ 7 : #define __AGENT_CONFIG_STALE_CLEANER_H_ 8 : 9 : #include <cmn/agent.h> 10 : #include <boost/function.hpp> 11 : 12 : // Stale cleaner to audit & delete old configuration, on a new client connect. 13 : // Waits for timeout, before cleaning the old configuration. 14 : class ConfigStaleCleaner { 15 : public: 16 : static const uint32_t kConfigStaleTimeout = 60 * 1000; 17 : typedef boost::function<void(uint32_t)> TimerCallback; 18 : 19 : ConfigStaleCleaner(Agent *agent, TimerCallback callback); 20 2 : void set_callback(TimerCallback callback) { audit_callback_ = callback; } 21 : virtual ~ConfigStaleCleaner(); 22 : virtual void StartStaleCleanTimer(int32_t version); 23 : virtual bool StaleEntryTimeout(int32_t version, Timer *timer); 24 2 : void set_timeout(uint32_t timeout) { timeout_ = timeout; } 25 : uint32_t timeout() const { return timeout_; } 26 3 : uint32_t TimersCount() const { return running_timer_list_.size(); } 27 : 28 : protected: 29 : Agent *agent_; 30 : 31 : private: 32 : uint32_t timeout_; 33 : // list of running audit timers (one per connect) 34 : std::set<Timer *> running_timer_list_; 35 : TimerCallback audit_callback_; 36 : DISALLOW_COPY_AND_ASSIGN(ConfigStaleCleaner); 37 : }; 38 : 39 : class InterfaceConfigStaleCleaner : public ConfigStaleCleaner { 40 : public: 41 : InterfaceConfigStaleCleaner(Agent *agent); 42 : virtual ~InterfaceConfigStaleCleaner(); 43 : virtual bool OnInterfaceConfigStaleTimeout(int32_t version); 44 : 45 : private: 46 : DISALLOW_COPY_AND_ASSIGN(InterfaceConfigStaleCleaner); 47 : }; 48 : 49 : #endif /* __AGENT_CONFIG_STALE_CLEANER_H_ */