Go to the documentation of this file.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 #include <saga/saga/error.hpp>
00018
00019 #include <saga/saga/uuid.hpp>
00020 #include <saga/saga/detail/monitorable.hpp>
00021 #include <saga/saga/detail/hold_any.hpp>
00022
00023
00024 #if defined(BOOST_MSVC)
00025 #pragma warning(push)
00026 #pragma warning(disable: 4251 4231 4275 4660)
00027 #endif
00028
00030 namespace saga
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 saga::detail::monitorable<task>,
00054 public task_base
00055 {
00056 private:
00058
00059 friend struct saga::impl::runtime;
00060 friend struct saga::detail::monitorable<task>;
00062
00063 protected:
00065
00066 TR1::shared_ptr <saga::impl::task_base> get_impl_sp(void) const;
00067 saga::impl::task_base* get_impl (void) const;
00068
00069 saga::impl::task_interface* get_task_if (void);
00070 saga::impl::task_interface const* get_task_if (void) const;
00071 typedef saga::detail::monitorable<task> monitorable_base;
00072
00073 explicit task (saga::impl::object* init);
00074 explicit task (saga::object const& o);
00075 task &operator= (saga::object const& o);
00077
00078 public:
00083 typedef task_base::state state;
00084 typedef task_base::Sync Sync;
00085 typedef task_base::Async Async;
00086 typedef task_base::Task Task;
00087
00088 task();
00089
00094 explicit task (saga::task_base::state t);
00095
00100 ~task ();
00101
00106 friend SAGA_EXPORT
00107 bool operator== (task const & lhs, task const & rhs);
00108
00113 friend SAGA_EXPORT
00114 bool operator< (task const & lhs, task const & rhs);
00115
00120 void run(void);
00121
00127 void cancel(void);
00128
00135 bool wait(double timeout = -1.0);
00136
00142 state get_state();
00143
00148 void rethrow();
00149
00155 saga::object get_object() const;
00156
00162 template <typename Retval>
00163 Retval& get_result();
00164
00165 template <typename Retval>
00166 Retval const& get_result() const;
00167
00169 void get_result();
00170 void get_result() const;
00171 };
00172
00173 namespace detail
00174 {
00176
00177
00178
00180
00181 SAGA_EXPORT inline saga::task run (saga::task t)
00182 {
00183 t.run();
00184 return t;
00185 }
00186
00187 SAGA_EXPORT inline saga::task wait (saga::task t, double timeout = -1.0)
00188 {
00189 t.wait (timeout);
00190 return t;
00191 }
00192
00193 SAGA_EXPORT inline saga::task run_wait (saga::task t, double timeout = -1.0)
00194 {
00195 if (saga::task_base::New == t.get_state())
00196 {
00197 t.run();
00198 t.wait(timeout);
00199 }
00200 return t;
00201 }
00202
00204
00205
00206 SAGA_EXPORT detail::hold_any& get_task_result(saga::task t);
00207
00209
00210 SAGA_EXPORT void set_selector_state(saga::task t,
00211 TR1::shared_ptr<impl::adaptor_selector_state> state);
00212
00214
00215 SAGA_EXPORT saga::task set_task_exception(saga::task t,
00216 saga::impl::object const *obj, saga::impl::exception_list const& l,
00217 saga::error e);
00219 }
00220
00222 }
00223
00224
00225 #if defined(BOOST_MSVC)
00226 #pragma warning(pop)
00227 #endif
00228
00229 #endif // SAGA_TASK_HPP
00230