diff --git a/src/remote/pv/beaconHandler.h b/src/remote/pv/beaconHandler.h index 5073362..bc7d361 100644 --- a/src/remote/pv/beaconHandler.h +++ b/src/remote/pv/beaconHandler.h @@ -29,11 +29,13 @@ namespace { class InternalClientContextImpl; - class BeaconCleanupHandler; } namespace epics { namespace pvAccess { +namespace detail { + class BeaconCleanupHandler; +} /** * BeaconHandler @@ -94,7 +96,7 @@ private: /** * Callback for cleaning up the beacon */ - std::shared_ptr _callback; + std::tr1::shared_ptr _callback; /** * Update beacon. diff --git a/src/remoteClient/clientContextImpl.cpp b/src/remoteClient/clientContextImpl.cpp index ee208fd..2419fa8 100644 --- a/src/remoteClient/clientContextImpl.cpp +++ b/src/remoteClient/clientContextImpl.cpp @@ -60,9 +60,51 @@ Status ClientChannelImpl::channelDestroyed( Status ClientChannelImpl::channelDisconnected( Status::STATUSTYPE_WARNING, "channel disconnected"); +namespace detail { +/** + * Handles cleanup of old beacons. + */ +class BeaconCleanupHandler +{ +public: + POINTER_DEFINITIONS(BeaconCleanupHandler); + + class Callback : public TimerCallback + { + public: + Callback(BeaconCleanupHandler& handler) : m_handler(handler) + { + } + + virtual void callback() OVERRIDE FINAL; + virtual void timerStopped() OVERRIDE FINAL; + + BeaconCleanupHandler& m_handler; + }; + + BeaconCleanupHandler(InternalClientContextImpl& impl, osiSockAddr addr); + ~BeaconCleanupHandler(); + + /** + * Extend the lifetime of the beacon, resetting removal countdown to 0 + */ + void touch() { epicsAtomicSetIntT(&m_count, 0); } + +private: + void remove(); + + std::tr1::shared_ptr m_callback; + osiSockAddr m_from; + InternalClientContextImpl& m_impl; + int m_count; +}; + +} // namespace detail }} + namespace { using namespace epics::pvAccess; +using namespace epics::pvAccess::detail; class ChannelGetFieldRequestImpl; @@ -3040,45 +3082,6 @@ enum ContextState { CONTEXT_DESTROYED }; - -/** - * Handles cleanup of old beacons. - */ -class BeaconCleanupHandler -{ -public: - POINTER_DEFINITIONS(BeaconCleanupHandler); - - class Callback : public TimerCallback - { - public: - Callback(BeaconCleanupHandler& handler) : m_handler(handler) - { - } - - virtual void callback() OVERRIDE FINAL; - virtual void timerStopped() OVERRIDE FINAL; - - BeaconCleanupHandler& m_handler; - }; - - BeaconCleanupHandler(InternalClientContextImpl& impl, osiSockAddr addr); - ~BeaconCleanupHandler(); - - /** - * Extend the lifetime of the beacon, resetting removal countdown to 0 - */ - void touch() { epicsAtomicSetIntT(&m_count, 0); } - -private: - void remove(); - - std::shared_ptr m_callback; - osiSockAddr m_from; - InternalClientContextImpl& m_impl; - int m_count; -}; - class InternalClientContextImpl : public ClientContextImpl, public ChannelProvider @@ -4397,7 +4400,7 @@ private: char ipa[64]; sockAddrToDottedIP(&responseFrom->sa, ipa, sizeof(ipa)); LOG(logLevelDebug, "Tracked beacon limit reached (%d), ignoring %s\n", maxTrackedBeacons, ipa); - return nullptr; + return BeaconHandler::shared_pointer(); } // stores weak_ptr @@ -4610,43 +4613,9 @@ private: TransportRegistry::transportVector_t m_flushTransports; - friend class BeaconCleanupHandler; + friend class epics::pvAccess::detail::BeaconCleanupHandler; }; - -BeaconCleanupHandler::BeaconCleanupHandler(InternalClientContextImpl& impl, osiSockAddr addr) : - m_from(addr), - m_impl(impl), - m_count(0) -{ - m_callback.reset(new Callback(*this)); - m_impl.m_timer->schedulePeriodic(m_callback, maxBeaconLifetime / 4, maxBeaconLifetime / 4); -} - -BeaconCleanupHandler::~BeaconCleanupHandler() -{ - m_impl.m_timer->cancel(m_callback); -} - -void BeaconCleanupHandler::Callback::callback() -{ - if (epicsAtomicIncrIntT(&m_handler.m_count) >= 5) { - m_handler.remove(); - } -} - -void BeaconCleanupHandler::Callback::timerStopped() -{ - m_handler.remove(); -} - -void BeaconCleanupHandler::remove() -{ - Lock guard(m_impl.m_beaconMapMutex); - m_impl.m_timer->cancel(m_callback); - m_impl.m_beaconHandlers.erase(m_from); -} - size_t InternalClientContextImpl::num_instances; size_t InternalClientContextImpl::InternalChannelImpl::num_instances; size_t InternalClientContextImpl::InternalChannelImpl::num_active; @@ -4850,5 +4819,42 @@ ChannelProvider::shared_pointer createClientProvider(const Configuration::shared return external; } +namespace detail { + +BeaconCleanupHandler::BeaconCleanupHandler(InternalClientContextImpl& impl, osiSockAddr addr) : + m_from(addr), + m_impl(impl), + m_count(0) +{ + m_callback.reset(new Callback(*this)); + m_impl.m_timer->schedulePeriodic(m_callback, maxBeaconLifetime / 4, maxBeaconLifetime / 4); +} + +BeaconCleanupHandler::~BeaconCleanupHandler() +{ + m_impl.m_timer->cancel(m_callback); +} + +void BeaconCleanupHandler::Callback::callback() +{ + if (epicsAtomicIncrIntT(&m_handler.m_count) >= 5) { + m_handler.remove(); + } +} + +void BeaconCleanupHandler::Callback::timerStopped() +{ + m_handler.remove(); +} + +void BeaconCleanupHandler::remove() +{ + Lock guard(m_impl.m_beaconMapMutex); + m_impl.m_timer->cancel(m_callback); + m_impl.m_beaconHandlers.erase(m_from); +} + +} + } };