bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / remotecontrol / Communicator.cxx
blobbf399cae8cebb4d8f48b8135579ed23a3b7d8930
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9 #include <algorithm>
10 #include <vector>
12 #include <com/sun/star/frame/Desktop.hpp>
13 #include <comphelper/processfactory.hxx>
14 #include <comphelper/documentinfo.hxx>
15 #include <config_version.h>
16 #include <rtl/string.hxx>
17 #include <rtl/strbuf.hxx>
19 #include "Communicator.hxx"
20 #include "Listener.hxx"
21 #include "Receiver.hxx"
22 #include "RemoteServer.hxx"
24 using namespace sd;
25 using namespace std;
26 using namespace com::sun::star;
27 using namespace osl;
29 Communicator::Communicator( IBluetoothSocket *pSocket ):
30 Thread( "CommunicatorThread" ),
31 mpSocket( pSocket ),
32 pTransmitter( 0 ),
33 mListener( 0 )
37 Communicator::~Communicator()
41 /// Close the underlying socket from another thread to force
42 /// an early exit / termination
43 void Communicator::forceClose()
45 if( mpSocket )
46 mpSocket->close();
49 // Run as a thread
50 void Communicator::execute()
52 pTransmitter = new Transmitter( mpSocket );
53 pTransmitter->create();
55 pTransmitter->addMessage( "LO_SERVER_SERVER_PAIRED\n\n",
56 Transmitter::PRIORITY_HIGH );
58 OStringBuffer aServerInformationBuffer;
59 aServerInformationBuffer.append( "LO_SERVER_INFO\n" LIBO_VERSION_DOTTED "\n\n" );
61 pTransmitter->addMessage( aServerInformationBuffer.makeStringAndClear(), Transmitter::PRIORITY_HIGH );
63 Receiver aReceiver( pTransmitter );
64 try {
65 uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
66 uno::Reference< frame::XFrame > xFrame ( xFramesSupplier->getActiveFrame(), uno::UNO_QUERY );
68 uno::Reference<presentation::XPresentationSupplier> xPS;
69 if( xFrame.is() )
70 xPS = uno::Reference<presentation::XPresentationSupplier>( xFrame->getController()->getModel(), uno::UNO_QUERY );
71 uno::Reference<presentation::XPresentation2> xPresentation;
72 if( xPS.is() )
73 xPresentation = uno::Reference<presentation::XPresentation2>( xPS->getPresentation(), uno::UNO_QUERY );
74 if ( xPresentation.is() && xPresentation->isRunning() )
76 presentationStarted( xPresentation->getController() );
78 else
80 pTransmitter->addMessage( "slideshow_finished\n\n",
81 Transmitter::PRIORITY_HIGH );
84 OStringBuffer aBuffer;
85 aBuffer
86 .append( "slideshow_info\n" )
87 .append( OUStringToOString( ::comphelper::DocumentInfo::getDocumentTitle( xFrame->getController()->getModel() ), RTL_TEXTENCODING_UTF8 ) )
88 .append("\n\n");
90 pTransmitter->addMessage( aBuffer.makeStringAndClear(), Transmitter::PRIORITY_LOW );
92 catch (uno::RuntimeException &)
96 sal_uInt64 aRet;
97 vector<OString> aCommand;
98 while ( true )
100 OString aLine;
101 aRet = mpSocket->readLine( aLine );
102 if ( aRet == 0 )
104 break; // I.e. transmission finished.
106 if ( aLine.getLength() )
108 aCommand.push_back( aLine );
110 else
112 aReceiver.pushCommand( aCommand );
113 aCommand.clear();
117 SAL_INFO ("sdremote", "Exiting transmission loop\n");
119 disposeListener();
121 pTransmitter->notifyFinished();
122 pTransmitter->join();
123 pTransmitter = NULL;
125 mpSocket->close();
126 delete mpSocket;
127 mpSocket = NULL;
129 RemoteServer::removeCommunicator( this );
132 void Communicator::informListenerDestroyed()
134 if ( pTransmitter )
135 pTransmitter->addMessage( "slideshow_finished\n\n",
136 Transmitter::PRIORITY_HIGH );
137 mListener.clear();
140 void Communicator::presentationStarted( const css::uno::Reference<
141 css::presentation::XSlideShowController > &rController )
143 if ( pTransmitter )
145 mListener = rtl::Reference<Listener>( new Listener( this, pTransmitter ) );
146 mListener->init( rController );
150 void Communicator::disposeListener()
152 if ( mListener.is() )
154 mListener->disposing();
155 mListener = NULL;
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */