Branch data 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 : : #include <rtl/unload.h>
20 : :
21 : : #include <cppuhelper/implbase1.hxx>
22 : : #include <cppuhelper/implbase2.hxx>
23 : :
24 : : #include <com/sun/star/connection/XConnection.hpp>
25 : : #include <com/sun/star/connection/XConnectionBroadcaster.hpp>
26 : :
27 : : #include <boost/unordered_set.hpp>
28 : : # include <osl/socket.hxx>
29 : : # include <osl/pipe.hxx>
30 : :
31 : : namespace stoc_connector
32 : : {
33 : : extern rtl_StandardModuleCount g_moduleCount;
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 (size_t)ref.get();
41 : : }
42 : : };
43 : :
44 : : template<class T>
45 : : struct ReferenceEqual
46 : : {
47 : 0 : sal_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 ::boost::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 ::rtl::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);
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);
74 : : virtual void SAL_CALL flush( ) throw(
75 : : ::com::sun::star::io::IOException,
76 : : ::com::sun::star::uno::RuntimeException);
77 : : virtual void SAL_CALL close( )
78 : : throw(::com::sun::star::io::IOException,
79 : : ::com::sun::star::uno::RuntimeException);
80 : : virtual ::rtl::OUString SAL_CALL getDescription( )
81 : : throw(::com::sun::star::uno::RuntimeException);
82 : : public:
83 : : ::osl::StreamPipe m_pipe;
84 : : oslInterlockedCount m_nStatus;
85 : : ::rtl::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 ::rtl::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);
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);
103 : : virtual void SAL_CALL flush( ) throw(
104 : : ::com::sun::star::io::IOException,
105 : : ::com::sun::star::uno::RuntimeException);
106 : : virtual void SAL_CALL close( )
107 : : throw(::com::sun::star::io::IOException,
108 : : ::com::sun::star::uno::RuntimeException);
109 : : virtual ::rtl::OUString SAL_CALL getDescription( )
110 : : throw(::com::sun::star::uno::RuntimeException);
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);
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);
118 : :
119 : : public:
120 : : void completeConnectionString();
121 : :
122 : : ::osl::ConnectorSocket m_socket;
123 : : ::osl::SocketAddr m_addr;
124 : : oslInterlockedCount m_nStatus;
125 : : ::rtl::OUString m_sDescription;
126 : :
127 : : ::osl::Mutex _mutex;
128 : : sal_Bool _started;
129 : : sal_Bool _closed;
130 : : sal_Bool _error;
131 : :
132 : : XStreamListener_hash_set _listeners;
133 : : };
134 : : }
135 : :
136 : :
137 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|