00001 #ifndef __OOUC_PROG__ 00002 #define __OOUC_PROG__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d O u c P r o g . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC03-76-SFO0515 with the Deprtment of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id: XrdOucProg.hh 32231 2010-02-05 18:24:46Z ganis $ 00014 00015 #include <sys/types.h> 00016 00017 class XrdSysError; 00018 class XrdOucStream; 00019 00020 class XrdOucProg 00021 { 00022 public: 00023 00024 // When creating an Prog object, you may pass an optional error routing object. 00025 // If you do so, error messages and all command output will be writen via the 00026 // error object. Otherwise, errors will be returned quietly. 00027 // 00028 XrdOucProg(XrdSysError *errobj=0) 00029 {eDest = errobj; myStream = 0; 00030 ArgBuff = Arg[0] = 0; numArgs = 0; theEFD = -1; 00031 } 00032 00033 ~XrdOucProg(); 00034 00035 // Feed() send a data to the program started by Start(). Several variations 00036 // exist to accomodate various needs. Note that should the program not be 00037 // running when Feed() is called, it is restarted. 00038 // 00039 int Feed(const char *data[], const int dlen[]); 00040 00041 int Feed(const char *data, int dlen) 00042 {const char *myData[2] = {data, 0}; 00043 const int myDlen[2] = {dlen, 0}; 00044 return Feed(myData, myDlen); 00045 } 00046 00047 int Feed(const char *data) {return Feed(data, (int)strlen(data));} 00048 00049 // getStream() returns the stream created by Start(). Use the object to get 00050 // lines written by the started program. 00051 // 00052 XrdOucStream *getStream() {return myStream;} 00053 00054 // Run executes the command that was passed via Setup(). You may pass 00055 // up to four additional arguments that will be added to the end of any 00056 // existing arguments. The ending status code of the program is returned. 00057 // 00058 int Run(XrdOucStream *Sp, const char *arg1=0, const char *arg2=0, 00059 const char *arg3=0, const char *arg4=0); 00060 00061 int Run(const char *arg1=0, const char *arg2=0, 00062 const char *arg3=0, const char *arg4=0); 00063 00064 00065 // Start executes the command that was passed via Setup(). The started 00066 // program is expected to linger so that you can send directives to it 00067 // via its standard in. Use Feed() to do this. If the output of the command 00068 // is wanted, use getStream() to get the stream object and use it to read 00069 // lines the program sends to standard out. 00070 // 00071 int Start(void); 00072 00073 // Setup takes a command string, checks that the program is executable and 00074 // sets up a parameter list structure. 00075 // Zero is returned upon success, otherwise a -errno is returned, 00076 // 00077 int Setup(const char *prog, XrdSysError *errP=0); 00078 00079 /******************************************************************************/ 00080 00081 private: 00082 int Restart(); 00083 XrdSysError *eDest; 00084 XrdOucStream *myStream; 00085 char *ArgBuff; 00086 char *Arg[64]; 00087 int numArgs; 00088 int lenArgs; 00089 int theEFD; 00090 }; 00091 #endif