Branch data Line data Source code
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 <comphelper/processfactory.hxx>
13 : :
14 : : #include "Communicator.hxx"
15 : : #include "ImagePreparer.hxx"
16 : : #include "Listener.hxx"
17 : : #include "Receiver.hxx"
18 : : #include "RemoteServer.hxx"
19 : :
20 : : using namespace sd;
21 : : using namespace std;
22 : : using namespace com::sun::star;
23 : : using namespace osl;
24 : :
25 : 0 : Communicator::Communicator( BufferedStreamSocket *pSocket ):
26 : : Thread( "CommunicatorThread" ),
27 : : mpSocket( pSocket ),
28 : : pTransmitter( 0 ),
29 : 0 : mListener( 0 )
30 : : {
31 : 0 : }
32 : :
33 : 0 : Communicator::~Communicator()
34 : : {
35 [ # # ]: 0 : }
36 : :
37 : : // Run as a thread
38 : 0 : void Communicator::execute()
39 : : {
40 [ # # ][ # # ]: 0 : pTransmitter = new Transmitter( mpSocket );
41 [ # # ]: 0 : pTransmitter->launch();
42 : :
43 : : pTransmitter->addMessage( "LO_SERVER_SERVER_PAIRED\n\n",
44 [ # # ]: 0 : Transmitter::PRIORITY_HIGH );
45 [ # # ]: 0 : Receiver aReceiver( pTransmitter );
46 : : try {
47 : : uno::Reference< lang::XMultiServiceFactory > xServiceManager(
48 [ # # ][ # # ]: 0 : ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
49 [ # # ]: 0 : uno::Reference< frame::XFramesSupplier > xFramesSupplier( xServiceManager->createInstance(
50 [ # # ][ # # ]: 0 : "com.sun.star.frame.Desktop" ) , uno::UNO_QUERY_THROW );
51 [ # # ][ # # ]: 0 : uno::Reference< frame::XFrame > xFrame ( xFramesSupplier->getActiveFrame(), uno::UNO_QUERY_THROW );
[ # # ]
52 [ # # ][ # # ]: 0 : uno::Reference<presentation::XPresentationSupplier> xPS ( xFrame->getController()->getModel(), uno::UNO_QUERY_THROW);
[ # # ][ # # ]
[ # # ]
53 : : uno::Reference<presentation::XPresentation2> xPresentation(
54 [ # # ][ # # ]: 0 : xPS->getPresentation(), uno::UNO_QUERY_THROW);
[ # # ]
55 [ # # ][ # # ]: 0 : if ( xPresentation->isRunning() )
[ # # ]
56 : : {
57 [ # # ][ # # ]: 0 : presentationStarted( xPresentation->getController() );
[ # # ]
58 [ # # ]: 0 : }
59 : : }
60 [ # # ]: 0 : catch (uno::RuntimeException &)
61 : : {
62 : : }
63 : :
64 : : sal_uInt64 aRet;
65 [ # # ]: 0 : vector<OString> aCommand;
66 : 0 : while ( true )
67 : : {
68 : 0 : OString aLine;
69 [ # # ]: 0 : aRet = mpSocket->readLine( aLine );
70 [ # # ]: 0 : if ( aRet == 0 )
71 : : {
72 : : break; // I.e. transmission finished.
73 : : }
74 [ # # ]: 0 : if ( aLine.getLength() )
75 : : {
76 [ # # ]: 0 : aCommand.push_back( aLine );
77 : : }
78 : : else
79 : : {
80 [ # # ][ # # ]: 0 : aReceiver.parseCommand( aCommand );
81 : 0 : aCommand.clear();
82 : : }
83 [ # # ]: 0 : }
84 : : // TODO: deal with transmision errors gracefully.
85 [ # # ]: 0 : disposeListener();
86 : :
87 [ # # ]: 0 : pTransmitter->notifyFinished();
88 [ # # ]: 0 : pTransmitter->join();
89 : 0 : pTransmitter = NULL;
90 : :
91 [ # # ][ # # ]: 0 : delete mpSocket;
92 : :
93 [ # # ][ # # ]: 0 : RemoteServer::removeCommunicator( this );
94 : 0 : }
95 : :
96 : 0 : void Communicator::informListenerDestroyed()
97 : : {
98 : 0 : mListener.clear();
99 : 0 : }
100 : :
101 : 0 : void Communicator::presentationStarted( const css::uno::Reference<
102 : : css::presentation::XSlideShowController > &rController )
103 : : {
104 [ # # ]: 0 : if ( pTransmitter )
105 : : {
106 [ # # ][ # # ]: 0 : mListener = rtl::Reference<Listener>( new Listener( this, pTransmitter ) );
107 : 0 : mListener->init( rController );
108 : : }
109 : 0 : }
110 : :
111 : 0 : void Communicator::disposeListener()
112 : : {
113 [ # # ]: 0 : if ( mListener.is() )
114 : : {
115 : 0 : mListener->disposing();
116 : 0 : mListener = NULL;
117 : : }
118 : 0 : }
119 : :
120 : 0 : Transmitter* Communicator::getTransmitter()
121 : : {
122 : 0 : return pTransmitter;
123 : : }
124 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|