LibreOffice Module sd (master) 1
Communicator.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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>
11
12#include <com/sun/star/frame/Desktop.hpp>
13#include <com/sun/star/presentation/XPresentation2.hpp>
14#include <com/sun/star/presentation/XPresentationSupplier.hpp>
17#include <config_version.h>
18#include <rtl/string.hxx>
19#include <sal/log.hxx>
20
21#include "Communicator.hxx"
22#include "IBluetoothSocket.hxx"
23#include "Listener.hxx"
24#include "Receiver.hxx"
25#include "Transmitter.hxx"
26#include <RemoteServer.hxx>
27
28using namespace sd;
29using namespace com::sun::star;
30using namespace osl;
31
32Communicator::Communicator( std::unique_ptr<IBluetoothSocket> pSocket ):
33 Thread( "CommunicatorThread" ),
34 mpSocket( std::move(pSocket) )
35{
36}
37
39{
40}
41
45{
46 if( mpSocket )
47 mpSocket->close();
48}
49
50// Run as a thread
52{
53 pTransmitter.reset( new Transmitter( mpSocket.get() ) );
54 pTransmitter->create();
55
56 pTransmitter->addMessage( "LO_SERVER_SERVER_PAIRED\n\n",
58
59 pTransmitter->addMessage( "LO_SERVER_INFO\n" LIBO_VERSION_DOTTED "\n\n",
61
62 Receiver aReceiver( pTransmitter.get() );
63 try {
64 uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
65 uno::Reference< frame::XFrame > xFrame = xFramesSupplier->getActiveFrame();
66
67 uno::Reference<presentation::XPresentationSupplier> xPS;
68 if( xFrame.is() )
69 xPS.set( xFrame->getController()->getModel(), uno::UNO_QUERY );
70 uno::Reference<presentation::XPresentation2> xPresentation;
71 if( xPS.is() )
72 xPresentation.set( xPS->getPresentation(), uno::UNO_QUERY );
73 if ( xPresentation.is() && xPresentation->isRunning() )
74 {
75 presentationStarted( xPresentation->getController() );
76 OString aBuffer =
77 "slideshow_info\n" +
78 OUStringToOString( ::comphelper::DocumentInfo::getDocumentTitle( xFrame->getController()->getModel() ), RTL_TEXTENCODING_UTF8 ) +
79 "\n\n";
80
82 }
83 else
84 {
85 pTransmitter->addMessage( "slideshow_finished\n\n",
87 }
88 }
89 catch (uno::RuntimeException &)
90 {
91 }
92
93 sal_uInt64 aRet;
94 std::vector<OString> aCommand;
95 while ( true )
96 {
97 OString aLine;
98 aRet = mpSocket->readLine( aLine );
99 if ( aRet == 0 )
100 {
101 break; // I.e. transmission finished.
102 }
103 if ( aLine.getLength() )
104 {
105 aCommand.push_back( aLine );
106 }
107 else
108 {
109 aReceiver.pushCommand( aCommand );
110 aCommand.clear();
111 }
112 }
113
114 SAL_INFO ("sdremote", "Exiting transmission loop");
115
117
118 pTransmitter->notifyFinished();
119 pTransmitter->join();
120 pTransmitter = nullptr;
121
122 mpSocket->close();
123 mpSocket.reset();
124
126}
127
129{
130 // called only from the Listener::disposing() method
131 // during disposal of this communicator
132
133 if ( pTransmitter )
134 pTransmitter->addMessage( "slideshow_finished\n\n",
136}
137
138void Communicator::presentationStarted( const css::uno::Reference<
139 css::presentation::XSlideShowController > &rController )
140{
141 if ( pTransmitter )
142 {
143 mListener.set( new Listener( this, pTransmitter.get() ) );
144 mListener->init( rController );
145 }
146}
147
149{
150 if ( mListener.is() )
151 {
152 mListener->dispose();
153 mListener = nullptr;
154 }
155}
156
157/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~Communicator() override
std::unique_ptr< Transmitter > pTransmitter
void forceClose()
Close the underlying socket from another thread to force an early exit / termination.
void presentationStarted(const css::uno::Reference< css::presentation::XSlideShowController > &rController)
std::unique_ptr< IBluetoothSocket > mpSocket
void execute() override
void informListenerDestroyed()
rtl::Reference< Listener > mListener
Slide show listener.
Definition: Listener.hxx:29
void pushCommand(const std::vector< OString > &rCommand)
Definition: Receiver.cxx:41
static void removeCommunicator(Communicator const *pCommunicator)
Definition: Server.cxx:217
#define SAL_INFO(area, stream)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
Reference< XFrame > xFrame
OUString aCommand
std::unique_ptr< char[]> aBuffer