| 1 | /*
|
|---|
| 2 | * FragmentController.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Nov 27, 2011
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef FRAGMENTCONTROLLER_HPP_
|
|---|
| 9 | #define FRAGMENTCONTROLLER_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 | #include "FragmentResult.hpp"
|
|---|
| 23 |
|
|---|
| 24 | #include "Controller/Commands/Operation.hpp"
|
|---|
| 25 | #include "Controller/Commands/CheckResultsOperation.hpp"
|
|---|
| 26 | #include "Controller/Commands/ReceiveJobsOperation.hpp"
|
|---|
| 27 | #include "Controller/Commands/SendResultsOperation.hpp"
|
|---|
| 28 | #include "Controller/Commands/ShutdownOperation.hpp"
|
|---|
| 29 |
|
|---|
| 30 | /** The FragmentController sends bunches of jobs to a FragmentScheduler,
|
|---|
| 31 | * waits for their calculation and is called when they are done. Then,
|
|---|
| 32 | * he loads the bunch of results from the Scheduler.
|
|---|
| 33 | *
|
|---|
| 34 | * While the FragmentScheduler and FragmentWorker rather act on their own
|
|---|
| 35 | * this is the piece to implant into the user software to allow for
|
|---|
| 36 | * communication with the Server/Worker duo to perform the calculation
|
|---|
| 37 | * of the fragments on distant computers.
|
|---|
| 38 | */
|
|---|
| 39 | class FragmentController
|
|---|
| 40 | {
|
|---|
| 41 | public:
|
|---|
| 42 | FragmentController(boost::asio::io_service& io_service);
|
|---|
| 43 | ~FragmentController();
|
|---|
| 44 |
|
|---|
| 45 | protected:
|
|---|
| 46 | /// The Connection to the server.
|
|---|
| 47 | Connection connection_;
|
|---|
| 48 |
|
|---|
| 49 | public:
|
|---|
| 50 |
|
|---|
| 51 | ReceiveJobsOperation recjobs;
|
|---|
| 52 | CheckResultsOperation checkres;
|
|---|
| 53 | SendResultsOperation sendres;
|
|---|
| 54 | ShutdownOperation shutdown;
|
|---|
| 55 |
|
|---|
| 56 | // get the exit flag of the last operations
|
|---|
| 57 | size_t getExitflag() const
|
|---|
| 58 | {
|
|---|
| 59 | if (recjobs.getExitflag() != 0)
|
|---|
| 60 | return recjobs.getExitflag();
|
|---|
| 61 | if (checkres.getExitflag() != 0)
|
|---|
| 62 | return checkres.getExitflag();
|
|---|
| 63 | if (sendres.getExitflag() != 0)
|
|---|
| 64 | return sendres.getExitflag();
|
|---|
| 65 | if (shutdown.getExitflag() != 0)
|
|---|
| 66 | return shutdown.getExitflag();
|
|---|
| 67 | return 0;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | /// place number of jobs into this controller
|
|---|
| 71 | void addJobs(const std::vector<FragmentJob> &jobs)
|
|---|
| 72 | {
|
|---|
| 73 | recjobs.addJobs(jobs);
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | /// get the results for the current jobs
|
|---|
| 77 | std::vector<FragmentResult> getResults()
|
|---|
| 78 | {
|
|---|
| 79 | return sendres.getResults();
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | /// Getter for doneJobs
|
|---|
| 83 | size_t getDoneJobs() const
|
|---|
| 84 | {
|
|---|
| 85 | return checkres.getDoneJobs();
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | /// Getter for number of jobs in the queue
|
|---|
| 89 | size_t getPresentJobs() const
|
|---|
| 90 | {
|
|---|
| 91 | return recjobs.getPresentJobs();
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | private:
|
|---|
| 95 | /// host name of server
|
|---|
| 96 | const std::string host;
|
|---|
| 97 |
|
|---|
| 98 | // service to connect to to
|
|---|
| 99 | const std::string service;
|
|---|
| 100 | };
|
|---|
| 101 |
|
|---|
| 102 | #endif /* FRAGMENTCONTROLLER_HPP_ */
|
|---|