1 | // |
---|
2 | // PipeStream.cpp |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/Foundation/src/PipeStream.cpp#1 $ |
---|
5 | // |
---|
6 | // Library: Foundation |
---|
7 | // Package: Processes |
---|
8 | // Module: PipeStream |
---|
9 | // |
---|
10 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
---|
11 | // and Contributors. |
---|
12 | // |
---|
13 | // Permission is hereby granted, free of charge, to any person or organization |
---|
14 | // obtaining a copy of the software and accompanying documentation covered by |
---|
15 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
16 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
17 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
18 | // do so, all subject to the following: |
---|
19 | // |
---|
20 | // The copyright notices in the Software and this entire statement, including |
---|
21 | // the above license grant, this restriction and the following disclaimer, |
---|
22 | // must be included in all copies of the Software, in whole or in part, and |
---|
23 | // all derivative works of the Software, unless such copies or derivative |
---|
24 | // works are solely in the form of machine-executable object code generated by |
---|
25 | // a source language processor. |
---|
26 | // |
---|
27 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
28 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
29 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
30 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
31 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
32 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
33 | // DEALINGS IN THE SOFTWARE. |
---|
34 | // |
---|
35 | |
---|
36 | |
---|
37 | #include <Poco/PipeStream.h> |
---|
38 | |
---|
39 | |
---|
40 | namespace Poco { |
---|
41 | |
---|
42 | |
---|
43 | // |
---|
44 | // PipeStreamBuf |
---|
45 | // |
---|
46 | |
---|
47 | |
---|
48 | PipeStreamBuf::PipeStreamBuf(const Pipe& pipe, openmode mode): |
---|
49 | BufferedStreamBuf(STREAM_BUFFER_SIZE, mode), |
---|
50 | _pipe(pipe) |
---|
51 | { |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | PipeStreamBuf::~PipeStreamBuf() |
---|
56 | { |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | int PipeStreamBuf::readFromDevice(char* buffer, std::streamsize length) |
---|
61 | { |
---|
62 | return _pipe.readBytes(buffer, (int) length); |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | int PipeStreamBuf::writeToDevice(const char* buffer, std::streamsize length) |
---|
67 | { |
---|
68 | return _pipe.writeBytes(buffer, (int) length); |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | void PipeStreamBuf::close() |
---|
73 | { |
---|
74 | _pipe.close(Pipe::CLOSE_BOTH); |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | // |
---|
79 | // PipeIOS |
---|
80 | // |
---|
81 | |
---|
82 | |
---|
83 | PipeIOS::PipeIOS(const Pipe& pipe, openmode mode): |
---|
84 | _buf(pipe, mode) |
---|
85 | { |
---|
86 | poco_ios_init(&_buf); |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | PipeIOS::~PipeIOS() |
---|
91 | { |
---|
92 | try |
---|
93 | { |
---|
94 | _buf.sync(); |
---|
95 | } |
---|
96 | catch (...) |
---|
97 | { |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | PipeStreamBuf* PipeIOS::rdbuf() |
---|
103 | { |
---|
104 | return &_buf; |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | void PipeIOS::close() |
---|
109 | { |
---|
110 | _buf.sync(); |
---|
111 | _buf.close(); |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | // |
---|
116 | // PipeOutputStream |
---|
117 | // |
---|
118 | |
---|
119 | |
---|
120 | PipeOutputStream::PipeOutputStream(const Pipe& pipe): |
---|
121 | PipeIOS(pipe, std::ios::out), |
---|
122 | std::ostream(&_buf) |
---|
123 | { |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | PipeOutputStream::~PipeOutputStream() |
---|
128 | { |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | // |
---|
133 | // PipeInputStream |
---|
134 | // |
---|
135 | |
---|
136 | |
---|
137 | PipeInputStream::PipeInputStream(const Pipe& pipe): |
---|
138 | PipeIOS(pipe, std::ios::in), |
---|
139 | std::istream(&_buf) |
---|
140 | { |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | PipeInputStream::~PipeInputStream() |
---|
145 | { |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | } // namespace Poco |
---|