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 <sal/log.hxx>
21 #include "Communicator.hxx"
22 #include "IBluetoothSocket.hxx"
23 #include "Listener.hxx"
24 #include "Receiver.hxx"
25 #include "Transmitter.hxx"
26 #include <RemoteServer.hxx>
29 using namespace com::sun::star
;
32 Communicator::Communicator( std::unique_ptr
<IBluetoothSocket
> pSocket
):
33 Thread( "CommunicatorThread" ),
34 mpSocket( std::move(pSocket
) )
38 Communicator::~Communicator()
42 /// Close the underlying socket from another thread to force
43 /// an early exit / termination
44 void Communicator::forceClose()
51 void Communicator::execute()
53 pTransmitter
.reset( new Transmitter( mpSocket
.get() ) );
54 pTransmitter
->create();
56 pTransmitter
->addMessage( "LO_SERVER_SERVER_PAIRED\n\n"_ostr
,
57 Transmitter::PRIORITY_HIGH
);
59 pTransmitter
->addMessage( "LO_SERVER_INFO\n" LIBO_VERSION_DOTTED
"\n\n"_ostr
,
60 Transmitter::PRIORITY_HIGH
);
62 Receiver
aReceiver( pTransmitter
.get() );
64 uno::Reference
< frame::XDesktop2
> xFramesSupplier
= frame::Desktop::create( ::comphelper::getProcessComponentContext() );
65 uno::Reference
< frame::XFrame
> xFrame
= xFramesSupplier
->getActiveFrame();
67 uno::Reference
<presentation::XPresentationSupplier
> xPS
;
69 xPS
.set( xFrame
->getController()->getModel(), uno::UNO_QUERY
);
70 uno::Reference
<presentation::XPresentation2
> xPresentation
;
72 xPresentation
.set( xPS
->getPresentation(), uno::UNO_QUERY
);
73 if ( xPresentation
.is() && xPresentation
->isRunning() )
75 presentationStarted( xPresentation
->getController() );
78 OUStringToOString( ::comphelper::DocumentInfo::getDocumentTitle( xFrame
->getController()->getModel() ), RTL_TEXTENCODING_UTF8
) +
81 pTransmitter
->addMessage( aBuffer
, Transmitter::PRIORITY_LOW
);
85 pTransmitter
->addMessage( "slideshow_finished\n\n"_ostr
,
86 Transmitter::PRIORITY_HIGH
);
89 catch (uno::RuntimeException
&)
94 std::vector
<OString
> aCommand
;
98 aRet
= mpSocket
->readLine( aLine
);
101 break; // I.e. transmission finished.
103 if ( aLine
.getLength() )
105 aCommand
.push_back( aLine
);
109 aReceiver
.pushCommand( aCommand
);
114 SAL_INFO ("sdremote", "Exiting transmission loop");
118 pTransmitter
->notifyFinished();
119 pTransmitter
->join();
120 pTransmitter
= nullptr;
125 RemoteServer::removeCommunicator( this );
128 void Communicator::informListenerDestroyed()
130 // called only from the Listener::disposing() method
131 // during disposal of this communicator
134 pTransmitter
->addMessage( "slideshow_finished\n\n"_ostr
,
135 Transmitter::PRIORITY_HIGH
);
138 void Communicator::presentationStarted( const css::uno::Reference
<
139 css::presentation::XSlideShowController
> &rController
)
143 mListener
.set( new Listener( this, pTransmitter
.get() ) );
144 mListener
->init( rController
);
148 void Communicator::disposeListener()
150 if ( mListener
.is() )
152 mListener
->dispose();
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */