LCOV - code coverage report
Current view: top level - sd/source/ui/remotecontrol - Communicator.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 68 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 8 0.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             : #include <comphelper/documentinfo.hxx>
      15             : #include <config_version.h>
      16             : #include <rtl/string.hxx>
      17             : #include <rtl/strbuf.hxx>
      18             : 
      19             : #include "Communicator.hxx"
      20             : #include "Listener.hxx"
      21             : #include "Receiver.hxx"
      22             : #include "RemoteServer.hxx"
      23             : 
      24             : using namespace sd;
      25             : using namespace std;
      26             : using namespace com::sun::star;
      27             : using namespace osl;
      28             : 
      29           0 : Communicator::Communicator( IBluetoothSocket *pSocket ):
      30             :     Thread( "CommunicatorThread" ),
      31             :     mpSocket( pSocket ),
      32             :     pTransmitter( 0 ),
      33           0 :     mListener( 0 )
      34             : {
      35           0 : }
      36             : 
      37           0 : Communicator::~Communicator()
      38             : {
      39           0 : }
      40             : 
      41             : /// Close the underlying socket from another thread to force
      42             : /// an early exit / termination
      43           0 : void Communicator::forceClose()
      44             : {
      45           0 :     if( mpSocket )
      46           0 :         mpSocket->close();
      47           0 : }
      48             : 
      49             : // Run as a thread
      50           0 : void Communicator::execute()
      51             : {
      52           0 :     pTransmitter = new Transmitter( mpSocket );
      53           0 :     pTransmitter->create();
      54             : 
      55             :     pTransmitter->addMessage( "LO_SERVER_SERVER_PAIRED\n\n",
      56           0 :                               Transmitter::PRIORITY_HIGH );
      57             : 
      58           0 :     OStringBuffer aServerInformationBuffer;
      59           0 :     aServerInformationBuffer.append( "LO_SERVER_INFO\n" LIBO_VERSION_DOTTED "\n\n" );
      60             : 
      61           0 :     pTransmitter->addMessage( aServerInformationBuffer.makeStringAndClear(), Transmitter::PRIORITY_HIGH );
      62             : 
      63           0 :     Receiver aReceiver( pTransmitter );
      64             :     try {
      65           0 :         uno::Reference< frame::XDesktop2 > xFramesSupplier = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
      66           0 :         uno::Reference< frame::XFrame > xFrame ( xFramesSupplier->getActiveFrame(), uno::UNO_QUERY );
      67             : 
      68           0 :         uno::Reference<presentation::XPresentationSupplier> xPS;
      69           0 :         if( xFrame.is() )
      70           0 :             xPS = uno::Reference<presentation::XPresentationSupplier>( xFrame->getController()->getModel(), uno::UNO_QUERY );
      71           0 :         uno::Reference<presentation::XPresentation2> xPresentation;
      72           0 :         if( xPS.is() )
      73           0 :             xPresentation = uno::Reference<presentation::XPresentation2>( xPS->getPresentation(), uno::UNO_QUERY );
      74           0 :         if ( xPresentation.is() && xPresentation->isRunning() )
      75             :         {
      76           0 :             presentationStarted( xPresentation->getController() );
      77             :         }
      78             :         else
      79             :         {
      80             :             pTransmitter->addMessage( "slideshow_finished\n\n",
      81           0 :                                       Transmitter::PRIORITY_HIGH );
      82             :         }
      83             : 
      84           0 :         OStringBuffer aBuffer;
      85             :         aBuffer
      86           0 :           .append( "slideshow_info\n" )
      87           0 :           .append( OUStringToOString( ::comphelper::DocumentInfo::getDocumentTitle( xFrame->getController()->getModel() ), RTL_TEXTENCODING_UTF8 ) )
      88           0 :           .append("\n\n");
      89             : 
      90           0 :         pTransmitter->addMessage( aBuffer.makeStringAndClear(), Transmitter::PRIORITY_LOW );
      91             :     }
      92           0 :     catch (uno::RuntimeException &)
      93             :     {
      94             :     }
      95             : 
      96             :     sal_uInt64 aRet;
      97           0 :     vector<OString> aCommand;
      98             :     while ( true )
      99             :     {
     100           0 :         OString aLine;
     101           0 :         aRet = mpSocket->readLine( aLine );
     102           0 :         if ( aRet == 0 )
     103             :         {
     104           0 :             break; // I.e. transmission finished.
     105             :         }
     106           0 :         if ( aLine.getLength() )
     107             :         {
     108           0 :             aCommand.push_back( aLine );
     109             :         }
     110             :         else
     111             :         {
     112           0 :             aReceiver.pushCommand( aCommand );
     113           0 :             aCommand.clear();
     114             :         }
     115           0 :     }
     116             : 
     117             :     SAL_INFO ("sdremote", "Exiting transmission loop\n");
     118             : 
     119           0 :     disposeListener();
     120             : 
     121           0 :     pTransmitter->notifyFinished();
     122           0 :     pTransmitter->join();
     123           0 :     pTransmitter = NULL;
     124             : 
     125           0 :     mpSocket->close();
     126           0 :     delete mpSocket;
     127           0 :     mpSocket = NULL;
     128             : 
     129           0 :     RemoteServer::removeCommunicator( this );
     130           0 : }
     131             : 
     132           0 : void Communicator::informListenerDestroyed()
     133             : {
     134           0 :     if ( pTransmitter )
     135             :         pTransmitter->addMessage( "slideshow_finished\n\n",
     136           0 :                                   Transmitter::PRIORITY_HIGH );
     137           0 :     mListener.clear();
     138           0 : }
     139             : 
     140           0 : void Communicator::presentationStarted( const css::uno::Reference<
     141             :      css::presentation::XSlideShowController > &rController )
     142             : {
     143           0 :     if ( pTransmitter )
     144             :     {
     145           0 :         mListener = rtl::Reference<Listener>( new Listener( this, pTransmitter ) );
     146           0 :         mListener->init( rController );
     147             :     }
     148           0 : }
     149             : 
     150           0 : void Communicator::disposeListener()
     151             : {
     152           0 :     if ( mListener.is() )
     153             :     {
     154           0 :         mListener->disposing();
     155           0 :         mListener = NULL;
     156             :     }
     157           0 : }
     158             : 
     159             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11