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 virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData ); 74 virtual void SAL_CALL flush( ); 75 virtual void SAL_CALL close( ); 76 virtual ::rtl::OUString SAL_CALL getDescription( ); 77 public: 78 ::osl::StreamPipe m_pipe; 79 oslInterlockedCount m_nStatus; 80 ::rtl::OUString m_sDescription; 81 }; 82 83 class SocketConnection : 84 public ::cppu::WeakImplHelper2< ::com::sun::star::connection::XConnection, ::com::sun::star::connection::XConnectionBroadcaster > 85 86 { 87 public: 88 SocketConnection( const ::rtl::OUString & sConnectionDescription ); 89 virtual ~SocketConnection(); 90 91 virtual sal_Int32 SAL_CALL read( ::com::sun::star::uno::Sequence< sal_Int8 >& aReadBytes, 92 sal_Int32 nBytesToRead ); 93 virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData ); 94 virtual void SAL_CALL flush( ); 95 virtual void SAL_CALL close( ); 96 virtual ::rtl::OUString SAL_CALL getDescription( ); 97 98 99 // XConnectionBroadcaster 100 virtual void SAL_CALL addStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener); 101 virtual void SAL_CALL removeStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener); 102 103 public: 104 void completeConnectionString(); 105 106 ::osl::ConnectorSocket m_socket; 107 ::osl::SocketAddr m_addr; 108 oslInterlockedCount m_nStatus; 109 ::rtl::OUString m_sDescription; 110 111 ::osl::Mutex _mutex; 112 sal_Bool _started; 113 sal_Bool _closed; 114 sal_Bool _error; 115 116 XStreamListener_hash_set _listeners; 117 }; 118 } 119