00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef SAGA_TASK_HPP
00010 #define SAGA_TASK_HPP
00011
00012
00013 #include <saga/saga/base.hpp>
00014 #include <saga/saga/util.hpp>
00015 #include <saga/saga/task_base.hpp>
00016 #include <saga/saga/object.hpp>
00017
00018 #include <saga/saga/uuid.hpp>
00019 #include <saga/saga/detail/monitorable.hpp>
00020 #include <saga/saga/detail/hold_any.hpp>
00021
00022
00023 #if defined(BOOST_MSVC)
00024 #pragma warning(push)
00025 #pragma warning(disable: 4251 4231 4275 4660)
00026 #endif
00027
00029 namespace saga
00030 {
00033 namespace metrics
00034 {
00036
00037
00038 char const* const task_state = "task.State";
00039
00040 }
00042
00050 class SAGA_EXPORT task
00051 : public object,
00052 public saga::detail::monitorable<task>,
00053 public task_base
00054 {
00055 private:
00057
00058 friend struct saga::impl::runtime;
00059 friend struct saga::detail::monitorable<task>;
00061
00062 protected:
00064
00065 TR1::shared_ptr <saga::impl::task_base> get_impl (void) const;
00066 saga::impl::task_interface* get_task_if (void);
00067 saga::impl::task_interface const* get_task_if (void) const;
00068 typedef saga::detail::monitorable<task> monitorable_base;
00069
00070 explicit task (saga::impl::object* init);
00071 explicit task (saga::object const& o);
00072 task &operator= (saga::object const& o);
00074
00075 public:
00080 typedef task_base::state state;
00081
00086 explicit task (saga::task_base::state t = saga::task_base::New);
00087
00092 ~task ();
00093
00098 friend SAGA_EXPORT
00099 bool operator== (task const & lhs, task const & rhs);
00100
00105 void run(void);
00106
00112 void cancel(void);
00113
00120 bool wait(double timeout = -1.0);
00121
00127 state get_state();
00128
00133 void rethrow();
00134
00140 saga::object get_object() const;
00141
00147 template <typename Retval>
00148 Retval& get_result();
00149
00150 template <typename Retval>
00151 Retval const& get_result() const;
00152
00154 void get_result();
00155 void get_result() const;
00156 };
00157
00158 namespace detail
00159 {
00161
00162
00163
00165
00166 SAGA_EXPORT inline saga::task run (saga::task t)
00167 {
00168 t.run();
00169 return t;
00170 }
00171
00172 SAGA_EXPORT inline saga::task wait (saga::task t, double timeout = -1.0)
00173 {
00174 t.wait (timeout);
00175 return t;
00176 }
00177
00178 SAGA_EXPORT inline saga::task run_wait (saga::task t, double timeout = -1.0)
00179 {
00180 if (saga::task_base::New == t.get_state())
00181 {
00182 t.run();
00183 t.wait(timeout);
00184 }
00185 return t;
00186 }
00187
00189
00190
00191 SAGA_EXPORT detail::hold_any& get_task_result(saga::task t);
00192
00194
00195 SAGA_EXPORT void set_selector_state(saga::task t,
00196 TR1::shared_ptr<impl::adaptor_selector_state> state);
00197
00199
00200 SAGA_EXPORT saga::task set_task_exception(saga::task t,
00201 saga::impl::object const *obj, saga::impl::exception_list const& e);
00203 }
00204
00206 }
00207
00208
00209 #if defined(BOOST_MSVC)
00210 #pragma warning(pop)
00211 #endif
00212
00213 #endif // SAGA_TASK_HPP
00214