xrootd
XrdOucProg.hh
Go to the documentation of this file.
1 #ifndef __OOUC_PROG__
2 #define __OOUC_PROG__
3 /******************************************************************************/
4 /* */
5 /* X r d O u c P r o g . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC03-76-SFO0515 with the Deprtment of Energy */
11 /******************************************************************************/
12 
13 #include <sys/types.h>
14 
15 class XrdSysError;
16 class XrdOucStream;
17 
19 {
20 public:
21 
22 // When creating an Prog object, you may pass an optional error routing object.
23 // If you do so, error messages and all command output will be writen via the
24 // error object. Otherwise, errors will be returned quietly.
25 //
27  {eDest = errobj; myStream = 0;
28  ArgBuff = Arg[0] = 0; numArgs = 0; theEFD = -1;
29  }
30 
31  ~XrdOucProg();
32 
33 // Feed() send a data to the program started by Start(). Several variations
34 // exist to accomodate various needs. Note that should the program not be
35 // running when Feed() is called, it is restarted.
36 //
37 int Feed(const char *data[], const int dlen[]);
38 
39 int Feed(const char *data, int dlen)
40  {const char *myData[2] = {data, 0};
41  const int myDlen[2] = {dlen, 0};
42  return Feed(myData, myDlen);
43  }
44 
45 int Feed(const char *data) {return Feed(data, (int)strlen(data));}
46 
47 // getStream() returns the stream created by Start(). Use the object to get
48 // lines written by the started program.
49 //
51 
52 // Run executes the command that was passed via Setup(). You may pass
53 // up to four additional arguments that will be added to the end of any
54 // existing arguments. The ending status code of the program is returned.
55 //
56 int Run(XrdOucStream *Sp, const char *arg1=0, const char *arg2=0,
57  const char *arg3=0, const char *arg4=0);
58 
59 int Run(const char *arg1=0, const char *arg2=0,
60  const char *arg3=0, const char *arg4=0);
61 
62 int Run(char *outBuff, int outBsz,
63  const char *arg1=0, const char *arg2=0,
64  const char *arg3=0, const char *arg4=0);
65 
66 // Start executes the command that was passed via Setup(). The started
67 // program is expected to linger so that you can send directives to it
68 // via its standard in. Use Feed() to do this. If the output of the command
69 // is wanted, use getStream() to get the stream object and use it to read
70 // lines the program sends to standard out.
71 //
72 int Start(void);
73 
74 // Setup takes a command string and sets up a parameter list. If a Proc pointer
75 // is passed, then the command executes via that function. Otherwise, it checks
76 // that the program (first token) is executable.
77 // Zero is returned upon success, otherwise a -errno is returned,
78 //
79 int Setup(const char *prog,
80  XrdSysError *errP=0,
81  int (*Proc)(XrdOucStream *, char **, int)=0
82  );
83 
84 /******************************************************************************/
85 
86 private:
87  int RunDone(XrdOucStream &cmd);
88  int Restart();
91  int (*myProc)(XrdOucStream *, char **, int);
92  char *ArgBuff;
93  char *Arg[64];
94  int numArgs;
95  int lenArgs;
96  int theEFD;
97 };
98 #endif