LCOV - code coverage report
Current view: top level - sd/source/ui/remotecontrol - Transmitter.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 36 0.0 %
Date: 2014-04-14 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 "Transmitter.hxx"
      10             : #include <iostream>
      11             : 
      12             : using namespace std;
      13             : using namespace osl; // Sockets etc.
      14             : using namespace sd;
      15             : 
      16           0 : Transmitter::Transmitter( IBluetoothSocket* aSocket )
      17             :   : pStreamSocket( aSocket ),
      18             :     mQueuesNotEmpty(),
      19             :     mFinishRequested(),
      20             :     mQueueMutex(),
      21             :     mLowPriority(),
      22           0 :     mHighPriority()
      23             : {
      24           0 : }
      25             : 
      26           0 : void SAL_CALL Transmitter::run()
      27             : {
      28             :     while ( true )
      29             :     {
      30           0 :         mQueuesNotEmpty.wait();
      31             : 
      32           0 :         if ( mFinishRequested.check() )
      33           0 :             return;
      34             : 
      35           0 :         ::osl::MutexGuard aQueueGuard( mQueueMutex );
      36           0 :         if ( !mHighPriority.empty() )
      37             :         {
      38           0 :             OString aMessage( mHighPriority.front() );
      39           0 :             mHighPriority.pop();
      40             :             SAL_INFO( "sdremote.bluetooth", "write high prio line '" << aMessage << "'" );
      41           0 :             pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
      42             :         }
      43           0 :         else if ( !mLowPriority.empty() )
      44             :         {
      45           0 :             OString aMessage( mLowPriority.front() );
      46           0 :             mLowPriority.pop();
      47             :             SAL_INFO( "sdremote.bluetooth", "write normal line '" << aMessage << "'" );
      48           0 :             pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
      49             :         }
      50             : 
      51           0 :         if ( mLowPriority.empty() && mHighPriority.empty() )
      52             :         {
      53           0 :             mQueuesNotEmpty.reset();
      54             :         }
      55           0 :     }
      56             : }
      57             : 
      58           0 : void Transmitter::notifyFinished()
      59             : {
      60           0 :     mFinishRequested.set();
      61           0 :     mQueuesNotEmpty.set();
      62           0 : }
      63             : 
      64           0 : Transmitter::~Transmitter()
      65             : {
      66           0 : }
      67             : 
      68           0 : void Transmitter::addMessage( const OString& aMessage, const Priority aPriority )
      69             : {
      70           0 :     ::osl::MutexGuard aQueueGuard( mQueueMutex );
      71           0 :     switch ( aPriority )
      72             :     {
      73             :         case PRIORITY_LOW:
      74           0 :             mLowPriority.push( aMessage );
      75           0 :             break;
      76             :         case PRIORITY_HIGH:
      77           0 :             mHighPriority.push( aMessage );
      78           0 :             break;
      79             :     }
      80           0 :     if ( !mQueuesNotEmpty.check() )
      81             :     {
      82           0 :         mQueuesNotEmpty.set();
      83           0 :     }
      84           0 : }
      85             : 
      86             : 
      87             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10