bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / remotecontrol / Transmitter.cxx
blobd03ff5bdffd5d423d8f1bc0a24805e5a1fd5a57d
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 osl_setThreadName("bluetooth Transmitter");
29 while ( true )
31 mQueuesNotEmpty.wait();
33 if ( mFinishRequested.check() )
34 return;
36 ::osl::MutexGuard aQueueGuard( mQueueMutex );
37 if ( !mHighPriority.empty() )
39 OString aMessage( mHighPriority.front() );
40 mHighPriority.pop();
41 SAL_INFO( "sdremote.bluetooth", "write high prio line '" << aMessage << "'" );
42 pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
44 else if ( !mLowPriority.empty() )
46 OString aMessage( mLowPriority.front() );
47 mLowPriority.pop();
48 SAL_INFO( "sdremote.bluetooth", "write normal line '" << aMessage << "'" );
49 pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
52 if ( mLowPriority.empty() && mHighPriority.empty() )
54 mQueuesNotEmpty.reset();
59 void Transmitter::notifyFinished()
61 mFinishRequested.set();
62 mQueuesNotEmpty.set();
65 Transmitter::~Transmitter()
69 void Transmitter::addMessage( const OString& aMessage, const Priority aPriority )
71 ::osl::MutexGuard aQueueGuard( mQueueMutex );
72 switch ( aPriority )
74 case PRIORITY_LOW:
75 mLowPriority.push( aMessage );
76 break;
77 case PRIORITY_HIGH:
78 mHighPriority.push( aMessage );
79 break;
81 if ( !mQueuesNotEmpty.check() )
83 mQueuesNotEmpty.set();
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */