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