| [41c1b7] | 1 | /*
 | 
|---|
 | 2 |  * SubmitResultOperation.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Feb 26, 2012
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef SUBMITRESULTOPERATION_HPP_
 | 
|---|
 | 9 | #define SUBMITRESULTOPERATION_HPP_
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | // include config.h
 | 
|---|
 | 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 13 | #include <config.h>
 | 
|---|
 | 14 | #endif
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | 
 | 
|---|
 | 17 | #include <boost/asio.hpp>
 | 
|---|
 | 18 | #include <string>
 | 
|---|
 | 19 | #include <vector>
 | 
|---|
 | 20 | 
 | 
|---|
 | 21 | #include "Connection.hpp"
 | 
|---|
 | 22 | 
 | 
|---|
| [f98c8e] | 23 | #include "Controller/Commands/AsyncOperation.hpp"
 | 
|---|
| [41c1b7] | 24 | #include "Jobs/FragmentJob.hpp"
 | 
|---|
 | 25 | #include "Results/FragmentResult.hpp"
 | 
|---|
 | 26 | #include "WorkerAddress.hpp"
 | 
|---|
 | 27 | 
 | 
|---|
| [f98c8e] | 28 | class SubmitResultOperation : public AsyncOperation  {
 | 
|---|
| [41c1b7] | 29 | public:
 | 
|---|
 | 30 |   /// Constructor for class SubmitResultOperation.
 | 
|---|
 | 31 |   SubmitResultOperation(Connection &_connection, const WorkerAddress &_address) :
 | 
|---|
| [f98c8e] | 32 |     AsyncOperation(std::string("submitresult"),_connection),
 | 
|---|
| [41c1b7] | 33 |     result( new FragmentResult(JobId::NoJob, std::string("EmptyResult")) ),
 | 
|---|
 | 34 |     address(_address),
 | 
|---|
 | 35 |     exitflag(OkFlag)
 | 
|---|
 | 36 |   {}
 | 
|---|
 | 37 |   /// Destructor for class SubmitResultOperation
 | 
|---|
 | 38 |   ~SubmitResultOperation() {}
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 |   /** Sets the result to submit.
 | 
|---|
 | 41 |    *
 | 
|---|
 | 42 |    * @param _result result to submit
 | 
|---|
 | 43 |    */
 | 
|---|
 | 44 |   void setResult(FragmentResult::ptr &_result)
 | 
|---|
 | 45 |   {
 | 
|---|
 | 46 |     result.reset();
 | 
|---|
 | 47 |     result = _result;
 | 
|---|
 | 48 |   }
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 | public:
 | 
|---|
 | 51 |   enum {
 | 
|---|
 | 52 |     OkFlag = 0,
 | 
|---|
 | 53 |     ErrorFlag = 1
 | 
|---|
 | 54 |   };
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 |   /** Returns the flag of the handled operation.
 | 
|---|
 | 57 |    *
 | 
|---|
 | 58 |    */
 | 
|---|
 | 59 |   size_t getFlag() const
 | 
|---|
 | 60 |   {
 | 
|---|
 | 61 |     return exitflag;
 | 
|---|
 | 62 |   }
 | 
|---|
 | 63 | 
 | 
|---|
 | 64 | protected:
 | 
|---|
 | 65 |   // virtual function pointer to the connection handler
 | 
|---|
 | 66 |   void handle_connect(const boost::system::error_code& e,
 | 
|---|
 | 67 |       boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 |   /// Callback function when address has been sent and result is about to.
 | 
|---|
 | 70 |   void handle_SendAddress(const boost::system::error_code& e);
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 |   /// Callback function when result has been sent.
 | 
|---|
 | 73 |   void handle_SendResult(const boost::system::error_code& e);
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 | private:
 | 
|---|
 | 76 |   // static entity of an empty result
 | 
|---|
 | 77 |   FragmentResult::ptr result;
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 |   //!> address for listener
 | 
|---|
 | 80 |   WorkerAddress address;
 | 
|---|
 | 81 | 
 | 
|---|
 | 82 |   /// exit flag
 | 
|---|
 | 83 |   size_t exitflag;
 | 
|---|
 | 84 | };
 | 
|---|
 | 85 | 
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 | #endif /* SUBMITRESULTOPERATION_HPP_ */
 | 
|---|