sbuild-run-parts.h

00001 /* Copyright © 2005-2009  Roger Leigh <rleigh@debian.org>
00002  *
00003  * schroot is free software: you can redistribute it and/or modify it
00004  * under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation, either version 3 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * schroot is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>.
00016  *
00017  *********************************************************************/
00018 
00019 #ifndef SBUILD_RUN_PARTS_H
00020 #define SBUILD_RUN_PARTS_H
00021 
00022 #include <sbuild/sbuild-custom-error.h>
00023 #include <sbuild/sbuild-environment.h>
00024 #include <sbuild/sbuild-types.h>
00025 
00026 #include <set>
00027 #include <string>
00028 
00029 #include <sys/types.h>
00030 #include <sys/stat.h>
00031 
00032 namespace sbuild
00033 {
00034 
00038   class run_parts
00039   {
00040   public:
00042     enum error_code
00043       {
00044         CHILD_FORK, 
00045         CHILD_WAIT, 
00046         EXEC,       
00047         PIPE,       
00048         DUP,        
00049         POLL,       
00050         READ        
00051       };
00052 
00054     typedef custom_error<error_code> error;
00055 
00070     run_parts (std::string const& directory,
00071                bool               lsb_mode = true,
00072                bool               abort_on_error = true,
00073                mode_t             umask = 022);
00074 
00076     ~run_parts ();
00077 
00083     bool
00084     get_verbose () const;
00085 
00091     void
00092     set_verbose (bool verbose);
00093 
00099     bool
00100     get_reverse () const;
00101 
00107     void
00108     set_reverse (bool reverse);
00109 
00119     int
00120     run(string_list const& command,
00121         environment const& env);
00122 
00130     template <class charT, class traits>
00131     friend
00132     std::basic_ostream<charT,traits>&
00133     operator << (std::basic_ostream<charT,traits>& stream,
00134                  run_parts const&                  rhs)
00135     {
00136       if (!rhs.reverse)
00137         {
00138           for (program_set::const_iterator pos = rhs.programs.begin();
00139                pos != rhs.programs.end();
00140                ++pos)
00141             stream << *pos << '\n';
00142         }
00143       else
00144         {
00145           for (program_set::const_reverse_iterator pos = rhs.programs.rbegin();
00146                pos != rhs.programs.rend();
00147                ++pos)
00148             stream << *pos << '\n';
00149         }
00150       return stream;
00151     }
00152 
00153   private:
00163     int
00164     run_child(std::string const& file,
00165               string_list const& command,
00166               environment const& env);
00167 
00176     void
00177     wait_for_child (pid_t pid,
00178                     int&  child_status);
00179 
00181     typedef std::set<std::string> program_set;
00182 
00184     bool        lsb_mode;
00186     bool        abort_on_error;
00188     mode_t      umask;
00190     bool        verbose;
00192     bool        reverse;
00194     std::string directory;
00196     program_set programs;
00197   };
00198 
00199 }
00200 
00201 #endif /* SBUILD_RUN_PARTS_H */
00202 
00203 /*
00204  * Local Variables:
00205  * mode:C++
00206  * End:
00207  */

Generated on Wed Jun 1 08:00:10 2011 for sbuild by  doxygen 1.5.6