LibreOffice Module sd (master) 1
Transmitter.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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>
12
13using namespace osl; // Sockets etc.
14using namespace sd;
15
16Transmitter::Transmitter( IBluetoothSocket* aSocket )
17 : pStreamSocket( aSocket ),
18 mFinishRequested( false )
19{
20}
21
22void SAL_CALL Transmitter::run()
23{
24 osl_setThreadName("bluetooth Transmitter");
25
26 while ( true )
27 {
29
30 ::osl::MutexGuard aGuard( mMutex );
31
32 if ( mFinishRequested ) {
33 return;
34 }
35 if ( !mHighPriority.empty() )
36 {
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() );
41 }
42 else if ( !mLowPriority.empty() )
43 {
44 OString aMessage( mLowPriority.front() );
45 mLowPriority.pop();
46 SAL_INFO( "sdremote.bluetooth", "write normal line '" << aMessage << "'" );
47 pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
48 }
49
50 if ( mLowPriority.empty() && mHighPriority.empty())
51 {
52 mProcessingRequired.reset();
53 }
54 }
55}
56
58{
59 ::osl::MutexGuard aGuard( mMutex );
60 mFinishRequested = true;
62}
63
65{
66}
67
68void Transmitter::addMessage( const OString& aMessage, const Priority aPriority )
69{
70 ::osl::MutexGuard aGuard( mMutex );
71 switch ( aPriority )
72 {
73 case PRIORITY_LOW:
74 mLowPriority.push( aMessage );
75 break;
76 case PRIORITY_HIGH:
77 mHighPriority.push( aMessage );
78 break;
79 }
80 if ( !mProcessingRequired.check() )
81 {
83 }
84}
85
86/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::osl::Condition mProcessingRequired
Definition: Transmitter.hxx:39
bool mFinishRequested
Used to indicate that we're done and the transmitter loop should exit.
Definition: Transmitter.hxx:46
virtual ~Transmitter() override
Definition: Transmitter.cxx:64
void notifyFinished()
Definition: Transmitter.cxx:57
std::queue< OString > mHighPriority
Queue for high priority messages. All access must be guarded my mMutex.
Definition: Transmitter.hxx:50
::sd::IBluetoothSocket * pStreamSocket
Definition: Transmitter.hxx:37
std::queue< OString > mLowPriority
Queue for low priority messages. All access must be guarded my mMutex.
Definition: Transmitter.hxx:48
virtual void SAL_CALL run() override
Definition: Transmitter.cxx:22
void addMessage(const OString &aMessage, const Priority aPriority)
Definition: Transmitter.cxx:68
::osl::Mutex mMutex
Definition: Transmitter.hxx:41
#define SAL_INFO(area, stream)
Interface for bluetooth data io.
virtual sal_Int32 write(const void *pBuffer, sal_uInt32 n)=0
Write a number of bytes.