File: cininserter.yo

package info (click to toggle)
bobcat 6.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,960 kB
  • sloc: cpp: 18,954; fortran: 5,617; makefile: 2,787; sh: 659; perl: 401; ansic: 26
file content (143 lines) | stat: -rw-r--r-- 6,132 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
includefile(include/header)

COMMENT(manpage, section, releasedate, archive, short name)
manpage(FBB::CinInserter)(3bobcat)(_CurYrs_)(libbobcat-dev__CurVers_)
                    (Executing Child Processes)

manpagename(FBB::CinInserter)(Runs external programs reading standard input)

manpagesynopsis()
    bf(#include <bobcat/cininserter>)nl()
    Linking option: tt(-lbobcat)

manpagedescription()
    The bf(FBB::CinInserter) class offers a basic interface for calling
external programs (so-called child processes) reading their standard input
streams. The standard output and standard error streams of the child processes
by default are not handled by tt(CinInserter) objects. The child's standard
input is provided through the tt(CinInserter) object: information inserted
into an tt(CinInserter) object is forwarded to the child process's standard
input stream. The tt(PATH) environment variable is not used when calling child
processes: child process programs must be specified using paths.

tt(CinInserter) objects may repeatedly be used to execute the same or
different child processes. Before starting the next child process, the current
child process must have finished.

Arguments passed to child processes may be surrounded by double or single
quotes. Arguments surrounded by double quotes have their double quotes
removed, while interpreting any escape-sequences that may have been used
within. Arguments surrounded by single quotes have their single quotes
removed, while accepting their content as-is. In addition unquoted
escape-sequences may be specified: those escape sequences are evaluated and
replaced by their intended characters (e.g., tt(\100) is converted to tt(@)).

When information of undetermined size or structure must be inserted into a
child process then the child process cannot determine when to stop. This
creates an interesting problem: the child process starts, and the parent
process must wait until its child process has finished processing its
input. But input can only be forwarded to the child's input stream after the
child process has started. To solve this problem tt(InterterFork) offers an
overloaded tt(execute) member, passing information to the child process via a
separate thread.

includefile(include/namespace)

manpagesection(INHERITS FROM)
    bf(FBB::Exec) (private),
    bf(FBB::OFdBuf) (private),
    bf(std::ostream).

manpagesection(CONSTRUCTOR)

    itemization(
    itb(CinInserter(size_t bufSize = 100))
       A tt(bufSize) argument may be specified: it defines the internal buffer
        size used by the tt(CinInserter's) streambuf. By default the stdandard
        output and standard error streams are not handled.
    itb(CinInserter(Mode mode, size_t bufSize = 100))
       The tt(mode) argument must be tt(CinInserter::CLOSE_STD). It indicates
        that the standard output and standard error streams are redirected to
        tt(/dev/null): any standard output generated by child processes is
        ignored. A tt(bufSize) argument may be specified: it defines the
        internal buffer size used by the tt(CinInserter's) streambuf.
    )

    Copy and move constructors (and assignment operators) are not available.

manpagesection(DESTRUCTOR)

    The destructor ends the tt(CinInserter's) child process, if it is still
    active.

manpagesection(MEMBERS)

    itemization(
    itb(void execute(std::string const &cmd))
        The argument specifies the command to execute: the command itself must
be specified as a path (the tt(PATH) environment variable isn't used).  This
member immediately returns, after which information can be inserted into the
tt(CinInserter) object which is then forwarded to the childprocess's standard
input stream. See also the description of the next (overloaded tt(execute))
member function.

Once all information has been inserted, the child process's standard input
stream must be closed. This is realized by either calling tt(stop); by
calling tt(execute) once again; or by ending the tt(CinInserter) object's
lifetime.

Arguments specified in the tt(cmd) string are passed to the child process, and
may optionally be specified using single or double quotes, as described in
this man-page's DESCRIPTION section.

    itb(bool execute(std::string const &cmd, std::string const &text))
        This member is used to forward a limited amount of information
(contained in the tt(text) parameter) to the child process specified at
tt(cmd) (defined identically as the tt(cmd) parameter of the previous
tt(execute) member).

This member returns tt(true) if the child process's exit value equals 0.

    itb(int stop())
        This function can be called after all information has been inserted
into the tt(CinInserter) object to close the child process's standard input
stream. It is not required after calling tt(execute(cmd, text)), or when
calling tt(execute) again, or when the tt(CinInseror) object's lifetime ends.

    This member returns the exit code of the last executed child process,
which may also be obtained from the next member:

    itb(int ret() const)
        Once a child process has finished this member provides the actual exit
code of the child process. Its value equals -1 before the first tt(exectue)
call.
    )

manpagesection(PROTECTED MEMBER)

    itemization(
    itb(Pipe &childInPipe())
       If derived classes need to override the redirections-members then they
        probabaly need access to the pipe read by the child process. This
        member provides a reference to that pipe. By default the parent
        process inserts information into the pipe, while the
        child process reads the inserted information from the pipe.
    )

manpagesection(EXAMPLE)

    verbinclude(../../cininserter/driver/driver.cc)

manpagefiles()
    em(bobcat/cininserter) - provides the class interface

manpageseealso()
    bf(bobcat)(7), bf(cerrextractor)(3bobcat), bf(coutextractor)(3bobcat),
    bf(execl)(3), bf(exec)(3bobcat),
    bf(fork)(3bobcat), bf(pipe)(3bobcat), bf(process)(3bobcat),
    bf(stdextractor)(3bobcat).

manpagebugs()
    None reported.

includefile(include/trailer)