fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / remotecontrol / Transmitter.cxx
blobcc7b8ec8bf76998034e45e727a7ac8e3447adc78
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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"
11 using namespace std;
12 using namespace osl; // Sockets etc.
13 using namespace sd;
15 Transmitter::Transmitter( IBluetoothSocket* aSocket )
16 : pStreamSocket( aSocket ),
17 mQueuesNotEmpty(),
18 mFinishRequested(),
19 mQueueMutex(),
20 mLowPriority(),
21 mHighPriority()
25 void SAL_CALL Transmitter::run()
27 while ( true )
29 mQueuesNotEmpty.wait();
31 if ( mFinishRequested.check() )
32 return;
34 ::osl::MutexGuard aQueueGuard( mQueueMutex );
35 if ( !mHighPriority.empty() )
37 OString aMessage( mHighPriority.front() );
38 mHighPriority.pop();
39 SAL_INFO( "sdremote.bluetooth", "write high prio line '" << aMessage << "'" );
40 pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
42 else if ( !mLowPriority.empty() )
44 OString aMessage( mLowPriority.front() );
45 mLowPriority.pop();
46 SAL_INFO( "sdremote.bluetooth", "write normal line '" << aMessage << "'" );
47 pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
50 if ( mLowPriority.empty() && mHighPriority.empty() )
52 mQueuesNotEmpty.reset();
57 void Transmitter::notifyFinished()
59 mFinishRequested.set();
60 mQueuesNotEmpty.set();
63 Transmitter::~Transmitter()
67 void Transmitter::addMessage( const OString& aMessage, const Priority aPriority )
69 ::osl::MutexGuard aQueueGuard( mQueueMutex );
70 switch ( aPriority )
72 case PRIORITY_LOW:
73 mLowPriority.push( aMessage );
74 break;
75 case PRIORITY_HIGH:
76 mHighPriority.push( aMessage );
77 break;
79 if ( !mQueuesNotEmpty.check() )
81 mQueuesNotEmpty.set();
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */