LibreOffice
LibreOffice 7.1 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
28namespace 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 )
51 }
52
53#if defined LIBO_INTERNAL_ONLY
54 Pipe::Pipe(Pipe && other) noexcept : m_handle(other.m_handle) {
55 other.m_handle = nullptr;
56 }
57#endif
58
60 : m_handle ( pipe )
61 {}
62
63
64 inline Pipe::Pipe(oslPipe pipe)
65 : m_handle( pipe )
66 {
67 if( m_handle )
69 }
70
71
72 inline Pipe::~Pipe()
73 {
74 if( 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) noexcept {
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 )
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 {
136 }
137
138
139 inline void SAL_CALL Pipe::clear()
140 {
141 if( m_handle )
142 {
144 m_handle = NULL;
145 }
146 }
147
148
149 inline oslPipeError SAL_CALL Pipe::accept(StreamPipe& Connection)
150 {
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
172
173
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
190 : Pipe( pipe , noacquire )
191 {}
192
193
194 inline sal_Int32 SAL_CALL StreamPipe::read(void* pBuffer, sal_Int32 n) const
195 {
196 return osl_readPipe( m_handle, pBuffer, n );
197 }
198
199
200 inline sal_Int32 SAL_CALL StreamPipe::write(const void* pBuffer, sal_Int32 n) const
201 {
202 return osl_writePipe( m_handle, pBuffer , n );
203 }
204
205
206 inline sal_Int32 SAL_CALL StreamPipe::recv(void* pBuffer, sal_Int32 BytesToRead) const
207 {
208 return osl_receivePipe( m_handle, pBuffer , BytesToRead );
209 }
210
211
212 inline sal_Int32 SAL_CALL StreamPipe::send(const void* pBuffer, sal_Int32 BytesToSend) const
213 {
214 return osl_sendPipe( m_handle, pBuffer , BytesToSend );
215 }
216
217}
218#endif
219
220/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
__sal_NoAcquire
Definition: types.h:349
@ SAL_NO_ACQUIRE
definition of a no acquire enum for ctors
Definition: types.h:352
oslPipeError
Definition: pipe.h:34
@ osl_Pipe_E_None
Definition: pipe.h:35
SAL_DLLPUBLIC sal_Int32 osl_writePipe(oslPipe Pipe, const void *pBuffer, sal_Int32 BufferSize)
Writes blocking onto the pipe.
SAL_DLLPUBLIC sal_Int32 osl_readPipe(oslPipe Pipe, void *pBuffer, sal_Int32 BufferSize)
Reads blocking from the pipe.
sal_uInt32 oslPipeOptions
Pipe creation options.
Definition: pipe.h:53
SAL_DLLPUBLIC sal_Int32 osl_sendPipe(oslPipe Pipe, const void *pBuffer, sal_Int32 BufferSize)
struct oslPipeImpl * oslPipe
Definition: pipe.h:57
SAL_DLLPUBLIC oslPipe osl_acceptPipe(oslPipe Pipe)
SAL_DLLPUBLIC void osl_closePipe(oslPipe Pipe)
Close the pipe.
SAL_DLLPUBLIC void osl_acquirePipe(oslPipe Pipe)
Increases the refcount of the pipe.
SAL_DLLPUBLIC sal_Int32 osl_receivePipe(oslPipe Pipe, void *pBuffer, sal_Int32 BufferSize)
SAL_DLLPUBLIC oslPipe osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options, oslSecurity Security)
Create or open a pipe.
SAL_DLLPUBLIC oslPipeError osl_getLastPipeError(oslPipe Pipe)
SAL_DLLPUBLIC void osl_releasePipe(oslPipe Pipe)
Decreases the refcount of the pipe.
Definition: component.hxx:30
Represents a pipe.
Definition: pipe_decl.hxx:33
bool is() const
Definition: pipe.hxx:121
Pipe()
Does not create a pipe.
Definition: pipe.hxx:31
~Pipe()
Destructor.
Definition: pipe.hxx:72
oslPipeError getError() const
Delivers a constant describing the last error for the pipe system.
Definition: pipe.hxx:159
Pipe & operator=(const Pipe &pipe)
Assignment operator.
Definition: pipe.hxx:93
oslPipe m_handle
Definition: pipe_decl.hxx:35
oslPipe getHandle() const
Definition: pipe.hxx:165
void close()
Closes the pipe.
Definition: pipe.hxx:133
oslPipeError accept(StreamPipe &Connection)
Accept connection on an existing pipe.
Definition: pipe.hxx:149
bool operator==(const Pipe &rPipe) const
Definition: pipe.hxx:127
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
void clear()
releases the underlying handle
Definition: pipe.hxx:139
A pipe to send or receive a stream of data.
Definition: pipe_decl.hxx:146
StreamPipe()
Creates an unattached pipe.
Definition: pipe.hxx:171
sal_Int32 write(const void *pBuffer, sal_Int32 n) const
Writes n bytes from pBuffer to the stream.
Definition: pipe.hxx:200
sal_Int32 recv(void *pBuffer, sal_Int32 BytesToRead) const
Tries to receives BytesToRead data from the connected pipe,.
Definition: pipe.hxx:206
sal_Int32 read(void *pBuffer, sal_Int32 n) const
Retrieves n bytes from the stream and copies them into pBuffer.
Definition: pipe.hxx:194
sal_Int32 send(const void *pBuffer, sal_Int32 BytesToSend) const
Tries to sends BytesToSend data from the connected pipe.
Definition: pipe.hxx:212
Encapsulate security information for one user.
Definition: security_decl.hxx:35