blocxx
UnnamedPipe.hpp
Go to the documentation of this file.
1/*******************************************************************************
2* Copyright (C) 2005, Vintela, Inc. All rights reserved.
3* Copyright (C) 2006, Novell, Inc. All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7*
8* * Redistributions of source code must retain the above copyright notice,
9* this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of
14* Vintela, Inc.,
15* nor Novell, Inc.,
16* nor the names of its contributors or employees may be used to
17* endorse or promote products derived from this software without
18* specific prior written permission.
19*
20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30* POSSIBILITY OF SUCH DAMAGE.
31*******************************************************************************/
32
33
37
38#ifndef BLOCXX_UNNAMEDPIPE_HPP_
39#define BLOCXX_UNNAMEDPIPE_HPP_
40#include "blocxx/BLOCXX_config.h"
42#include "blocxx/Exception.hpp"
44#include "blocxx/IOIFC.hpp"
45#include "blocxx/CommonFwd.hpp"
46#include "blocxx/Timeout.hpp"
49
50namespace BLOCXX_NAMESPACE
51{
52
53
55
60class BLOCXX_COMMON_API UnnamedPipe : public IOIFC, public IntrusiveCountableBase
61{
62public:
63 virtual ~UnnamedPipe();
64
73 int writeInt(int value);
74
84 int writeString(const String& strData);
85
94 int readInt(int* value);
95
107 int readString(String& strData);
108
109 static const int INFINITE_TIMEOUT = -1;
117 void setReadTimeout(const Timeout& timeout) { m_readTimeout = timeout; }
118 BLOCXX_DEPRECATED void setReadTimeout(int seconds) { m_readTimeout = Timeout::relative(seconds); }
134 void setWriteTimeout(const Timeout& timeout) { m_writeTimeout = timeout; }
135 BLOCXX_DEPRECATED void setWriteTimeout(int seconds) { m_writeTimeout = Timeout::relative(seconds); }
151 void setTimeouts(const Timeout& timeout) { m_readTimeout = m_writeTimeout = timeout; }
152 BLOCXX_DEPRECATED void setTimeouts(int seconds) { m_readTimeout = m_writeTimeout = Timeout::relative(seconds); }
153
163 String readAll();
164
168 virtual void open() = 0;
169
174 virtual int close() = 0;
175
179 virtual bool isOpen() const = 0;
180
184 virtual Select_t getReadSelectObj() const = 0;
185
189 virtual Select_t getWriteSelectObj() const = 0;
190
191
193 {
194 E_NONBLOCKING, //<! Non-Blocking mode flag.
195 E_BLOCKING //<! Blocking mode flag.
196 };
197
202 virtual void setBlocking(EBlockingMode isBlocking=E_BLOCKING) = 0;
203
209 virtual void setWriteBlocking(EBlockingMode isBlocking=E_BLOCKING) = 0;
210
216 virtual void setReadBlocking(EBlockingMode isBlocking=E_BLOCKING) = 0;
217
221 virtual EBlockingMode getReadBlocking() const = 0;
222
226 virtual EBlockingMode getWriteBlocking() const = 0;
227
232 virtual Descriptor getInputDescriptor() const = 0;
233
238 virtual Descriptor getOutputDescriptor() const = 0;
239
247 virtual void passDescriptor(Descriptor h, const UnnamedPipeRef& ackPipe = 0, const ProcessRef& targetProcess = 0) = 0;
248
257 virtual AutoDescriptor receiveDescriptor(const UnnamedPipeRef& ackPipe = 0) = 0;
258
259 virtual int closeInputHandle() = 0;
260 virtual int closeOutputHandle() = 0;
261
262
263 enum EOpen
264 {
267 };
268
275 static UnnamedPipeRef createUnnamedPipe(EOpen doOpen=E_OPEN);
283 static UnnamedPipeRef createUnnamedPipeFromDescriptor(AutoDescriptor inputAndOutput);
291 static UnnamedPipeRef createUnnamedPipeFromDescriptor(AutoDescriptor input, AutoDescriptor output);
292
302 static void createConnectedPipes(UnnamedPipeRef& first,
303 UnnamedPipeRef& second);
304
310 static UnnamedPipeRef createStdin();
316 static UnnamedPipeRef createStdout();
322 static UnnamedPipeRef createStdinStdout();
328 static UnnamedPipeRef createStderr();
329
330protected:
332 : m_readTimeout(Timeout::infinite)
333 , m_writeTimeout(Timeout::infinite)
334 {}
335private:
338};
340
341} // end namespace BLOCXX_NAMESPACE
342
343#endif // BLOCXX_UNNAMEDPIPE_HPP_
#define BLOCXX_DECLARE_APIEXCEPTION(NAME, LINKAGE_SPEC)
Declare a new exception class named <NAME>Exception that derives from Exception This macro is typical...
This String class is an abstract data type that represents as NULL terminated string of characters.
Definition String.hpp:67
A timeout can be absolute, which means that it will happen at the specified DateTime.
Definition Timeout.hpp:56
static Timeout relative(float seconds)
Definition Timeout.cpp:58
Abstract interface for an UnnamedPipe.
int readString(String &strData)
Reads a String from the pipe.
virtual Select_t getWriteSelectObj() const =0
Get the write select object.
virtual void setBlocking(EBlockingMode isBlocking=E_BLOCKING)=0
Set the pipe's blocking mode.
BLOCXX_DEPRECATED void setWriteTimeout(int seconds)
virtual EBlockingMode getReadBlocking() const =0
Get the current blocking mode for reading from pipe.
virtual int closeInputHandle()=0
void setTimeouts(const Timeout &timeout)
Sets the read & write timeout values.
virtual Descriptor getInputDescriptor() const =0
Get the underlying input descriptor.
virtual void setReadBlocking(EBlockingMode isBlocking=E_BLOCKING)=0
Set blocking mode for reading from pipe.
void setReadTimeout(const Timeout &timeout)
Sets the read timeout value.
static const int INFINITE_TIMEOUT
Timeout getReadTimeout()
Gets the read timeout value.
virtual void open()=0
Open the pipe.
int readInt(int *value)
Reads an int (native binary representation) from the pipe.
void setWriteTimeout(const Timeout &timeout)
Sets the write timeout value.
virtual void passDescriptor(Descriptor h, const UnnamedPipeRef &ackPipe=0, const ProcessRef &targetProcess=0)=0
Sends a Descriptor to the peer.
virtual bool isOpen() const =0
Is the pipe open or closed?
int writeString(const String &strData)
Writes a String to the pipe.
virtual int close()=0
Close the pipe.
int writeInt(int value)
Write an int (native binary representation) to the pipe.
virtual EBlockingMode getWriteBlocking() const =0
Get the current blocking mode for writing from pipe.
virtual void setWriteBlocking(EBlockingMode isBlocking=E_BLOCKING)=0
Set blocking mode for writing to pipe.
BLOCXX_DEPRECATED void setReadTimeout(int seconds)
BLOCXX_DEPRECATED void setTimeouts(int seconds)
virtual Descriptor getOutputDescriptor() const =0
Get the underlying output descriptor.
Timeout getWriteTimeout()
Gets the write timeout value.
virtual AutoDescriptor receiveDescriptor(const UnnamedPipeRef &ackPipe=0)=0
Gets a Descriptor from the peer.
virtual int closeOutputHandle()=0
virtual Select_t getReadSelectObj() const =0
Get the read select object.
Taken from RFC 1321.
IntrusiveReference< UnnamedPipe > UnnamedPipeRef
IntrusiveReference< Process > ProcessRef
AutoResource< AutoDescriptorPolicy > AutoDescriptor
An analog of std::auto_ptr for descriptors.
BLOCXX_EXPORT_TEMPLATE(BLOCXX_COMMON_API, Array, Bool)