23#include <rtl/malformeduriexception.hxx>
25#include <com/sun/star/connection/AlreadyAcceptingException.hpp>
26#include <com/sun/star/connection/ConnectionSetupException.hpp>
27#include <com/sun/star/connection/XAcceptor.hpp>
28#include <com/sun/star/lang/IllegalArgumentException.hpp>
29#include <com/sun/star/lang/XServiceInfo.hpp>
30#include <com/sun/star/uno/XComponentContext.hpp>
38using namespace ::
cppu;
45 class OAcceptor :
public WeakImplHelper< XAcceptor, XServiceInfo >
48 explicit OAcceptor(
const Reference< XComponentContext > & xCtx);
49 virtual ~OAcceptor()
override;
52 virtual Reference< XConnection > SAL_CALL accept(
const OUString& sConnectionDescription )
override;
53 virtual void SAL_CALL stopAccepting( )
override;
61 std::unique_ptr<io_acceptor::PipeAcceptor> m_pPipe;
62 std::unique_ptr<io_acceptor::SocketAcceptor> m_pSocket;
64 OUString m_sLastDescription;
67 Reference< XMultiComponentFactory >
_xSMgr;
68 Reference< XComponentContext >
_xCtx;
69 Reference<XAcceptor> _xAcceptor;
74OAcceptor::OAcceptor(
const Reference< XComponentContext > & xCtx )
75 : m_bInAccept( false )
76 ,
_xSMgr( xCtx->getServiceManager() )
80OAcceptor::~OAcceptor()
89 BeingInAccept(
bool *pFlag,std::u16string_view sConnectionDescription )
93 throw AlreadyAcceptingException( OUString::Concat(
"AlreadyAcceptingException :") + sConnectionDescription );
104Reference< XConnection > OAcceptor::accept(
const OUString &sConnectionDescription )
107 struct BeingInAccept guard( &m_bInAccept, sConnectionDescription );
109 Reference< XConnection > r;
110 if( !m_sLastDescription.isEmpty() &&
111 m_sLastDescription != sConnectionDescription )
114 throw ConnectionSetupException(
"acceptor::accept called multiple times with different connection strings\n" );
117 if( m_sLastDescription.isEmpty() )
123 if ( aDesc.getName() ==
"pipe" )
144 else if ( aDesc.getName() ==
"socket" )
147 if (aDesc.hasParameter(
149 aHost = aDesc.getParameter(
153 sal_uInt16 nPort =
static_cast< sal_uInt16
>(
158 = aDesc.getParameter(
159 "tcpnodelay").toInt32() != 0;
162 aHost, nPort, bTcpNoDelay, sConnectionDescription));
179 OUString delegatee =
"com.sun.star.connection.Acceptor." + aDesc.getName();
180 _xAcceptor.set(
_xSMgr->createInstanceWithContext(delegatee, _xCtx), UNO_QUERY);
183 throw ConnectionSetupException(
"Acceptor: unknown delegatee " + delegatee);
186 catch (
const rtl::MalformedUriException & rEx)
188 throw IllegalArgumentException(
190 Reference< XInterface > (),
193 m_sLastDescription = sConnectionDescription;
198 r = m_pPipe->accept();
202 r = m_pSocket->accept();
206 r = _xAcceptor->accept(sConnectionDescription);
212void SAL_CALL OAcceptor::stopAccepting( )
214 std::unique_lock guard(
m_mutex );
218 m_pPipe->stopAccepting();
220 else if ( m_pSocket )
222 m_pSocket->stopAccepting();
224 else if( _xAcceptor.is() )
226 _xAcceptor->stopAccepting();
231OUString OAcceptor::getImplementationName()
233 return "com.sun.star.comp.io.Acceptor";
236sal_Bool OAcceptor::supportsService(
const OUString& ServiceName)
241Sequence< OUString > OAcceptor::getSupportedServiceNames()
243 return {
"com.sun.star.connection.Acceptor" };
246extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
248 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
250 return cppu::acquire(
new OAcceptor(context));
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * io_OAcceptor_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
sal_Int32 toInt32(std::u16string_view rStr)
Reference< XMultiComponentFactory > _xSMgr
Reference< XComponentContext > _xCtx