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 <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"
26 using namespace com::sun::star
;
29 Communicator::Communicator( IBluetoothSocket
*pSocket
):
30 Thread( "CommunicatorThread" ),
37 Communicator::~Communicator()
41 /// Close the underlying socket from another thread to force
42 /// an early exit / termination
43 void Communicator::forceClose()
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
);
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
;
70 xPS
= uno::Reference
<presentation::XPresentationSupplier
>( xFrame
->getController()->getModel(), uno::UNO_QUERY
);
71 uno::Reference
<presentation::XPresentation2
> xPresentation
;
73 xPresentation
= uno::Reference
<presentation::XPresentation2
>( xPS
->getPresentation(), uno::UNO_QUERY
);
74 if ( xPresentation
.is() && xPresentation
->isRunning() )
76 presentationStarted( xPresentation
->getController() );
80 pTransmitter
->addMessage( "slideshow_finished\n\n",
81 Transmitter::PRIORITY_HIGH
);
84 OStringBuffer aBuffer
;
86 .append( "slideshow_info\n" )
87 .append( OUStringToOString( ::comphelper::DocumentInfo::getDocumentTitle( xFrame
->getController()->getModel() ), RTL_TEXTENCODING_UTF8
) )
90 pTransmitter
->addMessage( aBuffer
.makeStringAndClear(), Transmitter::PRIORITY_LOW
);
92 catch (uno::RuntimeException
&)
97 vector
<OString
> aCommand
;
101 aRet
= mpSocket
->readLine( aLine
);
104 break; // I.e. transmission finished.
106 if ( aLine
.getLength() )
108 aCommand
.push_back( aLine
);
112 aReceiver
.pushCommand( aCommand
);
117 SAL_INFO ("sdremote", "Exiting transmission loop\n");
121 pTransmitter
->notifyFinished();
122 pTransmitter
->join();
129 RemoteServer::removeCommunicator( this );
132 void Communicator::informListenerDestroyed()
135 pTransmitter
->addMessage( "slideshow_finished\n\n",
136 Transmitter::PRIORITY_HIGH
);
140 void Communicator::presentationStarted( const css::uno::Reference
<
141 css::presentation::XSlideShowController
> &rController
)
145 mListener
= rtl::Reference
<Listener
>( new Listener( this, pTransmitter
) );
146 mListener
->init( rController
);
150 void Communicator::disposeListener()
152 if ( mListener
.is() )
154 mListener
->disposing();
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */