Branch data Line data Source code
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 : :
11 : : using rtl::OString;
12 : : using namespace std;
13 : : using namespace osl; // Sockets etc.
14 : : using namespace sd;
15 : :
16 : 0 : Transmitter::Transmitter( BufferedStreamSocket* aSocket )
17 : : : Thread( "TransmitterThread" ),
18 : : pStreamSocket( aSocket ),
19 : : mQueuesNotEmpty(),
20 : : mFinishRequested(),
21 : : mQueueMutex(),
22 : : mLowPriority(),
23 [ # # ][ # # ]: 0 : mHighPriority()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
24 : : {
25 : 0 : }
26 : :
27 : 0 : void Transmitter::execute()
28 : : {
29 : 0 : while ( true )
30 : : {
31 [ # # ]: 0 : mQueuesNotEmpty.wait();
32 : :
33 [ # # ][ # # ]: 0 : if ( mFinishRequested.check() )
34 : 0 : return;
35 : :
36 [ # # ]: 0 : ::osl::MutexGuard aQueueGuard( mQueueMutex );
37 [ # # ]: 0 : if ( !mHighPriority.empty() )
38 : : {
39 [ # # ]: 0 : OString aMessage( mHighPriority.front() );
40 [ # # ]: 0 : mHighPriority.pop();
41 [ # # ]: 0 : pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
42 : : }
43 [ # # ]: 0 : else if ( !mLowPriority.empty() )
44 : : {
45 [ # # ]: 0 : OString aMessage( mLowPriority.front() );
46 [ # # ]: 0 : mLowPriority.pop();
47 [ # # ]: 0 : pStreamSocket->write( aMessage.getStr(), aMessage.getLength() );
48 : : }
49 : :
50 [ # # ][ # # ]: 0 : if ( mLowPriority.empty() && mHighPriority.empty() )
[ # # ]
51 : : {
52 [ # # ]: 0 : mQueuesNotEmpty.reset();
53 : : }
54 [ # # ]: 0 : }
55 : :
56 : : }
57 : :
58 : 0 : void Transmitter::notifyFinished()
59 : : {
60 : 0 : mFinishRequested.set();
61 : 0 : mQueuesNotEmpty.set();
62 : 0 : }
63 : :
64 [ # # ][ # # ]: 0 : Transmitter::~Transmitter()
[ # # ]
65 : : {
66 : :
67 [ # # ]: 0 : }
68 : :
69 : 0 : void Transmitter::addMessage( const OString& aMessage, const Priority aPriority )
70 : : {
71 [ # # ]: 0 : ::osl::MutexGuard aQueueGuard( mQueueMutex );
72 [ # # # ]: 0 : switch ( aPriority )
73 : : {
74 : : case PRIORITY_LOW:
75 [ # # ]: 0 : mLowPriority.push( aMessage );
76 : 0 : break;
77 : : case PRIORITY_HIGH:
78 [ # # ]: 0 : mHighPriority.push( aMessage );
79 : 0 : break;
80 : : }
81 [ # # ][ # # ]: 0 : if ( !mQueuesNotEmpty.check() )
82 : : {
83 [ # # ]: 0 : mQueuesNotEmpty.set();
84 [ # # ]: 0 : }
85 : 0 : }
86 : :
87 : :
88 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|