If you need to pass additional information to your handler, use <a
href="http://www.boost.org/libs/bind/bind.html">Boost.Bind</a>:
\code
+ // Handle callback function
+ void callback(UDPv4ClientSocketHandle handle, senf::Scheduler::EventId event) {..}
// Pass 'handle' as additional first argument to callback()
- Scheduler::instance().add(handle, boost::bind(&callback, handle, _1))
+ Scheduler::instance().add(handle, boost::bind(&callback, handle, _1), EV_READ)
+ // Timeout function
+ void timeout( int n) {..}
// Call timeout() handler with argument 'n'
Scheduler::instance().timeout(boost::bind(&timeout, n))
\endcode
href="http://www.boost.org/libs/bind/bind.html">Boost.Bind</a> or senf::membind()
\code
// e.g. in Foo::Foo() constructor:
- Scheduler::instance().add(handle_, senf::membind(&Foo::callback, this))
+ Scheduler::instance().add(handle_, senf::membind(&Foo::callback, this)), EV_READ)
\endcode
File descriptors are managed using add() or remove()
\code
- Scheduler::instance().add(handle, &callback);
+ Scheduler::instance().add(handle, &callback, EV_ALL);
Scheduler::instance().remove(handle);
\endcode
\todo Fix the file support to use threads (?) fork (?) and a pipe so it works reliably even
over e.g. NFS.
+
+ \todo Add a check in the alarm callback which is already called every x seconds to check,
+ that a single callback is not blocking.
*/
class Scheduler
: boost::noncopyable
the Handle interface defined above.
\param[in] cb callback
\param[in] eventMask arbitrary combination via '|'
- operator of EventId designators. */
+ operator of \ref senf::Scheduler::EventId "EventId"
+ designators. */
template <class Handle>
void remove(Handle const & handle, int eventMask = EV_ALL); ///< Remove event callback
/**< remove() will remove any callback registered for any of
\param[in] handle file descriptor or handle providing
the Handle interface defined above.
\param[in] eventMask arbitrary combination via '|'
- operator of EventId designators. */
-
+ operator of \ref senf::Scheduler::EventId "EventId"
+ designators. */
///\}
///\name Timeouts
unsigned timeout(ClockService::clock_type timeout, SimpleCallback const & cb);
///< Add timeout event
- /**< \param[in] timeout timeout in nanoseconds
+ /**< \returns timer id
+ \param[in] timeout timeout in nanoseconds
\param[in] cb callback to call after \a timeout
milliseconds */
void timeoutEarly(ClockService::clock_type v);
///< Set the \a timeoutEarly parameter
- ClockService::clock_type timeoutAdjust() const;\
+ ClockService::clock_type timeoutAdjust() const;
///< Fetch the \a timeoutAdjust parameter
void timeoutAdjust(ClockService::clock_type v);
///< Set the \a timeoutAdjust parameter
///< Remove signal handler for \a signal
/// The signal number passed to registerSignal or unregisterSignal is invalid
- struct InvalidSignalNumberException : public std::exception
- { virtual char const * what() const throw()
- { return "senf::Scheduler::InvalidSignalNumberException"; } };
+ struct InvalidSignalNumberException : public senf::Exception
+ { InvalidSignalNumberException()
+ : senf::Exception("senf::Scheduler::InvalidSignalNumberException"){} };
///\}
returns. */
ClockService::clock_type eventTime() const; ///< Return date/time of last event
+ /**< This is the timestamp, the last event has been
+ signaled. This is the real time at which the event is
+ delivered \e not the time it should have been delivered
+ (in the case of timers). */
protected:
*/
struct SchedulerLogTimeSource : public senf::log::TimeSource
{
- boost::posix_time::ptime operator()() const;
+ senf::log::time_type operator()() const;
};
}