1 // This is brl/bpro/bprb/bprb_batch_process_manager.h 2 #ifndef bprb_batch_process_manager_h_ 3 #define bprb_batch_process_manager_h_ 4 //: 5 // \file 6 // \brief This file defines a process manager for handing batch processing, i.e. no user interface 7 // \author J.L. Mundy 8 // \date January 31, 2008 9 // 10 // \verbatim 11 // Modifications 12 // 22 May 2012 - Peter Vanroose - catching failing redirect of stdout 13 // \endverbatim 14 15 #include <vector> 16 #include <iostream> 17 #include <string> 18 #ifdef _MSC_VER 19 # include <vcl_msvc_warnings.h> 20 #endif 21 #include <bprb/bprb_process_sptr.h> 22 #include <bprb/bprb_process_manager.h> 23 #include <brdb/brdb_value_sptr.h> 24 #include <bprb/bprb_parameters_sptr.h> 25 26 class bprb_batch_process_manager : public bprb_process_manager<bprb_batch_process_manager> 27 { 28 public: 29 // Destructor 30 ~bprb_batch_process_manager() override; 31 32 //: clear the database for new script processing 33 bool clear(); 34 35 //: initialize the process 36 bool init_process(std::string const& process_name); 37 38 //: print the default values of the process into the specified XML file 39 bool print_default_params(std::string const & process_name, std::string const& params_XML); 40 41 //: read and set the parameters from an XML file for the current process 42 bool set_params(std::string const& params_XML); 43 44 //: set the parameters from another parameter instance for the current process 45 bool set_params(const bprb_parameters_sptr& params); 46 47 //: set primitive data type input on current process 48 bool set_input(unsigned i, brdb_value_sptr const& input); 49 50 bool set_input_from_db(unsigned i, unsigned id, const std::string& type); 51 52 //: set input from the database 53 bool set_input_from_db(unsigned i, unsigned id); 54 55 //: put the output into the database 56 bool commit_output(unsigned i, unsigned& id); 57 58 //: put the output into the database 59 bool commit_output(unsigned i, unsigned& id, std::string& type); 60 61 //: put the output into the database 62 bool commit_all_outputs(std::vector<unsigned>& ids); 63 64 //: remove data from the database 65 bool remove_data(unsigned id); 66 67 //: Initialize the current process state variables 68 bool process_init(); 69 70 //: Run the current process 71 bool run_process(); 72 73 //: finish the current process 74 bool finish_process(); 75 76 //: set verbose on verbose()77 bool verbose() {verbose_ = true; return verbose_;} 78 79 //: set verbose off not_verbose()80 bool not_verbose() {verbose_ = false; return verbose_;} 81 82 //: return current verbosity get_verbose()83 bool get_verbose() {return verbose_;} 84 85 //: Debug purposes 86 void print_db(); 87 88 //: Set stdout 89 // \return false on failure 90 bool set_stdout(const std::string& file); 91 92 //: Reset stdout back to the console 93 // \return false on failure 94 bool reset_stdout(); 95 96 //: Interface to database binary read/write 97 void b_write_db(std::string const& path); 98 99 void b_read_db(std::string const& path); 100 101 friend class bprb_process_manager<bprb_batch_process_manager>; 102 103 protected: 104 // Constructor 105 bprb_batch_process_manager(); 106 107 // Members 108 bprb_process_sptr current_process_; 109 110 bool verbose_; 111 }; 112 113 #endif // bprb_batch_process_manager_h_ 114