LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/remotecontrol - Communicator.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 59 1.7 %
Date: 2013-07-09 Functions: 2 10 20.0 %
Legend: Lines: hit not hit

          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 <com/sun/star/frame/Desktop.hpp>
      13             : #include <comphelper/processfactory.hxx>
      14             : 
      15             : #include "Communicator.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( IBluetoothSocket *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             : /// Close the underlying socket from another thread to force
      38             : /// an early exit / termination
      39           0 : void Communicator::forceClose()
      40             : {
      41           0 :     if( mpSocket )
      42           0 :         mpSocket->close();
      43           0 : }
      44             : 
      45             : // Run as a thread
      46           0 : void Communicator::execute()
      47             : {
      48           0 :     pTransmitter = new Transmitter( mpSocket );
      49           0 :     pTransmitter->create();
      50             : 
      51             :     pTransmitter->addMessage( "LO_SERVER_SERVER_PAIRED\n\n",
      52           0 :                               Transmitter::PRIORITY_HIGH );
      53           0 :     Receiver aReceiver( pTransmitter );
      54             :     try {
      55           0 :         uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
      56           0 :         uno::Reference< frame::XFrame > xFrame ( xFramesSupplier->getActiveFrame(), uno::UNO_QUERY );
      57             : 
      58           0 :         uno::Reference<presentation::XPresentationSupplier> xPS;
      59           0 :         if( xFrame.is() )
      60           0 :             xPS = uno::Reference<presentation::XPresentationSupplier>( xFrame->getController()->getModel(), uno::UNO_QUERY );
      61           0 :         uno::Reference<presentation::XPresentation2> xPresentation;
      62           0 :         if( xPS.is() )
      63           0 :             xPresentation = uno::Reference<presentation::XPresentation2>( xPS->getPresentation(), uno::UNO_QUERY );
      64           0 :         if ( xPresentation.is() && xPresentation->isRunning() )
      65             :         {
      66           0 :             presentationStarted( xPresentation->getController() );
      67             :         }
      68             :         else
      69             :         {
      70             :             pTransmitter->addMessage( "slideshow_finished\n\n",
      71           0 :                                       Transmitter::PRIORITY_HIGH );
      72           0 :         }
      73             :     }
      74           0 :     catch (uno::RuntimeException &)
      75             :     {
      76             :     }
      77             : 
      78             :     sal_uInt64 aRet;
      79           0 :     vector<OString> aCommand;
      80             :     while ( true )
      81             :     {
      82           0 :         OString aLine;
      83           0 :         aRet = mpSocket->readLine( aLine );
      84           0 :         if ( aRet == 0 )
      85             :         {
      86           0 :             break; // I.e. transmission finished.
      87             :         }
      88           0 :         if ( aLine.getLength() )
      89             :         {
      90           0 :             aCommand.push_back( aLine );
      91             :         }
      92             :         else
      93             :         {
      94           0 :             aReceiver.pushCommand( aCommand );
      95           0 :             aCommand.clear();
      96             :         }
      97           0 :     }
      98           0 :     disposeListener();
      99             : 
     100           0 :     pTransmitter->notifyFinished();
     101           0 :     pTransmitter->join();
     102           0 :     pTransmitter = NULL;
     103             : 
     104           0 :     delete mpSocket;
     105             : 
     106           0 :     RemoteServer::removeCommunicator( this );
     107           0 : }
     108             : 
     109           0 : void Communicator::informListenerDestroyed()
     110             : {
     111           0 :     if ( pTransmitter )
     112             :         pTransmitter->addMessage( "slideshow_finished\n\n",
     113           0 :                                   Transmitter::PRIORITY_HIGH );
     114           0 :     mListener.clear();
     115           0 : }
     116             : 
     117           0 : void Communicator::presentationStarted( const css::uno::Reference<
     118             :      css::presentation::XSlideShowController > &rController )
     119             : {
     120           0 :     if ( pTransmitter )
     121             :     {
     122           0 :         mListener = rtl::Reference<Listener>( new Listener( this, pTransmitter ) );
     123           0 :         mListener->init( rController );
     124             :     }
     125           0 : }
     126             : 
     127           0 : void Communicator::disposeListener()
     128             : {
     129           0 :     if ( mListener.is() )
     130             :     {
     131           0 :         mListener->disposing();
     132           0 :         mListener = NULL;
     133             :     }
     134          33 : }
     135             : 
     136             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10