Archive / / / / scheduler.h
2007-09-19 19:50:54 UTC
previous next
#ifndef SCHEDULER_H_ #define SCHEDULER_H_ #include <boost/thread.hpp> #include <boost/utility.hpp> #include <boost/asio.hpp> #include <boost/shared_ptr.hpp> namespace Scheduler { class Task; class Manager : private boost::noncopyable { public: // Public methods, called from outside thread Manager(); ~Manager(); void add_task( boost::shared_ptr<Task> task, boost::posix_time::time_duration time_til_next); private: // Private TaskInfo struct, used below struct TaskInfo { TaskInfo( boost::shared_ptr<Task> _task, boost::shared_ptr<boost::asio::deadline_timer> _timer) : task(_task), timer(_timer) {} boost::shared_ptr<Task> task; boost::shared_ptr<boost::asio::deadline_timer> timer; }; private: // Private methods, called from inside the thread void start(); void add_task_int( boost::shared_ptr<Task> task, boost::posix_time::time_duration time_til_next); void execute_task( const boost::asio::error& error, TaskInfo task_info); private: // Private data boost::scoped_ptr<boost::thread> _thread; boost::asio::io_service _io_service; boost::scoped_ptr<boost::asio::io_service::work> _io_service_work; std::list<TaskInfo> _tasks; }; class Task { public: virtual ~Task() {} virtual boost::posix_time::time_duration start_task() = 0; }; extern boost::scoped_ptr<Manager> manager; } #endif /*SCHEDULER_H_*/