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