/src/libreoffice/include/osl/pipe.hxx
Line | Count | Source |
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 | 0 | : m_handle( NULL ) |
37 | 0 | {} |
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 | 0 | : m_handle( osl_createPipe( strName.pData, Options , rSecurity.getHandle() ) ) |
47 | 0 | {} |
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 | 0 | : m_handle ( pipe ) |
65 | 0 | {} |
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 | 0 | { |
78 | 0 | if( m_handle ) |
79 | 0 | osl_releasePipe( m_handle ); |
80 | 0 | } |
81 | | |
82 | | |
83 | | inline bool Pipe::create( const ::rtl::OUString & strName, |
84 | | oslPipeOptions Options, const Security &rSec ) |
85 | 0 | { |
86 | 0 | *this = Pipe( strName, Options, rSec ); |
87 | 0 | return is(); |
88 | 0 | } |
89 | | |
90 | | |
91 | | inline bool Pipe::create( const ::rtl::OUString & strName, oslPipeOptions Options ) |
92 | 0 | { |
93 | 0 | *this = Pipe( strName, Options ); |
94 | 0 | return is(); |
95 | 0 | } |
96 | | |
97 | | inline Pipe& SAL_CALL Pipe::operator= (const Pipe& pipe) |
98 | 0 | { |
99 | 0 | *this = pipe.getHandle(); |
100 | 0 | return *this; |
101 | 0 | } |
102 | | |
103 | | #if defined LIBO_INTERNAL_ONLY |
104 | 0 | Pipe & Pipe::operator =(Pipe && other) noexcept { |
105 | 0 | if (m_handle != nullptr) { |
106 | 0 | osl_releasePipe(m_handle); |
107 | 0 | } |
108 | 0 | m_handle = other.m_handle; |
109 | 0 | other.m_handle = nullptr; |
110 | 0 | return *this; |
111 | 0 | } |
112 | | #endif |
113 | | |
114 | | inline Pipe & SAL_CALL Pipe::operator=( oslPipe pipe) |
115 | 0 | { |
116 | 0 | if( pipe ) |
117 | 0 | osl_acquirePipe( pipe ); |
118 | 0 | if( m_handle ) |
119 | 0 | osl_releasePipe( m_handle ); |
120 | 0 | m_handle = pipe; |
121 | 0 | return *this; |
122 | 0 | } |
123 | | |
124 | | |
125 | | inline bool SAL_CALL Pipe::is() const |
126 | 0 | { |
127 | 0 | return m_handle != NULL; |
128 | 0 | } |
129 | | |
130 | | |
131 | | inline bool SAL_CALL Pipe::operator==( const Pipe& rPipe ) const |
132 | 0 | { |
133 | 0 | return m_handle == rPipe.m_handle; |
134 | 0 | } |
135 | | |
136 | | |
137 | | inline void SAL_CALL Pipe::close() |
138 | 0 | { |
139 | 0 | osl_closePipe( m_handle ); |
140 | 0 | } |
141 | | |
142 | | |
143 | | inline void SAL_CALL Pipe::clear() |
144 | 0 | { |
145 | 0 | if( m_handle ) |
146 | 0 | { |
147 | 0 | osl_releasePipe( m_handle ); |
148 | 0 | m_handle = NULL; |
149 | 0 | } |
150 | 0 | } |
151 | | |
152 | | |
153 | | inline oslPipeError SAL_CALL Pipe::accept(StreamPipe& Connection) |
154 | 0 | { |
155 | 0 | Connection = StreamPipe( osl_acceptPipe( m_handle ), SAL_NO_ACQUIRE); |
156 | 0 | if( Connection.is() ) |
157 | 0 | return osl_Pipe_E_None; |
158 | 0 | else |
159 | 0 | return getError(); |
160 | 0 | } |
161 | | |
162 | | |
163 | | inline oslPipeError SAL_CALL Pipe::getError() const |
164 | 0 | { |
165 | 0 | return osl_getLastPipeError( NULL ); |
166 | 0 | } |
167 | | |
168 | | |
169 | | inline oslPipe SAL_CALL Pipe::getHandle() const |
170 | 0 | { |
171 | 0 | return m_handle; |
172 | 0 | } |
173 | | |
174 | | |
175 | 0 | 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 | 0 | : Pipe( pipe , noacquire ) |
195 | 0 | {} |
196 | | |
197 | | |
198 | | inline sal_Int32 SAL_CALL StreamPipe::read(void* pBuffer, sal_Int32 n) const |
199 | 0 | { |
200 | 0 | return osl_readPipe( m_handle, pBuffer, n ); |
201 | 0 | } |
202 | | |
203 | | |
204 | | inline sal_Int32 SAL_CALL StreamPipe::write(const void* pBuffer, sal_Int32 n) const |
205 | 0 | { |
206 | 0 | return osl_writePipe( m_handle, pBuffer , n ); |
207 | 0 | } |
208 | | |
209 | | |
210 | | inline sal_Int32 SAL_CALL StreamPipe::recv(void* pBuffer, sal_Int32 BytesToRead) const |
211 | 0 | { |
212 | 0 | return osl_receivePipe( m_handle, pBuffer , BytesToRead ); |
213 | 0 | } |
214 | | |
215 | | |
216 | | inline sal_Int32 SAL_CALL StreamPipe::send(const void* pBuffer, sal_Int32 BytesToSend) const |
217 | 0 | { |
218 | 0 | return osl_sendPipe( m_handle, pBuffer , BytesToSend ); |
219 | 0 | } |
220 | | |
221 | | } |
222 | | #endif |
223 | | |
224 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |