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