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 
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"
48 #include "blocxx/NetworkTypes.hpp"
49 
50 namespace BLOCXX_NAMESPACE
51 {
52 
53 
55 
60 class BLOCXX_COMMON_API UnnamedPipe : public IOIFC, public IntrusiveCountableBase
61 {
62 public:
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); }
126  Timeout getReadTimeout() { return m_readTimeout; }
134  void setWriteTimeout(const Timeout& timeout) { m_writeTimeout = timeout; }
135  BLOCXX_DEPRECATED void setWriteTimeout(int seconds) { m_writeTimeout = Timeout::relative(seconds); }
143  Timeout getWriteTimeout() { return m_writeTimeout; }
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  };
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  {
266  E_OPEN
267  };
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 
330 protected:
332  : m_readTimeout(Timeout::infinite)
333  , m_writeTimeout(Timeout::infinite)
334  {}
335 private:
338 };
340 
341 } // end namespace BLOCXX_NAMESPACE
342 
343 #endif // BLOCXX_UNNAMEDPIPE_HPP_