LibreOffice LibreOffice 6.0 SDK C/C++ API Reference

pipe.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19 #ifndef INCLUDED_OSL_PIPE_HXX
20 #define INCLUDED_OSL_PIPE_HXX
21
22 #include "sal/config.h"
23
24 #include <cstddef>
25
26 #include "osl/pipe_decl.hxx"
27
28 namespace osl
29 {
30
31 inline Pipe::Pipe()
32 : m_handle( NULL )
33 {}
34
35
36 inline Pipe::Pipe(const ::rtl::OUString& strName, oslPipeOptions Options )
37 : m_handle( osl_createPipe( strName.pData, Options , NULL ) )
38 {}
39
40
41 inline Pipe::Pipe(const ::rtl::OUString& strName, oslPipeOptions Options,const Security & rSecurity)
42 : m_handle( osl_createPipe( strName.pData, Options , rSecurity.getHandle() ) )
43 {}
44
45
46 inline Pipe::Pipe(const Pipe& pipe )
47 : m_handle( pipe.m_handle )
48 {
49 if( m_handle )
50 osl_acquirePipe( m_handle );
51 }
52
53 #if defined LIBO_INTERNAL_ONLY
54 Pipe::Pipe(Pipe && other): m_handle(other.m_handle) {
55 other.m_handle = nullptr;
56 }
57 #endif
58
59 inline Pipe::Pipe( oslPipe pipe, __sal_NoAcquire )
60 : m_handle ( pipe )
61 {}
62
63
64 inline Pipe::Pipe(oslPipe pipe)
65 : m_handle( pipe )
66 {
67 if( m_handle )
68 osl_acquirePipe( m_handle );
69 }
70
71
72 inline Pipe::~Pipe()
73 {
74 if( m_handle )
75 osl_releasePipe( m_handle );
76 }
77
78
79 inline bool Pipe::create( const ::rtl::OUString & strName,
80 oslPipeOptions Options, const Security &rSec )
81 {
82 *this = Pipe( strName, Options, rSec );
83 return is();
84 }
85
86
87 inline bool Pipe::create( const ::rtl::OUString & strName, oslPipeOptions Options )
88 {
89 *this = Pipe( strName, Options );
90 return is();
91 }
92
93 inline Pipe& SAL_CALL Pipe::operator= (const Pipe& pipe)
94 {
95 *this = pipe.getHandle();
96 return *this;
97 }
98
99 #if defined LIBO_INTERNAL_ONLY
100 Pipe & Pipe::operator =(Pipe && other) {
101 if (m_handle != nullptr) {
102 osl_releasePipe(m_handle);
103 }
104 m_handle = other.m_handle;
105 other.m_handle = nullptr;
106 return *this;
107 }
108 #endif
109
110 inline Pipe & SAL_CALL Pipe::operator=( oslPipe pipe)
111 {
112 if( pipe )
113 osl_acquirePipe( pipe );
114 if( m_handle )
115 osl_releasePipe( m_handle );
116 m_handle = pipe;
117 return *this;
118 }
119
120
121 inline bool SAL_CALL Pipe::is() const
122 {
123 return m_handle != NULL;
124 }
125
126
127 inline bool SAL_CALL Pipe::operator==( const Pipe& rPipe ) const
128 {
129 return m_handle == rPipe.m_handle;
130 }
131
132
133 inline void SAL_CALL Pipe::close()
134 {
135 osl_closePipe( m_handle );
136 }
137
138
139 inline void SAL_CALL Pipe::clear()
140 {
141 if( m_handle )
142 {
143 osl_releasePipe( m_handle );
144 m_handle = NULL;
145 }
146 }
147
148
149 inline oslPipeError SAL_CALL Pipe::accept(StreamPipe& Connection)
150 {
151 Connection = StreamPipe( osl_acceptPipe( m_handle ), SAL_NO_ACQUIRE);
152 if( Connection.is() )
153 return osl_Pipe_E_None;
154 else
155 return getError();
156 }
157
158
159 inline oslPipeError SAL_CALL Pipe::getError() const
160 {
161 return osl_getLastPipeError( NULL );
162 }
163
164
165 inline oslPipe SAL_CALL Pipe::getHandle() const
166 {
167 return m_handle;
168 }
169
170
171 inline StreamPipe::StreamPipe(){}
172
173
174 inline StreamPipe::StreamPipe(oslPipe hPipe)
175 : Pipe( hPipe )
176 {
177 }
178
179
180 inline StreamPipe::StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options, const Security &rSec )
181 : Pipe( strName, Options , rSec )
182 {}
183
184
185 inline StreamPipe::StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options )
186 : Pipe( strName, Options )
187 {}
188
189
190 inline StreamPipe::StreamPipe(const StreamPipe& aPipe)
191 : Pipe( aPipe )
192 {}
193
194 inline StreamPipe::StreamPipe( oslPipe pipe, __sal_NoAcquire noacquire )
195 : Pipe( pipe , noacquire )
196 {}
197
198
199 inline sal_Int32 SAL_CALL StreamPipe::read(void* pBuffer, sal_Int32 n) const
200 {
201 return osl_readPipe( m_handle, pBuffer, n );
202 }
203
204
205 inline sal_Int32 SAL_CALL StreamPipe::write(const void* pBuffer, sal_Int32 n) const
206 {
207 return osl_writePipe( m_handle, pBuffer , n );
208 }
209
210
211 inline sal_Int32 SAL_CALL StreamPipe::recv(void* pBuffer, sal_Int32 BytesToRead) const
212 {
213 return osl_receivePipe( m_handle, pBuffer , BytesToRead );
214 }
215
216
217 inline sal_Int32 SAL_CALL StreamPipe::send(const void* pBuffer, sal_Int32 BytesToSend) const
218 {
219 return osl_sendPipe( m_handle, pBuffer , BytesToSend );
220 }
221
222 }
223 #endif
224
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
osl_acquirePipe
SAL_DLLPUBLIC void osl_acquirePipe(oslPipe Pipe)
Increases the refcount of the pipe.
osl_Pipe_E_None
Definition: pipe.h:35
osl::Pipe::accept
oslPipeError accept(StreamPipe &Connection)
Accept connection on an existing pipe.
Definition: pipe.hxx:149
osl::StreamPipe::read
sal_Int32 read(void *pBuffer, sal_Int32 n) const
Retrieves n bytes from the stream and copies them into pBuffer.
Definition: pipe.hxx:199
osl::Pipe::getError
oslPipeError getError() const
Delivers a constant describing the last error for the pipe system.
Definition: pipe.hxx:159
pipe_decl.hxx
osl::Pipe::create
bool create(const ::rtl::OUString &strName, oslPipeOptions Options, const Security &rSec)
Creates an insecure pipe that is accessible for all users with the given attributes.
Definition: pipe.hxx:79
osl::Pipe::close
void close()
Closes the pipe.
Definition: pipe.hxx:133
osl::Pipe::getHandle
oslPipe getHandle() const
Definition: pipe.hxx:165
osl::StreamPipe::send
sal_Int32 send(const void *pBuffer, sal_Int32 BytesToSend) const
Tries to sends BytesToSend data from the connected pipe.
Definition: pipe.hxx:217
osl::Pipe::is
bool is() const
Definition: pipe.hxx:121
osl_sendPipe
SAL_DLLPUBLIC sal_Int32 osl_sendPipe(oslPipe Pipe, const void *pBuffer, sal_Int32 BufferSize)
osl_receivePipe
SAL_DLLPUBLIC sal_Int32 osl_receivePipe(oslPipe Pipe, void *pBuffer, sal_Int32 BufferSize)
osl::Security
Encapsulate security information for one user.
Definition: security_decl.hxx:34
osl_acceptPipe
SAL_DLLPUBLIC oslPipe osl_acceptPipe(oslPipe Pipe)
osl::StreamPipe
A pipe to send or receive a stream of data.
Definition: pipe_decl.hxx:147
osl::StreamPipe::StreamPipe
StreamPipe()
Creates an unattached pipe.
Definition: pipe.hxx:171
osl_releasePipe
SAL_DLLPUBLIC void osl_releasePipe(oslPipe Pipe)
Decreases the refcount of the pipe.
osl
Definition: conditn.hxx:36
__sal_NoAcquire
__sal_NoAcquire
Definition: types.h:376
oslPipeOptions
sal_uInt32 oslPipeOptions
Pipe creation options.
Definition: pipe.h:53
osl::Pipe::m_handle
oslPipe m_handle
Definition: pipe_decl.hxx:35
SAL_NO_ACQUIRE
definition of a no acquire enum for ctors
Definition: types.h:380
config.h
osl_getLastPipeError
SAL_DLLPUBLIC oslPipeError osl_getLastPipeError(oslPipe Pipe)
osl::StreamPipe::write
sal_Int32 write(const void *pBuffer, sal_Int32 n) const
Writes n bytes from pBuffer to the stream.
Definition: pipe.hxx:205
osl::Pipe::operator==
bool operator==(const Pipe &rPipe) const
Definition: pipe.hxx:127
osl_writePipe
SAL_DLLPUBLIC sal_Int32 osl_writePipe(oslPipe Pipe, const void *pBuffer, sal_Int32 BufferSize)
Writes blocking onto the pipe.
osl_readPipe
SAL_DLLPUBLIC sal_Int32 osl_readPipe(oslPipe Pipe, void *pBuffer, sal_Int32 BufferSize)
Reads blocking from the pipe.
osl::Pipe::operator=
Pipe & operator=(const Pipe &pipe)
Assignment operator.
Definition: pipe.hxx:93
osl::Pipe::Pipe
Pipe()
Does not create a pipe.
Definition: pipe.hxx:31
osl::Pipe
Represents a pipe.
Definition: pipe_decl.hxx:32
oslPipeError
oslPipeError
Definition: pipe.h:34
osl::Pipe::~Pipe
~Pipe()
Destructor.
Definition: pipe.hxx:72
osl_createPipe
SAL_DLLPUBLIC oslPipe osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options, oslSecurity Security)
Create or open a pipe.
oslPipe
struct oslPipeImpl * oslPipe
Definition: pipe.h:57
osl_closePipe
SAL_DLLPUBLIC void osl_closePipe(oslPipe Pipe)
Close the pipe.
osl::StreamPipe::recv
sal_Int32 recv(void *pBuffer, sal_Int32 BytesToRead) const
Tries to receives BytesToRead data from the connected pipe,.
Definition: pipe.hxx:211
osl::Pipe::clear
void clear()
releases the underlying handle
Definition: pipe.hxx:139