LibreOffice
LibreOffice 5.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 #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 )
51  }
52 
53 
55  : m_handle ( pipe )
56  {}
57 
58 
59  inline Pipe::Pipe(oslPipe pipe)
60  : m_handle( pipe )
61  {
62  if( m_handle )
64  }
65 
66 
67  inline Pipe::~Pipe()
68  {
69  if( m_handle )
71  }
72 
73 
74  inline bool Pipe::create( const ::rtl::OUString & strName,
75  oslPipeOptions Options, const Security &rSec )
76  {
77  *this = Pipe( strName, Options, rSec );
78  return is();
79  }
80 
81 
82  inline bool Pipe::create( const ::rtl::OUString & strName, oslPipeOptions Options )
83  {
84  *this = Pipe( strName, Options );
85  return is();
86  }
87 
88  inline Pipe& SAL_CALL Pipe::operator= (const Pipe& pipe)
89  {
90  *this = pipe.getHandle();
91  return *this;
92  }
93 
94 
95  inline Pipe & SAL_CALL Pipe::operator=( oslPipe pipe)
96  {
97  if( pipe )
98  osl_acquirePipe( pipe );
99  if( m_handle )
101  m_handle = pipe;
102  return *this;
103  }
104 
105 
106  inline bool SAL_CALL Pipe::is() const
107  {
108  return m_handle != NULL;
109  }
110 
111 
112  inline bool SAL_CALL Pipe::operator==( const Pipe& rPipe ) const
113  {
114  return m_handle == rPipe.m_handle;
115  }
116 
117 
118  inline void SAL_CALL Pipe::close()
119  {
121  }
122 
123 
124  inline void SAL_CALL Pipe::clear()
125  {
126  if( m_handle )
127  {
129  m_handle = NULL;
130  }
131  }
132 
133 
134  inline oslPipeError SAL_CALL Pipe::accept(StreamPipe& Connection)
135  {
137  if( Connection.is() )
138  return osl_Pipe_E_None;
139  else
140  return getError();
141  }
142 
143 
144  inline oslPipeError SAL_CALL Pipe::getError() const
145  {
146  return osl_getLastPipeError( NULL );
147  }
148 
149 
150  inline oslPipe SAL_CALL Pipe::getHandle() const
151  {
152  return m_handle;
153  }
154 
155 
157 
158 
160  : Pipe( hPipe )
161  {
162  }
163 
164 
165  inline StreamPipe::StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options, const Security &rSec )
166  : Pipe( strName, Options , rSec )
167  {}
168 
169 
170  inline StreamPipe::StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options )
171  : Pipe( strName, Options )
172  {}
173 
174 
175  inline StreamPipe::StreamPipe(const StreamPipe& aPipe)
176  : Pipe( aPipe )
177  {}
178 
180  : Pipe( pipe , noacquire )
181  {}
182 
183 
184  inline sal_Int32 SAL_CALL StreamPipe::read(void* pBuffer, sal_Int32 n) const
185  {
186  return osl_readPipe( m_handle, pBuffer, n );
187  }
188 
189 
190  inline sal_Int32 SAL_CALL StreamPipe::write(const void* pBuffer, sal_Int32 n) const
191  {
192  return osl_writePipe( m_handle, pBuffer , n );
193  }
194 
195 
196  inline sal_Int32 SAL_CALL StreamPipe::recv(void* pBuffer, sal_Int32 BytesToRead) const
197  {
198  return osl_receivePipe( m_handle, pBuffer , BytesToRead );
199  }
200 
201 
202  inline sal_Int32 SAL_CALL StreamPipe::send(const void* pBuffer, sal_Int32 BytesToSend) const
203  {
204  return osl_sendPipe( m_handle, pBuffer , BytesToSend );
205  }
206 
207 }
208 #endif
209 
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC oslPipeError osl_getLastPipeError(oslPipe Pipe)
Pipe()
Does not create a pipe.
Definition: pipe.hxx:31
SAL_DLLPUBLIC void osl_acquirePipe(oslPipe Pipe)
increases the refcount of the pipe.
A pipe to send or receive a stream of data.
Definition: pipe_decl.hxx:139
oslPipeError
Definition: pipe.h:34
void clear()
releases the underlying handle
Definition: pipe.hxx:124
StreamPipe()
Creates an unattached pipe.
Definition: pipe.hxx:156
bool operator==(const Pipe &rPipe) const
Definition: pipe.hxx:112
sal_uInt32 oslPipeOptions
Definition: pipe.h:49
Definition: pipe.h:35
void close()
Closes the pipe.
Definition: pipe.hxx:118
SAL_DLLPUBLIC oslPipe osl_acceptPipe(oslPipe Pipe)
SAL_DLLPUBLIC oslPipe osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options, oslSecurity Security)
SAL_DLLPUBLIC sal_Int32 osl_writePipe(oslPipe Pipe, const void *pBuffer, sal_Int32 BufferSize)
Writes blocking onto the pipe.
SAL_DLLPUBLIC void osl_releasePipe(oslPipe)
decreases the refcount of the pipe.
sal_Int32 read(void *pBuffer, sal_Int32 n) const
Retrieves n bytes from the stream and copies them into pBuffer.
Definition: pipe.hxx:184
__sal_NoAcquire
Definition: types.h:384
bool is() const
Definition: pipe.hxx:106
~Pipe()
Destructor.
Definition: pipe.hxx:67
SAL_DLLPUBLIC sal_Int32 osl_sendPipe(oslPipe Pipe, const void *pBuffer, sal_Int32 BufferSize)
oslPipe getHandle() const
Definition: pipe.hxx:150
oslPipeError accept(StreamPipe &Connection)
Accept connection on an existing pipe.
Definition: pipe.hxx:134
sal_Int32 send(const void *pBuffer, sal_Int32 BytesToSend) const
Tries to sends BytesToSend data from the connected pipe.
Definition: pipe.hxx:202
SAL_DLLPUBLIC void osl_closePipe(oslPipe)
closes the pipe, any read,write or accept actions stop immeadiatly.
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:74
SAL_DLLPUBLIC sal_Int32 osl_receivePipe(oslPipe Pipe, void *pBuffer, sal_Int32 BufferSize)
definition of a no acquire enum for ctors
Definition: types.h:388
oslPipe m_handle
Definition: pipe_decl.hxx:35
oslPipeError getError() const
Delivers a constant describing the last error for the pipe system.
Definition: pipe.hxx:144
Represents a pipe.
Definition: pipe_decl.hxx:32
Pipe & operator=(const Pipe &pipe)
Assignment operator.
Definition: pipe.hxx:88
sal_Int32 write(const void *pBuffer, sal_Int32 n) const
Writes n bytes from pBuffer to the stream.
Definition: pipe.hxx:190
SAL_DLLPUBLIC sal_Int32 osl_readPipe(oslPipe Pipe, void *pBuffer, sal_Int32 BufferSize)
Reads blocking from the pipe.
sal_Int32 recv(void *pBuffer, sal_Int32 BytesToRead) const
Tries to receives BytesToRead data from the connected pipe,.
Definition: pipe.hxx:196
Definition: conditn.hxx:32
capsulate security information for one user.
Definition: security_decl.hxx:34
struct oslPipeImpl * oslPipe
Definition: pipe.h:53