replaced handler thread implementation from direct POSIX thread to
LiveSupport::Core::Thread
This commit is contained in:
parent
17afe62335
commit
a279b355c1
|
@ -21,7 +21,7 @@
|
|||
#
|
||||
#
|
||||
# Author : $Author: maroy $
|
||||
# Version : $Revision: 1.3 $
|
||||
# Version : $Revision: 1.4 $
|
||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/etc/Makefile.in,v $
|
||||
#
|
||||
# @configure_input@
|
||||
|
@ -85,6 +85,8 @@ TEST_RUNNER = ${TMP_DIR}/testRunner
|
|||
|
||||
DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config
|
||||
|
||||
export LD_LIBRARY_PATH=${USR_LIB_DIR}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Configuration parameters
|
||||
|
@ -110,18 +112,19 @@ LDFLAGS = @LDFLAGS@ -pthread \
|
|||
# Dependencies
|
||||
#-------------------------------------------------------------------------------
|
||||
PLAYLIST_EXECUTOR_LIB_OBJS = ${TMP_DIR}/HelixPlayer.o \
|
||||
${TMP_DIR}/HelixEventHandlerThread.o \
|
||||
${TMP_DIR}/AdviseSink.o \
|
||||
${TMP_DIR}/AuthenticationManager.o \
|
||||
${TMP_DIR}/ClientContext.o \
|
||||
${TMP_DIR}/ErrorSink.o \
|
||||
${TMP_DIR}/HelixIIDs.o \
|
||||
${TMP_DIR}/AudioPlayerFactory.o
|
||||
TEST_RUNNER_OBJS = ${TMP_DIR}/HelixPlayerTest.o \
|
||||
${TMP_DIR}/AudioPlayerFactoryTest.o \
|
||||
${TMP_DIR}/TestRunner.o
|
||||
TEST_RUNNER_OBJS = ${TMP_DIR}/TestRunner.o \
|
||||
${TMP_DIR}/HelixPlayerTest.o \
|
||||
${TMP_DIR}/AudioPlayerFactoryTest.o
|
||||
TEST_RUNNER_LIBS = -l${PLAYLIST_EXECUTOR_LIB} -l${CORE_LIB} \
|
||||
${HELIX_LIBS} \
|
||||
-lxml++-1.0 -lcppunit -ldl -lm -lpthread
|
||||
-lxml++-1.0 -lcppunit -ldl -lm
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
@ -152,8 +155,7 @@ distclean: clean docclean
|
|||
${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te*
|
||||
|
||||
check: all ${TEST_RUNNER}
|
||||
LD_LIBRARY_PATH=${USR_LIB_DIR} ${TEST_RUNNER} \
|
||||
-o ${TEST_RESULTS} -s ${TEST_XSLT}
|
||||
${TEST_RUNNER} -o ${TEST_RESULTS} -s ${TEST_XSLT}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Version : $Revision: 1.2 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/AudioPlayerFactory.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -100,7 +100,6 @@ AudioPlayerFactory :: configure(const xmlpp::Element & element)
|
|||
dynamic_cast<const xmlpp::Element*> (*(nodes.begin()));
|
||||
Ptr<HelixPlayer>::Ref hp(new HelixPlayer());
|
||||
hp->configure(*configElement);
|
||||
hp->initialize();
|
||||
audioPlayer = hp;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.2 $
|
||||
Version : $Revision: 1.3 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/AudioPlayerFactoryTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -85,6 +85,11 @@ AudioPlayerFactoryTest :: setUp(void) throw ()
|
|||
audioPlayerFactory = AudioPlayerFactory::getInstance();
|
||||
audioPlayerFactory->configure(*root);
|
||||
|
||||
// initialize the audio player configured by the factory
|
||||
Ptr<AudioPlayerInterface>::Ref audioPlayer;
|
||||
audioPlayer = audioPlayerFactory->getAudioPlayer();
|
||||
audioPlayer->initialize();
|
||||
|
||||
} catch (std::invalid_argument &e) {
|
||||
std::cerr << "semantic error in configuration file" << std::endl;
|
||||
} catch (xmlpp::exception &e) {
|
||||
|
@ -99,6 +104,17 @@ AudioPlayerFactoryTest :: setUp(void) throw ()
|
|||
void
|
||||
AudioPlayerFactoryTest :: tearDown(void) throw ()
|
||||
{
|
||||
try {
|
||||
Ptr<AudioPlayerFactory>::Ref audioPlayerFactory;
|
||||
audioPlayerFactory = AudioPlayerFactory::getInstance();
|
||||
|
||||
// de-initialize the audio player configured by the factory
|
||||
Ptr<AudioPlayerInterface>::Ref audioPlayer;
|
||||
audioPlayer = audioPlayerFactory->getAudioPlayer();
|
||||
audioPlayer->deInitialize();
|
||||
} catch (xmlpp::exception &e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/HelixEventHandlerThread.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include "LiveSupport/Core/TimeConversion.h"
|
||||
|
||||
#include "HelixEventHandlerThread.h"
|
||||
|
||||
|
||||
using namespace LiveSupport::Core;
|
||||
using namespace LiveSupport::PlaylistExecutor;
|
||||
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Constructor.
|
||||
*----------------------------------------------------------------------------*/
|
||||
HelixEventHandlerThread :: HelixEventHandlerThread(
|
||||
IHXClientEngine * clientEngine,
|
||||
Ptr<time_duration>::Ref granularity)
|
||||
throw ()
|
||||
{
|
||||
this->clientEngine = clientEngine;
|
||||
this->granularity = granularity;
|
||||
this->shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The main execution body of the thread.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
HelixEventHandlerThread :: run(void) throw ()
|
||||
{
|
||||
shouldRun = true;
|
||||
|
||||
while (shouldRun) {
|
||||
struct _HXxEvent * event = 0;
|
||||
clientEngine->EventOccurred(event);
|
||||
TimeConversion::sleep(granularity);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,146 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/HelixEventHandlerThread.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef HelixEventHandlerThread_h
|
||||
#define HelixEventHandlerThread_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include "LiveSupport/Core/RunnableInterface.h"
|
||||
#include "HelixPlayer.h"
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace PlaylistExecutor {
|
||||
|
||||
using namespace boost::posix_time;
|
||||
|
||||
using namespace LiveSupport::Core;
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* A thread that checks on Helix events every once in a while.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
class HelixEventHandlerThread : public virtual RunnableInterface
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* The Helix client engine to check.
|
||||
*/
|
||||
IHXClientEngine * clientEngine;
|
||||
|
||||
/**
|
||||
* The granularity of the thread: the time it will sleep
|
||||
* between checking up on the state of things.
|
||||
*/
|
||||
Ptr<time_duration>::Ref granularity;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the thread should still run, or
|
||||
* actually terminate.
|
||||
*/
|
||||
bool shouldRun;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
HelixEventHandlerThread(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param clientEngine the Helix client engine to check.
|
||||
* @param granularity the granularity of the thread: the time the
|
||||
* thread will sleep between checking up on things.
|
||||
*/
|
||||
HelixEventHandlerThread(IHXClientEngine * clientEngine,
|
||||
Ptr<time_duration>::Ref granularity)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* A virtual destructor, as this class has virtual functions.
|
||||
*/
|
||||
virtual
|
||||
~HelixEventHandlerThread(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* The main execution loop for the thread.
|
||||
*/
|
||||
virtual void
|
||||
run(void) throw ();
|
||||
|
||||
/**
|
||||
* Signal the thread to stop, gracefully.
|
||||
*/
|
||||
virtual void
|
||||
stop(void) throw ()
|
||||
{
|
||||
shouldRun = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace PlaylistExecutor
|
||||
} // namespace LiveSupport
|
||||
|
||||
|
||||
#endif // HelixEventHandlerThread_h
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.4 $
|
||||
Version : $Revision: 1.5 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/HelixPlayer.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -36,6 +36,7 @@
|
|||
#include "HelixDefs.h"
|
||||
|
||||
#include "LiveSupport/Core/TimeConversion.h"
|
||||
#include "HelixEventHandlerThread.h"
|
||||
#include "HelixPlayer.h"
|
||||
|
||||
|
||||
|
@ -77,25 +78,6 @@ static const std::string clntcoreName = "/clntcore.so";
|
|||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The main thread function for handling Helix events.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void *
|
||||
LiveSupport::PlaylistExecutor::eventHandlerThread(void * helixPlayer)
|
||||
throw ()
|
||||
{
|
||||
HelixPlayer * hPlayer = (HelixPlayer *) helixPlayer;
|
||||
Ptr<time_duration>::Ref sleepT(new time_duration(microseconds(10)));
|
||||
|
||||
while (hPlayer->handleEvents) {
|
||||
struct _HXxEvent * event = 0;
|
||||
hPlayer->clientEngine->EventOccurred(event);
|
||||
TimeConversion::sleep(sleepT);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
|
@ -202,15 +184,12 @@ HelixPlayer :: initialize(void) throw (std::exception)
|
|||
}
|
||||
|
||||
// start the event handling thread
|
||||
handleEvents = true;
|
||||
int ret;
|
||||
if ((ret = pthread_create(&eventHandlingThread,
|
||||
NULL,
|
||||
eventHandlerThread,
|
||||
(void *) this))) {
|
||||
// TODO: signal return code
|
||||
throw std::exception();
|
||||
}
|
||||
Ptr<time_duration>::Ref granurality(new time_duration(microseconds(10)));
|
||||
Ptr<RunnableInterface>::Ref handler(new HelixEventHandlerThread(
|
||||
clientEngine,
|
||||
granurality));
|
||||
eventHandlerThread.reset(new Thread(handler));
|
||||
eventHandlerThread->start();
|
||||
|
||||
// set up other variables
|
||||
playing = false;
|
||||
|
@ -226,8 +205,8 @@ HelixPlayer :: deInitialize(void) throw ()
|
|||
{
|
||||
if (initialized) {
|
||||
// signal stop to and wait for the event handling thread to stop
|
||||
handleEvents = false;
|
||||
pthread_join(eventHandlingThread, 0);
|
||||
eventHandlerThread->stop();
|
||||
eventHandlerThread->join();
|
||||
|
||||
// release Helix resources
|
||||
clientContext->Release();
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.3 $
|
||||
Version : $Revision: 1.4 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/HelixPlayer.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -41,12 +41,11 @@
|
|||
#endif
|
||||
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <dllacces.h>
|
||||
#include <dllpath.h>
|
||||
|
||||
#include "LiveSupport/Core/Configurable.h"
|
||||
#include "LiveSupport/Core/Thread.h"
|
||||
#include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h"
|
||||
|
||||
#include "AdviseSink.h"
|
||||
|
@ -90,13 +89,11 @@ using namespace LiveSupport::Core;
|
|||
* </pre></code>
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.3 $
|
||||
* @version $Revision: 1.4 $
|
||||
*/
|
||||
class HelixPlayer : virtual public Configurable,
|
||||
virtual public AudioPlayerInterface
|
||||
{
|
||||
friend void * eventHandlerThread(void *) throw();
|
||||
|
||||
private:
|
||||
/**
|
||||
* The name of the configuration XML elmenent used by HelixPlayer
|
||||
|
@ -143,24 +140,11 @@ class HelixPlayer : virtual public Configurable,
|
|||
*/
|
||||
std::string url;
|
||||
|
||||
/**
|
||||
* The event handling thread.
|
||||
*/
|
||||
pthread_t eventHandlingThread;
|
||||
|
||||
/**
|
||||
* Flag to indicate if this object has been initialized.
|
||||
*/
|
||||
bool initialized;
|
||||
|
||||
/**
|
||||
* Flag to mark if the event handling thread should be running
|
||||
* and handling events.
|
||||
* This is set by the HelixPlayer object, and read by the thread
|
||||
* to determine when to stop.
|
||||
*/
|
||||
bool handleEvents;
|
||||
|
||||
/**
|
||||
* Flag to indicate if the player is currently playing.
|
||||
* Make sure no to rely on this flag, as it's not aware of
|
||||
|
@ -169,6 +153,12 @@ class HelixPlayer : virtual public Configurable,
|
|||
*/
|
||||
bool playing;
|
||||
|
||||
/**
|
||||
* A thread for handling helix events, on a regular basis.
|
||||
* Helix apperantly needs to be polled all the time to function.
|
||||
*/
|
||||
Ptr<Thread>::Ref eventHandlerThread;
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -284,17 +274,6 @@ class HelixPlayer : virtual public Configurable,
|
|||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
/**
|
||||
* The main function of the thread that calls for handling of events
|
||||
* in the createEngine all the time.
|
||||
*
|
||||
* @param helixPlayer a pointer to the HelixPlayer object that started
|
||||
* this thread.
|
||||
* @return always 0
|
||||
*/
|
||||
void *
|
||||
eventHandlerThread(void * helixPlayer) throw ();
|
||||
|
||||
|
||||
} // namespace PlaylistExecutor
|
||||
} // namespace LiveSupport
|
||||
|
|
Loading…
Reference in New Issue