SAGA Adaptor CPI v.1.0
|
00001 // Copyright (c) 2005-2010 Hartmut Kaiser 00002 // 00003 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00005 00006 #ifndef SAGA_ADAPTORS_REGISTER_WORKITEM_HPP 00007 #define SAGA_ADAPTORS_REGISTER_WORKITEM_HPP 00008 00009 #include <saga/saga/util.hpp> 00010 #include <saga/saga/session.hpp> 00011 00012 #include <boost/date_time/posix_time/posix_time_duration.hpp> 00013 #include <boost/date_time/posix_time/ptime.hpp> 00014 #include <boost/system/error_code.hpp> 00015 00016 // suppress warnings about dependent classes not being exported from the dll 00017 #if defined(BOOST_MSVC) 00018 #pragma warning(push) 00019 #pragma warning(disable: 4251 4231 4660) 00020 #endif 00021 00022 namespace saga { namespace adaptors 00023 { 00025 // we use the boost::posix_time::ptime type for time representation 00026 typedef boost::posix_time::ptime time_type; 00027 00028 // we use the boost::posix_time::time_duration type as the duration 00029 // representation 00030 typedef boost::posix_time::time_duration duration_type; 00031 00033 // This is the prototype of any work item to be registered with this 00034 // interface. The function will be called as soon as the expiration time 00035 // specified while registering is reached. This function will be called at 00036 // most once, so re-occurring events need to be registered separately. 00037 typedef TR1::function<void(boost::system::error_code const&)> 00038 workitem_function; 00039 00041 typedef unsigned int workitem_cookie_handle; 00042 00044 // This is the main API for adaptors to register a work item to be executed 00045 // at a certain point in time or after a certain amount of time 00046 SAGA_EXPORT workitem_cookie_handle register_workitem( 00047 workitem_function f, time_type const& expire_at, 00048 saga::session const& s = saga::detail::get_the_session()); 00049 00050 SAGA_EXPORT workitem_cookie_handle register_workitem( 00051 workitem_function f, duration_type const& expire_from_now, 00052 saga::session const& s = saga::detail::get_the_session()); 00053 00055 // This is the API allowing to cancel the execution of a registered work 00056 // item. Note, this will call the registered function but will get passed 00057 // the error code 'booast::asio::error::operation_aborted'. If the 00058 // referenced work item has already expired but not called yet it cannot 00059 // be unregistered anymore and will be called with a success code. 00060 SAGA_EXPORT void unregister_workitem(workitem_cookie_handle, 00061 saga::session const& s = saga::detail::get_the_session()); 00062 }} 00063 00064 #endif 00065 00066