// Copyright (c) 2005-2006 Andre Merzky (andre@merzky.net) // Copyright (c) 2005-2007 Hartmut Kaiser (hartmut.kaiser@gmail.com) // Copyright (c) 2005-2006 Stephan Hirmer (shirmer@cct.lsu.edu) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef TASK_CONTAINER_HPP #define TASK_CONTAINER_HPP #include #include #include #include #include #if defined(BOOST_MSVC) #pragma warning(push) #pragma warning(disable: 4251 4231 4275 4660) #endif /////////////////////////////////////////////////////////////////////////////// namespace saga { namespace impl { /** * Class to store and handle some tasks through one handle. */ class task_container : public saga::impl::object, public saga::impl::monitorable { private: /*! list of all tasks added to this container */ typedef std::vector tasks_type; typedef tasks_type::iterator iterator_type; typedef tasks_type::const_iterator const_iterator_type; tasks_type task_list; /** * searches for the tasks out of task_list, which have the * wanted state. * * @param state the state of the tasks, you are searching for. * * @return set of tasks, which have already finished */ tasks_type get_tasks_with_state (saga::task::state state) const; /** * Waits for all tasks, stored in task_list to finish. */ void wait_for_all_tasks_to_finish (void) ; /** * searches and returns a task, with a given uuid */ saga::task get_task_by_uuid(saga::uuid const& id); TR1::shared_ptr bs; public: task_container (void); ~task_container (void); /** * Adds a task to this container. * * @param t the task, we want to add to this container */ void add_task (saga::task & t); /** * Removes a task from this container. * * @param t the task, we want to remove from this container * * @throw no_such_task, if the task which you want to remove * is not part of this container. */ void remove_task (saga::task t); /** * Blocking function, which waits timeout sec for the tasks to * finish. If they finish all before the end of this time, the * function returns immeadiately. * * @return a set of tasks, which have already finished * * @param timeout number of seconds this function will wait for * tasks to finish before returning. * @note timeout < 0.0 : wait until all tasks have finished. * timeout == 0.0 : returns set of finished tasks immed. * timeout > 0.0 : wait for timeout seconds, but if task * finish all before this time, return. * * @throw all_tasks_canceled, if all the tasks in this container * have been canceled already. */ tasks_type wait (const float & timeout = -1.0); /** * @returns a set, specifying the current state of all tasks, * stored in this container. */ std::vector get_states (void) const; /** * Cancels every task in this container. */ void cancel (void); /** * Provides access to list of all tasks of this container. * * @return the list of all tasks stored in this container. */ tasks_type list_tasks (void) const; /** * executes the tasks contained in this task container. * tries to use bulk adaptors if available * if not, executes the tasks one by one */ void run (); /** * runs the tasks in the taskcontainer one by one, without * considerating possible bulk adaptors. Not in the facade. */ void simple_run(); /** * sets one state to all the tasks contained in the taskcontainer * @param s the state to set. Not in the facade. */ void set_state_for_all(saga::task::state s); /** * allows to set the state of a task. The task is specified by * its uuid. Not in the facade. */ void set_state_by_uuid(std::vector& ids, saga::task::state s); /** * not in the facade. * * sets the bulk state for all the tasks, within this container */ void set_tasks_for_bulk_treatement(task_interface::bulk_treatment_state s = task_interface::actual_bulk_treated); /////////////////////////////////////////////////////////////////////// // return the monitorable interface to the facade virtual saga::impl::monitorable* get_monitorable() { return this; } virtual saga::impl::monitorable const* get_monitorable() const { return this; } }; /////////////////////////////////////////////////////////////////////////////// }} // namespace saga::impl #endif // TASK_CONTAINER_HPP