diff options
author | Andrzej J. R. Hunt <andrzej@ahunt.org> | 2012-07-13 17:34:49 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2012-08-06 10:22:56 +0100 |
commit | 05e4f2ac050f3d14f2e388fd3b33dcb8548182b8 (patch) | |
tree | ff745003ad75c47b984da452310f90c9a71750a0 /sd/source/ui/remotecontrol/Transmitter.cxx | |
parent | 01234d6aa88fed2f88b6080eabeeae5d391ebdbf (diff) |
Transmitter for queuing of messages (Client->Server), fixed protocol.
Change-Id: I Idcf6cf33b75dde2f921bec6c64e394e91994aba0
Diffstat (limited to 'sd/source/ui/remotecontrol/Transmitter.cxx')
-rw-r--r-- | sd/source/ui/remotecontrol/Transmitter.cxx | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/sd/source/ui/remotecontrol/Transmitter.cxx b/sd/source/ui/remotecontrol/Transmitter.cxx new file mode 100644 index 000000000000..276fc89bc442 --- /dev/null +++ b/sd/source/ui/remotecontrol/Transmitter.cxx @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#include "Transmitter.hxx" + +using rtl::OString; +using namespace std; +using namespace osl; // Sockets etc. +using namespace sd; + +Transmitter::Transmitter( StreamSocket &aSocket ) + : Thread( "TransmitterThread" ), + mStreamSocket( aSocket ), + mQueuesNotEmpty(), + mQueueMutex() +{ + launch(); + // Start a thread +} + +void +Transmitter::execute() +{ + while( mQueuesNotEmpty.wait() ) + { + while ( true ) + { + osl::MutexGuard aQueueGuard( mQueueMutex ); + while ( mHighPriority.size() ) + { + OString aMessage = mHighPriority.front(); + mHighPriority.pop(); + mStreamSocket.write( aMessage.getStr(), aMessage.getLength() ); + } + + if( mLowPriority.size() ) + { + OString aMessage = mLowPriority.front(); + mLowPriority.pop(); + mStreamSocket.write( aMessage.getStr(), aMessage.getLength() ); + } + + //fprintf( stderr, "Lowsize:%i, Highsize:%i\n", mLowPriority.size(), mHighPriority.size() ); + if ( (mLowPriority.size() == 0) && (mHighPriority.size() == 0) ) + { + mQueuesNotEmpty.reset(); + break; + } + } + + } + +} + +Transmitter::~Transmitter() +{ + +} + +void Transmitter::addMessage( OString aMessage, Priority aPriority ) +{ + osl::MutexGuard aQueueGuard( mQueueMutex ); + switch ( aPriority ) + { + case Priority::LOW: + mLowPriority.push( aMessage ); + break; + case Priority::HIGH: + mHighPriority.push( aMessage ); + break; + } + mQueuesNotEmpty.set(); + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file |