| [d920b9] | 1 | /* | 
|---|
|  | 2 | * SystemCommandJob.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Feb 5, 2011 | 
|---|
|  | 5 | *      Author: heber | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef SYSTEMCOMMANDJOB_HPP_ | 
|---|
|  | 9 | #define SYSTEMCOMMANDJOB_HPP_ | 
|---|
|  | 10 |  | 
|---|
|  | 11 | // include config.h | 
|---|
|  | 12 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 13 | #include <config.h> | 
|---|
|  | 14 | #endif | 
|---|
|  | 15 |  | 
|---|
|  | 16 | #include <boost/serialization/export.hpp> | 
|---|
|  | 17 |  | 
|---|
|  | 18 | #include <string> | 
|---|
|  | 19 |  | 
|---|
|  | 20 | #include "Jobs/FragmentJob.hpp" | 
|---|
|  | 21 |  | 
|---|
|  | 22 | class SystemCommandJobTest; | 
|---|
|  | 23 |  | 
|---|
|  | 24 | /** SystemCommandJob is an extension of FragmentJob that executes a system | 
|---|
|  | 25 | * command operating onto a specific outputfile. | 
|---|
|  | 26 | * | 
|---|
|  | 27 | * Implement extractResult() to get the desired result from the captured | 
|---|
|  | 28 | * output of the system command. | 
|---|
|  | 29 | * | 
|---|
|  | 30 | * Important is that this class is fully serializable such that it can be | 
|---|
|  | 31 | * transfered to a scheduler (server) and be deserialized by the Worker. | 
|---|
|  | 32 | */ | 
|---|
|  | 33 | class SystemCommandJob : public FragmentJob | 
|---|
|  | 34 | { | 
|---|
|  | 35 | //!> grant unit test access | 
|---|
|  | 36 | friend class SystemCommandJobTest; | 
|---|
|  | 37 | public: | 
|---|
|  | 38 | SystemCommandJob(const std::string &_command, const std::string &_outputfile, const JobId_t _JobId); | 
|---|
|  | 39 | ~SystemCommandJob(); | 
|---|
|  | 40 |  | 
|---|
|  | 41 | FragmentResult::ptr Work(); | 
|---|
|  | 42 |  | 
|---|
|  | 43 | bool operator==(const SystemCommandJob &other) const; | 
|---|
|  | 44 |  | 
|---|
|  | 45 | bool operator!=(const SystemCommandJob &other) const { | 
|---|
|  | 46 | return !(*this == other); | 
|---|
|  | 47 | } | 
|---|
|  | 48 |  | 
|---|
|  | 49 | private: | 
|---|
|  | 50 | virtual FragmentResult::ptr extractResult(const std::string &resultstring); | 
|---|
|  | 51 |  | 
|---|
|  | 52 | //!> string containing the command to launch the solver | 
|---|
|  | 53 | std::string command; | 
|---|
|  | 54 |  | 
|---|
|  | 55 | //!> string containing the configuration file for the solver | 
|---|
|  | 56 | std::string outputfile; | 
|---|
|  | 57 |  | 
|---|
|  | 58 | protected: | 
|---|
|  | 59 | //!> private default cstor for serialization only | 
|---|
|  | 60 | SystemCommandJob(); | 
|---|
|  | 61 |  | 
|---|
|  | 62 | private: | 
|---|
|  | 63 | friend class boost::serialization::access; | 
|---|
|  | 64 | // serialization | 
|---|
|  | 65 | template <typename Archive> | 
|---|
|  | 66 | void serialize(Archive& ar, const unsigned int version) | 
|---|
|  | 67 | { | 
|---|
|  | 68 | ar & boost::serialization::base_object<FragmentJob>(*this); | 
|---|
|  | 69 | ar & command; | 
|---|
|  | 70 | ar & outputfile; | 
|---|
|  | 71 | } | 
|---|
|  | 72 | }; | 
|---|
|  | 73 |  | 
|---|
|  | 74 | // we need to give this class a unique key for serialization | 
|---|
|  | 75 | // its is only serialized through its base class FragmentJob | 
|---|
|  | 76 | BOOST_CLASS_EXPORT_KEY(SystemCommandJob) | 
|---|
|  | 77 |  | 
|---|
|  | 78 | #endif /* SYSTEMCOMMANDJOB_HPP_ */ | 
|---|