update credits
[LibreOffice.git] / io / source / connector / connector.hxx
blob14abf3c6119f754c251aa2265b500ea534551956
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <cppuhelper/implbase1.hxx>
21 #include <cppuhelper/implbase2.hxx>
23 #include <com/sun/star/connection/XConnection.hpp>
24 #include <com/sun/star/connection/XConnectionBroadcaster.hpp>
26 #include <boost/unordered_set.hpp>
27 # include <osl/socket.hxx>
28 # include <osl/pipe.hxx>
30 namespace stoc_connector
32 template<class T>
33 struct ReferenceHash
35 size_t operator () (const ::com::sun::star::uno::Reference<T> & ref) const
37 return (size_t)ref.get();
41 template<class T>
42 struct ReferenceEqual
44 sal_Bool operator () (const ::com::sun::star::uno::Reference<T> & op1,
45 const ::com::sun::star::uno::Reference<T> & op2) const
47 return op1.get() == op2.get();
51 typedef ::boost::unordered_set< ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>,
52 ReferenceHash< ::com::sun::star::io::XStreamListener>,
53 ReferenceEqual< ::com::sun::star::io::XStreamListener> >
54 XStreamListener_hash_set;
56 class PipeConnection :
57 public ::cppu::WeakImplHelper1< ::com::sun::star::connection::XConnection >
60 public:
61 PipeConnection( const OUString &sConnectionDescription );
62 virtual ~PipeConnection();
64 virtual sal_Int32 SAL_CALL read( ::com::sun::star::uno::Sequence< sal_Int8 >& aReadBytes,
65 sal_Int32 nBytesToRead )
66 throw(::com::sun::star::io::IOException,
67 ::com::sun::star::uno::RuntimeException);
68 virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData )
69 throw(::com::sun::star::io::IOException,
70 ::com::sun::star::uno::RuntimeException);
71 virtual void SAL_CALL flush( ) throw(
72 ::com::sun::star::io::IOException,
73 ::com::sun::star::uno::RuntimeException);
74 virtual void SAL_CALL close( )
75 throw(::com::sun::star::io::IOException,
76 ::com::sun::star::uno::RuntimeException);
77 virtual OUString SAL_CALL getDescription( )
78 throw(::com::sun::star::uno::RuntimeException);
79 public:
80 ::osl::StreamPipe m_pipe;
81 oslInterlockedCount m_nStatus;
82 OUString m_sDescription;
85 class SocketConnection :
86 public ::cppu::WeakImplHelper2< ::com::sun::star::connection::XConnection, ::com::sun::star::connection::XConnectionBroadcaster >
89 public:
90 SocketConnection( const OUString & sConnectionDescription );
91 virtual ~SocketConnection();
93 virtual sal_Int32 SAL_CALL read( ::com::sun::star::uno::Sequence< sal_Int8 >& aReadBytes,
94 sal_Int32 nBytesToRead )
95 throw(::com::sun::star::io::IOException,
96 ::com::sun::star::uno::RuntimeException);
97 virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData )
98 throw(::com::sun::star::io::IOException,
99 ::com::sun::star::uno::RuntimeException);
100 virtual void SAL_CALL flush( ) throw(
101 ::com::sun::star::io::IOException,
102 ::com::sun::star::uno::RuntimeException);
103 virtual void SAL_CALL close( )
104 throw(::com::sun::star::io::IOException,
105 ::com::sun::star::uno::RuntimeException);
106 virtual OUString SAL_CALL getDescription( )
107 throw(::com::sun::star::uno::RuntimeException);
110 // XConnectionBroadcaster
111 virtual void SAL_CALL addStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener)
112 throw(::com::sun::star::uno::RuntimeException);
113 virtual void SAL_CALL removeStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener)
114 throw(::com::sun::star::uno::RuntimeException);
116 public:
117 void completeConnectionString();
119 ::osl::ConnectorSocket m_socket;
120 ::osl::SocketAddr m_addr;
121 oslInterlockedCount m_nStatus;
122 OUString m_sDescription;
124 ::osl::Mutex _mutex;
125 sal_Bool _started;
126 sal_Bool _closed;
127 sal_Bool _error;
129 XStreamListener_hash_set _listeners;
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */