| [ffe057] | 1 | /* | 
|---|
|  | 2 | * SpecificFragmentController.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Aug 27, 2012 | 
|---|
|  | 5 | *      Author: heber | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef SPECIFICFRAGMENTCONTROLLER_HPP_ | 
|---|
|  | 9 | #define SPECIFICFRAGMENTCONTROLLER_HPP_ | 
|---|
|  | 10 |  | 
|---|
|  | 11 |  | 
|---|
|  | 12 | // include config.h | 
|---|
|  | 13 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 14 | #include <config.h> | 
|---|
|  | 15 | #endif | 
|---|
|  | 16 |  | 
|---|
|  | 17 | #include "JobMarket/Controller/FragmentController.hpp" | 
|---|
| [8e84fe] | 18 | #include "JobMarket/types.hpp" | 
|---|
| [ffe057] | 19 | #include "JobMarket/Results/FragmentResult.hpp" | 
|---|
|  | 20 |  | 
|---|
| [d9f2b3] | 21 | #include <boost/function.hpp> | 
|---|
| [ffe057] | 22 | #include <map> | 
|---|
|  | 23 | #include <string> | 
|---|
|  | 24 | #include <vector> | 
|---|
|  | 25 |  | 
|---|
| [a498c1] | 26 | #include "Fragmentation/Automation/ResultContainer.hpp" | 
|---|
|  | 27 |  | 
|---|
| [ffe057] | 28 | /** This class extends FragmentController by some commodity functions used | 
|---|
|  | 29 | * within FragmentationAutomationAction. | 
|---|
|  | 30 | * | 
|---|
|  | 31 | */ | 
|---|
|  | 32 | class SpecificFragmentController : public FragmentController | 
|---|
|  | 33 | { | 
|---|
|  | 34 | public: | 
|---|
| [d9f2b3] | 35 | SpecificFragmentController(boost::asio::io_service &_io_service); | 
|---|
| [ffe057] | 36 | virtual ~SpecificFragmentController() | 
|---|
|  | 37 | {} | 
|---|
|  | 38 |  | 
|---|
| [d9f2b3] | 39 | typedef boost::function<void (const size_t,const size_t)> update_handler_t; | 
|---|
|  | 40 |  | 
|---|
|  | 41 | void setUpdateHandler(update_handler_t _handler) | 
|---|
|  | 42 | { | 
|---|
|  | 43 | handler = _handler; | 
|---|
|  | 44 | } | 
|---|
|  | 45 |  | 
|---|
| [ffe057] | 46 | void requestIds(const size_t numberjobs); | 
|---|
| [732507] | 47 | virtual void waitforResults(const size_t NoExpectedResults)=0; | 
|---|
| [ffe057] | 48 | void RunService(const std::string message); | 
|---|
|  | 49 |  | 
|---|
|  | 50 | /// getter and setter | 
|---|
|  | 51 |  | 
|---|
|  | 52 | void setHost(const std::string &_host) { host = _host; } | 
|---|
|  | 53 | void setPort(const std::string &_port) { port = _port; } | 
|---|
|  | 54 |  | 
|---|
|  | 55 | protected: | 
|---|
|  | 56 |  | 
|---|
| [732507] | 57 | /** Container for the results received from the server. | 
|---|
|  | 58 | * | 
|---|
|  | 59 | * These are received bit by bit until all jobs are calculated. | 
|---|
|  | 60 | * This struct takes of the waiting. | 
|---|
| [ffe057] | 61 | * | 
|---|
| [a498c1] | 62 | * We extend ResultContainer by functions to receive results from a | 
|---|
|  | 63 | * JobMarket server. | 
|---|
|  | 64 | * | 
|---|
| [ffe057] | 65 | */ | 
|---|
|  | 66 | template <typename T> | 
|---|
| [a498c1] | 67 | struct ReceiveResultContainer : public ResultContainer<T> { | 
|---|
| [732507] | 68 | /** cycle to wait for results | 
|---|
|  | 69 | * | 
|---|
|  | 70 | * \param NoExpectedResults number of expected results | 
|---|
|  | 71 | * \param io_service service used for waiting | 
|---|
|  | 72 | * \param callback ref to call controller functions | 
|---|
|  | 73 | */ | 
|---|
|  | 74 | void waitforResults( | 
|---|
|  | 75 | const size_t NoExpectedResults, | 
|---|
|  | 76 | boost::asio::io_service &io_service, | 
|---|
|  | 77 | SpecificFragmentController &callback); | 
|---|
|  | 78 |  | 
|---|
|  | 79 | /** Internal function to receive results if some are present. | 
|---|
|  | 80 | * | 
|---|
|  | 81 | * \param callback ref to call controller functions | 
|---|
|  | 82 | * \return number of received results | 
|---|
|  | 83 | */ | 
|---|
|  | 84 | size_t receiveResults(SpecificFragmentController &callback); | 
|---|
|  | 85 | }; | 
|---|
| [ffe057] | 86 |  | 
|---|
|  | 87 | protected: | 
|---|
|  | 88 | //!> hostname of the server to control | 
|---|
|  | 89 | std::string host; | 
|---|
|  | 90 | //!> port of the server to control | 
|---|
|  | 91 | std::string port; | 
|---|
|  | 92 | //!> reference to io_service for internal purposes | 
|---|
|  | 93 | boost::asio::io_service &io_service; | 
|---|
| [d9f2b3] | 94 | //!> update handler that is called in waitforResults() | 
|---|
|  | 95 | update_handler_t handler; | 
|---|
| [ffe057] | 96 | }; | 
|---|
|  | 97 |  | 
|---|
| [d4eaf1] | 98 | #include "SpecificFragmentController_ReceiveResultContainer_impl.hpp" | 
|---|
| [ffe057] | 99 |  | 
|---|
|  | 100 | #endif /* SPECIFICFRAGMENTCONTROLLER_HPP_ */ | 
|---|