summaryrefslogtreecommitdiffstats
path: root/include/osl/pipe.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/osl/pipe.h127
-rw-r--r--include/osl/pipe.hxx224
2 files changed, 351 insertions, 0 deletions
diff --git a/include/osl/pipe.h b/include/osl/pipe.h
new file mode 100644
index 000000000..f8835428d
--- /dev/null
+++ b/include/osl/pipe.h
@@ -0,0 +1,127 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+/*
+ * This file is part of LibreOffice published API.
+ */
+
+#ifndef INCLUDED_OSL_PIPE_H
+#define INCLUDED_OSL_PIPE_H
+
+#include "sal/config.h"
+
+#include "osl/security.h"
+#include "rtl/ustring.h"
+#include "sal/saldllapi.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ osl_Pipe_E_None, /*< no error */
+ osl_Pipe_E_NotFound, /*< Pipe could not be found */
+ osl_Pipe_E_AlreadyExists, /*< Pipe already exists */
+ osl_Pipe_E_NoProtocol, /*< Protocol not available */
+ osl_Pipe_E_NetworkReset, /*< Network dropped connection because of reset */
+ osl_Pipe_E_ConnectionAbort, /*< Software caused connection abort */
+ osl_Pipe_E_ConnectionReset, /*< Connection reset by peer */
+ osl_Pipe_E_NoBufferSpace, /*< No buffer space available */
+ osl_Pipe_E_TimedOut, /*< Connection timed out */
+ osl_Pipe_E_ConnectionRefused, /*< Connection refused */
+ osl_Pipe_E_invalidError, /*< unmapped error: always last entry in enum! */
+ osl_Pipe_E_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
+} oslPipeError;
+
+/** Pipe creation options.
+
+ A pipe can either be opened, or a new pipe can be created and opened.
+*/
+typedef sal_uInt32 oslPipeOptions;
+#define osl_Pipe_OPEN 0x0000 /*< open existing pipe */
+#define osl_Pipe_CREATE 0x0001 /*< create pipe and open it, fails if already exists */
+
+typedef struct oslPipeImpl * oslPipe;
+
+/** Create or open a pipe.
+
+ @param[in] strPipeName pipe name
+ @param[in] Options create or open the pipe
+ @param[in] Security pipe creator
+
+ @returns nullptr on failure, otherwise returns the pipe handle
+
+ @see osl_closePipe
+*/
+SAL_DLLPUBLIC oslPipe SAL_CALL osl_createPipe(
+ rtl_uString *strPipeName, oslPipeOptions Options, oslSecurity Security);
+
+/** Decreases the refcount of the pipe.
+
+ If the refcount drops to zero, the handle is destroyed.
+
+ @param[in] Pipe pipe handle
+
+ @see osl_acquirePipe
+ */
+SAL_DLLPUBLIC void SAL_CALL osl_releasePipe(oslPipe Pipe);
+
+/** Increases the refcount of the pipe.
+
+ @param[in] Pipe pipe handle
+
+ @see osl_releasePipe
+ */
+SAL_DLLPUBLIC void SAL_CALL osl_acquirePipe(oslPipe Pipe);
+
+/** Close the pipe.
+
+ Any read, write or accept actions stop immediately.
+
+ @param[in] Pipe pipe handle
+
+ @see osl_createPipe
+ */
+SAL_DLLPUBLIC void SAL_CALL osl_closePipe(oslPipe Pipe);
+
+
+SAL_DLLPUBLIC oslPipe SAL_CALL osl_acceptPipe(oslPipe Pipe);
+
+SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_sendPipe(oslPipe Pipe, const void* pBuffer, sal_Int32 BufferSize);
+SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_receivePipe(oslPipe Pipe, void* pBuffer, sal_Int32 BufferSize);
+
+/** Reads blocking from the pipe.
+ @return Number of read bytes. If less than BufferSize, the pipe was closed.
+ */
+SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_readPipe( oslPipe Pipe, void *pBuffer, sal_Int32 BufferSize );
+
+/** Writes blocking onto the pipe.
+ @return Number of written bytes. If less than BufferSize, the pipe was closed.
+ */
+SAL_DLLPUBLIC sal_Int32 SAL_CALL osl_writePipe( oslPipe Pipe, const void *pBuffer, sal_Int32 BufferSize );
+
+SAL_DLLPUBLIC oslPipeError SAL_CALL osl_getLastPipeError(oslPipe Pipe);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // INCLUDED_OSL_PIPE_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/osl/pipe.hxx b/include/osl/pipe.hxx
new file mode 100644
index 000000000..cb9e2ec24
--- /dev/null
+++ b/include/osl/pipe.hxx
@@ -0,0 +1,224 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+/*
+ * This file is part of LibreOffice published API.
+ */
+#ifndef INCLUDED_OSL_PIPE_HXX
+#define INCLUDED_OSL_PIPE_HXX
+
+#include "sal/config.h"
+
+#include <cstddef>
+
+#include "osl/pipe_decl.hxx"
+
+namespace osl
+{
+
+ inline Pipe::Pipe()
+ : m_handle( NULL )
+ {}
+
+
+ inline Pipe::Pipe(const ::rtl::OUString& strName, oslPipeOptions Options )
+ : m_handle( osl_createPipe( strName.pData, Options , NULL ) )
+ {}
+
+
+ inline Pipe::Pipe(const ::rtl::OUString& strName, oslPipeOptions Options,const Security & rSecurity)
+ : m_handle( osl_createPipe( strName.pData, Options , rSecurity.getHandle() ) )
+ {}
+
+
+ inline Pipe::Pipe(const Pipe& pipe )
+ : m_handle( pipe.m_handle )
+ {
+ if( m_handle )
+ osl_acquirePipe( m_handle );
+ }
+
+#if defined LIBO_INTERNAL_ONLY
+ Pipe::Pipe(Pipe && other) noexcept : m_handle(other.m_handle) {
+ other.m_handle = nullptr;
+ }
+#endif
+
+ inline Pipe::Pipe( oslPipe pipe, __sal_NoAcquire )
+ : m_handle ( pipe )
+ {}
+
+
+ inline Pipe::Pipe(oslPipe pipe)
+ : m_handle( pipe )
+ {
+ if( m_handle )
+ osl_acquirePipe( m_handle );
+ }
+
+
+ inline Pipe::~Pipe()
+ {
+ if( m_handle )
+ osl_releasePipe( m_handle );
+ }
+
+
+ inline bool Pipe::create( const ::rtl::OUString & strName,
+ oslPipeOptions Options, const Security &rSec )
+ {
+ *this = Pipe( strName, Options, rSec );
+ return is();
+ }
+
+
+ inline bool Pipe::create( const ::rtl::OUString & strName, oslPipeOptions Options )
+ {
+ *this = Pipe( strName, Options );
+ return is();
+ }
+
+ inline Pipe& SAL_CALL Pipe::operator= (const Pipe& pipe)
+ {
+ *this = pipe.getHandle();
+ return *this;
+ }
+
+#if defined LIBO_INTERNAL_ONLY
+ Pipe & Pipe::operator =(Pipe && other) noexcept {
+ if (m_handle != nullptr) {
+ osl_releasePipe(m_handle);
+ }
+ m_handle = other.m_handle;
+ other.m_handle = nullptr;
+ return *this;
+ }
+#endif
+
+ inline Pipe & SAL_CALL Pipe::operator=( oslPipe pipe)
+ {
+ if( pipe )
+ osl_acquirePipe( pipe );
+ if( m_handle )
+ osl_releasePipe( m_handle );
+ m_handle = pipe;
+ return *this;
+ }
+
+
+ inline bool SAL_CALL Pipe::is() const
+ {
+ return m_handle != NULL;
+ }
+
+
+ inline bool SAL_CALL Pipe::operator==( const Pipe& rPipe ) const
+ {
+ return m_handle == rPipe.m_handle;
+ }
+
+
+ inline void SAL_CALL Pipe::close()
+ {
+ osl_closePipe( m_handle );
+ }
+
+
+ inline void SAL_CALL Pipe::clear()
+ {
+ if( m_handle )
+ {
+ osl_releasePipe( m_handle );
+ m_handle = NULL;
+ }
+ }
+
+
+ inline oslPipeError SAL_CALL Pipe::accept(StreamPipe& Connection)
+ {
+ Connection = StreamPipe( osl_acceptPipe( m_handle ), SAL_NO_ACQUIRE);
+ if( Connection.is() )
+ return osl_Pipe_E_None;
+ else
+ return getError();
+ }
+
+
+ inline oslPipeError SAL_CALL Pipe::getError() const
+ {
+ return osl_getLastPipeError( NULL );
+ }
+
+
+ inline oslPipe SAL_CALL Pipe::getHandle() const
+ {
+ return m_handle;
+ }
+
+
+ inline StreamPipe::StreamPipe(){}
+
+
+ inline StreamPipe::StreamPipe(oslPipe hPipe)
+ : Pipe( hPipe )
+ {
+ }
+
+
+ inline StreamPipe::StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options, const Security &rSec )
+ : Pipe( strName, Options , rSec )
+ {}
+
+
+ inline StreamPipe::StreamPipe(const ::rtl::OUString& strName, oslPipeOptions Options )
+ : Pipe( strName, Options )
+ {}
+
+ inline StreamPipe::StreamPipe( oslPipe pipe, __sal_NoAcquire noacquire )
+ : Pipe( pipe , noacquire )
+ {}
+
+
+ inline sal_Int32 SAL_CALL StreamPipe::read(void* pBuffer, sal_Int32 n) const
+ {
+ return osl_readPipe( m_handle, pBuffer, n );
+ }
+
+
+ inline sal_Int32 SAL_CALL StreamPipe::write(const void* pBuffer, sal_Int32 n) const
+ {
+ return osl_writePipe( m_handle, pBuffer , n );
+ }
+
+
+ inline sal_Int32 SAL_CALL StreamPipe::recv(void* pBuffer, sal_Int32 BytesToRead) const
+ {
+ return osl_receivePipe( m_handle, pBuffer , BytesToRead );
+ }
+
+
+ inline sal_Int32 SAL_CALL StreamPipe::send(const void* pBuffer, sal_Int32 BytesToSend) const
+ {
+ return osl_sendPipe( m_handle, pBuffer , BytesToSend );
+ }
+
+}
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */