1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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>
31 using namespace com::sun::star
;
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()
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() );
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
;
73 xPS
.set( xFrame
->getController()->getModel(), uno::UNO_QUERY
);
74 uno::Reference
<presentation::XPresentation2
> xPresentation
;
76 xPresentation
.set( xPS
->getPresentation(), uno::UNO_QUERY
);
77 if ( xPresentation
.is() && xPresentation
->isRunning() )
79 presentationStarted( xPresentation
->getController() );
83 pTransmitter
->addMessage( "slideshow_finished\n\n",
84 Transmitter::PRIORITY_HIGH
);
87 OStringBuffer aBuffer
;
89 .append( "slideshow_info\n" )
90 .append( OUStringToOString( ::comphelper::DocumentInfo::getDocumentTitle( xFrame
->getController()->getModel() ), RTL_TEXTENCODING_UTF8
) )
93 pTransmitter
->addMessage( aBuffer
.makeStringAndClear(), Transmitter::PRIORITY_LOW
);
95 catch (uno::RuntimeException
&)
100 vector
<OString
> aCommand
;
104 aRet
= mpSocket
->readLine( aLine
);
107 break; // I.e. transmission finished.
109 if ( aLine
.getLength() )
111 aCommand
.push_back( aLine
);
115 aReceiver
.pushCommand( aCommand
);
120 SAL_INFO ("sdremote", "Exiting transmission loop");
124 pTransmitter
->notifyFinished();
125 pTransmitter
->join();
126 pTransmitter
= nullptr;
131 RemoteServer::removeCommunicator( this );
134 void Communicator::informListenerDestroyed()
137 pTransmitter
->addMessage( "slideshow_finished\n\n",
138 Transmitter::PRIORITY_HIGH
);
142 void Communicator::presentationStarted( const css::uno::Reference
<
143 css::presentation::XSlideShowController
> &rController
)
147 mListener
.set( new Listener( this, pTransmitter
.get() ) );
148 mListener
->init( rController
);
152 void Communicator::disposeListener()
154 if ( mListener
.is() )
156 mListener
->disposing();
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */