1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #include <rtl/unload.h> 24 25 #include <cppuhelper/implbase1.hxx> 26 #include <cppuhelper/implbase2.hxx> 27 28 #include <com/sun/star/connection/XConnection.hpp> 29 #include <com/sun/star/connection/XConnectionBroadcaster.hpp> 30 31 #include <hash_set> 32 # include <osl/socket.hxx> 33 # include <osl/pipe.hxx> 34 35 namespace stoc_connector 36 { 37 extern rtl_StandardModuleCount g_moduleCount; 38 39 template<class T> 40 struct ReferenceHash 41 { operator ()stoc_connector::ReferenceHash42 size_t operator () (const ::com::sun::star::uno::Reference<T> & ref) const 43 { 44 return (size_t)ref.get(); 45 } 46 }; 47 48 template<class T> 49 struct ReferenceEqual 50 { operator ()stoc_connector::ReferenceEqual51 sal_Bool operator () (const ::com::sun::star::uno::Reference<T> & op1, 52 const ::com::sun::star::uno::Reference<T> & op2) const 53 { 54 return op1.get() == op2.get(); 55 } 56 }; 57 58 typedef ::std::hash_set< ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>, 59 ReferenceHash< ::com::sun::star::io::XStreamListener>, 60 ReferenceEqual< ::com::sun::star::io::XStreamListener> > 61 XStreamListener_hash_set; 62 63 class PipeConnection : 64 public ::cppu::WeakImplHelper1< ::com::sun::star::connection::XConnection > 65 66 { 67 public: 68 PipeConnection( const ::rtl::OUString &sConnectionDescription ); 69 virtual ~PipeConnection(); 70 71 virtual sal_Int32 SAL_CALL read( ::com::sun::star::uno::Sequence< sal_Int8 >& aReadBytes, 72 sal_Int32 nBytesToRead ) 73 throw(::com::sun::star::io::IOException, 74 ::com::sun::star::uno::RuntimeException); 75 virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData ) 76 throw(::com::sun::star::io::IOException, 77 ::com::sun::star::uno::RuntimeException); 78 virtual void SAL_CALL flush( ) throw( 79 ::com::sun::star::io::IOException, 80 ::com::sun::star::uno::RuntimeException); 81 virtual void SAL_CALL close( ) 82 throw(::com::sun::star::io::IOException, 83 ::com::sun::star::uno::RuntimeException); 84 virtual ::rtl::OUString SAL_CALL getDescription( ) 85 throw(::com::sun::star::uno::RuntimeException); 86 public: 87 ::osl::StreamPipe m_pipe; 88 oslInterlockedCount m_nStatus; 89 ::rtl::OUString m_sDescription; 90 }; 91 92 class SocketConnection : 93 public ::cppu::WeakImplHelper2< ::com::sun::star::connection::XConnection, ::com::sun::star::connection::XConnectionBroadcaster > 94 95 { 96 public: 97 SocketConnection( const ::rtl::OUString & sConnectionDescription ); 98 virtual ~SocketConnection(); 99 100 virtual sal_Int32 SAL_CALL read( ::com::sun::star::uno::Sequence< sal_Int8 >& aReadBytes, 101 sal_Int32 nBytesToRead ) 102 throw(::com::sun::star::io::IOException, 103 ::com::sun::star::uno::RuntimeException); 104 virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData ) 105 throw(::com::sun::star::io::IOException, 106 ::com::sun::star::uno::RuntimeException); 107 virtual void SAL_CALL flush( ) throw( 108 ::com::sun::star::io::IOException, 109 ::com::sun::star::uno::RuntimeException); 110 virtual void SAL_CALL close( ) 111 throw(::com::sun::star::io::IOException, 112 ::com::sun::star::uno::RuntimeException); 113 virtual ::rtl::OUString SAL_CALL getDescription( ) 114 throw(::com::sun::star::uno::RuntimeException); 115 116 117 // XConnectionBroadcaster 118 virtual void SAL_CALL addStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener) 119 throw(::com::sun::star::uno::RuntimeException); 120 virtual void SAL_CALL removeStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener) 121 throw(::com::sun::star::uno::RuntimeException); 122 123 public: 124 void completeConnectionString(); 125 126 ::osl::ConnectorSocket m_socket; 127 ::osl::SocketAddr m_addr; 128 oslInterlockedCount m_nStatus; 129 ::rtl::OUString m_sDescription; 130 131 ::osl::Mutex _mutex; 132 sal_Bool _started; 133 sal_Bool _closed; 134 sal_Bool _error; 135 136 XStreamListener_hash_set _listeners; 137 }; 138 } 139 140 141