/* * SpecificFragmentController.hpp * * Created on: Aug 27, 2012 * Author: heber */ #ifndef SPECIFICFRAGMENTCONTROLLER_HPP_ #define SPECIFICFRAGMENTCONTROLLER_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "JobMarket/Controller/FragmentController.hpp" #include "JobMarket/types.hpp" #include "JobMarket/Results/FragmentResult.hpp" #include #include #include #include #include "Fragmentation/Automation/ResultContainer.hpp" /** This class extends FragmentController by some commodity functions used * within FragmentationAutomationAction. * */ class SpecificFragmentController : public FragmentController { public: SpecificFragmentController(boost::asio::io_service &_io_service); virtual ~SpecificFragmentController() {} typedef boost::function update_handler_t; void setUpdateHandler(update_handler_t _handler) { handler = _handler; } void requestIds(const size_t numberjobs); virtual void waitforResults(const size_t NoExpectedResults)=0; void RunService(const std::string message); /// getter and setter void setHost(const std::string &_host) { host = _host; } void setPort(const std::string &_port) { port = _port; } protected: /** Container for the results received from the server. * * These are received bit by bit until all jobs are calculated. * This struct takes of the waiting. * * We extend ResultContainer by functions to receive results from a * JobMarket server. * */ template struct ReceiveResultContainer : public ResultContainer { /** cycle to wait for results * * \param NoExpectedResults number of expected results * \param io_service service used for waiting * \param callback ref to call controller functions */ void waitforResults( const size_t NoExpectedResults, boost::asio::io_service &io_service, SpecificFragmentController &callback); /** Internal function to receive results if some are present. * * \param callback ref to call controller functions * \return number of received results */ size_t receiveResults(SpecificFragmentController &callback); }; protected: //!> hostname of the server to control std::string host; //!> port of the server to control std::string port; //!> reference to io_service for internal purposes boost::asio::io_service &io_service; //!> update handler that is called in waitforResults() update_handler_t handler; }; #include "SpecificFragmentController_ReceiveResultContainer_impl.hpp" #endif /* SPECIFICFRAGMENTCONTROLLER_HPP_ */