diff options
Diffstat (limited to 'io/source/connector')
-rw-r--r-- | io/source/connector/connector.component | 34 | ||||
-rw-r--r-- | io/source/connector/connector.cxx | 276 | ||||
-rw-r--r-- | io/source/connector/connector.hxx | 146 | ||||
-rw-r--r-- | io/source/connector/connectr.xml | 42 | ||||
-rw-r--r-- | io/source/connector/ctr_pipe.cxx | 120 | ||||
-rw-r--r-- | io/source/connector/ctr_socket.cxx | 257 | ||||
-rw-r--r-- | io/source/connector/makefile.mk | 81 |
7 files changed, 0 insertions, 956 deletions
diff --git a/io/source/connector/connector.component b/io/source/connector/connector.component deleted file mode 100644 index 95fa72aa5..000000000 --- a/io/source/connector/connector.component +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!--********************************************************************** -* -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* Copyright 2000, 2010 Oracle and/or its affiliates. -* -* OpenOffice.org - a multi-platform office productivity suite -* -* This file is part of OpenOffice.org. -* -* OpenOffice.org is free software: you can redistribute it and/or modify -* it under the terms of the GNU Lesser General Public License version 3 -* only, as published by the Free Software Foundation. -* -* OpenOffice.org is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Lesser General Public License version 3 for more details -* (a copy is included in the LICENSE file that accompanied this code). -* -* You should have received a copy of the GNU Lesser General Public License -* version 3 along with OpenOffice.org. If not, see -* <http://www.openoffice.org/license.html> -* for a copy of the LGPLv3 License. -* -**********************************************************************--> - -<component loader="com.sun.star.loader.SharedLibrary" - xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.comp.io.Connector"> - <service name="com.sun.star.connection.Connector"/> - </implementation> -</component> diff --git a/io/source/connector/connector.cxx b/io/source/connector/connector.cxx deleted file mode 100644 index 4d86512bb..000000000 --- a/io/source/connector/connector.cxx +++ /dev/null @@ -1,276 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_io.hxx" -#include <osl/mutex.hxx> -#include "osl/security.hxx" - -#include <uno/mapping.hxx> - -#include <cppuhelper/factory.hxx> -#include <cppuhelper/implbase2.hxx> -#include <cppuhelper/implementationentry.hxx> -#include "cppuhelper/unourl.hxx" -#include "rtl/malformeduriexception.hxx" - -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/connection/XConnector.hpp> - -#include "connector.hxx" - -#define IMPLEMENTATION_NAME "com.sun.star.comp.io.Connector" -#define SERVICE_NAME "com.sun.star.connection.Connector" - -using namespace ::osl; -using namespace ::rtl; -using namespace ::cppu; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::registry; -using namespace ::com::sun::star::connection; - -namespace stoc_connector -{ - rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT; - - class OConnector : public WeakImplHelper2< XConnector, XServiceInfo > - { - Reference< XMultiComponentFactory > _xSMgr; - Reference< XComponentContext > _xCtx; - public: - OConnector(const Reference< XComponentContext > &xCtx); - ~OConnector(); - // Methods - virtual Reference< XConnection > SAL_CALL connect( - const OUString& sConnectionDescription ) - throw( NoConnectException, ConnectionSetupException, RuntimeException); - - public: // XServiceInfo - virtual OUString SAL_CALL getImplementationName() throw(); - virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw(); - virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(); - }; - - OConnector::OConnector(const Reference< XComponentContext > &xCtx) - : _xSMgr( xCtx->getServiceManager() ) - , _xCtx( xCtx ) - { - g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); - } - - OConnector::~OConnector() - { - g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); - } - - Reference< XConnection > SAL_CALL OConnector::connect( const OUString& sConnectionDescription ) - throw( NoConnectException, ConnectionSetupException, RuntimeException) - { - OSL_TRACE( - "connector %s\n", - OUStringToOString( - sConnectionDescription, RTL_TEXTENCODING_ASCII_US).getStr()); - - // split string into tokens - try - { - cppu::UnoUrlDescriptor aDesc(sConnectionDescription); - - Reference< XConnection > r; - if (aDesc.getName().equalsAsciiL(RTL_CONSTASCII_STRINGPARAM( - "pipe"))) - { - rtl::OUString aName( - aDesc.getParameter( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("name")))); - - PipeConnection *pConn = new PipeConnection( sConnectionDescription ); - - if( pConn->m_pipe.create( aName.pData, osl_Pipe_OPEN, osl::Security() ) ) - { - r = Reference < XConnection > ( (XConnection * ) pConn ); - } - else - { - OUString sMessage = OUString(RTL_CONSTASCII_USTRINGPARAM("Connector : couldn't connect to pipe ")); - sMessage += aName; - sMessage += OUString(RTL_CONSTASCII_USTRINGPARAM("(")); - sMessage += OUString::valueOf( (sal_Int32 ) pConn->m_pipe.getError() ); - sMessage += OUString(RTL_CONSTASCII_USTRINGPARAM(")")); - delete pConn; - throw NoConnectException( sMessage ,Reference< XInterface > () ); - } - } - else if (aDesc.getName().equalsAsciiL(RTL_CONSTASCII_STRINGPARAM( - "socket"))) - { - rtl::OUString aHost; - if (aDesc.hasParameter( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("host")))) - aHost = aDesc.getParameter( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("host"))); - else - aHost = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( - "localhost")); - sal_uInt16 nPort = static_cast< sal_uInt16 >( - aDesc.getParameter( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("port"))). - toInt32()); - bool bTcpNoDelay - = aDesc.getParameter( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( - "tcpnodelay"))).toInt32() != 0; - - SocketConnection *pConn = new SocketConnection( sConnectionDescription); - - SocketAddr AddrTarget( aHost.pData, nPort ); - if(pConn->m_socket.connect(AddrTarget) != osl_Socket_Ok) - { - OUString sMessage = OUString(RTL_CONSTASCII_USTRINGPARAM("Connector : couldn't connect to socket (")); - OUString sError = pConn->m_socket.getErrorAsString(); - sMessage += sError; - sMessage += OUString(RTL_CONSTASCII_USTRINGPARAM(")")); - delete pConn; - throw NoConnectException( sMessage, Reference < XInterface > () ); - } - if( bTcpNoDelay ) - { - sal_Int32 nTcpNoDelay = sal_True; - pConn->m_socket.setOption( osl_Socket_OptionTcpNoDelay , &nTcpNoDelay, - sizeof( nTcpNoDelay ) , osl_Socket_LevelTcp ); - } - pConn->completeConnectionString(); - r = Reference< XConnection > ( (XConnection * ) pConn ); - } - else - { - OUString delegatee = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector.")); - delegatee += aDesc.getName(); - - OSL_TRACE( - "connector: trying to get service %s\n", - OUStringToOString( - delegatee, RTL_TEXTENCODING_ASCII_US).getStr()); - Reference<XConnector> xConnector( - _xSMgr->createInstanceWithContext(delegatee, _xCtx), UNO_QUERY ); - - if(!xConnector.is()) - { - OUString message(RTL_CONSTASCII_USTRINGPARAM("Connector: unknown delegatee ")); - message += delegatee; - - throw ConnectionSetupException(message, Reference<XInterface>()); - } - - sal_Int32 index = sConnectionDescription.indexOf((sal_Unicode) ','); - - r = xConnector->connect(sConnectionDescription.copy(index + 1).trim()); - } - return r; - } - catch (rtl::MalformedUriException & rEx) - { - throw ConnectionSetupException(rEx.getMessage(), - Reference< XInterface > ()); - } - } - - Sequence< OUString > connector_getSupportedServiceNames() - { - Sequence< OUString > seqNames(1); - seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICE_NAME)); - return seqNames; - } - - OUString connector_getImplementationName() - { - return OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); - } - - OUString OConnector::getImplementationName() throw() - { - return connector_getImplementationName(); - } - - sal_Bool OConnector::supportsService(const OUString& ServiceName) throw() - { - Sequence< OUString > aSNL = getSupportedServiceNames(); - const OUString * pArray = aSNL.getConstArray(); - - for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) - if( pArray[i] == ServiceName ) - return sal_True; - - return sal_False; - } - - Sequence< OUString > OConnector::getSupportedServiceNames(void) throw() - { - return connector_getSupportedServiceNames(); - } - - Reference< XInterface > SAL_CALL connector_CreateInstance( const Reference< XComponentContext > & xCtx) - { - return Reference < XInterface >( ( OWeakObject * ) new OConnector(xCtx) ); - } - - -} -using namespace stoc_connector; - -static struct ImplementationEntry g_entries[] = -{ - { - connector_CreateInstance, connector_getImplementationName , - connector_getSupportedServiceNames, createSingleComponentFactory , - &g_moduleCount.modCnt , 0 - }, - { 0, 0, 0, 0, 0, 0 } -}; - -extern "C" -{ - -sal_Bool SAL_CALL component_canUnload( TimeValue *pTime ) -{ - return g_moduleCount.canUnload( &g_moduleCount , pTime ); -} - -//================================================================================================== -SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( - const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) -{ - return component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries ); -} - -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/io/source/connector/connector.hxx b/io/source/connector/connector.hxx deleted file mode 100644 index 3ec7368aa..000000000 --- a/io/source/connector/connector.hxx +++ /dev/null @@ -1,146 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#include <rtl/unload.h> - -#include <cppuhelper/implbase1.hxx> -#include <cppuhelper/implbase2.hxx> - -#include <com/sun/star/connection/XConnection.hpp> -#include <com/sun/star/connection/XConnectionBroadcaster.hpp> - -#include <boost/unordered_set.hpp> -# include <osl/socket.hxx> -# include <osl/pipe.hxx> - -namespace stoc_connector -{ - extern rtl_StandardModuleCount g_moduleCount; - - template<class T> - struct ReferenceHash - { - size_t operator () (const ::com::sun::star::uno::Reference<T> & ref) const - { - return (size_t)ref.get(); - } - }; - - template<class T> - struct ReferenceEqual - { - sal_Bool operator () (const ::com::sun::star::uno::Reference<T> & op1, - const ::com::sun::star::uno::Reference<T> & op2) const - { - return op1.get() == op2.get(); - } - }; - - typedef ::boost::unordered_set< ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>, - ReferenceHash< ::com::sun::star::io::XStreamListener>, - ReferenceEqual< ::com::sun::star::io::XStreamListener> > - XStreamListener_hash_set; - - class PipeConnection : - public ::cppu::WeakImplHelper1< ::com::sun::star::connection::XConnection > - - { - public: - PipeConnection( const ::rtl::OUString &sConnectionDescription ); - virtual ~PipeConnection(); - - virtual sal_Int32 SAL_CALL read( ::com::sun::star::uno::Sequence< sal_Int8 >& aReadBytes, - sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData ) - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL flush( ) throw( - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL close( ) - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getDescription( ) - throw(::com::sun::star::uno::RuntimeException); - public: - ::osl::StreamPipe m_pipe; - oslInterlockedCount m_nStatus; - ::rtl::OUString m_sDescription; - }; - - class SocketConnection : - public ::cppu::WeakImplHelper2< ::com::sun::star::connection::XConnection, ::com::sun::star::connection::XConnectionBroadcaster > - - { - public: - SocketConnection( const ::rtl::OUString & sConnectionDescription ); - virtual ~SocketConnection(); - - virtual sal_Int32 SAL_CALL read( ::com::sun::star::uno::Sequence< sal_Int8 >& aReadBytes, - sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL write( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData ) - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL flush( ) throw( - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL close( ) - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getDescription( ) - throw(::com::sun::star::uno::RuntimeException); - - - // XConnectionBroadcaster - virtual void SAL_CALL addStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener) - throw(::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeStreamListener(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener>& aListener) - throw(::com::sun::star::uno::RuntimeException); - - public: - void completeConnectionString(); - - ::osl::ConnectorSocket m_socket; - ::osl::SocketAddr m_addr; - oslInterlockedCount m_nStatus; - ::rtl::OUString m_sDescription; - - ::osl::Mutex _mutex; - sal_Bool _started; - sal_Bool _closed; - sal_Bool _error; - - XStreamListener_hash_set _listeners; - }; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/io/source/connector/connectr.xml b/io/source/connector/connectr.xml deleted file mode 100644 index 5f324f7b9..000000000 --- a/io/source/connector/connectr.xml +++ /dev/null @@ -1,42 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE module-description PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "module-description.dtd"> -<module-description xmlns:xlink="http://www.w3.org/1999/xlink"> - <module-name> connector.uno </module-name> - <component-description> - <author> Joerg Budischewski </author> - <name> com.sun.star.comp.io.Connector </name> - <description> - This component allows - to establish a connection to another process. - </description> - <loader-name> com.sun.star.loader.SharedLibrary </loader-name> - <language> c++ </language> - <status value="final"/> - <supported-service> com.sun.star.connection.Connector </supported-service> - <service-dependency> ... </service-dependency> - <type> com.sun.star.connection.XConnector </type> - <type> com.sun.star.connection.XConnectionBroadcaster </type> - <type> com.sun.star.io.UnexpectedEOFException </type> - <type> com.sun.star.io.WrongFormatException </type> - <type> com.sun.star.lang.XComponent </type> - <type> com.sun.star.lang.XMultiServiceFactory </type> - <type> com.sun.star.lang.XSingleServiceFactory </type> - <type> com.sun.star.lang.XServiceInfo </type> - <type> com.sun.star.lang.XTypeProvider </type> - <type> com.sun.star.lang.IllegalArgumentException </type> - <type> com.sun.star.registry.XRegistryKey </type> - <type> com.sun.star.registry.XImplementationRegistration </type> - <type> com.sun.star.test.XSimpleTest </type> - <type> com.sun.star.lang.XSingleComponentFactory </type> - <type> com.sun.star.uno.XComponentContext </type> - <type> com.sun.star.uno.TypeClass </type> - <type> com.sun.star.uno.XWeak </type> - <type> com.sun.star.uno.XAggregation </type> - </component-description> - <project-build-dependency> cppuhelper </project-build-dependency> - <project-build-dependency> cppu </project-build-dependency> - <project-build-dependency> sal </project-build-dependency> - <runtime-module-dependency> cppuhelper2 </runtime-module-dependency> - <runtime-module-dependency> cppu2 </runtime-module-dependency> - <runtime-module-dependency> sal2 </runtime-module-dependency> -</module-description> diff --git a/io/source/connector/ctr_pipe.cxx b/io/source/connector/ctr_pipe.cxx deleted file mode 100644 index 8a347a7a7..000000000 --- a/io/source/connector/ctr_pipe.cxx +++ /dev/null @@ -1,120 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_io.hxx" - -#include "connector.hxx" - -using namespace ::osl; -using namespace ::rtl; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::io; -using namespace ::com::sun::star::connection; - - -namespace stoc_connector { - - PipeConnection::PipeConnection( const OUString & sConnectionDescription ) : - m_nStatus( 0 ), - m_sDescription( sConnectionDescription ) - { - g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); - // make it unique - m_sDescription += OUString(RTL_CONSTASCII_USTRINGPARAM(",uniqueValue=")); - m_sDescription += OUString::valueOf( - sal::static_int_cast< sal_Int64 >( - reinterpret_cast< sal_IntPtr >(&m_pipe)), - 10 ); - } - - PipeConnection::~PipeConnection() - { - g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); - } - - sal_Int32 PipeConnection::read( Sequence < sal_Int8 > & aReadBytes , sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException) - { - if( ! m_nStatus ) - { - if( aReadBytes.getLength() != nBytesToRead ) - { - aReadBytes.realloc( nBytesToRead ); - } - return m_pipe.read( aReadBytes.getArray() , aReadBytes.getLength() ); - } - else { - throw IOException(); - } - } - - void PipeConnection::write( const Sequence < sal_Int8 > &seq ) - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException) - { - if( ! m_nStatus ) - { - if( m_pipe.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() ) - { - throw IOException(); - } - } - else { - throw IOException(); - } - } - - void PipeConnection::flush( ) - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException) - { - - } - - void PipeConnection::close() - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException) - { - // ensure that close is called only once - if(1 == osl_incrementInterlockedCount( (&m_nStatus) ) ) - { - m_pipe.close(); - } - } - - OUString PipeConnection::getDescription() - throw( ::com::sun::star::uno::RuntimeException) - { - return m_sDescription; - } - -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/io/source/connector/ctr_socket.cxx b/io/source/connector/ctr_socket.cxx deleted file mode 100644 index 8d802eb92..000000000 --- a/io/source/connector/ctr_socket.cxx +++ /dev/null @@ -1,257 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_io.hxx" - -#include "connector.hxx" -#include <rtl/ustrbuf.hxx> -#include <algorithm> - -using namespace ::osl; -using namespace ::rtl; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::io; -using namespace ::com::sun::star::connection; - - -namespace stoc_connector { - template<class T> - void notifyListeners(SocketConnection * pCon, sal_Bool * notified, T t) - { - XStreamListener_hash_set listeners; - - { - ::osl::MutexGuard guard(pCon->_mutex); - if(!*notified) - { - *notified = sal_True; - listeners = pCon->_listeners; - } - } - - ::std::for_each(listeners.begin(), listeners.end(), t); - } - - - static void callStarted(Reference<XStreamListener> xStreamListener) - { - xStreamListener->started(); - } - - struct callError { - const Any & any; - - callError(const Any & any); - - void operator () (Reference<XStreamListener> xStreamListener); - }; - - callError::callError(const Any & aAny) - : any(aAny) - { - } - - void callError::operator () (Reference<XStreamListener> xStreamListener) - { - xStreamListener->error(any); - } - - static void callClosed(Reference<XStreamListener> xStreamListener) - { - xStreamListener->closed(); - } - - - SocketConnection::SocketConnection( const OUString &sConnectionDescription ) : - m_nStatus( 0 ), - m_sDescription( sConnectionDescription ), - _started(sal_False), - _closed(sal_False), - _error(sal_False) - { - // make it unique - g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); - m_sDescription += OUString( RTL_CONSTASCII_USTRINGPARAM( ",uniqueValue=" ) ); - m_sDescription += OUString::valueOf( - sal::static_int_cast< sal_Int64 >( - reinterpret_cast< sal_IntPtr >(&m_socket)), - 10 ); - } - - SocketConnection::~SocketConnection() - { - g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); - } - - void SocketConnection::completeConnectionString() - { - sal_Int32 nPort; - - nPort = m_socket.getPeerPort(); - - OUStringBuffer buf( 256 ); - buf.appendAscii( ",peerPort=" ); - buf.append( (sal_Int32) nPort ); - buf.appendAscii( ",peerHost=" ); - buf.append( m_socket.getPeerHost() ); - - buf.appendAscii( ",localPort=" ); - buf.append( (sal_Int32) nPort ); - buf.appendAscii( ",localHost=" ); - buf.append( m_socket.getLocalHost( ) ); - - m_sDescription += buf.makeStringAndClear(); - } - - sal_Int32 SocketConnection::read( Sequence < sal_Int8 > & aReadBytes , sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException) - { - if( ! m_nStatus ) - { - notifyListeners(this, &_started, callStarted); - - if( aReadBytes.getLength() != nBytesToRead ) - { - aReadBytes.realloc( nBytesToRead ); - } - sal_Int32 i = m_socket.read( aReadBytes.getArray() , aReadBytes.getLength() ); - - if(i != nBytesToRead && m_socket.getError() != osl_Socket_E_None) - { - OUString message(RTL_CONSTASCII_USTRINGPARAM("ctr_socket.cxx:SocketConnection::read: error - ")); - message += m_socket.getErrorAsString(); - - IOException ioException(message, Reference<XInterface>(static_cast<XConnection *>(this))); - - Any any; - any <<= ioException; - - notifyListeners(this, &_error, callError(any)); - - throw ioException; - } - - return i; - } - else - { - OUString message(RTL_CONSTASCII_USTRINGPARAM("ctr_socket.cxx:SocketConnection::read: error - connection already closed")); - - IOException ioException(message, Reference<XInterface>(static_cast<XConnection *>(this))); - - Any any; - any <<= ioException; - - notifyListeners(this, &_error, callError(any)); - - throw ioException; - } - } - - void SocketConnection::write( const Sequence < sal_Int8 > &seq ) - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException) - { - if( ! m_nStatus ) - { - if( m_socket.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() ) - { - OUString message(RTL_CONSTASCII_USTRINGPARAM("ctr_socket.cxx:SocketConnection::write: error - ")); - message += m_socket.getErrorAsString(); - - IOException ioException(message, Reference<XInterface>(static_cast<XConnection *>(this))); - - Any any; - any <<= ioException; - - notifyListeners(this, &_error, callError(any)); - - throw ioException; - } - } - else - { - OUString message(RTL_CONSTASCII_USTRINGPARAM("ctr_socket.cxx:SocketConnection::write: error - connection already closed")); - - IOException ioException(message, Reference<XInterface>(static_cast<XConnection *>(this))); - - Any any; - any <<= ioException; - - notifyListeners(this, &_error, callError(any)); - - throw ioException; - } - } - - void SocketConnection::flush( ) - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException) - { - - } - - void SocketConnection::close() - throw(::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException) - { - // ensure that close is called only once - if( 1 == osl_incrementInterlockedCount( (&m_nStatus) ) ) - { - m_socket.shutdown(); - notifyListeners(this, &_closed, callClosed); - } - } - - OUString SocketConnection::getDescription() - throw( ::com::sun::star::uno::RuntimeException) - { - return m_sDescription; - } - - - - // XConnectionBroadcaster - void SAL_CALL SocketConnection::addStreamListener(const Reference<XStreamListener> & aListener) throw(RuntimeException) - { - MutexGuard guard(_mutex); - - _listeners.insert(aListener); - } - - void SAL_CALL SocketConnection::removeStreamListener(const Reference<XStreamListener> & aListener) throw(RuntimeException) - { - MutexGuard guard(_mutex); - - _listeners.erase(aListener); - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/io/source/connector/makefile.mk b/io/source/connector/makefile.mk deleted file mode 100644 index e3a67abe6..000000000 --- a/io/source/connector/makefile.mk +++ /dev/null @@ -1,81 +0,0 @@ -#************************************************************************* -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# Copyright 2000, 2010 Oracle and/or its affiliates. -# -# OpenOffice.org - a multi-platform office productivity suite -# -# This file is part of OpenOffice.org. -# -# OpenOffice.org is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# only, as published by the Free Software Foundation. -# -# OpenOffice.org is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License version 3 for more details -# (a copy is included in the LICENSE file that accompanied this code). -# -# You should have received a copy of the GNU Lesser General Public License -# version 3 along with OpenOffice.org. If not, see -# <http://www.openoffice.org/license.html> -# for a copy of the LGPLv3 License. -# -#************************************************************************* - -PRJ=..$/.. - -PRJNAME=io -TARGET = connector.uno -ENABLE_EXCEPTIONS=TRUE -NO_BSYMBOLIC=TRUE -COMP1TYPELIST = connectr -COMPRDB=$(SOLARBINDIR)$/udkapi.rdb - -# --- Settings ----------------------------------------------------- -.INCLUDE : settings.mk -.IF "$(L10N_framework)"=="" -DLLPRE = -# ------------------------------------------------------------------ - -UNOUCRDEP=$(SOLARBINDIR)$/udkapi.rdb -UNOUCRRDB=$(SOLARBINDIR)$/udkapi.rdb -UNOUCROUT=$(OUT)$/inc$/connector -INCPRE+= $(UNOUCROUT) - - -SLOFILES= \ - $(SLO)$/connector.obj\ - $(SLO)$/ctr_pipe.obj\ - $(SLO)$/ctr_socket.obj - -SHL1TARGET= $(TARGET) -SHL1VERSIONMAP = $(SOLARENV)/src/unloadablecomponent.map -SHL1RPATH=URELIB - -SHL1STDLIBS= \ - $(SALLIB) \ - $(CPPULIB) \ - $(CPPUHELPERLIB) - -SHL1DEPN= -SHL1IMPLIB= i$(TARGET) -SHL1LIBS= $(SLB)$/$(TARGET).lib -SHL1DEF= $(MISC)$/$(SHL1TARGET).def - -DEF1NAME= $(SHL1TARGET) - -# --- Targets ------------------------------------------------------ -.ENDIF # L10N_framework - -.INCLUDE : target.mk - -ALLTAR : $(MISC)/connector.component - -$(MISC)/connector.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \ - connector.component - $(XSLTPROC) --nonet --stringparam uri \ - '$(COMPONENTPREFIX_URE_NATIVE)$(SHL1TARGETN:f)' -o $@ \ - $(SOLARENV)/bin/createcomponent.xslt connector.component |