00001 #ifndef toast_async_dispatcher_hpp_INCLUDED
00002 #define toast_async_dispatcher_hpp_INCLUDED
00003
00004 #include <list>
00005 #include <boost/bind.hpp>
00006 #include <toast/async/request.hpp>
00007
00008 namespace toast {
00009 namespace async {
00010
00011 namespace detail {
00012
00013 template <typename T, typename U, typename V>
00014 void request_helper(T const &f,
00015 U const &c,
00016 V const &push)
00017 {
00018 std::list<request> temp(1, boost::bind(c, f()));
00019 push(temp);
00020 }
00021
00022
00023 }
00024
00040 class thread_specific_request_queue
00041 {
00042 thread_specific_request_queue();
00043 public:
00052 static boost::function<void (std::list<request> &)> get_push();
00053
00059 static void pop_one(std::list<request> &);
00060
00066 static void pop(std::list<request> &);
00067
00075 static boost::function<void ()> on_push(boost::function<void ()> const &);
00076 };
00077
00091 template <typename T>
00092 request make_request(boost::function<T ()> const &f,
00093 boost::function<void (T)> const &c)
00094 {
00095 return boost::bind(&detail::request_helper<
00096 boost::function<T ()>,
00097 boost::function<void (T)>,
00098 boost::function<void (std::list<request> &)> >,
00099 f,
00100 c,
00101 thread_specific_request_queue::get_push());
00102 }
00103
00106 }
00107 }
00108
00217 #endif // toast_async_dispatcher_hpp_INCLUDED