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-07-09 10:57:32 +01:00
|
|
|
|
2012-07-30 08:34:41 +02:00
|
|
|
RemoteServer::RemoteServer()
|
|
|
|
: Thread( "RemoteServerThread" ), mSocket()
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run as a thread
|
2012-07-30 08:34:41 +02:00
|
|
|
void RemoteServer::listenThread()
|
2012-07-09 10:57:32 +01:00
|
|
|
{
|
2012-07-18 16:14:52 +02:00
|
|
|
pTransmitter = new Transmitter( mStreamSocket );
|
|
|
|
pTransmitter->launch();
|
|
|
|
Receiver aReceiver( pTransmitter );
|
2012-07-17 17:48:07 +02:00
|
|
|
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-08-06 14:59:08 +02:00
|
|
|
catch (uno::RuntimeException &)
|
2012-07-17 17:48:07 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-19 15:36:24 +02:00
|
|
|
sal_uInt64 aRet, aRead;
|
|
|
|
vector<char> aBuffer;
|
|
|
|
vector<OString> aCommand;
|
|
|
|
aRead = 0;
|
|
|
|
while ( true )
|
2012-07-09 10:57:32 +01:00
|
|
|
{
|
2012-07-19 15:36:24 +02:00
|
|
|
aBuffer.resize( aRead + 100 );
|
|
|
|
aRet = mStreamSocket.recv( &aBuffer[aRead], 100 );
|
|
|
|
if ( aRet == 0 )
|
2012-07-09 15:53:03 +01:00
|
|
|
{
|
2012-07-19 15:36:24 +02:00
|
|
|
break; // I.e. transmission finished.
|
|
|
|
}
|
|
|
|
aRead += aRet;
|
|
|
|
vector<char>::iterator aIt;
|
|
|
|
while ( (aIt = find( aBuffer.begin(), aBuffer.end(), '\n' ))
|
|
|
|
!= aBuffer.end() )
|
|
|
|
{
|
|
|
|
sal_uInt64 aLocation = aIt - aBuffer.begin();
|
2012-07-13 17:34:49 +01:00
|
|
|
|
2012-07-19 15:36:24 +02:00
|
|
|
aCommand.push_back( OString( &(*aBuffer.begin()), aLocation ) );
|
|
|
|
if ( aIt == aBuffer.begin() )
|
|
|
|
{
|
|
|
|
aReceiver.parseCommand( aCommand );
|
|
|
|
aCommand.clear();
|
2012-07-12 22:10:33 +01:00
|
|
|
}
|
2012-08-06 10:53:19 +02:00
|
|
|
aBuffer.erase( aBuffer.begin(), aIt + 1 ); // Also delete the empty line
|
2012-07-19 15:36:24 +02:00
|
|
|
aRead -= (aLocation + 1);
|
2012-07-09 15:53:03 +01:00
|
|
|
}
|
2012-07-09 10:57:32 +01:00
|
|
|
}
|
2012-07-19 15:36:24 +02:00
|
|
|
// TODO: deal with transmision errors gracefully.
|
2012-07-20 17:50:10 +02:00
|
|
|
presentationStopped();
|
2012-07-19 18:43:18 +02:00
|
|
|
|
2012-08-07 09:03:41 +02:00
|
|
|
pTransmitter->notifyFinished();
|
|
|
|
pTransmitter->join();
|
2012-07-18 16:14:52 +02:00
|
|
|
pTransmitter = NULL;
|
2012-07-19 15:36:24 +02:00
|
|
|
fprintf( stderr, "Finished listening\n" );
|
2012-07-09 10:57:32 +01:00
|
|
|
}
|
|
|
|
|
2012-08-07 18:03:23 +02:00
|
|
|
void RemoteServer::pairClient()
|
|
|
|
{
|
|
|
|
// Pairing: client sends PIN, server asks user, replies with accepted/rejected.
|
|
|
|
// We have to wait here until the user opens the dialog via the menu,
|
|
|
|
// typs in the pin etc.
|
|
|
|
}
|
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-07-11 17:44:41 +01:00
|
|
|
fprintf( stderr, "Awaiting a connection.\n" );
|
2012-08-07 09:29:35 +02:00
|
|
|
if ( mSocket.acceptConnection( mStreamSocket ) == osl_Socket_Error ) {
|
|
|
|
// Socket closed or other problem
|
|
|
|
return;
|
|
|
|
}
|
2012-07-10 16:36:04 +01:00
|
|
|
fprintf( stderr, "Accepted a connection!\n" );
|
2012-07-09 15:53:03 +01:00
|
|
|
listenThread();
|
|
|
|
}
|
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-07-30 08:34:41 +02:00
|
|
|
void RemoteServer::informListenerDestroyed()
|
2012-07-19 13:02:03 +02:00
|
|
|
{
|
|
|
|
mListener.clear();
|
|
|
|
}
|
2012-07-17 16:44:46 +02:00
|
|
|
|
2012-07-30 08:34:41 +02:00
|
|
|
void RemoteServer::presentationStarted( const css::uno::Reference<
|
2012-07-18 10:19:35 +02:00
|
|
|
css::presentation::XSlideShowController > &rController )
|
2012-07-17 16:44:46 +02:00
|
|
|
{
|
2012-07-18 16:14:52 +02:00
|
|
|
if ( pTransmitter )
|
|
|
|
{
|
2012-07-19 13:02:03 +02:00
|
|
|
mListener = rtl::Reference<Listener>( new Listener( spServer, pTransmitter ) );
|
|
|
|
mListener->init( 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
|
|
|
{
|
|
|
|
if ( mListener.is() )
|
|
|
|
{
|
|
|
|
mListener->disposing();
|
|
|
|
mListener = NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-07-17 16:44:46 +02:00
|
|
|
|
2012-07-30 08:34:41 +02:00
|
|
|
RemoteServer *sd::RemoteServer::spServer = NULL;
|
|
|
|
Transmitter *sd::RemoteServer::pTransmitter = NULL;
|
|
|
|
rtl::Reference<Listener> sd::RemoteServer::mListener = NULL;
|
2012-07-09 17:26:27 +01:00
|
|
|
|
2012-07-30 08:34:41 +02:00
|
|
|
void RemoteServer::setup()
|
2012-07-09 17:26:27 +01:00
|
|
|
{
|
|
|
|
if (spServer)
|
|
|
|
return;
|
|
|
|
|
2012-07-30 08:34:41 +02:00
|
|
|
spServer = new RemoteServer();
|
2012-07-09 17:26:27 +01:00
|
|
|
spServer->launch();
|
|
|
|
}
|
|
|
|
|
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: */
|