LibreOffice
LibreOffice 24.2 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 
32 namespace 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 )
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 
64  : m_handle ( pipe )
65  {}
66 
67 
68  inline Pipe::Pipe(oslPipe pipe)
69  : m_handle( pipe )
70  {
71  if( m_handle )
73  }
74 
75 
76  inline Pipe::~Pipe()
77  {
78  if( 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 )
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  {
140  }
141 
142 
143  inline void SAL_CALL Pipe::clear()
144  {
145  if( m_handle )
146  {
148  m_handle = NULL;
149  }
150  }
151 
152 
153  inline oslPipeError SAL_CALL Pipe::accept(StreamPipe& Connection)
154  {
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 
176 
177 
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 
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: */
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
SAL_DLLPUBLIC sal_Int32 osl_receivePipe(oslPipe Pipe, void *pBuffer, sal_Int32 BufferSize)
sal_Int32 recv(void *pBuffer, sal_Int32 BytesToRead) const
Tries to receives BytesToRead data from the connected pipe,.
Definition: pipe.hxx:210
struct oslPipeImpl * oslPipe
Definition: pipe.h:60
SAL_DLLPUBLIC void osl_closePipe(oslPipe Pipe)
Close the pipe.
Represents a pipe.
Definition: pipe_decl.hxx:36
Definition: condition.hxx:31
oslPipeError accept(StreamPipe &Connection)
Accept connection on an existing pipe.
Definition: pipe.hxx:153
oslPipeError getError() const
Delivers a constant describing the last error for the pipe system.
Definition: pipe.hxx:163
void close()
Closes the pipe.
Definition: pipe.hxx:137
sal_Int32 send(const void *pBuffer, sal_Int32 BytesToSend) const
Tries to sends BytesToSend data from the connected pipe.
Definition: pipe.hxx:216
StreamPipe()
Creates an unattached pipe.
Definition: pipe.hxx:175
bool is() const
Definition: pipe.hxx:125
oslPipeError
Definition: pipe.h:37
SAL_DLLPUBLIC sal_Int32 osl_sendPipe(oslPipe Pipe, const void *pBuffer, sal_Int32 BufferSize)
SAL_DLLPUBLIC sal_Int32 osl_writePipe(oslPipe Pipe, const void *pBuffer, sal_Int32 BufferSize)
Writes blocking onto the pipe.
oslPipe getHandle() const
Definition: pipe.hxx:169
__sal_NoAcquire
Definition: types.h:352
SAL_DLLPUBLIC oslPipe osl_acceptPipe(oslPipe Pipe)
Encapsulate security information for one user.
Definition: security_decl.hxx:38
SAL_DLLPUBLIC void osl_releasePipe(oslPipe Pipe)
Decreases the refcount of the pipe.
A pipe to send or receive a stream of data.
Definition: pipe_decl.hxx:149
sal_Int32 read(void *pBuffer, sal_Int32 n) const
Retrieves n bytes from the stream and copies them into pBuffer.
Definition: pipe.hxx:198
Definition: pipe.h:38
Pipe & operator=(const Pipe &pipe)
Assignment operator.
Definition: pipe.hxx:97
definition of a no acquire enum for ctors
Definition: types.h:356
SAL_DLLPUBLIC sal_Int32 osl_readPipe(oslPipe Pipe, void *pBuffer, sal_Int32 BufferSize)
Reads blocking from the pipe.
Pipe()
Does not create a pipe.
Definition: pipe.hxx:35
~Pipe()
Destructor.
Definition: pipe.hxx:76
SAL_DLLPUBLIC oslPipe osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options, oslSecurity Security)
Create or open a pipe.
oslPipe m_handle
Definition: pipe_decl.hxx:39
sal_uInt32 oslPipeOptions
Pipe creation options.
Definition: pipe.h:56
SAL_DLLPUBLIC oslPipeError osl_getLastPipeError(oslPipe Pipe)
void clear()
releases the underlying handle
Definition: pipe.hxx:143
SAL_DLLPUBLIC void osl_acquirePipe(oslPipe Pipe)
Increases the refcount of the pipe.
bool operator==(const Pipe &rPipe) const
Definition: pipe.hxx:131
sal_Int32 write(const void *pBuffer, sal_Int32 n) const
Writes n bytes from pBuffer to the stream.
Definition: pipe.hxx:204