Line data Source code
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 : #ifndef INCLUDED_IO_SOURCE_CONNECTOR_CONNECTOR_HXX
21 : #define INCLUDED_IO_SOURCE_CONNECTOR_CONNECTOR_HXX
22 :
23 : #include <cppuhelper/implbase1.hxx>
24 : #include <cppuhelper/implbase2.hxx>
25 :
26 : #include <com/sun/star/connection/XConnection.hpp>
27 : #include <com/sun/star/connection/XConnectionBroadcaster.hpp>
28 :
29 : #include <unordered_set>
30 : #include <osl/socket.hxx>
31 : #include <osl/pipe.hxx>
32 :
33 : namespace stoc_connector
34 : {
35 : template<class T>
36 : struct ReferenceHash
37 : {
38 0 : size_t operator () (const ::com::sun::star::uno::Reference<T> & ref) const
39 : {
40 0 : return reinterpret_cast<size_t>(ref.get());
41 : }
42 : };
43 :
44 : template<class T>
45 : struct ReferenceEqual
46 : {
47 0 : bool operator () (const ::com::sun::star::uno::Reference<T> & op1,
48 : const ::com::sun::star::uno::Reference<T> & op2) const
49 : {
50 0 : return op1.get() == op2.get();
51 : }
52 : };
53 :
54 : typedef std::unordered_set< ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>,
55 : ReferenceHash< ::com::sun::star::io::XStreamListener>,
56 : ReferenceEqual< ::com::sun::star::io::XStreamListener> >
57 : XStreamListener_hash_set;
58 :
59 : class PipeConnection :
60 : public ::cppu::WeakImplHelper1< ::com::sun::star::connection::XConnection >
61 :
62 : {
63 : public:
64 : PipeConnection( const OUString &sConnectionDescription );
65 : virtual ~PipeConnection();
66 :
67 : virtual sal_Int32 SAL_CALL read( ::com::sun::star::uno::Sequence< sal_Int8 >& aReadBytes,
68 : sal_Int32 nBytesToRead )
69 : throw(::com::sun::star::io::IOException,
70 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
71 : virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData )
72 : throw(::com::sun::star::io::IOException,
73 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
74 : virtual void SAL_CALL flush( ) throw(
75 : ::com::sun::star::io::IOException,
76 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
77 : virtual void SAL_CALL close( )
78 : throw(::com::sun::star::io::IOException,
79 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
80 : virtual OUString SAL_CALL getDescription( )
81 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
82 : public:
83 : ::osl::StreamPipe m_pipe;
84 : oslInterlockedCount m_nStatus;
85 : OUString m_sDescription;
86 : };
87 :
88 : class SocketConnection :
89 : public ::cppu::WeakImplHelper2< ::com::sun::star::connection::XConnection, ::com::sun::star::connection::XConnectionBroadcaster >
90 :
91 : {
92 : public:
93 : SocketConnection( const OUString & sConnectionDescription );
94 : virtual ~SocketConnection();
95 :
96 : virtual sal_Int32 SAL_CALL read( ::com::sun::star::uno::Sequence< sal_Int8 >& aReadBytes,
97 : sal_Int32 nBytesToRead )
98 : throw(::com::sun::star::io::IOException,
99 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
100 : virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData )
101 : throw(::com::sun::star::io::IOException,
102 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
103 : virtual void SAL_CALL flush( ) throw(
104 : ::com::sun::star::io::IOException,
105 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
106 : virtual void SAL_CALL close( )
107 : throw(::com::sun::star::io::IOException,
108 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
109 : virtual OUString SAL_CALL getDescription( )
110 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
111 :
112 :
113 : // XConnectionBroadcaster
114 : virtual void SAL_CALL addStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener)
115 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
116 : virtual void SAL_CALL removeStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener)
117 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
118 :
119 : public:
120 : void completeConnectionString();
121 :
122 : ::osl::ConnectorSocket m_socket;
123 : ::osl::SocketAddr m_addr;
124 : oslInterlockedCount m_nStatus;
125 : OUString m_sDescription;
126 :
127 : ::osl::Mutex _mutex;
128 : bool _started;
129 : bool _closed;
130 : bool _error;
131 :
132 : XStreamListener_hash_set _listeners;
133 : };
134 : }
135 :
136 : #endif // INCLUDED_IO_SOURCE_CONNECTOR_CONNECTOR_HXX
137 :
138 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|