1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 #include "Transmitter.hxx"
10 #include "IBluetoothSocket.hxx"
11 #include <sal/log.hxx>
13 using namespace osl
; // Sockets etc.
16 Transmitter::Transmitter( IBluetoothSocket
* aSocket
)
17 : pStreamSocket( aSocket
),
18 mFinishRequested( false )
22 void SAL_CALL
Transmitter::run()
24 osl_setThreadName("bluetooth Transmitter");
28 mProcessingRequired
.wait();
34 ::osl::MutexGuard
aGuard(mMutex
);
36 if (mFinishRequested
) {
39 if (!mHighPriority
.empty())
41 aMessage
= mHighPriority
.front();
45 else if (!mLowPriority
.empty())
47 aMessage
= mLowPriority
.front();
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
);
87 mLowPriority
.push( aMessage
);
90 mHighPriority
.push( aMessage
);
93 if ( !mProcessingRequired
.check() )
95 mProcessingRequired
.set();
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */