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