summaryrefslogtreecommitdiff
path: root/io/source/connector
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2020-07-13 20:00:37 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-07-14 10:27:34 +0200
commitd1038da54d02f39019b47cffcbf5f94b8cfbcbce (patch)
treeb217e1d93369c0b1e869b08acb15ffbaca0715ce /io/source/connector
parent332e805dad96c5a06b1b8aeea159d17f4abb302a (diff)
io: create instances with uno constructors
See tdf#74608 for motivation. Change-Id: Ic5942f00147e4024ffc3d5880cf3c7462bcc14de Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98678 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'io/source/connector')
-rw-r--r--io/source/connector/connector.cxx190
1 files changed, 89 insertions, 101 deletions
diff --git a/io/source/connector/connector.cxx b/io/source/connector/connector.cxx
index f5b77a43cb7d..c6f01e130814 100644
--- a/io/source/connector/connector.cxx
+++ b/io/source/connector/connector.cxx
@@ -31,7 +31,6 @@
#include <com/sun/star/connection/XConnector.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
-#include <services.hxx>
#include "connector.hxx"
#define IMPLEMENTATION_NAME "com.sun.star.comp.io.Connector"
@@ -43,9 +42,7 @@ using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::connection;
-namespace stoc_connector
-{
- namespace {
+namespace {
class OConnector : public WeakImplHelper< XConnector, XServiceInfo >
{
@@ -64,128 +61,119 @@ namespace stoc_connector
virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
};
- }
+}
- OConnector::OConnector(const Reference< XComponentContext > &xCtx)
- : _xSMgr( xCtx->getServiceManager() )
- , _xCtx( xCtx )
- {}
+OConnector::OConnector(const Reference< XComponentContext > &xCtx)
+ : _xSMgr( xCtx->getServiceManager() )
+ , _xCtx( xCtx )
+{}
- Reference< XConnection > SAL_CALL OConnector::connect( const OUString& sConnectionDescription )
+Reference< XConnection > SAL_CALL OConnector::connect( const OUString& sConnectionDescription )
+{
+ // split string into tokens
+ try
{
- // split string into tokens
- try
+ cppu::UnoUrlDescriptor aDesc(sConnectionDescription);
+
+ Reference< XConnection > r;
+ if ( aDesc.getName() == "pipe" )
{
- cppu::UnoUrlDescriptor aDesc(sConnectionDescription);
+ OUString aName(aDesc.getParameter("name"));
- Reference< XConnection > r;
- if ( aDesc.getName() == "pipe" )
- {
- OUString aName(aDesc.getParameter("name"));
-
- std::unique_ptr<PipeConnection> pConn(new PipeConnection( sConnectionDescription ));
-
- if( pConn->m_pipe.create( aName.pData, osl_Pipe_OPEN, osl::Security() ) )
- {
- r.set( static_cast<XConnection *>(pConn.release()) );
- }
- else
- {
- OUString const sMessage(
- "Connector : couldn't connect to pipe \"" + aName + "\": "
- + OUString::number(pConn->m_pipe.getError()));
- SAL_WARN("io.connector", sMessage);
- throw NoConnectException( sMessage );
- }
- }
- else if ( aDesc.getName() == "socket" )
+ std::unique_ptr<stoc_connector::PipeConnection> pConn(new stoc_connector::PipeConnection( sConnectionDescription ));
+
+ if( pConn->m_pipe.create( aName.pData, osl_Pipe_OPEN, osl::Security() ) )
{
- OUString aHost;
- if (aDesc.hasParameter("host"))
- aHost = aDesc.getParameter("host");
- else
- aHost = "localhost";
- sal_uInt16 nPort = static_cast< sal_uInt16 >(
- aDesc.getParameter("port").
- toInt32());
- bool bTcpNoDelay
- = aDesc.getParameter("tcpnodelay").toInt32() != 0;
-
- std::unique_ptr<SocketConnection> pConn(new SocketConnection( sConnectionDescription));
-
- SocketAddr AddrTarget( aHost.pData, nPort );
- if(pConn->m_socket.connect(AddrTarget) != osl_Socket_Ok)
- {
- OUString sMessage("Connector : couldn't connect to socket (");
- OUString sError = pConn->m_socket.getErrorAsString();
- sMessage += sError + ")";
- throw NoConnectException( sMessage );
- }
- // we enable tcpNoDelay for loopback connections because
- // it can make a significant speed difference on linux boxes.
- if( bTcpNoDelay || aHost == "localhost" || aHost.startsWith("127.0.0.") )
- {
- sal_Int32 nTcpNoDelay = sal_Int32(true);
- pConn->m_socket.setOption( osl_Socket_OptionTcpNoDelay , &nTcpNoDelay,
- sizeof( nTcpNoDelay ) , osl_Socket_LevelTcp );
- }
- pConn->completeConnectionString();
r.set( static_cast<XConnection *>(pConn.release()) );
}
else
{
- OUString delegatee= "com.sun.star.connection.Connector." + aDesc.getName();
-
- Reference<XConnector> xConnector(
- _xSMgr->createInstanceWithContext(delegatee, _xCtx), UNO_QUERY );
-
- if(!xConnector.is())
- throw ConnectionSetupException("Connector: unknown delegatee " + delegatee);
+ OUString const sMessage(
+ "Connector : couldn't connect to pipe \"" + aName + "\": "
+ + OUString::number(pConn->m_pipe.getError()));
+ SAL_WARN("io.connector", sMessage);
+ throw NoConnectException( sMessage );
+ }
+ }
+ else if ( aDesc.getName() == "socket" )
+ {
+ OUString aHost;
+ if (aDesc.hasParameter("host"))
+ aHost = aDesc.getParameter("host");
+ else
+ aHost = "localhost";
+ sal_uInt16 nPort = static_cast< sal_uInt16 >(
+ aDesc.getParameter("port").
+ toInt32());
+ bool bTcpNoDelay
+ = aDesc.getParameter("tcpnodelay").toInt32() != 0;
- sal_Int32 index = sConnectionDescription.indexOf(',');
+ std::unique_ptr<stoc_connector::SocketConnection> pConn(new stoc_connector::SocketConnection( sConnectionDescription));
- r = xConnector->connect(sConnectionDescription.copy(index + 1).trim());
+ SocketAddr AddrTarget( aHost.pData, nPort );
+ if(pConn->m_socket.connect(AddrTarget) != osl_Socket_Ok)
+ {
+ OUString sMessage("Connector : couldn't connect to socket (");
+ OUString sError = pConn->m_socket.getErrorAsString();
+ sMessage += sError + ")";
+ throw NoConnectException( sMessage );
+ }
+ // we enable tcpNoDelay for loopback connections because
+ // it can make a significant speed difference on linux boxes.
+ if( bTcpNoDelay || aHost == "localhost" || aHost.startsWith("127.0.0.") )
+ {
+ sal_Int32 nTcpNoDelay = sal_Int32(true);
+ pConn->m_socket.setOption( osl_Socket_OptionTcpNoDelay , &nTcpNoDelay,
+ sizeof( nTcpNoDelay ) , osl_Socket_LevelTcp );
}
- return r;
+ pConn->completeConnectionString();
+ r.set( static_cast<XConnection *>(pConn.release()) );
}
- catch (const rtl::MalformedUriException & rEx)
+ else
{
- throw ConnectionSetupException(rEx.getMessage());
- }
- }
+ OUString delegatee= "com.sun.star.connection.Connector." + aDesc.getName();
- Sequence< OUString > connector_getSupportedServiceNames()
- {
- Sequence< OUString > seqNames { SERVICE_NAME };
- return seqNames;
- }
+ Reference<XConnector> xConnector(
+ _xSMgr->createInstanceWithContext(delegatee, _xCtx), UNO_QUERY );
- OUString connector_getImplementationName()
- {
- return IMPLEMENTATION_NAME;
- }
+ if(!xConnector.is())
+ throw ConnectionSetupException("Connector: unknown delegatee " + delegatee);
- OUString OConnector::getImplementationName()
- {
- return connector_getImplementationName();
- }
+ sal_Int32 index = sConnectionDescription.indexOf(',');
- sal_Bool OConnector::supportsService(const OUString& ServiceName)
- {
- return cppu::supportsService(this, ServiceName);
+ r = xConnector->connect(sConnectionDescription.copy(index + 1).trim());
+ }
+ return r;
}
-
- Sequence< OUString > OConnector::getSupportedServiceNames()
+ catch (const rtl::MalformedUriException & rEx)
{
- return connector_getSupportedServiceNames();
+ throw ConnectionSetupException(rEx.getMessage());
}
+}
- Reference< XInterface > connector_CreateInstance( const Reference< XComponentContext > & xCtx)
- {
- return Reference < XInterface >( static_cast<OWeakObject *>(new OConnector(xCtx)) );
- }
+OUString OConnector::getImplementationName()
+{
+ return IMPLEMENTATION_NAME;
+}
+sal_Bool OConnector::supportsService(const OUString& ServiceName)
+{
+ return cppu::supportsService(this, ServiceName);
+}
+
+Sequence< OUString > OConnector::getSupportedServiceNames()
+{
+ return { SERVICE_NAME };
+}
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+io_OConnector_get_implementation(
+ css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
+{
+ return cppu::acquire(new OConnector(context));
}
+
+
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */