| 1 | /*
|
|---|
| 2 | * ReceiveJobsOperation.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Dec 11, 2011
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef FRAGMENTCONTROLLER_RECEIVEJOBSOPERATION_HPP_
|
|---|
| 9 | #define FRAGMENTCONTROLLER_RECEIVEJOBSOPERATION_HPP_
|
|---|
| 10 |
|
|---|
| 11 | // include config.h
|
|---|
| 12 | #ifdef HAVE_CONFIG_H
|
|---|
| 13 | #include <config.h>
|
|---|
| 14 | #endif
|
|---|
| 15 |
|
|---|
| 16 | #include <boost/asio.hpp>
|
|---|
| 17 | #include <string>
|
|---|
| 18 | #include <vector>
|
|---|
| 19 |
|
|---|
| 20 | #include "Connection.hpp"
|
|---|
| 21 | #include "FragmentJob.hpp"
|
|---|
| 22 |
|
|---|
| 23 | #include "Controller/Commands/Operation.hpp"
|
|---|
| 24 |
|
|---|
| 25 | class ReceiveJobsOperation : public Operation {
|
|---|
| 26 | public:
|
|---|
| 27 | /// Constructor for class ReceiveJobsOperation.
|
|---|
| 28 | ReceiveJobsOperation(Connection &_connection, const std::string& _host, const std::string& _service) :
|
|---|
| 29 | Operation(_connection, _host, _service) {}
|
|---|
| 30 | /// Destructor for class ReceiveJobsOperation
|
|---|
| 31 | ~ReceiveJobsOperation() {}
|
|---|
| 32 |
|
|---|
| 33 | public:
|
|---|
| 34 | /// Placing receive jobs operations into an io_service
|
|---|
| 35 | virtual void operator()();
|
|---|
| 36 |
|
|---|
| 37 | // virtual function pointer to the connection handler
|
|---|
| 38 | virtual void handle_connect(const boost::system::error_code& e,
|
|---|
| 39 | boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
|
|---|
| 40 |
|
|---|
| 41 | /// Handle completion of a calculate operation.
|
|---|
| 42 | void handle_connect_calc(const boost::system::error_code& e,
|
|---|
| 43 | boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
|
|---|
| 44 |
|
|---|
| 45 | /// Callback function when bunch of jobs have been sent.
|
|---|
| 46 | void handle_SendJobs(const boost::system::error_code& e);
|
|---|
| 47 |
|
|---|
| 48 | /// internal function to connect to server and send jobs for calculation
|
|---|
| 49 | void connect_calc();
|
|---|
| 50 |
|
|---|
| 51 | /// Setter for jobs
|
|---|
| 52 | void addJobs(const std::vector<FragmentJob> &jobs);
|
|---|
| 53 |
|
|---|
| 54 | /** Getter for number of jobs present in the queue.
|
|---|
| 55 | *
|
|---|
| 56 | * \return jobs.size()
|
|---|
| 57 | */
|
|---|
| 58 | size_t getPresentJobs() const
|
|---|
| 59 | {
|
|---|
| 60 | return jobs.size();
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | protected:
|
|---|
| 64 | void handle_FinishOperation(const boost::system::error_code& e);
|
|---|
| 65 |
|
|---|
| 66 | /// bunch of jobs
|
|---|
| 67 | std::vector<FragmentJob> jobs;
|
|---|
| 68 | };
|
|---|
| 69 |
|
|---|
| 70 | #endif /* FRAGMENTCONTROLLER_RECEIVEJOBSOPERATION_HPP_ */
|
|---|