1 | /*
|
---|
2 | * CheckResultsOperation.hpp
|
---|
3 | *
|
---|
4 | * Created on: Dec 11, 2011
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef FRAGMENTCONTROLLER_CHECKRESULTSOPERATION_HPP_
|
---|
9 | #define FRAGMENTCONTROLLER_CHECKRESULTSOPERATION_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 <set>
|
---|
18 | #include <string>
|
---|
19 |
|
---|
20 | #include "JobMarket/Connection.hpp"
|
---|
21 |
|
---|
22 | #include "JobMarket/Operations/AsyncOperation.hpp"
|
---|
23 | #include "JobMarket/types.hpp"
|
---|
24 |
|
---|
25 | /** This Operations requests number of present jobs and present results (done
|
---|
26 | * jobs) from the server.
|
---|
27 | *
|
---|
28 | */
|
---|
29 | class CheckResultsOperation : public AsyncOperation {
|
---|
30 | public:
|
---|
31 | /// Constructor for class CheckResultsOperation.
|
---|
32 | CheckResultsOperation(Connection &_connection,
|
---|
33 | const boost::function<void ()> _callback_on_success = NoOpCallback,
|
---|
34 | const boost::function<void ()> _callback_on_failure = NoOpCallback) :
|
---|
35 | AsyncOperation(std::string("checkresults"), _connection, _callback_on_success, _callback_on_failure),
|
---|
36 | jobids(emptyids),
|
---|
37 | jobInfo((size_t)2, 0)
|
---|
38 | {}
|
---|
39 | /// Destructor for class CheckResultsOperation
|
---|
40 | ~CheckResultsOperation() {}
|
---|
41 |
|
---|
42 | public:
|
---|
43 | // virtual function pointer to the connection handler
|
---|
44 | virtual void handle_connect(const boost::system::error_code& e,
|
---|
45 | boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
|
---|
46 |
|
---|
47 | /// Callback function when sending jobids to know state of.
|
---|
48 | void handle_SendJobIds(const boost::system::error_code& e);
|
---|
49 |
|
---|
50 | /// Callback function when doneJobs have been received.
|
---|
51 | void handle_ReceiveJobInfo(const boost::system::error_code& e);
|
---|
52 |
|
---|
53 | /// Setter for internal vector of jobids to check
|
---|
54 | void setJobIds(const std::set<JobId_t> &_jobids)
|
---|
55 | { const_cast<std::set<JobId_t> &>(jobids) = _jobids; }
|
---|
56 |
|
---|
57 | /// Getter for presentJobs
|
---|
58 | size_t getPresentJobs() const;
|
---|
59 |
|
---|
60 | /// Getter for doneJobs
|
---|
61 | size_t getDoneJobs() const;
|
---|
62 |
|
---|
63 | protected:
|
---|
64 | //!> internal ref to the jobids to check
|
---|
65 | const std::set<JobId_t> &jobids;
|
---|
66 |
|
---|
67 | /// current jobs left to calculate and currently calculated results
|
---|
68 | std::vector<size_t> jobInfo;
|
---|
69 |
|
---|
70 | private:
|
---|
71 | //!> internal empty ids vector to use as default ref
|
---|
72 | static const std::set<JobId_t> emptyids;
|
---|
73 |
|
---|
74 | };
|
---|
75 |
|
---|
76 | #endif /* FRAGMENTCONTROLLER_CHECKRESULTSOPERATION_HPP_ */
|
---|