command.h

Go to the documentation of this file.
00001 /* -*- Mode: c++ -*- */
00002 /*
00003  *  this is part of Spm
00004  *
00005  *  Copyright (c) 2005-2007 Guillaume Chevallereau
00006  *
00007  *  This program is free software. You can redistribute it and/or modify it 
00008  *  under the terms of the GNU General Public License as published by the 
00009  *  Free Software Foundation. Either version 2 of the license or (at your 
00010  *  option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be usefull but WITHOUT
00013  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00014  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
00015  *  more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License along 
00018  *  with this program; if not, write to the Free Software Foundation, Inc., 
00019  *  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
00020  */
00021 #ifndef __COMMAND_H__
00022 #define __COMMAND_H__
00023 
00024 #include <vector>
00025 #include <map>
00026 #include <boost/filesystem/path.hpp>
00027 #include <miniXml/ustring.h>
00028 
00029 namespace Spm
00030 {
00031   namespace Util
00032   {
00037     class Command
00038     {
00039     private :
00040       miniXml::ustring cmd_;
00041       boost::filesystem::path workingDir_;
00042       std::vector<miniXml::ustring> args_;
00043       std::map<miniXml::ustring,
00044                miniXml::ustring> envs_;
00045       unsigned int pid_;
00046       int retVal_;
00047       
00048 
00049     public:
00053       Command (const miniXml::ustring & cmd);
00054 
00057       Command ();
00058 
00059       void setCommand (const miniXml::ustring & cmd);
00060       
00065       void add (const miniXml::ustring & arg);
00066 
00072       void add (const miniXml::ustring & var,
00073                 const miniXml::ustring & val);
00074       
00080       bool execSync (miniXml::ustring & out,
00081                      miniXml::ustring & err);
00082       
00089       bool execASync (int & out,
00090                       int & err,
00091                       int & in);                      
00092       
00096       const boost::filesystem::path & getWorkingDir ();
00097 
00101       void setWorkingDir (const boost::filesystem::path & dir);
00102 
00106       unsigned int getPid ();
00107 
00111       int getReturnValue ();
00112 
00113       /*
00114          \brief Execute a simple command
00115          \param cmd The command to execute
00116          \param out The command output 
00117          \param err The command error
00118          \return the value returned by the execution of the command
00119        */
00120       static int exec (const miniXml::ustring & cmd,
00121                        miniXml::ustring & out,
00122                        miniXml::ustring & err);
00123       
00128       bool wait ();
00129       
00130       /*
00131         \brief Send a signal to the command
00132         \param signal the signal to send (KILL by default)
00133        */
00134       void kill (int signal = 9);
00135 
00136 
00142       static void argsFromString (const miniXml::ustring & str,
00143                                   std::vector<miniXml::ustring> & args);
00144     };
00145   }
00146 }
00147 #endif

Generated on Sat Mar 21 17:00:14 2009 for libSpm by  doxygen 1.5.2