xref: /AOO41X/main/sal/inc/osl/pipe.hxx (revision 565d668c30d8a6cacc881c774c5068be5401257d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _OSL_PIPE_HXX_
24 #define _OSL_PIPE_HXX_
25 
26 #include <osl/pipe_decl.hxx>
27 
28 namespace osl
29 {
30     //______________________________________________________________________________
Pipe()31     inline Pipe::Pipe()
32         : m_handle( 0 )
33     {}
34 
35     //______________________________________________________________________________
Pipe(const::rtl::OUString & strName,oslPipeOptions Options)36     inline Pipe::Pipe(const ::rtl::OUString& strName, oslPipeOptions Options )
37         : m_handle( osl_createPipe( strName.pData, Options , 0 ) )
38     {}
39 
40     //______________________________________________________________________________
Pipe(const::rtl::OUString & strName,oslPipeOptions Options,const Security & rSecurity)41     inline Pipe::Pipe(const ::rtl::OUString& strName, oslPipeOptions Options,const Security & rSecurity)
42         : m_handle( osl_createPipe( strName.pData, Options , rSecurity.getHandle() ) )
43     {}
44 
45     //______________________________________________________________________________
Pipe(const Pipe & pipe)46     inline Pipe::Pipe(const Pipe& pipe )
47         : m_handle( pipe.m_handle )
48     {
49         if( m_handle )
50             osl_acquirePipe( m_handle );
51     }
52 
53     //______________________________________________________________________________
Pipe(oslPipe pipe,__sal_NoAcquire)54     inline Pipe::Pipe( oslPipe pipe, __sal_NoAcquire )
55         : m_handle ( pipe )
56     {}
57 
58     //______________________________________________________________________________
Pipe(oslPipe pipe)59     inline Pipe::Pipe(oslPipe pipe)
60         : m_handle( pipe )
61     {
62         if( m_handle )
63             osl_acquirePipe( m_handle );
64     }
65 
66     //______________________________________________________________________________
~Pipe()67     inline Pipe::~Pipe()
68     {
69         if( m_handle )
70             osl_releasePipe( m_handle );
71     }
72 
73     //______________________________________________________________________________
create(const::rtl::OUString & strName,oslPipeOptions Options,const Security & rSec)74     inline sal_Bool Pipe::create( const ::rtl::OUString & strName,
75                                   oslPipeOptions Options, const Security &rSec )
76     {
77         *this = Pipe( strName, Options, rSec );
78         return is();
79     }
80 
81     //______________________________________________________________________________
create(const::rtl::OUString & strName,oslPipeOptions Options)82     inline sal_Bool Pipe::create( const ::rtl::OUString & strName, oslPipeOptions Options  )
83     {
84         *this = Pipe( strName, Options );
85         return is();
86     }
87     //______________________________________________________________________________
operator =(const Pipe & pipe)88     inline Pipe& SAL_CALL Pipe::operator= (const Pipe& pipe)
89     {
90         *this = pipe.getHandle();
91         return *this;
92     }
93 
94     //______________________________________________________________________________
operator =(oslPipe pipe)95     inline Pipe & SAL_CALL Pipe::operator=( oslPipe pipe)
96     {
97         if( pipe )
98             osl_acquirePipe( pipe );
99         if( m_handle )
100             osl_releasePipe( m_handle );
101         m_handle = pipe;
102         return *this;
103     }
104 
105     //______________________________________________________________________________
is() const106     inline sal_Bool SAL_CALL Pipe::is() const
107     {
108         return m_handle != 0;
109     }
110 
111     //______________________________________________________________________________
operator ==(const Pipe & rPipe) const112     inline sal_Bool SAL_CALL Pipe::operator==( const Pipe& rPipe ) const
113     {
114         return m_handle == rPipe.m_handle;
115     }
116 
117     //______________________________________________________________________________
close()118     inline void SAL_CALL Pipe::close()
119     {
120         osl_closePipe( m_handle );
121     }
122 
123     //______________________________________________________________________________
clear()124     inline void SAL_CALL Pipe::clear()
125     {
126         if( m_handle )
127         {
128             osl_releasePipe( m_handle );
129             m_handle = 0;
130         }
131     }
132 
133     //______________________________________________________________________________
accept(StreamPipe & Connection)134     inline oslPipeError SAL_CALL Pipe::accept(StreamPipe& Connection)
135     {
136         Connection = StreamPipe( osl_acceptPipe( m_handle ), SAL_NO_ACQUIRE);
137         if( Connection.is() )
138             return osl_Pipe_E_None;
139         else
140             return getError();
141     }
142 
143     //______________________________________________________________________________
getError() const144     inline oslPipeError SAL_CALL Pipe::getError() const
145     {
146         return osl_getLastPipeError( 0 );
147     }
148 
149     //______________________________________________________________________________
getHandle() const150     inline oslPipe SAL_CALL Pipe::getHandle() const
151     {
152         return m_handle;
153     }
154 
155     //______________________________________________________________________________
StreamPipe()156     inline StreamPipe::StreamPipe(){}
157 
158     //______________________________________________________________________________
StreamPipe(oslPipe hPipe)159     inline StreamPipe::StreamPipe(oslPipe hPipe)
160         : Pipe( hPipe )
161     {
162     }
163 
164     //______________________________________________________________________________
StreamPipe(const::rtl::OUString & strName,oslPipeOptions Options,const Security & rSec)165     inline StreamPipe::StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options, const Security &rSec )
166         : Pipe( strName, Options , rSec )
167     {}
168 
169     //______________________________________________________________________________
StreamPipe(const::rtl::OUString & strName,oslPipeOptions Options)170     inline StreamPipe::StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options  )
171         : Pipe( strName, Options )
172     {}
173 
174     //______________________________________________________________________________
StreamPipe(const StreamPipe & aPipe)175     inline StreamPipe::StreamPipe(const StreamPipe& aPipe)
176         : Pipe( aPipe )
177     {}
178     //______________________________________________________________________________
StreamPipe(oslPipe pipe,__sal_NoAcquire noacquire)179     inline StreamPipe::StreamPipe( oslPipe pipe, __sal_NoAcquire noacquire )
180         : Pipe( pipe , noacquire )
181     {}
182 
183     //______________________________________________________________________________
read(void * pBuffer,sal_Int32 n) const184     inline sal_Int32 SAL_CALL StreamPipe::read(void* pBuffer, sal_Int32 n) const
185     {
186         return osl_readPipe( m_handle, pBuffer, n );
187     }
188 
189     //______________________________________________________________________________
write(const void * pBuffer,sal_Int32 n) const190     inline sal_Int32 SAL_CALL StreamPipe::write(const void* pBuffer, sal_Int32 n) const
191     {
192         return osl_writePipe( m_handle, pBuffer , n );
193     }
194 
195     //______________________________________________________________________________
recv(void * pBuffer,sal_Int32 BytesToRead) const196     inline sal_Int32 SAL_CALL StreamPipe::recv(void* pBuffer, sal_Int32 BytesToRead) const
197     {
198         return osl_receivePipe( m_handle, pBuffer , BytesToRead );
199     }
200 
201     //______________________________________________________________________________
send(const void * pBuffer,sal_Int32 BytesToSend) const202     inline sal_Int32 SAL_CALL StreamPipe::send(const void* pBuffer, sal_Int32 BytesToSend) const
203     {
204         return osl_sendPipe( m_handle, pBuffer , BytesToSend );
205     }
206 
207 }
208 #endif
209