xref: /aoo41x/main/sal/inc/osl/pipe_decl.hxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #ifndef _OSL_PIPE_DECL_HXX_
28*cdf0e10cSrcweir #define _OSL_PIPE_DECL_HXX_
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <osl/pipe.h>
31*cdf0e10cSrcweir #	include <osl/security.hxx>
32*cdf0e10cSrcweir #include <rtl/ustring.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir namespace osl {
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir class StreamPipe;
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir /** Represents a pipe.
39*cdf0e10cSrcweir */
40*cdf0e10cSrcweir class Pipe
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir protected:
43*cdf0e10cSrcweir 	oslPipe m_handle;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir public:
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir 	/** Does not create a pipe. Use assignment operator to
48*cdf0e10cSrcweir 	    make this a useable pipe.
49*cdf0e10cSrcweir 	*/
50*cdf0e10cSrcweir 	inline Pipe();
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 	/** Creates an insecure pipe that is accessible for all users.
53*cdf0e10cSrcweir 		@param strName
54*cdf0e10cSrcweir 		@param Options
55*cdf0e10cSrcweir 	*/
56*cdf0e10cSrcweir 	inline Pipe(const ::rtl::OUString& strName, oslPipeOptions Options);
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 	/** Creates a secure pipe that access depends on the umask settings.
59*cdf0e10cSrcweir 		@param strName
60*cdf0e10cSrcweir 		@param Options
61*cdf0e10cSrcweir 		@param Security
62*cdf0e10cSrcweir 	*/
63*cdf0e10cSrcweir 	inline Pipe(const ::rtl::OUString& strName, oslPipeOptions Options,const Security & rSecurity);
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 	/** Copy constructor.
66*cdf0e10cSrcweir 	*/
67*cdf0e10cSrcweir 	inline Pipe(const Pipe& pipe);
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 	/** Constructs a Pipe reference without acquiring the handle
70*cdf0e10cSrcweir 	*/
71*cdf0e10cSrcweir 	inline Pipe( oslPipe pipe, __sal_NoAcquire noacquire );
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 	/** Creates pipe as wrapper around the underlying oslPipe.
74*cdf0e10cSrcweir 		@param Pipe
75*cdf0e10cSrcweir 	*/
76*cdf0e10cSrcweir     inline Pipe(oslPipe Pipe);
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 	/** Destructor. Destroys the underlying oslPipe.
79*cdf0e10cSrcweir 	*/
80*cdf0e10cSrcweir     inline ~Pipe();
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 	inline sal_Bool SAL_CALL is() const;
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	/** Creates an insecure pipe that is accessible for all users
85*cdf0e10cSrcweir 		with the given attributes.
86*cdf0e10cSrcweir 		If the pipe was already created, the old one will be discarded.
87*cdf0e10cSrcweir 		@param strName
88*cdf0e10cSrcweir 		@param Options
89*cdf0e10cSrcweir 		@param Security
90*cdf0e10cSrcweir 		@return True if socket was successfully created.
91*cdf0e10cSrcweir 	*/
92*cdf0e10cSrcweir 	inline sal_Bool create( const ::rtl::OUString & strName,
93*cdf0e10cSrcweir 							oslPipeOptions Options, const Security &rSec );
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	/** Creates a secure that access rights depend on the umask settings
96*cdf0e10cSrcweir 		with the given attributes.
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 		If socket was already created, the old one will be discarded.
99*cdf0e10cSrcweir 		@param strName
100*cdf0e10cSrcweir 		@param Options
101*cdf0e10cSrcweir 		@return True if socket was successfully created.
102*cdf0e10cSrcweir 	*/
103*cdf0e10cSrcweir 	inline sal_Bool create( const ::rtl::OUString & strName, oslPipeOptions Options = osl_Pipe_OPEN );
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	/** releases the underlying handle
106*cdf0e10cSrcweir 	 */
107*cdf0e10cSrcweir 	inline void SAL_CALL clear();
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 	/** Assignment operator. If pipe was already created, the old one will
110*cdf0e10cSrcweir 		be discarded.
111*cdf0e10cSrcweir 	*/
112*cdf0e10cSrcweir 	inline Pipe& SAL_CALL operator= (const Pipe& pipe);
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 	/** Assignment operator. If pipe was already created, the old one will
115*cdf0e10cSrcweir 		be discarded.
116*cdf0e10cSrcweir 	*/
117*cdf0e10cSrcweir 	inline Pipe& SAL_CALL operator= (const oslPipe pipe );
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	/** Checks if the pipe is valid.
120*cdf0e10cSrcweir 		@return True if the object represents a valid pipe.
121*cdf0e10cSrcweir 	*/
122*cdf0e10cSrcweir 	inline sal_Bool SAL_CALL isValid() const;
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 	inline sal_Bool SAL_CALL operator==( const Pipe& rPipe ) const;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 	/** Closes the pipe.
127*cdf0e10cSrcweir 	*/
128*cdf0e10cSrcweir     inline void SAL_CALL close();
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 	/** Accept connection on an existing pipe
131*cdf0e10cSrcweir 	*/
132*cdf0e10cSrcweir 	inline oslPipeError SAL_CALL accept(StreamPipe& Connection);
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	/** Delivers a constant decribing the last error for the pipe system.
136*cdf0e10cSrcweir 		@return ENONE if no error occured, invalid_PipeError if
137*cdf0e10cSrcweir 		an unknown (unmapped) error occured, otherwise an enum describing the
138*cdf0e10cSrcweir 		error.
139*cdf0e10cSrcweir 	*/
140*cdf0e10cSrcweir 	inline oslPipeError SAL_CALL getError() const;
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 	inline oslPipe SAL_CALL getHandle() const;
143*cdf0e10cSrcweir };
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir /** A pipe to send or receive a stream of data.
146*cdf0e10cSrcweir */
147*cdf0e10cSrcweir class StreamPipe : public Pipe
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir public:
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 	/** Creates an unattached pipe. You must attach the pipe to an oslPipe
152*cdf0e10cSrcweir 		e.g. by using the operator=(oslPipe), before you can use the stream-
153*cdf0e10cSrcweir 		functionality of the object.
154*cdf0e10cSrcweir 	*/
155*cdf0e10cSrcweir 	inline StreamPipe();
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 	/** Creates pipe as wrapper around the underlying oslPipe.
158*cdf0e10cSrcweir 		@param Pipe
159*cdf0e10cSrcweir 	*/
160*cdf0e10cSrcweir     inline StreamPipe(oslPipe Pipe);
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 	/** Copy constructor.
163*cdf0e10cSrcweir 		@param Pipe
164*cdf0e10cSrcweir 	*/
165*cdf0e10cSrcweir     inline StreamPipe(const StreamPipe& Pipe);
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	/** Creates a pipe.
168*cdf0e10cSrcweir 		@param strName
169*cdf0e10cSrcweir 		@param Options
170*cdf0e10cSrcweir 	*/
171*cdf0e10cSrcweir     inline StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options = osl_Pipe_OPEN);
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	/** Creates a pipe.
174*cdf0e10cSrcweir 		@param strName
175*cdf0e10cSrcweir 		@param Options
176*cdf0e10cSrcweir 		@param rSec
177*cdf0e10cSrcweir 	*/
178*cdf0e10cSrcweir     inline StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options, const Security &rSec );
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 	/** Constructs a Pipe reference without acquiring the handle
181*cdf0e10cSrcweir 	*/
182*cdf0e10cSrcweir 	inline StreamPipe( oslPipe pipe, __sal_NoAcquire noacquire );
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 	/** Attaches the oslPipe to this object. If the object
185*cdf0e10cSrcweir 		already was attached to an oslPipe, the old one will
186*cdf0e10cSrcweir 		be closed and destroyed.
187*cdf0e10cSrcweir 		@param Pipe.
188*cdf0e10cSrcweir 	*/
189*cdf0e10cSrcweir 	inline StreamPipe & SAL_CALL operator=(oslPipe Pipe);
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	/** Assignment operator
192*cdf0e10cSrcweir 	*/
193*cdf0e10cSrcweir 	inline StreamPipe& SAL_CALL operator=(const Pipe& pipe);
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 	/** Tries to receives BytesToRead data from the connected pipe,
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 		@param pBuffer [out] Points to a buffer that will be filled with the received
198*cdf0e10cSrcweir 		data.
199*cdf0e10cSrcweir 		@param BytesToRead [in] The number of bytes to read. pBuffer must have at least
200*cdf0e10cSrcweir 		this size.
201*cdf0e10cSrcweir 		@return the number of received bytes.
202*cdf0e10cSrcweir 	*/
203*cdf0e10cSrcweir 	inline sal_Int32 SAL_CALL recv(void* pBuffer, sal_Int32 BytesToRead) const;
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 	/** Tries to sends BytesToSend data from the connected pipe.
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 		@param pBuffer [in] Points to a buffer that contains the send-data.
208*cdf0e10cSrcweir 		@param BytesToSend [in] The number of bytes to send. pBuffer must have at least
209*cdf0e10cSrcweir 		this size.
210*cdf0e10cSrcweir 		@return the number of transfered bytes.
211*cdf0e10cSrcweir 	*/
212*cdf0e10cSrcweir 	inline sal_Int32 SAL_CALL send(const void* pBuffer, sal_Int32 BytesToSend) const;
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 	/** Retrieves n bytes from the stream and copies them into pBuffer.
215*cdf0e10cSrcweir 		The method avoids incomplete reads due to packet boundaries.
216*cdf0e10cSrcweir 		@param pBuffer receives the read data.
217*cdf0e10cSrcweir 		@param n the number of bytes to read. pBuffer must be large enough
218*cdf0e10cSrcweir 		to hold the n bytes!
219*cdf0e10cSrcweir 		@return	the number of read bytes. The number will only be smaller than
220*cdf0e10cSrcweir 		n if an exceptional condition (e.g. connection closed) occurs.
221*cdf0e10cSrcweir 	*/
222*cdf0e10cSrcweir     inline sal_Int32 SAL_CALL read(void* pBuffer, sal_Int32 n) const;
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 	/** Writes n bytes from pBuffer to the stream. The method avoids
225*cdf0e10cSrcweir 		incomplete writes due to packet boundaries.
226*cdf0e10cSrcweir 		@param pBuffer contains the data to be written.
227*cdf0e10cSrcweir 		@param n the number of bytes to write.
228*cdf0e10cSrcweir 		@return the number of written bytes. The number will only be smaller than
229*cdf0e10cSrcweir 		n if an exceptional condition (e.g. connection closed) occurs.
230*cdf0e10cSrcweir 	*/
231*cdf0e10cSrcweir     sal_Int32 SAL_CALL write(const void* pBuffer, sal_Int32 n) const;
232*cdf0e10cSrcweir };
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir #endif
236