| [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 |
|
|---|
| 23 | #include "Jobs/FragmentJob.hpp"
|
|---|
| [50d095] | 24 | #include "Operations/AsyncOperation.hpp"
|
|---|
| [41c1b7] | 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.
|
|---|
| [9a3f84] | 70 | void handle_SendChoice(const boost::system::error_code& e);
|
|---|
| [41c1b7] | 71 |
|
|---|
| 72 | /// Callback function when result has been sent.
|
|---|
| 73 | void handle_SendResult(const boost::system::error_code& e);
|
|---|
| 74 |
|
|---|
| [9a3f84] | 75 | /// Callback function when result has been sent.
|
|---|
| 76 | void handle_FinishOperation(const boost::system::error_code& e);
|
|---|
| 77 |
|
|---|
| [41c1b7] | 78 | private:
|
|---|
| 79 | // static entity of an empty result
|
|---|
| 80 | FragmentResult::ptr result;
|
|---|
| 81 |
|
|---|
| 82 | //!> address for listener
|
|---|
| 83 | WorkerAddress address;
|
|---|
| 84 |
|
|---|
| 85 | /// exit flag
|
|---|
| 86 | size_t exitflag;
|
|---|
| 87 | };
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 | #endif /* SUBMITRESULTOPERATION_HPP_ */
|
|---|