xref: /trunk/main/sal/inc/osl/pipe.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _OSL_PIPE_HXX_
28 #define _OSL_PIPE_HXX_
29 
30 #include <osl/pipe_decl.hxx>
31 
32 namespace osl
33 {
34     //______________________________________________________________________________
35     inline Pipe::Pipe()
36         : m_handle( 0 )
37     {}
38 
39     //______________________________________________________________________________
40     inline Pipe::Pipe(const ::rtl::OUString& strName, oslPipeOptions Options )
41         : m_handle( osl_createPipe( strName.pData, Options , 0 ) )
42     {}
43 
44     //______________________________________________________________________________
45     inline Pipe::Pipe(const ::rtl::OUString& strName, oslPipeOptions Options,const Security & rSecurity)
46         : m_handle( osl_createPipe( strName.pData, Options , rSecurity.getHandle() ) )
47     {}
48 
49     //______________________________________________________________________________
50     inline Pipe::Pipe(const Pipe& pipe )
51         : m_handle( pipe.m_handle )
52     {
53         if( m_handle )
54             osl_acquirePipe( m_handle );
55     }
56 
57     //______________________________________________________________________________
58     inline Pipe::Pipe( oslPipe pipe, __sal_NoAcquire )
59         : m_handle ( pipe )
60     {}
61 
62     //______________________________________________________________________________
63     inline Pipe::Pipe(oslPipe pipe)
64         : m_handle( pipe )
65     {
66         if( m_handle )
67             osl_acquirePipe( m_handle );
68     }
69 
70     //______________________________________________________________________________
71     inline Pipe::~Pipe()
72     {
73         if( m_handle )
74             osl_releasePipe( m_handle );
75     }
76 
77     //______________________________________________________________________________
78     inline sal_Bool Pipe::create( const ::rtl::OUString & strName,
79                                   oslPipeOptions Options, const Security &rSec )
80     {
81         *this = Pipe( strName, Options, rSec );
82         return is();
83     }
84 
85     //______________________________________________________________________________
86     inline sal_Bool Pipe::create( const ::rtl::OUString & strName, oslPipeOptions Options  )
87     {
88         *this = Pipe( strName, Options );
89         return is();
90     }
91     //______________________________________________________________________________
92     inline Pipe& SAL_CALL Pipe::operator= (const Pipe& pipe)
93     {
94         *this = pipe.getHandle();
95         return *this;
96     }
97 
98     //______________________________________________________________________________
99     inline Pipe & SAL_CALL Pipe::operator=( oslPipe pipe)
100     {
101         if( pipe )
102             osl_acquirePipe( pipe );
103         if( m_handle )
104             osl_releasePipe( m_handle );
105         m_handle = pipe;
106         return *this;
107     }
108 
109     //______________________________________________________________________________
110     inline sal_Bool SAL_CALL Pipe::is() const
111     {
112         return m_handle != 0;
113     }
114 
115     //______________________________________________________________________________
116     inline sal_Bool SAL_CALL Pipe::operator==( const Pipe& rPipe ) const
117     {
118         return m_handle == rPipe.m_handle;
119     }
120 
121     //______________________________________________________________________________
122     inline void SAL_CALL Pipe::close()
123     {
124         osl_closePipe( m_handle );
125     }
126 
127     //______________________________________________________________________________
128     inline void SAL_CALL Pipe::clear()
129     {
130         if( m_handle )
131         {
132             osl_releasePipe( m_handle );
133             m_handle = 0;
134         }
135     }
136 
137     //______________________________________________________________________________
138     inline oslPipeError SAL_CALL Pipe::accept(StreamPipe& Connection)
139     {
140         Connection = StreamPipe( osl_acceptPipe( m_handle ), SAL_NO_ACQUIRE);
141         if( Connection.is() )
142             return osl_Pipe_E_None;
143         else
144             return getError();
145     }
146 
147     //______________________________________________________________________________
148     inline oslPipeError SAL_CALL Pipe::getError() const
149     {
150         return osl_getLastPipeError( 0 );
151     }
152 
153     //______________________________________________________________________________
154     inline oslPipe SAL_CALL Pipe::getHandle() const
155     {
156         return m_handle;
157     }
158 
159     //______________________________________________________________________________
160     inline StreamPipe::StreamPipe(){}
161 
162     //______________________________________________________________________________
163     inline StreamPipe::StreamPipe(oslPipe hPipe)
164         : Pipe( hPipe )
165     {
166     }
167 
168     //______________________________________________________________________________
169     inline StreamPipe::StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options, const Security &rSec )
170         : Pipe( strName, Options , rSec )
171     {}
172 
173     //______________________________________________________________________________
174     inline StreamPipe::StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options  )
175         : Pipe( strName, Options )
176     {}
177 
178     //______________________________________________________________________________
179     inline StreamPipe::StreamPipe(const StreamPipe& aPipe)
180         : Pipe( aPipe )
181     {}
182     //______________________________________________________________________________
183     inline StreamPipe::StreamPipe( oslPipe pipe, __sal_NoAcquire noacquire )
184         : Pipe( pipe , noacquire )
185     {}
186 
187     //______________________________________________________________________________
188     inline sal_Int32 SAL_CALL StreamPipe::read(void* pBuffer, sal_Int32 n) const
189     {
190         return osl_readPipe( m_handle, pBuffer, n );
191     }
192 
193     //______________________________________________________________________________
194     inline sal_Int32 SAL_CALL StreamPipe::write(const void* pBuffer, sal_Int32 n) const
195     {
196         return osl_writePipe( m_handle, pBuffer , n );
197     }
198 
199     //______________________________________________________________________________
200     inline sal_Int32 SAL_CALL StreamPipe::recv(void* pBuffer, sal_Int32 BytesToRead) const
201     {
202         return osl_receivePipe( m_handle, pBuffer , BytesToRead );
203     }
204 
205     //______________________________________________________________________________
206     inline sal_Int32 SAL_CALL StreamPipe::send(const void* pBuffer, sal_Int32 BytesToSend) const
207     {
208         return osl_sendPipe( m_handle, pBuffer , BytesToSend );
209     }
210 
211 }
212 #endif
213