added event scheduler module
This commit is contained in:
parent
d7d84661c4
commit
5a0544bedf
|
@ -0,0 +1,87 @@
|
|||
#!/bin/sh
|
||||
#-------------------------------------------------------------------------------
|
||||
# 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/eventScheduler/bin/autogen.sh,v $
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Run this to set up the build system: configure, makefiles, etc.
|
||||
# (based on the version in enlightenment's cvs)
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
package="EventScheduler"
|
||||
|
||||
# assume we're in $basedir/bin
|
||||
basedir=`dirname $0`/..
|
||||
test -z "$basedir" && basedir=.
|
||||
|
||||
tmpdir=$basedir/tmp
|
||||
|
||||
cd "$tmpdir"
|
||||
DIE=0
|
||||
|
||||
# look at all other directories as seen from ${basedir}/tmp
|
||||
tmpdir=.
|
||||
bindir=../bin
|
||||
etcdir=../etc
|
||||
|
||||
(autoheader --version) < /dev/null > /dev/null 2>&1 || {
|
||||
echo
|
||||
echo "You must have autoconf installed to compile $package."
|
||||
echo "Download the appropriate package for your distribution,"
|
||||
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
|
||||
DIE=1
|
||||
}
|
||||
|
||||
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
|
||||
echo
|
||||
echo "You must have autoconf installed to compile $package."
|
||||
echo "Download the appropriate package for your distribution,"
|
||||
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
|
||||
DIE=1
|
||||
}
|
||||
|
||||
if test "$DIE" -eq 1; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test -z "$*"; then
|
||||
echo "I am going to run ./configure with no arguments - if you wish "
|
||||
echo "to pass any to it, please specify them on the $0 command line."
|
||||
fi
|
||||
|
||||
echo "Generating configuration files for $package, please wait...."
|
||||
|
||||
configure_ac=${etcdir}/configure.ac
|
||||
configure=${tmpdir}/configure
|
||||
|
||||
#echo " aclocal $ACLOCAL_FLAGS"
|
||||
#aclocal $ACLOCAL_FLAGS
|
||||
echo " autoheader ${configure_ac}"
|
||||
autoheader ${configure_ac}
|
||||
echo " autoconf -o ${configure} ${configure_ac}"
|
||||
autoconf -o ${configure} ${configure_ac}
|
||||
|
||||
${configure} "$@" && echo
|
|
@ -0,0 +1,80 @@
|
|||
#!/bin/sh
|
||||
#-------------------------------------------------------------------------------
|
||||
# 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/eventScheduler/bin/gen_coverage_data.sh,v $
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
# This script generates code coverage data for the module
|
||||
#-------------------------------------------------------------------------------
|
||||
module="LiveSupport EventScheduler"
|
||||
|
||||
reldir=`dirname $0`/..
|
||||
basedir=`cd $reldir; pwd; cd -`
|
||||
bindir=$basedir/bin
|
||||
docdir=$basedir/doc
|
||||
tmpdir=$basedir/tmp
|
||||
|
||||
usrdir=`cd $basedir/../../usr; pwd; cd -`
|
||||
|
||||
coverage_report_dir=$docdir/coverage
|
||||
|
||||
raw_coverage_file=$tmpdir/raw_coverage.info
|
||||
coverage_file=$tmpdir/coverage.info
|
||||
|
||||
lcov=$usrdir/bin/lcov
|
||||
genhtml=$usrdir/bin/genhtml
|
||||
|
||||
|
||||
cd $basedir
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Re-configure with covarege collection enabled, compile and run the tests
|
||||
#-------------------------------------------------------------------------------
|
||||
$bindir/autogen.sh --enable-coverage
|
||||
make clean
|
||||
make check
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Generate some symlinks so that the sources are visible from tmpdir
|
||||
#-------------------------------------------------------------------------------
|
||||
ln -s $basedir/include $tmpdir/include
|
||||
ln -s $basedir/src $tmpdir/src
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Use lcov to generate an HTML report on the coverage data
|
||||
#-------------------------------------------------------------------------------
|
||||
$lcov -d $tmpdir -c > $raw_coverage_file
|
||||
$lcov -e $raw_coverage_file "$tmpdir/*" > $coverage_file
|
||||
rm -rf $coverage_report_dir
|
||||
mkdir -p $coverage_report_dir
|
||||
$genhtml -t "$module" -o $coverage_report_dir $coverage_file
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Clean up
|
||||
#-------------------------------------------------------------------------------
|
||||
rm -f $tmpdir/include
|
||||
rm -f $tmpdir/src
|
|
@ -0,0 +1 @@
|
|||
keep me
|
|
@ -0,0 +1,161 @@
|
|||
#-------------------------------------------------------------------------------
|
||||
# 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/eventScheduler/etc/Makefile.in,v $
|
||||
#
|
||||
# @configure_input@
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# General command definitions
|
||||
#-------------------------------------------------------------------------------
|
||||
MKDIR = mkdir -p
|
||||
RM = rm -f
|
||||
RMDIR = rm -rf
|
||||
DOXYGEN = doxygen
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Basic directory and file definitions
|
||||
#-------------------------------------------------------------------------------
|
||||
BASE_DIR = @builddir@
|
||||
DOC_DIR = ${BASE_DIR}/doc
|
||||
DOXYGEN_DIR = ${DOC_DIR}/doxygen
|
||||
COVERAGE_DIR = ${DOC_DIR}/coverage
|
||||
ETC_DIR = ${BASE_DIR}/etc
|
||||
INCLUDE_DIR = ${BASE_DIR}/include
|
||||
LIB_DIR = ${BASE_DIR}/lib
|
||||
SRC_DIR = ${BASE_DIR}/src
|
||||
TMP_DIR = ${BASE_DIR}/tmp
|
||||
|
||||
USR_DIR = ${BASE_DIR}/../../usr
|
||||
USR_INCLUDE_DIR = ${USR_DIR}/include
|
||||
USR_LIB_DIR = ${USR_DIR}/lib
|
||||
BOOST_INCLUDE_DIR = ${USR_INCLUDE_DIR}/boost-1_31
|
||||
LIBXMLPP_INCLUDE_DIR = ${USR_INCLUDE_DIR}/libxml++-1.0
|
||||
|
||||
MODULES_DIR = ${BASE_DIR}/..
|
||||
|
||||
CORE_DIR = ${MODULES_DIR}/core
|
||||
CORE_INCLUDE_DIR = ${CORE_DIR}/include
|
||||
CORE_LIB_DIR = ${CORE_DIR}/lib
|
||||
CORE_LIB = livesupport_core
|
||||
CORE_LIB_FILE = ${CORE_LIB_DIR}/lib${CORE_LIB}.a
|
||||
|
||||
VPATH = ${SRC_DIR}
|
||||
|
||||
TEST_RESULTS = ${DOC_DIR}/testResults.xml
|
||||
# the text result XSLT has to be relative to the test result file, e.g. TMP_DIR
|
||||
TEST_XSLT = ../etc/testResultToHtml.xsl
|
||||
|
||||
EVENT_SCHEDULER_LIB = livesupport_event_scheduler
|
||||
EVENT_SCHEDULER_LIB_FILE = ${LIB_DIR}/lib${EVENT_SCHEDULER_LIB}.a
|
||||
TEST_RUNNER = ${TMP_DIR}/testRunner
|
||||
|
||||
DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Configuration parameters
|
||||
#-------------------------------------------------------------------------------
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CXXFLAGS = @CXXFLAGS@ @DEFS@ @COVERAGE_CXXFLAGS@ \
|
||||
-Wall -Wno-long-long \
|
||||
-I${USR_INCLUDE_DIR} \
|
||||
-I${BOOST_INCLUDE_DIR} \
|
||||
-I${LIBXMLPP_INCLUDE_DIR} \
|
||||
-I${CORE_INCLUDE_DIR} \
|
||||
-I${INCLUDE_DIR} -I${TMP_DIR}
|
||||
LDFLAGS = @LDFLAGS@ -L${USR_LIB_DIR} -L${CORE_LIB_DIR} -L${LIB_DIR}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Dependencies
|
||||
#-------------------------------------------------------------------------------
|
||||
EVENT_SCHEDULER_LIB_OBJS = ${TMP_DIR}/SchedulerThread.o
|
||||
TEST_RUNNER_OBJS = ${TMP_DIR}/TestScheduledEvent.o \
|
||||
${TMP_DIR}/TestEventContainer.o \
|
||||
${TMP_DIR}/SchedulerThreadTest.o \
|
||||
${TMP_DIR}/TestRunner.o
|
||||
TEST_RUNNER_LIBS = -l${EVENT_SCHEDULER_LIB} -l${CORE_LIB} \
|
||||
-lxml++-1.0 -lcppunit -ldl
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Targets
|
||||
#-------------------------------------------------------------------------------
|
||||
.PHONY: all dir_setup doc clean docclean depclean distclean
|
||||
|
||||
all: dir_setup ${EVENT_SCHEDULER_LIB_FILE}
|
||||
|
||||
dir_setup: ${TMP_DIR} ${DOXYGEN_DIR}
|
||||
|
||||
doc:
|
||||
${DOXYGEN} ${DOXYGEN_CONFIG}
|
||||
|
||||
clean:
|
||||
${RM} ${EVENT_SCHEDULER_LIB_OBJS} ${EVENT_SCHEDULER_LIB_FILE}
|
||||
${RM} ${TEST_RUNNER_OBJS} ${TEST_RUNNER}
|
||||
${RM} ${TMP_DIR}/*.bb ${TMP_DIR}/*.bbg ${TMP_DIR}/*.da ${TMP_DIR}/*.info
|
||||
|
||||
docclean:
|
||||
${RMDIR} ${DOXYGEN_DIR}/html
|
||||
${RMDIR} ${COVERAGE_DIR}/*
|
||||
${RM} ${TEST_RESULTS}
|
||||
|
||||
depclean: clean
|
||||
|
||||
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}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Specific targets
|
||||
#-------------------------------------------------------------------------------
|
||||
${EVENT_SCHEDULER_LIB_FILE}: ${EVENT_SCHEDULER_LIB_OBJS}
|
||||
${AR} crus $@ $^
|
||||
|
||||
${TMP_DIR}:
|
||||
${MKDIR} ${TMP_DIR}
|
||||
|
||||
${DOXYGEN_DIR}:
|
||||
${MKDIR} ${DOXYGEN_DIR}
|
||||
|
||||
${TEST_RUNNER}: ${CORE_LIB_FILE} ${TEST_RUNNER_OBJS} ${EVENT_SCHEDULER_LIB_FILE}
|
||||
${CXX} ${LDFLAGS} -o $@ ${TEST_RUNNER_OBJS} ${TEST_RUNNER_LIBS}
|
||||
|
||||
${CORE_LIB_FILE}:
|
||||
${MAKE} -C ${CORE_DIR}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Pattern rules
|
||||
#-------------------------------------------------------------------------------
|
||||
${TMP_DIR}/%.o : ${SRC_DIR}/%.cxx
|
||||
${CXX} ${CPPFLAGS} ${CXXFLAGS} -c -o $@ $<
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
dnl-----------------------------------------------------------------------------
|
||||
dnl Copyright (c) 2004 Media Development Loan Fund
|
||||
dnl
|
||||
dnl This file is part of the LiveSupport project.
|
||||
dnl http://livesupport.campware.org/
|
||||
dnl To report bugs, send an e-mail to bugs@campware.org
|
||||
dnl
|
||||
dnl LiveSupport is free software; you can redistribute it and/or modify
|
||||
dnl it under the terms of the GNU General Public License as published by
|
||||
dnl the Free Software Foundation; either version 2 of the License, or
|
||||
dnl (at your option) any later version.
|
||||
dnl
|
||||
dnl LiveSupport is distributed in the hope that it will be useful,
|
||||
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
dnl GNU General Public License for more details.
|
||||
dnl
|
||||
dnl You should have received a copy of the GNU General Public License
|
||||
dnl along with LiveSupport; if not, write to the Free Software
|
||||
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
dnl
|
||||
dnl
|
||||
dnl Author : $Author: maroy $
|
||||
dnl Version : $Revision: 1.1 $
|
||||
dnl Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/eventScheduler/etc/configure.ac,v $
|
||||
dnl-----------------------------------------------------------------------------
|
||||
|
||||
dnl-----------------------------------------------------------------------------
|
||||
dnl NOTE: Run all configure related scripts from the tmp directory of the
|
||||
dnl project.
|
||||
dnl This is due to the fact that configure spreads a lot of trash around,
|
||||
dnl like atom4te cache directories, config.* files, etc. into the directory
|
||||
dnl it is being run from. We clearly don't want these in our base directory.
|
||||
dnl-----------------------------------------------------------------------------
|
||||
AC_INIT(EventScheduler, 1.0, bugs@campware.org)
|
||||
AC_PREREQ(2.59)
|
||||
AC_COPYRIGHT([Copyright (c) 2004 Media Development Loan Fund under the GNU GPL])
|
||||
AC_REVISION($Revision: 1.1 $)
|
||||
|
||||
AC_CONFIG_SRCDIR(../src/SchedulerThread.cxx)
|
||||
|
||||
AC_CONFIG_HEADERS(configure.h)
|
||||
AC_PROG_CXX()
|
||||
|
||||
AC_CHECK_HEADERS(getopt.h unistd.h sys/time.h pthread.h)
|
||||
|
||||
dnl-----------------------------------------------------------------------------
|
||||
dnl enable compilaton for code coverage data
|
||||
dnl-----------------------------------------------------------------------------
|
||||
AC_SUBST(COVERAGE_CXXFLAGS)
|
||||
|
||||
AC_ARG_ENABLE( coverage,
|
||||
[ --enable-coverage enable code coverage data generaton (no) ],
|
||||
ENABLE_COVERAGE=${enableval}, ENABLE_COVERAGE="no" )
|
||||
|
||||
if test "x${ENABLE_COVERAGE}" == "xyes" ; then
|
||||
COVERAGE_CXXFLAGS="-fprofile-arcs -ftest-coverage"
|
||||
AC_MSG_RESULT([compiling in code coverage mode])
|
||||
else
|
||||
AC_MSG_RESULT([not compiling in code coverage mode])
|
||||
fi
|
||||
|
||||
|
||||
AC_CONFIG_FILES(../Makefile:../etc/Makefile.in)
|
||||
|
||||
AC_OUTPUT()
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
|
||||
<xsl:template match="/">
|
||||
<html>
|
||||
<head>
|
||||
<title>LiveSupport unit test results</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Preface</h1>
|
||||
This document is part of the
|
||||
<a href="http://livesupport.campware.org/">LiveSupport</a>
|
||||
project, Copyright © 2004 <a href="http://www.mdlf.org/">Media
|
||||
Development Loan Fund</a>, under the GNU
|
||||
<a href="http://www.gnu.org/licenses/gpl.html">GPL</a>.
|
||||
<br/>
|
||||
This is an automatically generated document.
|
||||
<h1>Scope</h1>
|
||||
This document contains the generated unit test results for the
|
||||
<a href="http://livesupport.campware.org/">LiveSupport</a> project.
|
||||
<h1>Summary</h1>
|
||||
<xsl:for-each select="//Statistics">
|
||||
<table>
|
||||
<tr>
|
||||
<td><b>Total number of tests:</b></td>
|
||||
<td><xsl:value-of select="Tests"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Tests passed:</b></td>
|
||||
<td><xsl:value-of select="count(/*/SuccessfulTests/Test)"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Tests failed:</b></td>
|
||||
<td><xsl:value-of select="Failures"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Test errors:</b></td>
|
||||
<td><xsl:value-of select="Errors"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
</xsl:for-each>
|
||||
<h1>Tests</h1>
|
||||
<table>
|
||||
<tr>
|
||||
<th>test name</th>
|
||||
<th>test status</th>
|
||||
</tr>
|
||||
<xsl:for-each select="//Test | //FailedTest">
|
||||
<xsl:sort select="Name"/>
|
||||
<tr>
|
||||
<td><xsl:value-of select="Name"/></td>
|
||||
<xsl:if test="ancestor::FailedTests"><td bgcolor="red">failed</td></xsl:if>
|
||||
<xsl:if test="ancestor::SuccessfulTests"><td bgcolor="lightblue">passed</td></xsl:if>
|
||||
</tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/eventScheduler/include/LiveSupport/EventScheduler/EventContainerInterface.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef LiveSupport_EventScheduler_EventContainerInterface_h
|
||||
#define LiveSupport_EventScheduler_EventContainerInterface_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/EventScheduler/ScheduledEventInterface.h"
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace EventScheduler {
|
||||
|
||||
using namespace boost::posix_time;
|
||||
|
||||
using namespace LiveSupport;
|
||||
using namespace LiveSupport::Core;
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* Base interface for providing the events to get schedulerd by the
|
||||
* EventScheduler.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
class EventContainerInterface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* A virtual destructor, as this class has virtual functions.
|
||||
*/
|
||||
virtual
|
||||
~EventContainerInterface(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first event after the specified timepoint.
|
||||
*
|
||||
* @param when return the first event after this timepoint,
|
||||
* @return the first event to schedule after the specified
|
||||
* timepoint. may be a reference to 0, if currently
|
||||
* there are no known events after the specified time.
|
||||
*/
|
||||
virtual Ptr<ScheduledEventInterface>::Ref
|
||||
getNextEvent(Ptr<ptime>::Ref when) throw () = 0;
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace EventScheduler
|
||||
} // namespace LiveSupport
|
||||
|
||||
|
||||
#endif // LiveSupport_EventScheduler_EventContainerInterface_h
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/eventScheduler/include/LiveSupport/EventScheduler/ScheduledEventInterface.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef LiveSupport_EventScheduler_ScheduledEventInterface_h
|
||||
#define LiveSupport_EventScheduler_ScheduledEventInterface_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/Ptr.h"
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace EventScheduler {
|
||||
|
||||
using namespace boost::posix_time;
|
||||
|
||||
using namespace LiveSupport;
|
||||
using namespace LiveSupport::Core;
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* The base class for all events scheduled by the EventScheduler.
|
||||
* Subclass this one, and implement the necessary functions to have
|
||||
* a class that can be scheduled.
|
||||
*
|
||||
* The lifetime of the scheduled event is as follows, if it is scheduled
|
||||
* to start at time S and end at time E, where E = S + event.eventLength():
|
||||
* <ul>
|
||||
* <li>latest at S - event.maxTimeToInitialize(): event.initialize()</li>
|
||||
* <li>at S: event.start()</li>
|
||||
* <li>at E: event.stop()</li>
|
||||
* <li>after E: event.deInitialize()</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
class ScheduledEventInterface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* A virtual destructor, as this class has virtual functions.
|
||||
*/
|
||||
virtual
|
||||
~ScheduledEventInterface(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell the time this event is scheduled for.
|
||||
*
|
||||
* @return the time this event is scheduled for.
|
||||
*/
|
||||
virtual Ptr<ptime>::Ref
|
||||
getScheduledTime(void) throw () = 0;
|
||||
|
||||
/**
|
||||
* Initialize the event object.
|
||||
* This should finishin at most maxTimeToInitialize() time.
|
||||
* Use this call to allocate any resources that will be needed
|
||||
* by the event itself.
|
||||
*
|
||||
* @exception std::exception on initialization problems.
|
||||
* a raised exception will result in the cancellation
|
||||
* of the event.
|
||||
* @see #maxTimeToInitialize
|
||||
*/
|
||||
virtual void
|
||||
initialize(void) throw (std::exception) = 0;
|
||||
|
||||
/**
|
||||
* The maximum time for the initalize() function to complete.
|
||||
* It is the responsibility of the ScheduledEventInterface object to
|
||||
* complete the initialization in that time.
|
||||
*
|
||||
* @return the maximum time for the initialize() function to complete.
|
||||
* @see #initialize
|
||||
*/
|
||||
virtual Ptr<time_duration>::Ref
|
||||
maxTimeToInitialize(void) throw () = 0;
|
||||
|
||||
/**
|
||||
* De-initialize the event object.
|
||||
*/
|
||||
virtual void
|
||||
deInitialize(void) throw () = 0;
|
||||
|
||||
/**
|
||||
* Start the event.
|
||||
* This function call should start the execution of the event in
|
||||
* a separate thread, and return immediately.
|
||||
*/
|
||||
virtual void
|
||||
start(void) throw () = 0;
|
||||
|
||||
/**
|
||||
* The length of the event.
|
||||
* The scheduler will call stop() when this much time has passed
|
||||
* after calling start().
|
||||
*
|
||||
* @return the length of the event, in time.
|
||||
*/
|
||||
virtual Ptr<time_duration>::Ref
|
||||
eventLength(void) throw () = 0;
|
||||
|
||||
/**
|
||||
* Stop the event.
|
||||
* This function call should result in the event stopping, if
|
||||
* this has not happened yet. The event execution should be stopped
|
||||
* and ready to be de-initialized after this call returns.
|
||||
*/
|
||||
virtual void
|
||||
stop(void) throw () = 0;
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace EventScheduler
|
||||
} // namespace LiveSupport
|
||||
|
||||
|
||||
#endif // LiveSupport_EventScheduler_ScheduledEventInterface_h
|
||||
|
|
@ -0,0 +1 @@
|
|||
keep me
|
|
@ -0,0 +1,185 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/eventScheduler/src/SchedulerThread.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#error need unistd.h
|
||||
#endif
|
||||
|
||||
|
||||
#include "LiveSupport/Core/TimeConversion.h"
|
||||
|
||||
#include "SchedulerThread.h"
|
||||
|
||||
|
||||
using namespace LiveSupport::Core;
|
||||
using namespace LiveSupport::EventScheduler;
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Constructor.
|
||||
*----------------------------------------------------------------------------*/
|
||||
SchedulerThread :: SchedulerThread(
|
||||
Ptr<EventContainerInterface>::Ref eventContainer,
|
||||
Ptr<time_duration>::Ref granularity)
|
||||
throw ()
|
||||
{
|
||||
this->eventContainer = eventContainer;
|
||||
this->granularity = granularity;
|
||||
this->shouldRun = true;
|
||||
|
||||
getNextEvent(TimeConversion::now());
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Get the next event from the eventContainer
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SchedulerThread :: getNextEvent(Ptr<ptime>::Ref when) throw ()
|
||||
{
|
||||
nextEvent = eventContainer->getNextEvent(when);
|
||||
if (nextEvent.get()) {
|
||||
nextEventTime = nextEvent->getScheduledTime();
|
||||
nextInitTime.reset(new ptime(*nextEventTime
|
||||
- *granularity
|
||||
- *nextEvent->maxTimeToInitialize()));
|
||||
nextEventEnd.reset(new ptime(*nextEventTime
|
||||
+ *nextEvent->eventLength()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The main execution body of the thread.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SchedulerThread :: nextStep(Ptr<ptime>::Ref now) throw ()
|
||||
{
|
||||
if (!nextEvent.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (imminent(now, nextInitTime)) {
|
||||
nextEvent->initialize();
|
||||
} else if (imminent(now, nextEventTime)) {
|
||||
Ptr<time_duration>::Ref timeLeft(new time_duration(*nextEventTime
|
||||
- *now));
|
||||
TimeConversion::sleep(timeLeft);
|
||||
nextEvent->start();
|
||||
} else if (imminent(now, nextEventEnd)) {
|
||||
Ptr<time_duration>::Ref timeLeft(new time_duration(*nextEventEnd
|
||||
- *now));
|
||||
TimeConversion::sleep(timeLeft);
|
||||
nextEvent->stop();
|
||||
nextEvent->deInitialize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The main execution body of the thread.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SchedulerThread :: run(void) throw ()
|
||||
{
|
||||
while (shouldRun) {
|
||||
Ptr<ptime>::Ref start = TimeConversion::now();
|
||||
|
||||
nextStep(start);
|
||||
|
||||
// sleep until the next granularity
|
||||
Ptr<ptime>::Ref end = TimeConversion::now();
|
||||
Ptr<time_duration>::Ref diff(new time_duration(*end - *start));
|
||||
if (*diff <= *granularity) {
|
||||
Ptr<time_duration>::Ref sleepTime(new time_duration(*granularity
|
||||
- *diff));
|
||||
TimeConversion::sleep(sleepTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The POSIX thread function for this thread.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void *
|
||||
SchedulerThread :: posixThreadFunction(void * schedulerThread) throw ()
|
||||
{
|
||||
SchedulerThread * sThread = (SchedulerThread *) schedulerThread;
|
||||
|
||||
sThread->run();
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Start the thread.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SchedulerThread :: start(void) throw (std::exception)
|
||||
{
|
||||
int ret;
|
||||
if ((ret = pthread_create(&thread, 0, posixThreadFunction, this))) {
|
||||
// TODO: signal return code
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Join the thread.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SchedulerThread :: join(void) throw ()
|
||||
{
|
||||
int ret;
|
||||
if ((ret = pthread_join(thread, 0))) {
|
||||
// TODO: signal return code
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,241 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/eventScheduler/src/SchedulerThread.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef SchedulerThread_h
|
||||
#define SchedulerThread_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PTHREAD_H
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#error need pthread.h
|
||||
#endif
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include "LiveSupport/EventScheduler/ScheduledEventInterface.h"
|
||||
#include "LiveSupport/EventScheduler/EventContainerInterface.h"
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace EventScheduler {
|
||||
|
||||
using namespace boost::posix_time;
|
||||
|
||||
using namespace LiveSupport;
|
||||
using namespace LiveSupport::Core;
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* The main, executing thread of the scheduler.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
class SchedulerThread
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* The event container, to get the events from.
|
||||
*/
|
||||
Ptr<EventContainerInterface>::Ref eventContainer;
|
||||
|
||||
/**
|
||||
* The next event to execute.
|
||||
*/
|
||||
Ptr<ScheduledEventInterface>::Ref nextEvent;
|
||||
|
||||
/**
|
||||
* The execution time of the next event.
|
||||
*/
|
||||
Ptr<ptime>::Ref nextEventTime;
|
||||
|
||||
/**
|
||||
* The time to start the initialization of the next event.
|
||||
*/
|
||||
Ptr<ptime>::Ref nextInitTime;
|
||||
|
||||
/**
|
||||
* The ending time of the next event.
|
||||
*/
|
||||
Ptr<ptime>::Ref nextEventEnd;
|
||||
|
||||
/**
|
||||
* The granularity of the scheduler: the time it will sleep
|
||||
* between checking up on the state of things.
|
||||
*/
|
||||
Ptr<time_duration>::Ref granularity;
|
||||
|
||||
/**
|
||||
* The POSIX thread for this object.
|
||||
*/
|
||||
pthread_t thread;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the thread should still run, or
|
||||
* actually terminate.
|
||||
*/
|
||||
bool shouldRun;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
SchedulerThread(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* The thread function for the POSIX thread interface.
|
||||
*
|
||||
* @param schedulerThread pointer to this SchedulerThread instance.
|
||||
* @return always 0
|
||||
*/
|
||||
static void *
|
||||
posixThreadFunction(void * schedulerThread) throw ();
|
||||
|
||||
/**
|
||||
* Get the next event.
|
||||
*
|
||||
* @param when get the first event after this specified time.
|
||||
*/
|
||||
void
|
||||
getNextEvent(Ptr<ptime>::Ref when) throw ();
|
||||
|
||||
/**
|
||||
* Tell if the specified time falls within now and the next
|
||||
* waking up. Basically tells if it is within now and
|
||||
* now + granularity.
|
||||
*
|
||||
* @param now the current time.
|
||||
* @param time check this time if it is imminent.
|
||||
* @return true if the specified time falls within now and
|
||||
* now + granularity, false otherwise.
|
||||
*/
|
||||
bool
|
||||
imminent(Ptr<ptime>::Ref now,
|
||||
Ptr<ptime>::Ref when) const throw ()
|
||||
{
|
||||
return *when >= *now && (*now + *granularity) > *when;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the next step on the active event, if any is imminent.
|
||||
*
|
||||
* @param now the current time.
|
||||
*/
|
||||
void
|
||||
nextStep(Ptr<ptime>::Ref now) throw ();
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The main execution loop for the thread.
|
||||
*/
|
||||
virtual void
|
||||
run(void) throw ();
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param eventContainer the container this thread will get its
|
||||
* events to schedule from.
|
||||
* @param granularity the granularity of the thread: the time the
|
||||
* thread will sleep between checking up on things.
|
||||
*/
|
||||
SchedulerThread(Ptr<EventContainerInterface>::Ref eventContainer,
|
||||
Ptr<time_duration>::Ref granularity)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* A virtual destructor, as this class has virtual functions.
|
||||
*/
|
||||
virtual
|
||||
~SchedulerThread(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the execution of the thread.
|
||||
* This funcion will create a new thread and starts executing
|
||||
* it by the run() function of this object. Start will
|
||||
* return immediately.
|
||||
*
|
||||
* @exception std::exception if the thread could not be started.
|
||||
*/
|
||||
virtual void
|
||||
start(void) throw (std::exception);
|
||||
|
||||
/**
|
||||
* Signal the thread to stop, gracefully.
|
||||
*/
|
||||
virtual void
|
||||
stop(void) throw ()
|
||||
{
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join the thread.
|
||||
* Wait for the thread to terminate and free up all its resources.
|
||||
*/
|
||||
virtual void
|
||||
join(void) throw ();
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace EventScheduler
|
||||
} // namespace LiveSupport
|
||||
|
||||
|
||||
#endif // SchedulerThread_h
|
||||
|
|
@ -0,0 +1,183 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/eventScheduler/src/SchedulerThreadTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#error "Need unistd.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "LiveSupport/Core/TimeConversion.h"
|
||||
#include "SchedulerThread.h"
|
||||
#include "TestScheduledEvent.h"
|
||||
#include "TestEventContainer.h"
|
||||
#include "SchedulerThreadTest.h"
|
||||
|
||||
|
||||
using namespace boost::posix_time;
|
||||
|
||||
using namespace LiveSupport::Core;
|
||||
using namespace LiveSupport::EventScheduler;
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(SchedulerThreadTest);
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Set up the test environment
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SchedulerThreadTest :: setUp(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Clean up the test environment
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SchedulerThreadTest :: tearDown(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test to see if the HelixPlayer engine can be started and stopped
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SchedulerThreadTest :: firstTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
Ptr<TestScheduledEvent>::Ref event;
|
||||
Ptr<TestEventContainer>::Ref container;
|
||||
Ptr<SchedulerThread>::Ref schedulerThread;
|
||||
Ptr<ptime>::Ref now;
|
||||
Ptr<ptime>::Ref when;
|
||||
Ptr<time_duration>::Ref initTime;
|
||||
Ptr<time_duration>::Ref eventLength;
|
||||
Ptr<time_duration>::Ref granularity;
|
||||
TestScheduledEvent::State state;
|
||||
|
||||
/* time timeline for this test is:
|
||||
initialize - 1sec, sometime before start
|
||||
start - now + 5sec
|
||||
stop - start + 3 sec
|
||||
*/
|
||||
|
||||
now = TimeConversion::now();
|
||||
when.reset(new ptime(*now + seconds(5)));
|
||||
initTime.reset(new time_duration(seconds(1)));
|
||||
eventLength.reset(new time_duration(seconds(3)));
|
||||
granularity.reset(new time_duration(seconds(1)));
|
||||
|
||||
event.reset(new TestScheduledEvent(when, initTime, eventLength));
|
||||
container.reset(new TestEventContainer(event));
|
||||
|
||||
schedulerThread.reset(new SchedulerThread(container, granularity));
|
||||
|
||||
schedulerThread->start();
|
||||
|
||||
CPPUNIT_ASSERT(event->getState() == TestScheduledEvent::created);
|
||||
state = event->getState();
|
||||
|
||||
for (bool running = true; running; ) {
|
||||
// check for each state, and see if they are entered into in a correct
|
||||
// order
|
||||
now = TimeConversion::now();
|
||||
switch (event->getState()) {
|
||||
case TestScheduledEvent::created:
|
||||
CPPUNIT_ASSERT(state == TestScheduledEvent::created);
|
||||
break;
|
||||
|
||||
case TestScheduledEvent::initializing:
|
||||
// as the init time is same as granularity, we will only
|
||||
// see initializing once, and can assume that the previous
|
||||
// state was 'created'
|
||||
CPPUNIT_ASSERT(state == TestScheduledEvent::created);
|
||||
break;
|
||||
|
||||
case TestScheduledEvent::initialized:
|
||||
CPPUNIT_ASSERT(state == TestScheduledEvent::initializing
|
||||
|| state == TestScheduledEvent::initialized);
|
||||
break;
|
||||
|
||||
case TestScheduledEvent::running:
|
||||
CPPUNIT_ASSERT(state == TestScheduledEvent::initialized
|
||||
|| state == TestScheduledEvent::running);
|
||||
// see if the state changed from initialized to running
|
||||
// at the appropriate time
|
||||
if (state == TestScheduledEvent::initialized) {
|
||||
CPPUNIT_ASSERT(*when <= *now
|
||||
&& *now <= *when + *granularity);
|
||||
}
|
||||
break;
|
||||
|
||||
case TestScheduledEvent::stopped:
|
||||
CPPUNIT_ASSERT(state == TestScheduledEvent::running
|
||||
|| state == TestScheduledEvent::stopped);
|
||||
break;
|
||||
|
||||
case TestScheduledEvent::deInitialized:
|
||||
// accept running as a possible previous state, as we might
|
||||
// not catch the stopped state at all
|
||||
CPPUNIT_ASSERT(state == TestScheduledEvent::running
|
||||
|| state == TestScheduledEvent::stopped);
|
||||
running = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
CPPUNIT_FAIL("unrecognized event state");
|
||||
}
|
||||
state = event->getState();
|
||||
TimeConversion::sleep(granularity);
|
||||
}
|
||||
|
||||
schedulerThread->stop();
|
||||
schedulerThread->join();
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/eventScheduler/src/SchedulerThreadTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef SchedulerThreadTest_h
|
||||
#define SchedulerThreadTest_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace EventScheduler {
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* Unit test for the EventScheduler class.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
* @see EventScheduler
|
||||
*/
|
||||
class SchedulerThreadTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(SchedulerThreadTest);
|
||||
CPPUNIT_TEST(firstTest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* A simple test.
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
firstTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Set up the environment for the test case.
|
||||
*/
|
||||
void
|
||||
setUp(void) throw ();
|
||||
|
||||
/**
|
||||
* Clean up the environment after the test case.
|
||||
*/
|
||||
void
|
||||
tearDown(void) throw ();
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace EventScheduler
|
||||
} // namespace LiveSupport
|
||||
|
||||
#endif // SchedulerThreadTest_h
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/eventScheduler/src/TestEventContainer.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#error need unistd.h
|
||||
#endif
|
||||
|
||||
|
||||
#include "TestEventContainer.h"
|
||||
|
||||
|
||||
using namespace LiveSupport::Core;
|
||||
using namespace LiveSupport::EventScheduler;
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Constructor.
|
||||
*----------------------------------------------------------------------------*/
|
||||
TestEventContainer :: TestEventContainer(
|
||||
Ptr<ScheduledEventInterface>::Ref event)
|
||||
throw ()
|
||||
{
|
||||
this->event = event;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Return the first scheduled event after the specified timepoint
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<ScheduledEventInterface>::Ref
|
||||
TestEventContainer :: getNextEvent(Ptr<ptime>::Ref when) throw ()
|
||||
{
|
||||
if (*when < *event->getScheduledTime()) {
|
||||
return event;
|
||||
} else {
|
||||
// return an empty reference
|
||||
Ptr<ScheduledEventInterface>::Ref empty;
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/eventScheduler/src/TestEventContainer.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef TestEventContainer_h
|
||||
#define TestEventContainer_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include "LiveSupport/EventScheduler/EventContainerInterface.h"
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace EventScheduler {
|
||||
|
||||
using namespace boost::posix_time;
|
||||
|
||||
using namespace LiveSupport;
|
||||
using namespace LiveSupport::Core;
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* An event container for testing purposes.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
class TestEventContainer : public virtual EventContainerInterface
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* The only event that this container holds.
|
||||
*/
|
||||
Ptr<ScheduledEventInterface>::Ref event;
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param event the only event this container will hold.
|
||||
*/
|
||||
TestEventContainer(Ptr<ScheduledEventInterface>::Ref event)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* A virtual destructor, as this class has virtual functions.
|
||||
*/
|
||||
virtual
|
||||
~TestEventContainer(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first event after the specified timepoint.
|
||||
*
|
||||
* @param when return the first event after this timepoint,
|
||||
* @return the first event to schedule after the specified
|
||||
* timepoint. may be a reference to 0, if currently
|
||||
* there are no known events after the specified time.
|
||||
*/
|
||||
virtual Ptr<ScheduledEventInterface>::Ref
|
||||
getNextEvent(Ptr<ptime>::Ref when) throw ();
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace EventScheduler
|
||||
} // namespace LiveSupport
|
||||
|
||||
|
||||
#endif // TestEventContainer_h
|
||||
|
|
@ -0,0 +1,281 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/eventScheduler/src/TestRunner.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#error "Need unistd.h"
|
||||
#endif
|
||||
|
||||
#if HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#else
|
||||
#error "Need getopt.h"
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <cppunit/BriefTestProgressListener.h>
|
||||
#include <cppunit/CompilerOutputter.h>
|
||||
#include <cppunit/XmlOutputter.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/TestResult.h>
|
||||
#include <cppunit/TestResultCollector.h>
|
||||
#include <cppunit/TestRunner.h>
|
||||
|
||||
#include "LiveSupport/Core/Ptr.h"
|
||||
|
||||
|
||||
using namespace LiveSupport::Core;
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
/**
|
||||
* Our copyright notice, should be at most 80 columns
|
||||
*/
|
||||
static const char copyrightNotice[] =
|
||||
"Copyright (c) 2004 Media Development Loan Fund under the GNU GPL";
|
||||
|
||||
/**
|
||||
* String describing the short options.
|
||||
*/
|
||||
static const char options[] = "ho:s:v";
|
||||
|
||||
/**
|
||||
* Structure describing the long options
|
||||
*/
|
||||
static const struct option longOptions[] = {
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ "output", required_argument, 0, 'o' },
|
||||
{ "stylesheet", required_argument, 0, 's' },
|
||||
{ "version", no_argument, 0, 'v' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
/**
|
||||
* The encoding to use for the output file.
|
||||
*/
|
||||
static const std::string encoding = "utf-8";
|
||||
|
||||
/**
|
||||
* The output XML file name.
|
||||
*/
|
||||
static Ptr<std::string>::Ref xmlOutFileName;
|
||||
|
||||
/**
|
||||
* The XSLT attached to the output file.
|
||||
*/
|
||||
static Ptr<std::string>::Ref xsltFileName;
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
/**
|
||||
* Print program version.
|
||||
*
|
||||
* @param os the std::ostream to print to.
|
||||
*/
|
||||
static void
|
||||
printVersion ( std::ostream & os );
|
||||
|
||||
/**
|
||||
* Print program usage information.
|
||||
*
|
||||
* @param invocation the command line command used to invoke this program.
|
||||
* @param os the std::ostream to print to.
|
||||
*/
|
||||
static void
|
||||
printUsage ( const char invocation[],
|
||||
std::ostream & os );
|
||||
|
||||
/**
|
||||
* Process command line arguments.
|
||||
*
|
||||
* @param argc the number of arguments.
|
||||
* @param argv the arguments themselves.
|
||||
* @return true of all went well, false in case the program should exit
|
||||
* after this call.
|
||||
*/
|
||||
static bool
|
||||
processArguments(int argc, char *argv[]);
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Run all tests
|
||||
*----------------------------------------------------------------------------*/
|
||||
int
|
||||
main( int argc,
|
||||
char * argv[] ) throw ()
|
||||
{
|
||||
if (!processArguments(argc, argv)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Create the event manager and test controller
|
||||
CPPUNIT_NS::TestResult controller;
|
||||
|
||||
// Add a listener that colllects test result
|
||||
CPPUNIT_NS::TestResultCollector result;
|
||||
controller.addListener( &result );
|
||||
|
||||
// Add a listener that print dots as test run.
|
||||
CPPUNIT_NS::BriefTestProgressListener progress;
|
||||
controller.addListener( &progress );
|
||||
|
||||
// Add the top suite to the test runner
|
||||
CPPUNIT_NS::TestRunner runner;
|
||||
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
|
||||
runner.run( controller );
|
||||
|
||||
// Print test in a compiler compatible format.
|
||||
CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
|
||||
outputter.setLocationFormat("%p:%l:");
|
||||
outputter.write();
|
||||
|
||||
// also generate an XML document as an output
|
||||
std::ofstream xmlOutFile(xmlOutFileName->c_str());
|
||||
CPPUNIT_NS::XmlOutputter xmlOutputter(&result, xmlOutFile, encoding);
|
||||
xmlOutputter.setStandalone(false);
|
||||
if (xsltFileName) {
|
||||
xmlOutputter.setStyleSheet(*xsltFileName);
|
||||
}
|
||||
xmlOutputter.write();
|
||||
xmlOutFile.flush();
|
||||
xmlOutFile.close();
|
||||
|
||||
return result.wasSuccessful() ? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Process command line arguments.
|
||||
*----------------------------------------------------------------------------*/
|
||||
static bool
|
||||
processArguments(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
while ((i = getopt_long(argc, argv, options, longOptions, 0)) != -1) {
|
||||
switch (i) {
|
||||
case 'h':
|
||||
printUsage(argv[0], std::cout);
|
||||
return false;
|
||||
|
||||
case 'o':
|
||||
xmlOutFileName.reset(new std::string(optarg));
|
||||
break;
|
||||
|
||||
case 's':
|
||||
xsltFileName.reset(new std::string(optarg));
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
printVersion(std::cout);
|
||||
return false;
|
||||
|
||||
default:
|
||||
printUsage(argv[0], std::cout);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
std::cerr << "error processing command line arguments" << std::endl;
|
||||
printUsage(argv[0], std::cout);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!xmlOutFileName) {
|
||||
std::cerr << "mandatory option output file name not specified"
|
||||
<< std::endl;
|
||||
printUsage(argv[0], std::cout);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cerr << "writing output to '" << *xmlOutFileName << '\'' << std::endl;
|
||||
if (xsltFileName) {
|
||||
std::cerr << "using XSLT file '" << *xsltFileName << '\'' << std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Print program version.
|
||||
*----------------------------------------------------------------------------*/
|
||||
static void
|
||||
printVersion ( std::ostream & os )
|
||||
{
|
||||
os << PACKAGE_NAME << ' ' << PACKAGE_VERSION << std::endl
|
||||
<< "Unit test runner" << std::endl
|
||||
<< copyrightNotice << std::endl;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Print program usage.
|
||||
*----------------------------------------------------------------------------*/
|
||||
static void
|
||||
printUsage ( const char invocation[],
|
||||
std::ostream & os )
|
||||
{
|
||||
os << PACKAGE_NAME << ' ' << PACKAGE_VERSION << std::endl
|
||||
<< "Unit test runner" << std::endl
|
||||
<< std::endl
|
||||
<< "Usage: " << invocation << " [OPTION]"
|
||||
<< std::endl
|
||||
<< " mandatory options:" << std::endl
|
||||
<< " -o, --output=file.name write test results into this XML file"
|
||||
<< std::endl
|
||||
<< " optional options:" << std::endl
|
||||
<< " -s, --stylesheet specify this XSLT for the output file"
|
||||
<< std::endl
|
||||
<< " this is either an absolute URI, or a"
|
||||
<< std::endl
|
||||
<< " relative path for the output document"
|
||||
<< std::endl
|
||||
<< " -h, --help display this help and exit" << std::endl
|
||||
<< " -v, --version display version information and exit"
|
||||
<< std::endl
|
||||
<< std::endl
|
||||
<< "Report bugs to " << PACKAGE_BUGREPORT << std::endl;
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/eventScheduler/src/TestScheduledEvent.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#error need unistd.h
|
||||
#endif
|
||||
|
||||
#include "LiveSupport/Core/TimeConversion.h"
|
||||
|
||||
#include "TestScheduledEvent.h"
|
||||
|
||||
|
||||
using namespace LiveSupport::Core;
|
||||
using namespace LiveSupport::EventScheduler;
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Constructor.
|
||||
*----------------------------------------------------------------------------*/
|
||||
TestScheduledEvent :: TestScheduledEvent(
|
||||
Ptr<ptime>::Ref when,
|
||||
Ptr<time_duration>::Ref maxTimeToInitialize,
|
||||
Ptr<time_duration>::Ref eventLength)
|
||||
throw ()
|
||||
{
|
||||
this->when = when;
|
||||
this->initTime = maxTimeToInitialize;
|
||||
this->length = eventLength;
|
||||
state = created;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Initialize the event object.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
TestScheduledEvent :: initialize(void) throw (std::exception)
|
||||
{
|
||||
state = initializing;
|
||||
TimeConversion::sleep(initTime);
|
||||
state = initialized;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Initialize the event object.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
TestScheduledEvent :: deInitialize(void) throw ()
|
||||
{
|
||||
state = deInitialized;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Initialize the event object.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
TestScheduledEvent :: start(void) throw ()
|
||||
{
|
||||
state = running;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Initialize the event object.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
TestScheduledEvent :: stop(void) throw ()
|
||||
{
|
||||
state = stopped;
|
||||
}
|
||||
|
|
@ -0,0 +1,222 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/eventScheduler/src/TestScheduledEvent.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef TestScheduledEvent_h
|
||||
#define TestScheduledEvent_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include "LiveSupport/EventScheduler/ScheduledEventInterface.h"
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace EventScheduler {
|
||||
|
||||
using namespace boost::posix_time;
|
||||
|
||||
using namespace LiveSupport;
|
||||
using namespace LiveSupport::Core;
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* A scheduled event for testing purposes.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
class TestScheduledEvent : public virtual ScheduledEventInterface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Enumeration describing the possible states of the event.
|
||||
*/
|
||||
typedef enum { created,
|
||||
initializing,
|
||||
initialized,
|
||||
running,
|
||||
stopped,
|
||||
deInitialized } State;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The time this event is scheduled for.
|
||||
*/
|
||||
Ptr<ptime>::Ref when;
|
||||
|
||||
/**
|
||||
* The maximum time this event should get initialized.
|
||||
*/
|
||||
Ptr<time_duration>::Ref initTime;
|
||||
|
||||
/**
|
||||
* The length of the event.
|
||||
*/
|
||||
Ptr<time_duration>::Ref length;
|
||||
|
||||
/**
|
||||
* The current state of the event.
|
||||
*/
|
||||
State state;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param when the time this event is scheduled for.
|
||||
* @param maxTimeToInitialize the maximum time for this event
|
||||
* to initialize.
|
||||
* @param eventLength the length of the event.
|
||||
*/
|
||||
TestScheduledEvent(Ptr<ptime>::Ref when,
|
||||
Ptr<time_duration>::Ref maxTimeToInitialize,
|
||||
Ptr<time_duration>::Ref eventLength)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* A virtual destructor, as this class has virtual functions.
|
||||
*/
|
||||
virtual
|
||||
~TestScheduledEvent(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current state of the event.
|
||||
*/
|
||||
virtual State
|
||||
getState(void) const throw ()
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell the time this event is scheduled for.
|
||||
*
|
||||
* @return the time this event is scheduled for.
|
||||
*/
|
||||
virtual Ptr<ptime>::Ref
|
||||
getScheduledTime(void) throw ()
|
||||
{
|
||||
return when;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the event object.
|
||||
* This should finishin at most maxTimeToInitialize() time.
|
||||
* Use this call to allocate any resources that will be needed
|
||||
* by the event itself.
|
||||
*
|
||||
* @exception std::exception on initialization problems.
|
||||
* a raised exception will result in the cancellation
|
||||
* of the event.
|
||||
* @see #maxTimeToInitialize
|
||||
*/
|
||||
virtual void
|
||||
initialize(void) throw (std::exception);
|
||||
|
||||
/**
|
||||
* The maximum time for the initalize() function to complete.
|
||||
* It is the responsibility of the ScheduledEventInterface object to
|
||||
* complete the initialization in that time.
|
||||
*
|
||||
* @return the maximum time for the initialize() function to complete.
|
||||
* @see #initialize
|
||||
*/
|
||||
virtual Ptr<time_duration>::Ref
|
||||
maxTimeToInitialize(void) throw ()
|
||||
{
|
||||
return initTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* De-initialize the event object.
|
||||
*/
|
||||
virtual void
|
||||
deInitialize(void) throw ();
|
||||
|
||||
/**
|
||||
* Start the event.
|
||||
* This function call should start the execution of the event in
|
||||
* a separate thread, and return immediately.
|
||||
*/
|
||||
virtual void
|
||||
start(void) throw ();
|
||||
|
||||
/**
|
||||
* The length of the event.
|
||||
* The scheduler will call stop() when this much time has passed
|
||||
* after calling start().
|
||||
*
|
||||
* @return the length of the event, in time.
|
||||
*/
|
||||
virtual Ptr<time_duration>::Ref
|
||||
eventLength(void) throw ()
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the event.
|
||||
* This function call should result in the event stopping, if
|
||||
* this has not happened yet. The processing of this event should
|
||||
* persue in a seperate thread, and the function itself should
|
||||
* return immediately.
|
||||
*/
|
||||
virtual void
|
||||
stop(void) throw ();
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace EventScheduler
|
||||
} // namespace LiveSupport
|
||||
|
||||
|
||||
#endif // TestScheduledEvent_h
|
||||
|
|
@ -0,0 +1 @@
|
|||
keep me
|
Loading…
Reference in New Issue