20#include <osl/security.hxx>
26#include <rtl/malformeduriexception.hxx>
30#include <com/sun/star/lang/XServiceInfo.hpp>
31#include <com/sun/star/connection/ConnectionSetupException.hpp>
32#include <com/sun/star/connection/NoConnectException.hpp>
33#include <com/sun/star/connection/XConnector.hpp>
34#include <com/sun/star/uno/XComponentContext.hpp>
39using namespace ::
cppu;
46 class OConnector :
public WeakImplHelper< XConnector, XServiceInfo >
48 Reference< XMultiComponentFactory >
_xSMgr;
49 Reference< XComponentContext >
_xCtx;
51 explicit OConnector(
const Reference< XComponentContext > &xCtx);
54 virtual Reference< XConnection > SAL_CALL connect(
55 const OUString& sConnectionDescription )
override;
65OConnector::OConnector(
const Reference< XComponentContext > &xCtx)
66 :
_xSMgr( xCtx->getServiceManager() )
70Reference< XConnection > SAL_CALL OConnector::connect(
const OUString& sConnectionDescription )
77 Reference< XConnection > r;
78 if ( aDesc.getName() ==
"pipe" )
80 OUString
aName(aDesc.getParameter(
"name"));
84 if( pConn->m_pipe.create(
aName.pData, osl_Pipe_OPEN, osl::Security() ) )
91 "Connector : couldn't connect to pipe \"" + aName +
"\": "
92 + OUString::number(pConn->m_pipe.getError()));
94 throw NoConnectException( sMessage );
97 else if ( aDesc.getName() ==
"socket" )
100 if (aDesc.hasParameter(
"host"))
101 aHost = aDesc.getParameter(
"host");
104 sal_uInt16 nPort =
static_cast< sal_uInt16
>(
105 aDesc.getParameter(
"port").
108 = aDesc.getParameter(
"tcpnodelay").toInt32() != 0;
112 SocketAddr AddrTarget( aHost.pData, nPort );
113 if(pConn->m_socket.connect(AddrTarget) != osl_Socket_Ok)
115 OUString
sMessage(
"Connector : couldn't connect to socket (");
116 OUString sError = pConn->m_socket.getErrorAsString();
118 throw NoConnectException( sMessage );
122 if( bTcpNoDelay || aHost ==
"localhost" || aHost.startsWith(
"127.0.0.") )
124 sal_Int32 nTcpNoDelay = sal_Int32(
true);
125 pConn->m_socket.setOption( osl_Socket_OptionTcpNoDelay , &nTcpNoDelay,
126 sizeof( nTcpNoDelay ) , osl_Socket_LevelTcp );
128 pConn->completeConnectionString();
133 OUString delegatee=
"com.sun.star.connection.Connector." + aDesc.getName();
135 Reference<XConnector> xConnector(
136 _xSMgr->createInstanceWithContext(delegatee, _xCtx), UNO_QUERY );
139 throw ConnectionSetupException(
"Connector: unknown delegatee " + delegatee);
141 sal_Int32
index = sConnectionDescription.indexOf(
',');
143 r = xConnector->connect(OUString(
o3tl::trim(sConnectionDescription.subView(index + 1))));
147 catch (
const rtl::MalformedUriException & rEx)
149 throw ConnectionSetupException(rEx.getMessage());
153OUString OConnector::getImplementationName()
155 return "com.sun.star.comp.io.Connector";
158sal_Bool OConnector::supportsService(
const OUString& ServiceName)
163Sequence< OUString > OConnector::getSupportedServiceNames()
165 return {
"com.sun.star.connection.Connector" };
168extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
170 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
172 return cppu::acquire(
new OConnector(context));
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * io_OConnector_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
#define SAL_WARN(area, stream)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)
sal_Int32 toInt32(std::u16string_view rStr)
Reference< XMultiComponentFactory > _xSMgr
Reference< XComponentContext > _xCtx