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 {
00031
00034 namespace metrics
00035 {
00037
00038
00039 char const* const task_state = "task.State";
00040
00041 }
00043
00051 class SAGA_EXPORT task
00052 : public object,
00053 public detail::monitorable<task>,
00054 public task_base
00055 {
00056 private:
00058
00059 friend struct saga::impl::runtime;
00060 friend struct detail::monitorable<task>;
00062
00063 protected:
00065
00066 saga::impl::task_interface* get_task_if (void);
00067 saga::impl::task_interface const* get_task_if (void) const;
00068 typedef 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 (void) const;
00128
00133 void rethrow() const;
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);
00193 }
00194
00196 }
00197
00198
00199 #if defined(BOOST_MSVC)
00200 #pragma warning(pop)
00201 #endif
00202
00203 #endif // SAGA_TASK_HPP
00204