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