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