// JobCreator.h #ifndef dial__JobCreator_H #define dial__JobCreator_H // David Adams // July 2003 // // Base class for a factory to create jobs. // // A class (rather than a function) is used so that data such // as a queue name can be included in the creator. #include #include #include #include "dial_job/JobId.h" class XmlElement; namespace dset { class Dataset; } namespace dial { class Application; class Task; class JobPreferences; class Job; class JobCreator { public: // typedefs // Pointer to a function to create a job creator from an XML element. typedef const JobCreator* (*Creator) (const XmlElement&); // Creator name. typedef std::string CreatorName; // List of Creator names. typedef std::vector CreatorList; public: // static functions // Create a job creator from an XML description. // Caller is responsible for managing the job creator. // The creator is selected using ele.name(). static const JobCreator* create(const XmlElement& ele); // Register a creator. // Returns 0 for success. // Fails if name is already used for a different creator. static int register_creator(CreatorName name, Creator pfun); // Return the list of registered creator names. static const CreatorList& creators(); // Return if a creator name is registered. static bool has_creator(CreatorName name); // Promote a job to its full type. // It is assumed that the creator registered with name // job.full_type() + "Creator" // can be used for this purpose. // Caller is responsible for managing the returned object. //static Job* promote(Job& job); public: // virtual methods // Destructor. virtual ~JobCreator(); // Validity. virtual bool is_valid() const =0; // Create a new local job. // Caller is responsible for managing (deleting) the job. // Returns 0 for error. virtual Job* create_local_job(JobId jid, const Application& app, const Task& tsk, const dset::Dataset& dst, const JobPreferences& prf, std::string rundir, std::string runfile) const =0; // Convert a generic job to this type. // Caller is reponsible for managing the returned object. virtual Job* convert(const Job& job) const =0; // To xml. virtual const XmlElement* xml() const =0; // Output stream. virtual std::ostream& ostr(std::ostream& lhs) const =0; }; } // end namespace dial // Output stream. std::ostream& operator<<(std::ostream& lhs, const dial::JobCreator& rhs); #endif