2012-07-11 17:44:41 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
2012-07-09 10:57:32 +01:00
|
|
|
#include <stdlib.h>
|
2012-07-12 22:10:33 +01:00
|
|
|
#include <algorithm>
|
2012-07-09 10:57:32 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2012-08-07 13:12:06 +02:00
|
|
|
#include "officecfg/Office/Common.hxx"
|
2012-07-17 23:03:31 +02:00
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
|
2012-07-09 12:20:45 +01:00
|
|
|
#include "sddll.hxx"
|
2012-07-09 15:53:03 +01:00
|
|
|
|
2012-08-02 11:28:38 +02:00
|
|
|
#include "DiscoveryService.hxx"
|
2012-07-19 18:43:18 +02:00
|
|
|
#include "ImagePreparer.hxx"
|
|
|
|
#include "Listener.hxx"
|
|
|
|
#include "Receiver.hxx"
|
2012-07-30 08:34:41 +02:00
|
|
|
#include "RemoteServer.hxx"
|
2012-07-18 22:04:09 +02:00
|
|
|
|
2012-07-09 10:57:32 +01:00
|
|
|
using namespace std;
|
2012-07-09 15:53:03 +01:00
|
|
|
using namespace sd;
|
2012-07-17 17:48:07 +02:00
|
|
|
using namespace ::com::sun::star;
|
2012-07-12 22:10:33 +01:00
|
|
|
using rtl::OString;
|
2012-08-10 17:20:16 +02:00
|
|
|
using namespace ::osl;
|
|
|
|
|
|
|
|
// struct ClientInfoInternal:
|
|
|
|
// ClientInfo
|
|
|
|
// {
|
|
|
|
// osl::StreamSocket mStreamSocket;
|
|
|
|
// rtl::OUString mPin;
|
|
|
|
// ClientInfoInternal( const rtl::OUString rName,
|
|
|
|
// const rtl::OUString rAddress,
|
|
|
|
// osl::StreamSocket &rSocket, rtl::OUString rPin ):
|
|
|
|
// ClientInfo( rName, rAddress ),
|
|
|
|
// mStreamSocket( rSocket ),
|
|
|
|
// mPin( rPin ) {}
|
|
|
|
// };
|
|
|
|
|
|
|
|
RemoteServer::RemoteServer() :
|
|
|
|
Thread( "RemoteServerThread" ),
|
|
|
|
mSocket(),
|
|
|
|
mDataMutex(),
|
|
|
|
mCommunicators(),
|
|
|
|
mAvailableClients()
|
2012-07-09 10:57:32 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-30 08:34:41 +02:00
|
|
|
RemoteServer::~RemoteServer()
|
2012-07-09 10:57:32 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-30 08:34:41 +02:00
|
|
|
void RemoteServer::execute()
|
2012-07-09 15:53:03 +01:00
|
|
|
{
|
2012-07-10 16:36:04 +01:00
|
|
|
osl::SocketAddr aAddr( "0", PORT );
|
2012-07-09 15:53:03 +01:00
|
|
|
if ( !mSocket.bind( aAddr ) )
|
|
|
|
{
|
|
|
|
// Error binding
|
|
|
|
}
|
|
|
|
|
2012-07-10 16:36:04 +01:00
|
|
|
if ( !mSocket.listen(3) )
|
2012-07-09 15:53:03 +01:00
|
|
|
{
|
|
|
|
// Error listening
|
|
|
|
}
|
|
|
|
while ( true )
|
|
|
|
{
|
2012-08-10 17:20:16 +02:00
|
|
|
StreamSocket aSocket;
|
2012-08-10 18:42:49 +02:00
|
|
|
if ( mSocket.acceptConnection( aSocket ) == osl_Socket_Error )
|
|
|
|
{
|
|
|
|
return; // Closed, or other issue.
|
|
|
|
}
|
|
|
|
BufferedStreamSocket *pSocket = new BufferedStreamSocket( aSocket);
|
|
|
|
OString aLine;
|
|
|
|
if ( pSocket->readLine( aLine)
|
|
|
|
&& aLine.equals( "LO_SERVER_CLIENT_PAIR" ) &&
|
|
|
|
pSocket->readLine( aLine ) )
|
|
|
|
{
|
|
|
|
OString aName( aLine );
|
|
|
|
|
|
|
|
if ( ! pSocket->readLine( aLine ) ) delete pSocket;
|
|
|
|
OString aPin( aLine );
|
|
|
|
|
|
|
|
SocketAddr aClientAddr;
|
|
|
|
pSocket->getPeerAddr( aClientAddr );
|
|
|
|
OUString aAddress = aClientAddr.getHostname();
|
|
|
|
|
2012-08-10 17:20:16 +02:00
|
|
|
MutexGuard aGuard( mDataMutex );
|
2012-08-10 18:42:49 +02:00
|
|
|
mAvailableClients.push_back( new ClientInfoInternal(
|
|
|
|
OStringToOUString( aName, RTL_TEXTENCODING_UTF8 ),
|
|
|
|
aAddress, pSocket, OStringToOUString( aPin,
|
|
|
|
RTL_TEXTENCODING_UTF8 ) ) );
|
|
|
|
|
|
|
|
// Read off any additional non-empty lines
|
|
|
|
do
|
|
|
|
{
|
|
|
|
pSocket->readLine( aLine );
|
|
|
|
}
|
|
|
|
while ( aLine.getLength() > 0 );
|
|
|
|
} else {
|
|
|
|
delete pSocket;
|
2012-08-07 09:29:35 +02:00
|
|
|
}
|
2012-07-09 15:53:03 +01:00
|
|
|
}
|
2012-07-09 12:20:45 +01:00
|
|
|
|
2012-07-09 15:53:03 +01:00
|
|
|
}
|
2012-07-09 12:20:45 +01:00
|
|
|
|
2012-08-10 17:20:16 +02:00
|
|
|
RemoteServer *sd::RemoteServer::spServer = NULL;
|
|
|
|
|
|
|
|
void RemoteServer::setup()
|
2012-07-19 13:02:03 +02:00
|
|
|
{
|
2012-08-10 17:20:16 +02:00
|
|
|
if (spServer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
spServer = new RemoteServer();
|
|
|
|
spServer->launch();
|
2012-07-19 13:02:03 +02:00
|
|
|
}
|
2012-07-17 16:44:46 +02:00
|
|
|
|
2012-08-10 17:20:16 +02:00
|
|
|
|
2012-07-30 08:34:41 +02:00
|
|
|
void RemoteServer::presentationStarted( const css::uno::Reference<
|
2012-08-10 17:20:16 +02:00
|
|
|
css::presentation::XSlideShowController > &rController )
|
2012-07-17 16:44:46 +02:00
|
|
|
{
|
2012-08-10 17:20:16 +02:00
|
|
|
if ( !spServer )
|
|
|
|
return;
|
|
|
|
MutexGuard aGuard( spServer->mDataMutex );
|
|
|
|
for ( vector<Communicator*>::const_iterator aIt = spServer->mCommunicators.begin();
|
|
|
|
aIt < spServer->mCommunicators.end(); aIt++ )
|
2012-07-18 16:14:52 +02:00
|
|
|
{
|
2012-08-10 17:20:16 +02:00
|
|
|
(*aIt)->presentationStarted( rController );
|
2012-07-18 16:14:52 +02:00
|
|
|
}
|
2012-07-17 16:44:46 +02:00
|
|
|
}
|
2012-07-30 08:34:41 +02:00
|
|
|
void RemoteServer::presentationStopped()
|
2012-07-20 12:02:54 +02:00
|
|
|
{
|
2012-08-10 17:20:16 +02:00
|
|
|
if ( !spServer )
|
|
|
|
return;
|
|
|
|
MutexGuard aGuard( spServer->mDataMutex );
|
|
|
|
for ( vector<Communicator*>::const_iterator aIt = spServer->mCommunicators.begin();
|
|
|
|
aIt < spServer->mCommunicators.end(); aIt++ )
|
2012-07-20 12:02:54 +02:00
|
|
|
{
|
2012-08-10 17:20:16 +02:00
|
|
|
(*aIt)->disposeListener();
|
2012-07-20 12:02:54 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-17 16:44:46 +02:00
|
|
|
|
2012-08-10 17:20:16 +02:00
|
|
|
void RemoteServer::removeCommunicator( Communicator* mCommunicator )
|
2012-07-09 17:26:27 +01:00
|
|
|
{
|
2012-08-10 17:20:16 +02:00
|
|
|
if ( !spServer )
|
|
|
|
return;
|
|
|
|
MutexGuard aGuard( spServer->mDataMutex );
|
|
|
|
for ( vector<Communicator*>::iterator aIt = spServer->mCommunicators.begin();
|
|
|
|
aIt < spServer->mCommunicators.end(); aIt++ )
|
|
|
|
{
|
|
|
|
if ( mCommunicator == *aIt )
|
|
|
|
{
|
|
|
|
spServer->mCommunicators.erase( aIt );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-07-09 17:26:27 +01:00
|
|
|
}
|
|
|
|
|
2012-08-10 17:20:16 +02:00
|
|
|
std::vector<ClientInfo*> RemoteServer::getClients()
|
2012-08-10 13:27:40 +02:00
|
|
|
{
|
2012-08-10 17:20:16 +02:00
|
|
|
if ( !spServer )
|
|
|
|
std::vector<ClientInfo*>();
|
|
|
|
MutexGuard aGuard( spServer->mDataMutex );
|
|
|
|
std::vector<ClientInfo*> aClients;
|
|
|
|
aClients.assign( spServer->mAvailableClients.begin(),
|
|
|
|
spServer->mAvailableClients.end() );
|
|
|
|
return aClients;
|
2012-08-10 13:27:40 +02:00
|
|
|
}
|
|
|
|
|
2012-08-10 18:42:49 +02:00
|
|
|
sal_Bool RemoteServer::connectClient( ClientInfo* pClient, rtl::OUString aPin )
|
2012-08-10 13:27:40 +02:00
|
|
|
{
|
2012-08-10 18:42:49 +02:00
|
|
|
if ( !spServer )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ClientInfoInternal *apClient = (ClientInfoInternal*) pClient;
|
|
|
|
if ( apClient->mPin.equals( aPin ) )
|
|
|
|
{
|
|
|
|
Communicator* pCommunicator = new Communicator( apClient->mpStreamSocket );
|
|
|
|
MutexGuard aGuard( spServer->mDataMutex );
|
|
|
|
|
|
|
|
spServer->mCommunicators.push_back( pCommunicator );
|
|
|
|
|
|
|
|
for ( vector<ClientInfoInternal*>::iterator aIt = spServer->mAvailableClients.begin();
|
|
|
|
aIt < spServer->mAvailableClients.end(); aIt++ )
|
|
|
|
{
|
|
|
|
if ( pClient == *aIt )
|
|
|
|
{
|
|
|
|
spServer->mAvailableClients.erase( aIt );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-10 13:27:40 +02:00
|
|
|
}
|
|
|
|
|
2012-07-09 12:20:45 +01:00
|
|
|
void SdDLL::RegisterRemotes()
|
|
|
|
{
|
2012-08-07 13:12:06 +02:00
|
|
|
// Disable unless in experimental mode for now
|
|
|
|
uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
|
|
|
|
if (!xContext.is() || !officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
|
|
|
|
return;
|
|
|
|
|
|
|
|
sd::RemoteServer::setup();
|
|
|
|
sd::DiscoveryService::setup();
|
2012-07-10 16:36:04 +01:00
|
|
|
|
2012-07-09 12:20:45 +01:00
|
|
|
}
|
2012-07-12 17:59:08 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|