bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / remotecontrol / Communicator.cxx
blobcf5540078e89fe5aa49eb883d48b4897d0ffa59c
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 <com/sun/star/presentation/XPresentation2.hpp>
14 #include <com/sun/star/presentation/XPresentationSupplier.hpp>
15 #include <comphelper/processfactory.hxx>
16 #include <comphelper/documentinfo.hxx>
17 #include <config_version.h>
18 #include <rtl/string.hxx>
19 #include <rtl/strbuf.hxx>
20 #include <sal/log.hxx>
22 #include "Communicator.hxx"
23 #include "IBluetoothSocket.hxx"
24 #include "Listener.hxx"
25 #include "Receiver.hxx"
26 #include "Transmitter.hxx"
27 #include <RemoteServer.hxx>
29 using namespace sd;
30 using namespace std;
31 using namespace com::sun::star;
32 using namespace osl;
34 Communicator::Communicator( std::unique_ptr<IBluetoothSocket> pSocket ):
35 Thread( "CommunicatorThread" ),
36 mpSocket( std::move(pSocket) )
40 Communicator::~Communicator()
44 /// Close the underlying socket from another thread to force
45 /// an early exit / termination
46 void Communicator::forceClose()
48 if( mpSocket )
49 mpSocket->close();
52 // Run as a thread
53 void Communicator::execute()
55 pTransmitter.reset( new Transmitter( mpSocket.get() ) );
56 pTransmitter->create();
58 pTransmitter->addMessage( "LO_SERVER_SERVER_PAIRED\n\n",
59 Transmitter::PRIORITY_HIGH );
61 OStringBuffer aServerInformationBuffer;
62 aServerInformationBuffer.append( "LO_SERVER_INFO\n" LIBO_VERSION_DOTTED "\n\n" );
64 pTransmitter->addMessage( aServerInformationBuffer.makeStringAndClear(), Transmitter::PRIORITY_HIGH );
66 Receiver aReceiver( pTransmitter.get() );
67 try {
68 uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
69 uno::Reference< frame::XFrame > xFrame ( xFramesSupplier->getActiveFrame(), uno::UNO_QUERY );
71 uno::Reference<presentation::XPresentationSupplier> xPS;
72 if( xFrame.is() )
73 xPS.set( xFrame->getController()->getModel(), uno::UNO_QUERY );
74 uno::Reference<presentation::XPresentation2> xPresentation;
75 if( xPS.is() )
76 xPresentation.set( xPS->getPresentation(), uno::UNO_QUERY );
77 if ( xPresentation.is() && xPresentation->isRunning() )
79 presentationStarted( xPresentation->getController() );
81 else
83 pTransmitter->addMessage( "slideshow_finished\n\n",
84 Transmitter::PRIORITY_HIGH );
87 OStringBuffer aBuffer;
88 aBuffer
89 .append( "slideshow_info\n" )
90 .append( OUStringToOString( ::comphelper::DocumentInfo::getDocumentTitle( xFrame->getController()->getModel() ), RTL_TEXTENCODING_UTF8 ) )
91 .append("\n\n");
93 pTransmitter->addMessage( aBuffer.makeStringAndClear(), Transmitter::PRIORITY_LOW );
95 catch (uno::RuntimeException &)
99 sal_uInt64 aRet;
100 vector<OString> aCommand;
101 while ( true )
103 OString aLine;
104 aRet = mpSocket->readLine( aLine );
105 if ( aRet == 0 )
107 break; // I.e. transmission finished.
109 if ( aLine.getLength() )
111 aCommand.push_back( aLine );
113 else
115 aReceiver.pushCommand( aCommand );
116 aCommand.clear();
120 SAL_INFO ("sdremote", "Exiting transmission loop");
122 disposeListener();
124 pTransmitter->notifyFinished();
125 pTransmitter->join();
126 pTransmitter = nullptr;
128 mpSocket->close();
129 mpSocket.reset();
131 RemoteServer::removeCommunicator( this );
134 void Communicator::informListenerDestroyed()
136 if ( pTransmitter )
137 pTransmitter->addMessage( "slideshow_finished\n\n",
138 Transmitter::PRIORITY_HIGH );
139 mListener.clear();
142 void Communicator::presentationStarted( const css::uno::Reference<
143 css::presentation::XSlideShowController > &rController )
145 if ( pTransmitter )
147 mListener.set( new Listener( this, pTransmitter.get() ) );
148 mListener->init( rController );
152 void Communicator::disposeListener()
154 if ( mListener.is() )
156 mListener->disposing();
157 mListener = nullptr;
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */