bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / remotecontrol / Transmitter.cxx
blob8f3b7d24c184eef3e2d5d23b6c5fc73ca4e4aa61
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"
10 #include "IBluetoothSocket.hxx"
11 #include <sal/log.hxx>
13 using namespace std;
14 using namespace osl; // Sockets etc.
15 using namespace sd;
17 Transmitter::Transmitter( IBluetoothSocket* aSocket )
18 : pStreamSocket( aSocket ),
19 mQueuesNotEmpty(),
20 mFinishRequested(),
21 mQueueMutex(),
22 mLowPriority(),
23 mHighPriority()
27 void SAL_CALL Transmitter::run()
29 osl_setThreadName("bluetooth Transmitter");
31 while ( true )
33 mQueuesNotEmpty.wait();
35 if ( mFinishRequested.check() )
36 return;
38 ::osl::MutexGuard aQueueGuard( mQueueMutex );
39 if ( !mHighPriority.empty() )
41 OString aMessage( mHighPriority.front() );
42 mHighPriority.pop();
43 SAL_INFO( "sdremote.bluetooth", "write high prio line '" << aMessage << "'" );
44 pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
46 else if ( !mLowPriority.empty() )
48 OString aMessage( mLowPriority.front() );
49 mLowPriority.pop();
50 SAL_INFO( "sdremote.bluetooth", "write normal line '" << aMessage << "'" );
51 pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
54 if ( mLowPriority.empty() && mHighPriority.empty() )
56 mQueuesNotEmpty.reset();
61 void Transmitter::notifyFinished()
63 mFinishRequested.set();
64 mQueuesNotEmpty.set();
67 Transmitter::~Transmitter()
71 void Transmitter::addMessage( const OString& aMessage, const Priority aPriority )
73 ::osl::MutexGuard aQueueGuard( mQueueMutex );
74 switch ( aPriority )
76 case PRIORITY_LOW:
77 mLowPriority.push( aMessage );
78 break;
79 case PRIORITY_HIGH:
80 mHighPriority.push( aMessage );
81 break;
83 if ( !mQueuesNotEmpty.check() )
85 mQueuesNotEmpty.set();
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */