fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / remotecontrol / Communicator.cxx
blobd8077d22c9e902f31f27c4ab6637bc2998e9884b
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>
15 #include "Communicator.hxx"
16 #include "Listener.hxx"
17 #include "Receiver.hxx"
18 #include "RemoteServer.hxx"
20 using namespace sd;
21 using namespace std;
22 using namespace com::sun::star;
23 using namespace osl;
25 Communicator::Communicator( IBluetoothSocket *pSocket ):
26 Thread( "CommunicatorThread" ),
27 mpSocket( pSocket ),
28 pTransmitter( 0 ),
29 mListener( 0 )
33 Communicator::~Communicator()
37 /// Close the underlying socket from another thread to force
38 /// an early exit / termination
39 void Communicator::forceClose()
41 if( mpSocket )
42 mpSocket->close();
45 // Run as a thread
46 void Communicator::execute()
48 pTransmitter = new Transmitter( mpSocket );
49 pTransmitter->create();
51 pTransmitter->addMessage( "LO_SERVER_SERVER_PAIRED\n\n",
52 Transmitter::PRIORITY_HIGH );
53 Receiver aReceiver( pTransmitter );
54 try {
55 uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
56 uno::Reference< frame::XFrame > xFrame ( xFramesSupplier->getActiveFrame(), uno::UNO_QUERY );
58 uno::Reference<presentation::XPresentationSupplier> xPS;
59 if( xFrame.is() )
60 xPS = uno::Reference<presentation::XPresentationSupplier>( xFrame->getController()->getModel(), uno::UNO_QUERY );
61 uno::Reference<presentation::XPresentation2> xPresentation;
62 if( xPS.is() )
63 xPresentation = uno::Reference<presentation::XPresentation2>( xPS->getPresentation(), uno::UNO_QUERY );
64 if ( xPresentation.is() && xPresentation->isRunning() )
66 presentationStarted( xPresentation->getController() );
68 else
70 pTransmitter->addMessage( "slideshow_finished\n\n",
71 Transmitter::PRIORITY_HIGH );
74 catch (uno::RuntimeException &)
78 sal_uInt64 aRet;
79 vector<OString> aCommand;
80 while ( true )
82 OString aLine;
83 aRet = mpSocket->readLine( aLine );
84 if ( aRet == 0 )
86 break; // I.e. transmission finished.
88 if ( aLine.getLength() )
90 aCommand.push_back( aLine );
92 else
94 aReceiver.pushCommand( aCommand );
95 aCommand.clear();
98 disposeListener();
100 pTransmitter->notifyFinished();
101 pTransmitter->join();
102 pTransmitter = NULL;
104 if( mpSocket )
106 mpSocket->close();
107 delete mpSocket;
108 mpSocket = NULL;
111 RemoteServer::removeCommunicator( this );
114 void Communicator::informListenerDestroyed()
116 if ( pTransmitter )
117 pTransmitter->addMessage( "slideshow_finished\n\n",
118 Transmitter::PRIORITY_HIGH );
119 mListener.clear();
122 void Communicator::presentationStarted( const css::uno::Reference<
123 css::presentation::XSlideShowController > &rController )
125 if ( pTransmitter )
127 mListener = rtl::Reference<Listener>( new Listener( this, pTransmitter ) );
128 mListener->init( rController );
132 void Communicator::disposeListener()
134 if ( mListener.is() )
136 mListener->disposing();
137 mListener = NULL;
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */