// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+/** \mainpage The SENF Scheduler library
+
+ */
+
#ifndef HH_Scheduler_
#define HH_Scheduler_ 1
// Custom includes
#include <map>
+#include <queue>
#include <boost/function.hpp>
#include <boost/utility.hpp>
#include <boost/call_traits.hpp>
+#include "Utils/MicroTime.hh"
+
//#include "scheduler.mpp"
///////////////////////////////hh.p////////////////////////////////////////
-namespace satcom {
-namespace lib {
+/** \brief SENF Project namespace */
+namespace senf {
/** \brief Singleton class to manage the event loop
descriptiors with this class and pass callback functions to be
called on input, output or error. This functions are specified
using boost::function objects
+
+ \todo Fix EventId parameter (probably to int) to allow |-ing
+ without casting ...
*/
class Scheduler
: boost::noncopyable
typedef boost::function<void (typename boost::call_traits<Handle>::param_type,
EventId) > Callback;
};
- typedef GenericCallback<int>::Callback Callback;
+ typedef boost::function<void (EventId)> SimpleCallback;
+ typedef boost::function<void ()> TimerCallback;
///////////////////////////////////////////////////////////////////////////
///\name Structors and default members
///@}
///////////////////////////////////////////////////////////////////////////
- void add(int fd, Callback const & cb, EventId eventMask = EV_ALL);
- void remove(int fd, EventId eventMask = EV_ALL);
-
template <class Handle>
void add(Handle const & handle,
typename GenericCallback<Handle>::Callback const & cb,
- EventId eventMask = EV_ALL);
- template <class Handle>
- void remove(Handle const & handle, EventId eventMask = EV_ALL);
+ int eventMask = EV_ALL);
+ template <class Handle>
+ void remove(Handle const & handle, int eventMask = EV_ALL);
- void process();
+ void timeout(unsigned long timeout, TimerCallback const & cb);
+ void process();
void terminate();
protected:
private:
Scheduler();
+
+ void do_add(int fd, SimpleCallback const & cb, int eventMask = EV_ALL);
+ void do_remove(int fd, int eventMask = EV_ALL);
- struct EventSpec
+ struct EventSpec
{
- Callback cb_read;
- Callback cb_prio;
- Callback cb_write;
- Callback cb_hup;
- Callback cb_err;
+ SimpleCallback cb_read;
+ SimpleCallback cb_prio;
+ SimpleCallback cb_write;
+ SimpleCallback cb_hup;
+ SimpleCallback cb_err;
int epollMask() const;
};
+
+ struct TimerSpec
+ {
+ TimerSpec() : timeout(), cb() {}
+ TimerSpec(unsigned long long timeout_, TimerCallback cb_)
+ : timeout(timeout_), cb(cb_) {}
+
+ bool operator< (TimerSpec const & other) const
+ { return timeout > other.timeout; }
+
+ unsigned long long timeout;
+ TimerCallback cb;
+ };
typedef std::map<int,EventSpec> FdTable;
+ typedef std::priority_queue<TimerSpec> TimerQueue;
FdTable fdTable_;
+ TimerQueue timerQueue_;
int epollFd_;
bool terminate_;
};
-}}
+ int retrieve_filehandle(int fd);
+
+}
///////////////////////////////hh.e////////////////////////////////////////
#include "Scheduler.cci"
\f
// Local Variables:
// mode: c++
-// c-file-style: "satcom"
+// c-file-style: "senf"
// End: