LibreOffice: osl/pipe.hxx Source File

LibreOffice LibreOffice 7.3 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
20/*
21 * This file is part of LibreOffice published API.
22 */
23#ifndef INCLUDED_OSL_PIPE_HXX
24#define INCLUDED_OSL_PIPE_HXX
25
26#include "sal/config.h"
27
28#include <cstddef>
29
30#include "osl/pipe_decl.hxx"
31
32namespace osl
33{
34
35 inline Pipe::Pipe()
36 : m_handle( NULL )
37 {}
38
39
40 inline Pipe::Pipe(const ::rtl::OUString& strName, oslPipeOptions Options )
41 : m_handle( osl_createPipe( strName.pData, Options , NULL ) )
42 {}
43
44
45 inline Pipe::Pipe(const ::rtl::OUString& strName, oslPipeOptions Options,const Security & rSecurity)
46 : m_handle( osl_createPipe( strName.pData, Options , rSecurity.getHandle() ) )
47 {}
48
49
50 inline Pipe::Pipe(const Pipe& pipe )
51 : m_handle( pipe.m_handle )
52 {
53 if( m_handle )
54 osl_acquirePipe( m_handle );
55 }
56
57#if defined LIBO_INTERNAL_ONLY
58 Pipe::Pipe(Pipe && other) noexcept : m_handle(other.m_handle) {
59 other.m_handle = nullptr;
60 }
61#endif
62
63 inline Pipe::Pipe( oslPipe pipe, __sal_NoAcquire )
64 : m_handle ( pipe )
65 {}
66
67
68 inline Pipe::Pipe(oslPipe pipe)
69 : m_handle( pipe )
70 {
71 if( m_handle )
72 osl_acquirePipe( m_handle );
73 }
74
75
76 inline Pipe::~Pipe()
77 {
78 if( m_handle )
79 osl_releasePipe( m_handle );
80 }
81
82
83 inline bool Pipe::create( const ::rtl::OUString & strName,
84 oslPipeOptions Options, const Security &rSec )
85 {
86 *this = Pipe( strName, Options, rSec );
87 return is();
88 }
89
90
91 inline bool Pipe::create( const ::rtl::OUString & strName, oslPipeOptions Options )
92 {
93 *this = Pipe( strName, Options );
94 return is();
95 }
96
97 inline Pipe& SAL_CALL Pipe::operator= (const Pipe& pipe)
98 {
99 *this = pipe.getHandle();
100 return *this;
101 }
102
103#if defined LIBO_INTERNAL_ONLY
104 Pipe & Pipe::operator =(Pipe && other) noexcept {
105 if (m_handle != nullptr) {
106 osl_releasePipe(m_handle);
107 }
108 m_handle = other.m_handle;
109 other.m_handle = nullptr;
110 return *this;
111 }
112#endif
113
114 inline Pipe & SAL_CALL Pipe::operator=( oslPipe pipe)
115 {
116 if( pipe )
117 osl_acquirePipe( pipe );
118 if( m_handle )
119 osl_releasePipe( m_handle );
120 m_handle = pipe;
121 return *this;
122 }
123
124
125 inline bool SAL_CALL Pipe::is() const
126 {
127 return m_handle != NULL;
128 }
129
130
131 inline bool SAL_CALL Pipe::operator==( const Pipe& rPipe ) const
132 {
133 return m_handle == rPipe.m_handle;
134 }
135
136
137 inline void SAL_CALL Pipe::close()
138 {
139 osl_closePipe( m_handle );
140 }
141
142
143 inline void SAL_CALL Pipe::clear()
144 {
145 if( m_handle )
146 {
147 osl_releasePipe( m_handle );
148 m_handle = NULL;
149 }
150 }
151
152
153 inline oslPipeError SAL_CALL Pipe::accept(StreamPipe& Connection)
154 {
155 Connection = StreamPipe( osl_acceptPipe( m_handle ), SAL_NO_ACQUIRE);
156 if( Connection.is() )
157 return osl_Pipe_E_None;
158 else
159 return getError();
160 }
161
162
163 inline oslPipeError SAL_CALL Pipe::getError() const
164 {
165 return osl_getLastPipeError( NULL );
166 }
167
168
169 inline oslPipe SAL_CALL Pipe::getHandle() const
170 {
171 return m_handle;
172 }
173
174
175 inline StreamPipe::StreamPipe(){}
176
177
178 inline StreamPipe::StreamPipe(oslPipe hPipe)
179 : Pipe( hPipe )
180 {
181 }
182
183
184 inline StreamPipe::StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options, const Security &rSec )
185 : Pipe( strName, Options , rSec )
186 {}
187
188
189 inline StreamPipe::StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options )
190 : Pipe( strName, Options )
191 {}
192
193 inline StreamPipe::StreamPipe( oslPipe pipe, __sal_NoAcquire noacquire )
194 : Pipe( pipe , noacquire )
195 {}
196
197
198 inline sal_Int32 SAL_CALL StreamPipe::read(void* pBuffer, sal_Int32 n) const
199 {
200 return osl_readPipe( m_handle, pBuffer, n );
201 }
202
203
204 inline sal_Int32 SAL_CALL StreamPipe::write(const void* pBuffer, sal_Int32 n) const
205 {
206 return osl_writePipe( m_handle, pBuffer , n );
207 }
208
209
210 inline sal_Int32 SAL_CALL StreamPipe::recv(void* pBuffer, sal_Int32 BytesToRead) const
211 {
212 return osl_receivePipe( m_handle, pBuffer , BytesToRead );
213 }
214
215
216 inline sal_Int32 SAL_CALL StreamPipe::send(const void* pBuffer, sal_Int32 BytesToSend) const
217 {
218 return osl_sendPipe( m_handle, pBuffer , BytesToSend );
219 }
220
221}
222#endif
223
224/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
config.h
__sal_NoAcquire
__sal_NoAcquire
Definition: types.h:353
SAL_NO_ACQUIRE
@ SAL_NO_ACQUIRE
definition of a no acquire enum for ctors
Definition: types.h:356
oslPipeError
oslPipeError
Definition: pipe.h:37
osl_Pipe_E_None
@ osl_Pipe_E_None
Definition: pipe.h:38
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.
oslPipeOptions
sal_uInt32 oslPipeOptions
Pipe creation options.
Definition: pipe.h:56
osl_sendPipe
SAL_DLLPUBLIC sal_Int32 osl_sendPipe(oslPipe Pipe, const void *pBuffer, sal_Int32 BufferSize)
oslPipe
struct oslPipeImpl * oslPipe
Definition: pipe.h:60
osl_acceptPipe
SAL_DLLPUBLIC oslPipe osl_acceptPipe(oslPipe Pipe)
osl_closePipe
SAL_DLLPUBLIC void osl_closePipe(oslPipe Pipe)
Close the pipe.
osl_acquirePipe
SAL_DLLPUBLIC void osl_acquirePipe(oslPipe Pipe)
Increases the refcount of the pipe.
osl_receivePipe
SAL_DLLPUBLIC sal_Int32 osl_receivePipe(oslPipe Pipe, void *pBuffer, sal_Int32 BufferSize)
osl_createPipe
SAL_DLLPUBLIC oslPipe osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options, oslSecurity Security)
Create or open a pipe.
osl_getLastPipeError
SAL_DLLPUBLIC oslPipeError osl_getLastPipeError(oslPipe Pipe)
osl_releasePipe
SAL_DLLPUBLIC void osl_releasePipe(oslPipe Pipe)
Decreases the refcount of the pipe.
pipe_decl.hxx
osl
Definition: condition.hxx:31
osl::Pipe
Represents a pipe.
Definition: pipe_decl.hxx:37
osl::Pipe::is
bool is() const
Definition: pipe.hxx:125
osl::Pipe::Pipe
Pipe()
Does not create a pipe.
Definition: pipe.hxx:35
osl::Pipe::~Pipe
~Pipe()
Destructor.
Definition: pipe.hxx:76
osl::Pipe::getError
oslPipeError getError() const
Delivers a constant describing the last error for the pipe system.
Definition: pipe.hxx:163
osl::Pipe::operator=
Pipe & operator=(const Pipe &pipe)
Assignment operator.
Definition: pipe.hxx:97
osl::Pipe::m_handle
oslPipe m_handle
Definition: pipe_decl.hxx:39
osl::Pipe::getHandle
oslPipe getHandle() const
Definition: pipe.hxx:169
osl::Pipe::close
void close()
Closes the pipe.
Definition: pipe.hxx:137
osl::Pipe::accept
oslPipeError accept(StreamPipe &Connection)
Accept connection on an existing pipe.
Definition: pipe.hxx:153
osl::Pipe::operator==
bool operator==(const Pipe &rPipe) const
Definition: pipe.hxx:131
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:83
osl::Pipe::clear
void clear()
releases the underlying handle
Definition: pipe.hxx:143
osl::StreamPipe
A pipe to send or receive a stream of data.
Definition: pipe_decl.hxx:150
osl::StreamPipe::StreamPipe
StreamPipe()
Creates an unattached pipe.
Definition: pipe.hxx:175
osl::StreamPipe::write
sal_Int32 write(const void *pBuffer, sal_Int32 n) const
Writes n bytes from pBuffer to the stream.
Definition: pipe.hxx:204
osl::StreamPipe::recv
sal_Int32 recv(void *pBuffer, sal_Int32 BytesToRead) const
Tries to receives BytesToRead data from the connected pipe,.
Definition: pipe.hxx:210
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:198
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:216
osl::Security
Encapsulate security information for one user.
Definition: security_decl.hxx:39