libmoost
|
00001 /* vim:set ts=3 sw=3 sts=3 et: */ 00030 #ifndef MOOST_THREAD_SIMPLE_JOB_SCHEDULER_HPP 00031 #define MOOST_THREAD_SIMPLE_JOB_SCHEDULER_HPP 00032 00033 #include <string> 00034 #include <vector> 00035 00036 #include <boost/shared_ptr.hpp> 00037 #include <boost/noncopyable.hpp> 00038 #include <boost/bind.hpp> 00039 00040 #include "job_batch.hpp" 00041 00042 namespace moost { namespace thread { 00043 00044 class simple_job_batch : public job_batch 00045 , public boost::noncopyable 00046 { 00047 public: 00048 simple_job_batch() 00049 : m_count(0) 00050 { 00051 } 00052 00053 virtual void add(job_t job) 00054 { 00055 try 00056 { 00057 job(); // JFDI! :) 00058 } 00059 catch (const std::exception& e) 00060 { 00061 m_errors.push_back(e.what()); 00062 } 00063 catch (...) 00064 { 00065 m_errors.push_back("unknown exception caught"); 00066 } 00067 00068 ++m_count; 00069 } 00070 00071 void run() 00072 { 00073 } 00074 00075 size_t count() const 00076 { 00077 return m_count; 00078 } 00079 00080 const std::vector<std::string>& errors() const 00081 { 00082 return m_errors; 00083 } 00084 00085 private: 00086 size_t m_count; 00087 std::vector<std::string> m_errors; 00088 }; 00089 00090 class simple_job_scheduler : public boost::noncopyable 00091 { 00092 public: 00093 typedef simple_job_batch job_batch_type; 00094 00095 void dispatch(boost::shared_ptr<job_batch_type>) 00096 { 00097 } 00098 }; 00099 00100 }} 00101 00102 #endif