Main Page | Class List | File List | Class Members

SimpleScheduler.hpp

00001 /*
00002  * Copyright (C) 2003-2004
00003  * Slawomir Lisznianski <slisznianski@asyncnet.com>
00004  *
00005  * Permission to use, copy, modify, distribute and sell this software
00006  * and its documentation for any purpose is hereby granted without fee,
00007  * provided that the above copyright notice appear in all copies and
00008  * that both that copyright notice and this permission notice appear
00009  * in supporting documentation. Slawomir Lisznianski makes no
00010  * representations about the suitability of this software for any
00011  * purpose. It is provided "as is" without express or implied warranty.
00012  *
00013  */
00014 
00015 #ifndef RHA_SIMPLESCHEDULER_HPP
00016 #define RHA_SIMPLESCHEDULER_HPP
00017 
00018 // For noncopyable semantics.
00019 #include <boost/utility.hpp>
00020 
00021 namespace Rha
00022 {
00032   template<class E>
00033   class SimpleScheduler :
00034     private boost::noncopyable
00035   {
00036   public:
00037     typedef SimpleScheduler<E> OfType;
00038     typedef typename E::Task   Task;
00039     typedef typename E::Queue  Queue;
00040     typedef E                  Executor;
00041 
00043     SimpleScheduler();
00049     SimpleScheduler(const Queue& queue);
00056     SimpleScheduler(const Executor& exec);
00064     SimpleScheduler(const Queue& queue, const Executor& exec);
00065 
00073     ~SimpleScheduler() throw (); // Do not inherit.
00074 
00080     inline SimpleScheduler<E>&
00081     push(const Task& task);
00082 
00088     inline SimpleScheduler<E>&
00089     operator<<(const Task& task);
00090 
00091   private:
00092     // Initializes queue and executor.
00093     // Guaranteed to be invoked prior to
00094     // begin scheduling.
00095     //
00096     void setUp__();
00097 
00098     Queue    M_queue;
00099     Executor M_executor;
00100   };
00101 }
00102 
00103 using namespace Rha;
00104 
00105 template <class E>
00106 SimpleScheduler<E>::SimpleScheduler()
00107 {
00108   setUp__();
00109 }
00110 
00111 template <class E>
00112 SimpleScheduler<E>::SimpleScheduler(const Queue& queue) :
00113   M_queue(queue)
00114 {
00115   setUp__();
00116 }
00117 
00118 template <class E>
00119 SimpleScheduler<E>::SimpleScheduler(const Executor& exec) :
00120   M_executor(exec)
00121 {
00122   setUp__();
00123 }
00124 
00125 template <class E>
00126 SimpleScheduler<E>::SimpleScheduler(const Queue& queue, const Executor& exec) :
00127   M_queue(queue), M_executor(exec)
00128 {
00129   setUp__();
00130 }
00131 
00132 template <class E>
00133 SimpleScheduler<E>::~SimpleScheduler() throw ()
00134 {}
00135 
00136 template <class E>
00137 SimpleScheduler<E>&
00138 SimpleScheduler<E>::push(const Task& task)
00139 {
00140   M_executor(task);
00141   return (*this);
00142 }
00143 
00144 template <class E>
00145 SimpleScheduler<E>&
00146 SimpleScheduler<E>::operator<<(const Task& task)
00147 {
00148   M_executor(task);
00149   return (*this);
00150 }
00151 
00152 template <class E>
00153 void
00154 SimpleScheduler<E>::setUp__()
00155 {
00156   M_queue.setUp();
00157   M_executor.setUp(&M_queue);
00158 }
00159 
00160 #endif // RHA_SIMPLESCHEDULER_HPP