tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / remotecontrol / Transmitter.cxx
blob7992e5b94bd645c7e69e4561cb0aadf6b5e97ac8
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 osl; // Sockets etc.
14 using namespace sd;
16 Transmitter::Transmitter( IBluetoothSocket* aSocket )
17 : pStreamSocket( aSocket ),
18 mFinishRequested( false )
22 void SAL_CALL Transmitter::run()
24 osl_setThreadName("bluetooth Transmitter");
26 while ( true )
28 mProcessingRequired.wait();
30 OString aMessage;
31 bool isHighPrio = {};
34 ::osl::MutexGuard aGuard(mMutex);
36 if (mFinishRequested) {
37 return;
39 if (!mHighPriority.empty())
41 aMessage = mHighPriority.front();
42 mHighPriority.pop();
43 isHighPrio = true;
45 else if (!mLowPriority.empty())
47 aMessage = mLowPriority.front();
48 mLowPriority.pop();
49 isHighPrio = false;
53 SAL_INFO("sdremote.bluetooth", "write " << (isHighPrio ? "high prio" : "normal") << " line '" << aMessage << "'");
54 // pStreamSocket is owned by Communicator, which joins this thread
55 // before destroying pStreamSocket so it can't die here.
56 // Sending is SLOW and blocks!
57 pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
60 ::osl::MutexGuard aGuard(mMutex);
62 if (mLowPriority.empty() && mHighPriority.empty())
64 mProcessingRequired.reset();
70 void Transmitter::notifyFinished()
72 ::osl::MutexGuard aGuard( mMutex );
73 mFinishRequested = true;
74 mProcessingRequired.set();
77 Transmitter::~Transmitter()
81 void Transmitter::addMessage( const OString& aMessage, const Priority aPriority )
83 ::osl::MutexGuard aGuard( mMutex );
84 switch ( aPriority )
86 case PRIORITY_LOW:
87 mLowPriority.push( aMessage );
88 break;
89 case PRIORITY_HIGH:
90 mHighPriority.push( aMessage );
91 break;
93 if ( !mProcessingRequired.check() )
95 mProcessingRequired.set();
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */