2012-07-13 17:34:49 +01:00
|
|
|
/* -*- 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" ),
|
2012-07-18 16:14:52 +02:00
|
|
|
mStreamSocket( aSocket ),
|
|
|
|
mQueuesNotEmpty(),
|
|
|
|
mQueueMutex(),
|
|
|
|
mLowPriority(),
|
|
|
|
mHighPriority()
|
2012-07-13 17:34:49 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-18 22:04:09 +02:00
|
|
|
void Transmitter::execute()
|
2012-07-13 17:34:49 +01:00
|
|
|
{
|
2012-07-17 23:03:31 +02:00
|
|
|
fprintf( stderr, "Waiting\n" );
|
2012-07-13 17:34:49 +01:00
|
|
|
while( mQueuesNotEmpty.wait() )
|
|
|
|
{
|
2012-07-18 10:19:35 +02:00
|
|
|
fprintf( stderr, "Continuing after condition\n" );
|
2012-07-13 17:34:49 +01:00
|
|
|
while ( true )
|
|
|
|
{
|
2012-07-18 22:04:09 +02:00
|
|
|
fprintf( stderr, "Trying to acquire mutex in Transmitter Thread\n" );
|
2012-07-18 16:14:52 +02:00
|
|
|
::osl::MutexGuard aQueueGuard( mQueueMutex );
|
2012-07-18 22:04:09 +02:00
|
|
|
fprintf( stderr, "Acquired mutex in Transmitter Thread\n" );
|
2012-07-13 17:34:49 +01:00
|
|
|
while ( mHighPriority.size() )
|
|
|
|
{
|
2012-07-17 23:22:39 +02:00
|
|
|
OString aMessage( mHighPriority.front() );
|
2012-07-13 17:34:49 +01:00
|
|
|
mHighPriority.pop();
|
2012-07-17 23:03:31 +02:00
|
|
|
fprintf(stderr , " Writing HIGHP:\n%s<<END>>", aMessage.getStr() );
|
2012-07-13 17:34:49 +01:00
|
|
|
mStreamSocket.write( aMessage.getStr(), aMessage.getLength() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( mLowPriority.size() )
|
|
|
|
{
|
2012-07-17 23:22:39 +02:00
|
|
|
OString aMessage( mLowPriority.front() );
|
2012-07-13 17:34:49 +01:00
|
|
|
mLowPriority.pop();
|
2012-07-17 23:03:31 +02:00
|
|
|
fprintf(stderr , " Writing LOWP:\n%s<<END>>", aMessage.getStr() );
|
2012-07-13 17:34:49 +01:00
|
|
|
mStreamSocket.write( aMessage.getStr(), aMessage.getLength() );
|
|
|
|
}
|
|
|
|
|
2012-07-18 16:14:52 +02:00
|
|
|
if ( mLowPriority.empty() && mHighPriority.empty() )
|
2012-07-13 17:34:49 +01:00
|
|
|
{
|
|
|
|
mQueuesNotEmpty.reset();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Transmitter::~Transmitter()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-18 16:14:52 +02:00
|
|
|
void Transmitter::addMessage( const OString& aMessage, const Priority aPriority )
|
2012-07-13 17:34:49 +01:00
|
|
|
{
|
2012-07-18 16:14:52 +02:00
|
|
|
fprintf(stderr, "Acquiring\n");
|
|
|
|
::osl::MutexGuard aQueueGuard( mQueueMutex );
|
|
|
|
fprintf(stderr, "Acquired\n" );
|
2012-07-13 17:34:49 +01:00
|
|
|
switch ( aPriority )
|
|
|
|
{
|
|
|
|
case Priority::LOW:
|
2012-07-18 16:14:52 +02:00
|
|
|
fprintf(stderr, "PushingLow\n");
|
2012-07-13 17:34:49 +01:00
|
|
|
mLowPriority.push( aMessage );
|
|
|
|
break;
|
|
|
|
case Priority::HIGH:
|
2012-07-18 22:04:09 +02:00
|
|
|
fprintf(stderr, "PushingHigh\n<<<%s>>>\n", aMessage.getStr() );
|
2012-07-13 17:34:49 +01:00
|
|
|
mHighPriority.push( aMessage );
|
|
|
|
break;
|
|
|
|
}
|
2012-07-18 16:14:52 +02:00
|
|
|
fprintf( stderr, "Setting\n" );
|
|
|
|
if ( !mQueuesNotEmpty.check() )
|
2012-07-18 22:04:09 +02:00
|
|
|
{
|
2012-07-18 16:14:52 +02:00
|
|
|
mQueuesNotEmpty.set();
|
2012-07-18 22:04:09 +02:00
|
|
|
fprintf( stderr, "Condition has now been set\n" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Condition was already set\n" );
|
|
|
|
}
|
2012-07-18 10:19:35 +02:00
|
|
|
fprintf( stderr, "Added\n" );
|
2012-07-18 22:04:09 +02:00
|
|
|
fprintf( stderr, "Front:\n<<<%s>>>\n", mHighPriority.front().getStr() );
|
2012-07-13 17:34:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|