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/* Produced by Andrew Hanushevsky for Stanford University under contract */
9/* DE-AC02-76-SFO0515 with the Deprtment of Energy */
10/* */
11/* This file is part of the XRootD software suite. */
12/* */
13/* XRootD is free software: you can redistribute it and/or modify it under */
14/* the terms of the GNU Lesser General Public License as published by the */
15/* Free Software Foundation, either version 3 of the License, or (at your */
16/* option) any later version. */
17/* */
18/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21/* License for more details. */
22/* */
23/* You should have received a copy of the GNU Lesser General Public License */
24/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26/* */
27/* The copyright holder's institutional names and contributor's names may not */
28/* be used to endorse or promote products derived from this software without */
29/* specific prior written permission of the institution or contributor. */
30/******************************************************************************/
31
32#include <sys/types.h>
33
34class XrdSysError;
35class XrdOucStream;
36
38{
39public:
40
41// When creating an Prog object, you may pass an optional error routing object.
42// If you do so, error messages and all command output will be writen via the
43// error object. Otherwise, errors will be returned quietly.
44//
45 XrdOucProg(XrdSysError *errobj=0, int efd=-1)
46 : eDest(errobj), myStream(0), myProc(0), ArgBuff(0),
47 numArgs(0), theEFD(efd) {Arg[0] = 0;}
48
50
51// Feed() send a data to the program started by Start(). Several variations
52// exist to accomodate various needs. Note that should the program not be
53// running when Feed() is called, it is restarted.
54//
55int Feed(const char *data[], const int dlen[]);
56
57int Feed(const char *data, int dlen)
58 {const char *myData[2] = {data, 0};
59 const int myDlen[2] = {dlen, 0};
60 return Feed(myData, myDlen);
61 }
62
63int Feed(const char *data) {return Feed(data, (int)strlen(data));}
64
65// getStream() returns the stream created by Start(). Use the object to get
66// lines written by the started program.
67//
69
70// Run executes the command that was passed via Setup(). You may pass
71// additional arguments to be appended to the existing ones. The
72// method also allows envars to be set in forked process via envV vector
73// which contains strings "var=val" and terminaes with a null pointer.
74//
75int Run(XrdOucStream *Sp, const char *argV[], int argc=0,
76 const char *envV[]=0);
77
78// Run executes the command that was passed via Setup(). You may pass
79// up to four additional arguments that will be added to the end of any
80// existing arguments. The ending status code of the program is returned.
81//
82int Run(XrdOucStream *Sp, const char *arg1=0, const char *arg2=0,
83 const char *arg3=0, const char *arg4=0);
84
85int Run(const char *arg1=0, const char *arg2=0,
86 const char *arg3=0, const char *arg4=0);
87
88int Run(char *outBuff, int outBsz,
89 const char *arg1=0, const char *arg2=0,
90 const char *arg3=0, const char *arg4=0);
91
92// RunDone should be called to drain the output stream and get the ending
93// status of the running process.
94//
96
97// Start executes the command that was passed via Setup(). The started
98// program is expected to linger so that you can send directives to it
99// via its standard in. Use Feed() to do this. If the output of the command
100// is wanted, use getStream() to get the stream object and use it to read
101// lines the program sends to standard out.
102//
103int Start(void);
104
105// Setup takes a command string and sets up a parameter list. If a Proc pointer
106// is passed, then the command executes via that function. Otherwise, it checks
107// that the program (first token) is executable.
108// Zero is returned upon success, otherwise a -errno is returned,
109//
110int Setup(const char *prog,
111 XrdSysError *errP=0,
112 int (*Proc)(XrdOucStream *, char **, int)=0
113 );
114
115/******************************************************************************/
116
117private:
118 int Restart();
121 int (*myProc)(XrdOucStream *, char **, int);
122 char *ArgBuff;
123 char *Arg[64];
127};
128#endif
Definition: XrdOucProg.hh:38
int RunDone(XrdOucStream &cmd)
int numArgs
Definition: XrdOucProg.hh:124
int lenArgs
Definition: XrdOucProg.hh:125
int Feed(const char *data, int dlen)
Definition: XrdOucProg.hh:57
int Run(const char *arg1=0, const char *arg2=0, const char *arg3=0, const char *arg4=0)
XrdSysError * eDest
Definition: XrdOucProg.hh:119
int(* myProc)(XrdOucStream *, char **, int)
Definition: XrdOucProg.hh:121
XrdOucStream * getStream()
Definition: XrdOucProg.hh:68
XrdOucStream * myStream
Definition: XrdOucProg.hh:120
int Run(char *outBuff, int outBsz, const char *arg1=0, const char *arg2=0, const char *arg3=0, const char *arg4=0)
XrdOucProg(XrdSysError *errobj=0, int efd=-1)
Definition: XrdOucProg.hh:45
int Feed(const char *data)
Definition: XrdOucProg.hh:63
char * Arg[64]
Definition: XrdOucProg.hh:123
int Start(void)
int theEFD
Definition: XrdOucProg.hh:126
int Run(XrdOucStream *Sp, const char *arg1=0, const char *arg2=0, const char *arg3=0, const char *arg4=0)
int Restart()
int Run(XrdOucStream *Sp, const char *argV[], int argc=0, const char *envV[]=0)
int Feed(const char *data[], const int dlen[])
char * ArgBuff
Definition: XrdOucProg.hh:122
int Setup(const char *prog, XrdSysError *errP=0, int(*Proc)(XrdOucStream *, char **, int)=0)
Definition: XrdOucStream.hh:46
Definition: XrdSysError.hh:90