2012-08-10 17:20:16 +02: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/.
|
|
|
|
*/
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
|
|
|
|
#include "Communicator.hxx"
|
|
|
|
#include "Listener.hxx"
|
|
|
|
#include "Receiver.hxx"
|
|
|
|
#include "RemoteServer.hxx"
|
|
|
|
|
|
|
|
using namespace sd;
|
|
|
|
using namespace std;
|
|
|
|
using namespace com::sun::star;
|
|
|
|
using namespace osl;
|
|
|
|
|
2012-08-10 18:42:49 +02:00
|
|
|
Communicator::Communicator( BufferedStreamSocket *pSocket ):
|
2012-08-10 17:20:16 +02:00
|
|
|
Thread( "CommunicatorThread" ),
|
2012-08-10 18:42:49 +02:00
|
|
|
mpSocket( pSocket ),
|
2012-08-10 17:20:16 +02:00
|
|
|
pTransmitter( 0 ),
|
|
|
|
mListener( 0 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Communicator::~Communicator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run as a thread
|
|
|
|
void Communicator::execute()
|
|
|
|
{
|
2012-08-22 12:44:42 +02:00
|
|
|
pTransmitter = new Transmitter( mpSocket );
|
2012-11-23 17:59:41 +01:00
|
|
|
pTransmitter->create();
|
2012-08-10 18:42:49 +02:00
|
|
|
|
|
|
|
pTransmitter->addMessage( "LO_SERVER_SERVER_PAIRED\n\n",
|
|
|
|
Transmitter::PRIORITY_HIGH );
|
2012-08-10 17:20:16 +02:00
|
|
|
Receiver aReceiver( pTransmitter );
|
|
|
|
try {
|
|
|
|
uno::Reference< lang::XMultiServiceFactory > xServiceManager(
|
|
|
|
::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
|
|
|
|
uno::Reference< frame::XFramesSupplier > xFramesSupplier( xServiceManager->createInstance(
|
|
|
|
"com.sun.star.frame.Desktop" ) , uno::UNO_QUERY_THROW );
|
|
|
|
uno::Reference< frame::XFrame > xFrame ( xFramesSupplier->getActiveFrame(), uno::UNO_QUERY_THROW );
|
|
|
|
uno::Reference<presentation::XPresentationSupplier> xPS ( xFrame->getController()->getModel(), uno::UNO_QUERY_THROW);
|
|
|
|
uno::Reference<presentation::XPresentation2> xPresentation(
|
|
|
|
xPS->getPresentation(), uno::UNO_QUERY_THROW);
|
|
|
|
if ( xPresentation->isRunning() )
|
|
|
|
{
|
|
|
|
presentationStarted( xPresentation->getController() );
|
|
|
|
}
|
2012-09-18 11:16:45 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pTransmitter->addMessage( "slideshow_finished\n\n",
|
|
|
|
Transmitter::PRIORITY_HIGH );
|
|
|
|
}
|
2012-08-10 17:20:16 +02:00
|
|
|
}
|
|
|
|
catch (uno::RuntimeException &)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-22 12:44:42 +02:00
|
|
|
sal_uInt64 aRet;
|
2012-08-10 17:20:16 +02:00
|
|
|
vector<OString> aCommand;
|
|
|
|
while ( true )
|
|
|
|
{
|
2012-08-22 12:44:42 +02:00
|
|
|
OString aLine;
|
|
|
|
aRet = mpSocket->readLine( aLine );
|
2012-08-10 17:20:16 +02:00
|
|
|
if ( aRet == 0 )
|
|
|
|
{
|
|
|
|
break; // I.e. transmission finished.
|
|
|
|
}
|
2012-08-22 12:44:42 +02:00
|
|
|
if ( aLine.getLength() )
|
2012-08-10 17:20:16 +02:00
|
|
|
{
|
2012-08-22 12:44:42 +02:00
|
|
|
aCommand.push_back( aLine );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aReceiver.parseCommand( aCommand );
|
|
|
|
aCommand.clear();
|
2012-08-10 17:20:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
disposeListener();
|
|
|
|
|
|
|
|
pTransmitter->notifyFinished();
|
|
|
|
pTransmitter->join();
|
|
|
|
pTransmitter = NULL;
|
|
|
|
|
2012-08-10 18:42:49 +02:00
|
|
|
delete mpSocket;
|
|
|
|
|
2012-08-10 17:20:16 +02:00
|
|
|
RemoteServer::removeCommunicator( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Communicator::informListenerDestroyed()
|
|
|
|
{
|
2012-11-23 17:59:41 +01:00
|
|
|
if ( pTransmitter )
|
|
|
|
pTransmitter->addMessage( "slideshow_finished\n\n",
|
|
|
|
Transmitter::PRIORITY_HIGH );
|
2012-08-10 17:20:16 +02:00
|
|
|
mListener.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Communicator::presentationStarted( const css::uno::Reference<
|
|
|
|
css::presentation::XSlideShowController > &rController )
|
|
|
|
{
|
|
|
|
if ( pTransmitter )
|
|
|
|
{
|
|
|
|
mListener = rtl::Reference<Listener>( new Listener( this, pTransmitter ) );
|
|
|
|
mListener->init( rController );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Communicator::disposeListener()
|
|
|
|
{
|
|
|
|
if ( mListener.is() )
|
|
|
|
{
|
|
|
|
mListener->disposing();
|
|
|
|
mListener = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|