| 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"
 | 
|---|
| 18 | #include "JobMarket/types.hpp"
 | 
|---|
| 19 | #include "JobMarket/Results/FragmentResult.hpp"
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include <boost/function.hpp>
 | 
|---|
| 22 | #include <map>
 | 
|---|
| 23 | #include <string>
 | 
|---|
| 24 | #include <vector>
 | 
|---|
| 25 | 
 | 
|---|
| 26 | #include "Fragmentation/Automation/ResultContainer.hpp"
 | 
|---|
| 27 | 
 | 
|---|
| 28 | /** This class extends FragmentController by some commodity functions used
 | 
|---|
| 29 |  * within FragmentationAutomationAction.
 | 
|---|
| 30 |  *
 | 
|---|
| 31 |  */
 | 
|---|
| 32 | class SpecificFragmentController : public FragmentController
 | 
|---|
| 33 | {
 | 
|---|
| 34 | public:
 | 
|---|
| 35 |   SpecificFragmentController(boost::asio::io_service &_io_service);
 | 
|---|
| 36 |   virtual ~SpecificFragmentController()
 | 
|---|
| 37 |   {}
 | 
|---|
| 38 | 
 | 
|---|
| 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 | 
 | 
|---|
| 46 |   void requestIds(const size_t numberjobs);
 | 
|---|
| 47 |   virtual void waitforResults(const size_t NoExpectedResults)=0;
 | 
|---|
| 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 | 
 | 
|---|
| 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.
 | 
|---|
| 61 |    *
 | 
|---|
| 62 |    * We extend ResultContainer by functions to receive results from a
 | 
|---|
| 63 |    * JobMarket server.
 | 
|---|
| 64 |    *
 | 
|---|
| 65 |    */
 | 
|---|
| 66 |   template <typename T>
 | 
|---|
| 67 |   struct ReceiveResultContainer : public ResultContainer<T> {
 | 
|---|
| 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 |   };
 | 
|---|
| 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;
 | 
|---|
| 94 |   //!> update handler that is called in waitforResults()
 | 
|---|
| 95 |   update_handler_t handler;
 | 
|---|
| 96 | };
 | 
|---|
| 97 | 
 | 
|---|
| 98 | #include "SpecificFragmentController_ReceiveResultContainer_impl.hpp"
 | 
|---|
| 99 | 
 | 
|---|
| 100 | #endif /* SPECIFICFRAGMENTCONTROLLER_HPP_ */
 | 
|---|