blocxx

UnnamedPipe.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2005, Vintela, Inc. All rights reserved.
00003 * Copyright (C) 2006, Novell, Inc. All rights reserved.
00004 * 
00005 * Redistribution and use in source and binary forms, with or without
00006 * modification, are permitted provided that the following conditions are met:
00007 * 
00008 *     * Redistributions of source code must retain the above copyright notice,
00009 *       this list of conditions and the following disclaimer.
00010 *     * Redistributions in binary form must reproduce the above copyright
00011 *       notice, this list of conditions and the following disclaimer in the
00012 *       documentation and/or other materials provided with the distribution.
00013 *     * Neither the name of 
00014 *       Vintela, Inc., 
00015 *       nor Novell, Inc., 
00016 *       nor the names of its contributors or employees may be used to 
00017 *       endorse or promote products derived from this software without 
00018 *       specific prior written permission.
00019 * 
00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00024 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00025 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00026 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00029 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030 * POSSIBILITY OF SUCH DAMAGE.
00031 *******************************************************************************/
00032 
00033 
00038 #ifndef BLOCXX_UNNAMEDPIPE_HPP_
00039 #define BLOCXX_UNNAMEDPIPE_HPP_
00040 #include "blocxx/BLOCXX_config.h"
00041 #include "blocxx/IntrusiveCountableBase.hpp"
00042 #include "blocxx/Exception.hpp"
00043 #include "blocxx/IntrusiveReference.hpp"
00044 #include "blocxx/IOIFC.hpp"
00045 #include "blocxx/CommonFwd.hpp"
00046 #include "blocxx/Timeout.hpp"
00047 #include "blocxx/AutoDescriptor.hpp"
00048 #include "blocxx/NetworkTypes.hpp"
00049 
00050 namespace BLOCXX_NAMESPACE
00051 {
00052 
00053 
00054 BLOCXX_DECLARE_APIEXCEPTION(UnnamedPipe, BLOCXX_COMMON_API);
00055 
00060 class BLOCXX_COMMON_API UnnamedPipe : public IOIFC, public IntrusiveCountableBase
00061 {
00062 public:
00063    virtual ~UnnamedPipe();
00064 
00073    int writeInt(int value);
00074 
00084    int writeString(const String& strData);
00085 
00094    int readInt(int* value);
00095 
00107    int readString(String& strData);
00108 
00109    static const int INFINITE_TIMEOUT = -1;
00117    void setReadTimeout(const Timeout& timeout) { m_readTimeout = timeout; }
00118    BLOCXX_DEPRECATED void setReadTimeout(int seconds) { m_readTimeout = Timeout::relative(seconds); }
00126    Timeout getReadTimeout() { return m_readTimeout; }
00134    void setWriteTimeout(const Timeout& timeout) { m_writeTimeout = timeout; }
00135    BLOCXX_DEPRECATED void setWriteTimeout(int seconds) { m_writeTimeout = Timeout::relative(seconds); }
00143    Timeout getWriteTimeout() { return m_writeTimeout; }
00151    void setTimeouts(const Timeout& timeout) { m_readTimeout = m_writeTimeout = timeout; }
00152    BLOCXX_DEPRECATED void setTimeouts(int seconds) { m_readTimeout = m_writeTimeout = Timeout::relative(seconds); }
00153 
00163    String readAll();
00164 
00168    virtual void open() = 0;
00169 
00174    virtual int close() = 0;
00175 
00179    virtual bool isOpen() const = 0;
00180 
00184    virtual Select_t getReadSelectObj() const = 0;
00185 
00189    virtual Select_t getWriteSelectObj() const = 0;
00190 
00191 
00192    enum EBlockingMode
00193    {
00194       E_NONBLOCKING, //<! Non-Blocking mode flag.
00195       E_BLOCKING  //<! Blocking mode flag.
00196    };
00202    virtual void setBlocking(EBlockingMode isBlocking=E_BLOCKING) = 0;
00203 
00209    virtual void setWriteBlocking(EBlockingMode isBlocking=E_BLOCKING) = 0;
00210 
00216    virtual void setReadBlocking(EBlockingMode isBlocking=E_BLOCKING) = 0;
00217 
00221    virtual EBlockingMode getReadBlocking() const = 0;
00222 
00226    virtual EBlockingMode getWriteBlocking() const = 0;
00227 
00232    virtual Descriptor getInputDescriptor() const = 0;
00233    
00238    virtual Descriptor getOutputDescriptor() const = 0;
00239 
00247    virtual void passDescriptor(Descriptor h, const UnnamedPipeRef& ackPipe = 0, const ProcessRef& targetProcess = 0) = 0;
00248 
00257    virtual AutoDescriptor receiveDescriptor(const UnnamedPipeRef& ackPipe = 0) = 0;
00258 
00259    virtual int closeInputHandle() = 0;
00260    virtual int closeOutputHandle() = 0;
00261 
00262 
00263    enum EOpen
00264    {
00265       E_DONT_OPEN,
00266       E_OPEN
00267    };
00275    static UnnamedPipeRef createUnnamedPipe(EOpen doOpen=E_OPEN);
00283    static UnnamedPipeRef createUnnamedPipeFromDescriptor(AutoDescriptor inputAndOutput);
00291    static UnnamedPipeRef createUnnamedPipeFromDescriptor(AutoDescriptor input, AutoDescriptor output);
00292 
00302    static void createConnectedPipes(UnnamedPipeRef& first,
00303                                     UnnamedPipeRef& second);
00304 
00310    static UnnamedPipeRef createStdin();
00316    static UnnamedPipeRef createStdout();
00322    static UnnamedPipeRef createStdinStdout();
00328    static UnnamedPipeRef createStderr();
00329 
00330 protected:
00331    UnnamedPipe()
00332       : m_readTimeout(Timeout::infinite)
00333       , m_writeTimeout(Timeout::infinite)
00334    {}
00335 private:
00336    Timeout m_readTimeout;
00337    Timeout m_writeTimeout;
00338 };
00339 BLOCXX_EXPORT_TEMPLATE(BLOCXX_COMMON_API, IntrusiveReference, UnnamedPipe);
00340 
00341 } // end namespace BLOCXX_NAMESPACE
00342 
00343 #endif   // BLOCXX_UNNAMEDPIPE_HPP_