1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pipe_decl.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _OSL_PIPE_DECL_HXX_
31 #define _OSL_PIPE_DECL_HXX_
34 # include <osl/security.hxx>
35 #include <rtl/ustring.hxx>
41 /** Represents a pipe.
50 /** Does not create a pipe. Use assignment operator to
51 make this a useable pipe.
55 /** Creates an insecure pipe that is accessible for all users.
59 inline Pipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
);
61 /** Creates a secure pipe that access depends on the umask settings.
66 inline Pipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
,const Security
& rSecurity
);
70 inline Pipe(const Pipe
& pipe
);
72 /** Constructs a Pipe reference without acquiring the handle
74 inline Pipe( oslPipe pipe
, __sal_NoAcquire noacquire
);
76 /** Creates pipe as wrapper around the underlying oslPipe.
79 inline Pipe(oslPipe Pipe
);
81 /** Destructor. Destroys the underlying oslPipe.
85 inline sal_Bool SAL_CALL
is() const;
87 /** Creates an insecure pipe that is accessible for all users
88 with the given attributes.
89 If the pipe was already created, the old one will be discarded.
93 @return True if socket was successfully created.
95 inline sal_Bool
create( const ::rtl::OUString
& strName
,
96 oslPipeOptions Options
, const Security
&rSec
);
98 /** Creates a secure that access rights depend on the umask settings
99 with the given attributes.
101 If socket was already created, the old one will be discarded.
104 @return True if socket was successfully created.
106 inline sal_Bool
create( const ::rtl::OUString
& strName
, oslPipeOptions Options
= osl_Pipe_OPEN
);
108 /** releases the underlying handle
110 inline void SAL_CALL
clear();
112 /** Assignment operator. If pipe was already created, the old one will
115 inline Pipe
& SAL_CALL
operator= (const Pipe
& pipe
);
117 /** Assignment operator. If pipe was already created, the old one will
120 inline Pipe
& SAL_CALL
operator= (const oslPipe pipe
);
122 /** Checks if the pipe is valid.
123 @return True if the object represents a valid pipe.
125 inline sal_Bool SAL_CALL
isValid() const;
127 inline sal_Bool SAL_CALL
operator==( const Pipe
& rPipe
) const;
131 inline void SAL_CALL
close();
133 /** Accept connection on an existing pipe
135 inline oslPipeError SAL_CALL
accept(StreamPipe
& Connection
);
138 /** Delivers a constant decribing the last error for the pipe system.
139 @return ENONE if no error occured, invalid_PipeError if
140 an unknown (unmapped) error occured, otherwise an enum describing the
143 inline oslPipeError SAL_CALL
getError() const;
145 inline oslPipe SAL_CALL
getHandle() const;
148 /** A pipe to send or receive a stream of data.
150 class StreamPipe
: public Pipe
154 /** Creates an unattached pipe. You must attach the pipe to an oslPipe
155 e.g. by using the operator=(oslPipe), before you can use the stream-
156 functionality of the object.
160 /** Creates pipe as wrapper around the underlying oslPipe.
163 inline StreamPipe(oslPipe Pipe
);
165 /** Copy constructor.
168 inline StreamPipe(const StreamPipe
& Pipe
);
174 inline StreamPipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
= osl_Pipe_OPEN
);
181 inline StreamPipe(const ::rtl::OUString
& strName
, oslPipeOptions Options
, const Security
&rSec
);
183 /** Constructs a Pipe reference without acquiring the handle
185 inline StreamPipe( oslPipe pipe
, __sal_NoAcquire noacquire
);
187 /** Attaches the oslPipe to this object. If the object
188 already was attached to an oslPipe, the old one will
189 be closed and destroyed.
192 inline StreamPipe
& SAL_CALL
operator=(oslPipe Pipe
);
194 /** Assignment operator
196 inline StreamPipe
& SAL_CALL
operator=(const Pipe
& pipe
);
198 /** Tries to receives BytesToRead data from the connected pipe,
200 @param pBuffer [out] Points to a buffer that will be filled with the received
202 @param BytesToRead [in] The number of bytes to read. pBuffer must have at least
204 @return the number of received bytes.
206 inline sal_Int32 SAL_CALL
recv(void* pBuffer
, sal_Int32 BytesToRead
) const;
208 /** Tries to sends BytesToSend data from the connected pipe.
210 @param pBuffer [in] Points to a buffer that contains the send-data.
211 @param BytesToSend [in] The number of bytes to send. pBuffer must have at least
213 @return the number of transfered bytes.
215 inline sal_Int32 SAL_CALL
send(const void* pBuffer
, sal_Int32 BytesToSend
) const;
217 /** Retrieves n bytes from the stream and copies them into pBuffer.
218 The method avoids incomplete reads due to packet boundaries.
219 @param pBuffer receives the read data.
220 @param n the number of bytes to read. pBuffer must be large enough
222 @return the number of read bytes. The number will only be smaller than
223 n if an exceptional condition (e.g. connection closed) occurs.
225 inline sal_Int32 SAL_CALL
read(void* pBuffer
, sal_Int32 n
) const;
227 /** Writes n bytes from pBuffer to the stream. The method avoids
228 incomplete writes due to packet boundaries.
229 @param pBuffer contains the data to be written.
230 @param n the number of bytes to write.
231 @return the number of written bytes. The number will only be smaller than
232 n if an exceptional condition (e.g. connection closed) occurs.
234 sal_Int32 SAL_CALL
write(const void* pBuffer
, sal_Int32 n
) const;