added XML-RPC function reschedule

This commit is contained in:
maroy 2004-08-02 03:34:58 +00:00
parent eebd0acc87
commit 65269691aa
15 changed files with 1269 additions and 15 deletions

View File

@ -21,7 +21,7 @@
#
#
# Author : $Author: maroy $
# Version : $Revision: 1.5 $
# Version : $Revision: 1.6 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/etc/Makefile.in,v $
#
# @configure_input@
@ -113,6 +113,7 @@ SCHEDULER_OBJS = ${TMP_DIR}/SignalDispatcher.o \
${TMP_DIR}/DisplayScheduleMethod.o \
${TMP_DIR}/DisplayPlaylistMethod.o \
${TMP_DIR}/RemoveFromScheduleMethod.o \
${TMP_DIR}/RescheduleMethod.o \
${TMP_DIR}/ScheduleFactory.o \
${TMP_DIR}/PostgresqlSchedule.o
@ -128,10 +129,12 @@ TEST_RUNNER_OBJS = ${SCHEDULER_OBJS} \
${TMP_DIR}/SchedulerDaemonDisplayScheduleTest.o \
${TMP_DIR}/SchedulerDaemonDisplayPlaylistTest.o \
${TMP_DIR}/SchedulerDaemonRemoveFromScheduleTest.o \
${TMP_DIR}/SchedulerDaemonRescheduleTest.o \
${TMP_DIR}/UploadPlaylistMethodTest.o \
${TMP_DIR}/DisplayScheduleMethodTest.o \
${TMP_DIR}/DisplayPlaylistMethodTest.o \
${TMP_DIR}/RemoveFromScheduleMethodTest.o \
${TMP_DIR}/RescheduleMethodTest.o \
${TMP_DIR}/PostgresqlScheduleTest.o \
${TMP_DIR}/TestRunner.o
TEST_RUNNER_LIBS = ${SCHEDULER_EXE_LIBS} -lcppunit -ldl

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.3 $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlSchedule.cxx,v $
------------------------------------------------------------------------------*/
@ -96,6 +96,21 @@ const std::string PostgresqlSchedule::isTimeframaAvailableStmt =
const std::string PostgresqlSchedule::schedulePlaylistStmt =
"INSERT INTO schedule(id, playlist, starts, ends) VALUES(?, ?, ?, ?)";
/*------------------------------------------------------------------------------
* The SQL statement for getting a schedule entry based on its id
* The parameters for this call are: entryId
* and returns the properties: id, playlist, starts, ends for the entry
*----------------------------------------------------------------------------*/
const std::string PostgresqlSchedule::getScheduleEntryStmt =
"SELECT id, playlist, starts, ends FROM schedule WHERE id = ?";
/*------------------------------------------------------------------------------
* The SQL statement for rescheduling a playlist (an UPDATE call).
* There parameters for this call are: new start, new end, id.
*----------------------------------------------------------------------------*/
const std::string PostgresqlSchedule::reschedulePlaylistStmt =
"UPDATE schedule SET starts = ?, ends = ? WHERE id = ?";
/*------------------------------------------------------------------------------
* The SQL statement for querying scheduled entries for a time interval
* The parameters for this call are: from, to
@ -398,3 +413,103 @@ PostgresqlSchedule :: removeFromSchedule(
}
}
/*------------------------------------------------------------------------------
* Get a ScheduleEntry based on a schedule entry id.
*----------------------------------------------------------------------------*/
Ptr<ScheduleEntry>::Ref
PostgresqlSchedule :: getScheduleEntry(Ptr<UniqueId>::Ref entryId)
throw (std::invalid_argument)
{
Ptr<Connection>::Ref conn;
Ptr<ScheduleEntry>::Ref entry;
try {
conn = cm->getConnection();
Ptr<PreparedStatement>::Ref pstmt(conn->prepareStatement(
getScheduleEntryStmt));
pstmt->setInt(1, entryId->getId());
Ptr<ResultSet>::Ref rs(pstmt->executeQuery());
if (rs->next()) {
Ptr<Timestamp>::Ref timestamp(new Timestamp());
Ptr<UniqueId>::Ref id(new UniqueId(rs->getInt(1)));
Ptr<UniqueId>::Ref playlistId(new UniqueId(rs->getInt(2)));
*timestamp = rs->getTimestamp(3);
Ptr<ptime>::Ref startTime = Conversion::timestampToPtime(timestamp);
*timestamp = rs->getTimestamp(4);
Ptr<ptime>::Ref endTime = Conversion::timestampToPtime(timestamp);
entry.reset(new ScheduleEntry(id, playlistId, startTime, endTime));
}
cm->returnConnection(conn);
} catch (std::exception &e) {
if (conn) {
cm->returnConnection(conn);
}
// TODO: report error
return entry;
}
if (!entry) {
throw std::invalid_argument("no schedule entry by the specified id");
}
return entry;
}
/*------------------------------------------------------------------------------
* Reschedule an entry
*----------------------------------------------------------------------------*/
void
PostgresqlSchedule :: reschedule(Ptr<UniqueId>::Ref entryId,
Ptr<ptime>::Ref playtime)
throw (std::invalid_argument)
{
Ptr<ScheduleEntry>::Ref entry = getScheduleEntry(entryId);
Ptr<ptime>::Ref ends(new ptime((*playtime)
+ *(entry->getPlaylength())));
if (!isTimeframeAvailable(playtime, ends)) {
throw std::invalid_argument("new playtime not available");
}
Ptr<Connection>::Ref conn;
bool result = false;
try {
conn = cm->getConnection();
Ptr<Timestamp>::Ref timestamp;
Ptr<PreparedStatement>::Ref pstmt(conn->prepareStatement(
reschedulePlaylistStmt));
timestamp = Conversion::ptimeToTimestamp(playtime);
pstmt->setTimestamp(1, *timestamp);
timestamp = Conversion::ptimeToTimestamp(ends);
pstmt->setTimestamp(2, *timestamp);
pstmt->setInt(3, entryId->getId());
result = pstmt->executeUpdate() == 1;
cm->returnConnection(conn);
} catch (std::exception &e) {
if (conn) {
cm->returnConnection(conn);
}
throw std::invalid_argument(e.what());
}
if (!result) {
throw std::invalid_argument("couldn't insert into database");
}
}

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlSchedule.h,v $
------------------------------------------------------------------------------*/
@ -81,7 +81,7 @@ using namespace LiveSupport::Core;
* </code></pre>
*
* @author $Author: maroy $
* @version $Revision: 1.4 $
* @version $Revision: 1.5 $
*/
class PostgresqlSchedule : public Configurable,
public ScheduleInterface
@ -112,6 +112,16 @@ class PostgresqlSchedule : public Configurable,
*/
static const std::string schedulePlaylistStmt;
/**
* The SQL statement for rescheduling an entry.
*/
static const std::string reschedulePlaylistStmt;
/**
* The SQL statement for getting a schedule entry based on its id
*/
static const std::string getScheduleEntryStmt;
/**
* The SQL statement for getting the schedules for a time interval
*/
@ -270,6 +280,31 @@ class PostgresqlSchedule : public Configurable,
virtual void
removeFromSchedule(Ptr<const UniqueId>::Ref entryId)
throw (std::invalid_argument);
/**
* Return a schedule entry for a specified id.
*
* @param entryId the id of the entry to get.
* @return the ScheduleEntry for the specified id.
* @exception std::invalid_argument if no entry by the specified
* id exists.
*/
virtual Ptr<ScheduleEntry>::Ref
getScheduleEntry(Ptr<UniqueId>::Ref entryId)
throw (std::invalid_argument);
/**
* Reschedule an event to a different time.
*
* @param entryId the id of the entry to reschedule.
* @param playtime the new time for the schedule.
* @exception std::invalid_argument if there is something already
* scheduled for the new duration.
*/
virtual void
reschedule(Ptr<UniqueId>::Ref entryId,
Ptr<ptime>::Ref playtime)
throw (std::invalid_argument);
};

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx,v $
------------------------------------------------------------------------------*/
@ -393,3 +393,66 @@ PostgresqlScheduleTest :: removeFromScheduleTest(void)
}
/*------------------------------------------------------------------------------
* Test rescheduling.
*----------------------------------------------------------------------------*/
void
PostgresqlScheduleTest :: rescheduleTest(void)
throw (CPPUNIT_NS::Exception)
{
// create a 1 hour long playlist
Ptr<UniqueId>::Ref playlistId = UniqueId::generateId();
Ptr<time_duration>::Ref playlength(new time_duration(1, 0, 0));
Ptr<Playlist>::Ref playlist(new Playlist(playlistId, playlength));
Ptr<ptime>::Ref from;
Ptr<ptime>::Ref to;
Ptr<UniqueId>::Ref entryId1;
Ptr<UniqueId>::Ref entryId2;
Ptr<ScheduleEntry>::Ref entry;
// at the very first, try to reschedule something not scheduled
bool gotException = false;
try {
entryId1.reset(new UniqueId(9999));
from.reset(new ptime(time_from_string("2004-07-23 10:00:00")));
schedule->reschedule(entryId1, from);
} catch (std::invalid_argument &e) {
gotException = true;
}
CPPUNIT_ASSERT(gotException);
try {
// schedule our playlist for 2004-07-23, 10 o'clock
from.reset(new ptime(time_from_string("2004-07-23 10:00:00")));
entryId1 = schedule->schedulePlaylist(playlist, from);
// schedule our playlist for 2004-07-23, 12 o'clock
from.reset(new ptime(time_from_string("2004-07-23 12:00:00")));
entryId2 = schedule->schedulePlaylist(playlist, from);
// now let's reschedule the first to a valid timepoint
from.reset(new ptime(time_from_string("2004-07-23 08:00:00")));
schedule->reschedule(entryId1, from);
entry = schedule->getScheduleEntry(entryId1);
CPPUNIT_ASSERT((bool) entry);
CPPUNIT_ASSERT(*(entry->getStartTime()) == *from);
// try to reschedule the second one into the first, should fail
gotException = false;
try {
from.reset(new ptime(time_from_string("2004-07-23 08:30:00")));
schedule->reschedule(entryId1, from);
} catch (std::invalid_argument &e) {
gotException = true;
}
CPPUNIT_ASSERT(gotException);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
}

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.3 $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlScheduleTest.h,v $
------------------------------------------------------------------------------*/
@ -64,7 +64,7 @@ using namespace LiveSupport::Core;
* Unit test for the PostgresqlSchedule class.
*
* @author $Author: maroy $
* @version $Revision: 1.3 $
* @version $Revision: 1.4 $
* @see PostgresqlSchedule
*/
class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture
@ -76,6 +76,7 @@ class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(getScheduleEntriesTest);
CPPUNIT_TEST(scheduleEntryExistsTest);
CPPUNIT_TEST(removeFromScheduleTest);
CPPUNIT_TEST(rescheduleTest);
CPPUNIT_TEST_SUITE_END();
private:
@ -141,6 +142,14 @@ class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture
void
removeFromScheduleTest(void) throw (CPPUNIT_NS::Exception);
/**
* Schedule some playlists, then reschedule them.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
rescheduleTest(void) throw (CPPUNIT_NS::Exception);
public:
/**

View File

@ -0,0 +1,174 @@
/*------------------------------------------------------------------------------
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/products/scheduler/src/RescheduleMethod.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_TIME_H
#include <time.h>
#else
#error need time.h
#endif
#include <string>
#include "ScheduleInterface.h"
#include "ScheduleFactory.h"
#include "RescheduleMethod.h"
using namespace boost;
using namespace boost::posix_time;
using namespace LiveSupport;
using namespace LiveSupport::Core;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* The name of this XML-RPC method.
*----------------------------------------------------------------------------*/
const std::string RescheduleMethod::methodName = "reschedule";
/*------------------------------------------------------------------------------
* The name of the playlist id member in the XML-RPC parameter
* structure.
*----------------------------------------------------------------------------*/
const std::string RescheduleMethod::scheduleEntryIdName =
"scheduleEntryId";
/*------------------------------------------------------------------------------
* The name of the playtime member in the XML-RPC parameter
* structure.
*----------------------------------------------------------------------------*/
const std::string RescheduleMethod::playtimeName = "playtime";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Construct the method and register it right away.
*----------------------------------------------------------------------------*/
RescheduleMethod :: RescheduleMethod (
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer) throw()
: XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get())
{
}
/*------------------------------------------------------------------------------
* Extract the UniqueId from an XML-RPC function call parameter
*----------------------------------------------------------------------------*/
Ptr<UniqueId>::Ref
RescheduleMethod :: extractScheduleEntryId(
XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument)
{
if (!xmlRpcValue.hasMember(scheduleEntryIdName)) {
throw std::invalid_argument("no playlist id in parameter structure");
}
Ptr<UniqueId>::Ref id(new UniqueId((int) xmlRpcValue[scheduleEntryIdName]));
return id;
}
/*------------------------------------------------------------------------------
* Extract the playtime from an XML-RPC function call parameter
*----------------------------------------------------------------------------*/
Ptr<ptime>::Ref
RescheduleMethod :: extractPlayschedule(
XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument)
{
if (!xmlRpcValue.hasMember(playtimeName)) {
throw std::invalid_argument("no playtime in parameter structure");
}
struct tm tm = (struct tm) xmlRpcValue[playtimeName];
gregorian::date date(tm.tm_year, tm.tm_mon, tm.tm_mday);
time_duration hours(tm.tm_hour, tm.tm_min, tm.tm_sec);
Ptr<ptime>::Ref ptime(new ptime(date, hours));
return ptime;
}
/*------------------------------------------------------------------------------
* Execute the upload playlist method XML-RPC function call.
*----------------------------------------------------------------------------*/
void
RescheduleMethod :: execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
try {
if (!parameters.valid()) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
Ptr<UniqueId>::Ref entryId = extractScheduleEntryId(parameters[0]);
Ptr<ptime>::Ref playschedule = extractPlayschedule(parameters[0]);
Ptr<UniqueId>::Ref scheduleEntryId;
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule();
if (!schedule->scheduleEntryExists(entryId)) {
// TODO: mark error;
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
schedule->reschedule(entryId, playschedule);
} catch (std::invalid_argument &e) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
returnValue = XmlRpc::XmlRpcValue(true);
}

View File

@ -0,0 +1,170 @@
/*------------------------------------------------------------------------------
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/products/scheduler/src/RescheduleMethod.h,v $
------------------------------------------------------------------------------*/
#ifndef RescheduleMethod_h
#define RescheduleMethod_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <string>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <XmlRpcServerMethod.h>
#include <XmlRpcValue.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/UniqueId.h"
namespace LiveSupport {
namespace Scheduler {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An XML-RPC method object to reschedule an already scheduled event.
*
* The name of the method when called through XML-RPC is "reschedule".
* The expected parameter is an XML-RPC structure, with the following
* members:
* <ul>
* <li>scheduleEntryId - int - the id of the schedule entry to reschedule
* </li>
* <li>playtime - datetime - the new playing time for the entry</li>
* </ul>
* The return value is true if all went well,
* or a boolean false, if there were errors.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class RescheduleMethod : public XmlRpc::XmlRpcServerMethod
{
private:
/**
* The name of this method, as it will be registered into the
* XML-RPC server.
*/
static const std::string methodName;
/**
* The name of the scheduled entry id member in the XML-RPC parameter
* structure.
*/
static const std::string scheduleEntryIdName;
/**
* The name of the playtime member in the XML-RPC parameter
* structure.
*/
static const std::string playtimeName;
/**
* Extract the schedule entry id from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a UniqueId that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no UniqueId
* in xmlRpcValue
*/
Ptr<UniqueId>::Ref
extractScheduleEntryId(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the playtime from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return the playing time, as stored in the XML-RPC parameter
* @exception std::invalid_argument if there was no playtime
* in xmlRpcValue
*/
Ptr<boost::posix_time::ptime>::Ref
extractPlayschedule(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
public:
/**
* A default constructor, for testing purposes.
*/
RescheduleMethod(void) throw ()
: XmlRpc::XmlRpcServerMethod(methodName)
{
}
/**
* Constuctor that registers the method with the server right away.
*
* @param xmlRpcServer the XML-RPC server to register with.
*/
RescheduleMethod(
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer)
throw ();
/**
* Execute the upload playlist command on the Scheduler daemon.
*
* @param parameters XML-RPC function call parameters
* @param returnValue the return value of the call (out parameter)
*/
void
execute( XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Scheduler
} // namespace LiveSupport
#endif // RescheduleMethod_h

View File

@ -0,0 +1,191 @@
/*------------------------------------------------------------------------------
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/products/scheduler/src/RescheduleMethodTest.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 <XmlRpcValue.h>
#include "LiveSupport/Db/ConnectionManagerFactory.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "ScheduleFactory.h"
#include "UploadPlaylistMethod.h"
#include "RescheduleMethod.h"
#include "RescheduleMethodTest.h"
using namespace LiveSupport::Db;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(RescheduleMethodTest);
/**
* The name of the configuration file for the schedule factory.
*/
const std::string RescheduleMethodTest::scheduleConfig =
"etc/scheduleFactory.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Configure a Configurable with an XML file.
*----------------------------------------------------------------------------*/
void
RescheduleMethodTest :: configure(
Ptr<Configurable>::Ref configurable,
const std::string fileName)
throw (std::invalid_argument,
xmlpp::exception)
{
Ptr<xmlpp::DomParser>::Ref parser(new xmlpp::DomParser(fileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
configurable->configure(*root);
}
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
RescheduleMethodTest :: setUp(void) throw ()
{
try {
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
configure(sf, scheduleConfig);
schedule = sf->getSchedule();
schedule->install();
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (xmlpp::exception &e) {
CPPUNIT_FAIL("error parsing configuration file");
} catch (std::exception &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
RescheduleMethodTest :: tearDown(void) throw ()
{
schedule->uninstall();
}
/*------------------------------------------------------------------------------
* Just a very simple smoke test
*----------------------------------------------------------------------------*/
void
RescheduleMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<UploadPlaylistMethod>::Ref uploadMethod(new UploadPlaylistMethod());
Ptr<RescheduleMethod>::Ref rescheduleMethod(new RescheduleMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result;
struct tm time;
Ptr<UniqueId>::Ref entryId;
// let's upload something so we can reschedule it
parameters["playlistId"] = 1;
time.tm_year = 2001;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 18;
time.tm_min = 31;
time.tm_sec = 1;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
uploadMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.valid());
entryId.reset(new UniqueId((int) result));
// now let's reschedule it
parameters.clear();
result.clear();
parameters["scheduleEntryId"] = (int) entryId->getId();
time.tm_year = 2001;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 12;
time.tm_min = 31;
time.tm_sec = 1;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
rescheduleMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT((bool) result);
// now let's reschedule unto itself, should fail
parameters.clear();
result.clear();
parameters["scheduleEntryId"] = (int) entryId->getId();
time.tm_year = 2001;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 12;
time.tm_min = 51;
time.tm_sec = 1;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
rescheduleMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(!((bool) result));
}

View File

@ -0,0 +1,134 @@
/*------------------------------------------------------------------------------
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/products/scheduler/src/RescheduleMethodTest.h,v $
------------------------------------------------------------------------------*/
#ifndef RescheduleMethodTest_h
#define RescheduleMethodTest_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 Scheduler {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the RescheduleMethod class.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @see RescheduleMethod
*/
class RescheduleMethodTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(RescheduleMethodTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST_SUITE_END();
/**
* The name of the configuration file for the schedule factory.
*/
static const std::string scheduleConfig;
/**
* The schedule used during the test.
*/
Ptr<ScheduleInterface>::Ref schedule;
/**
* Configure a configurable with an XML file.
*
* @param configurable configure this
* @param fileName the name of the XML file to configure with.
* @exception std::invalid_argument on configuration errors.
* @exception xmlpp::exception on XML parsing errors.
*/
void
configure(Ptr<Configurable>::Ref configurable,
std::string fileName)
throw (std::invalid_argument,
xmlpp::exception);
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 Scheduler
} // namespace LiveSupport
#endif // RescheduleMethodTest_h

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/ScheduleEntry.h,v $
------------------------------------------------------------------------------*/
@ -68,7 +68,7 @@ using namespace LiveSupport::Core;
* A scheduled event.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
class ScheduleEntry
{
@ -93,6 +93,11 @@ class ScheduleEntry
*/
Ptr<ptime>::Ref endTime;
/**
* The playling length of the event.
*/
Ptr<time_duration>::Ref playlength;
/**
* The default constructor.
*/
@ -121,6 +126,8 @@ class ScheduleEntry
this->playlistId = playlistId;
this->startTime = startTime;
this->endTime = endTime;
playlength.reset(new time_duration(*endTime - *startTime));
}
/**
@ -166,6 +173,17 @@ class ScheduleEntry
{
return endTime;
}
/**
* Return the playlength of the schedule entry.
*
* @return the playing length of the schedule entry.
*/
Ptr<const time_duration>::Ref
getPlaylength(void) const throw ()
{
return playlength;
}
};

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.3 $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/ScheduleInterface.h,v $
------------------------------------------------------------------------------*/
@ -70,7 +70,7 @@ using namespace LiveSupport::Core;
* The generic interface for the component scheduling events.
*
* @author $Author: maroy $
* @version $Revision: 1.3 $
* @version $Revision: 1.4 $
*/
class ScheduleInterface : virtual public Installable
{
@ -93,7 +93,7 @@ class ScheduleInterface : virtual public Installable
* @param playlist the playlist to schedule.
* @param playtime the time to schedule the playlist for.
* @return the id of the newly created playlist.
* @exception std::invalid_argument if the there is something
* @exception std::invalid_argument if there is something
* already scheduled for the duration of the playlist.
*/
virtual Ptr<UniqueId>::Ref
@ -140,6 +140,33 @@ class ScheduleInterface : virtual public Installable
removeFromSchedule(Ptr<const UniqueId>::Ref entryId)
throw (std::invalid_argument)
= 0;
/**
* Return a schedule entry for a specified id.
*
* @param entryId the id of the entry to get.
* @return the ScheduleEntry for the specified id.
* @exception std::invalid_argument if no entry by the specified
* id exists.
*/
virtual Ptr<ScheduleEntry>::Ref
getScheduleEntry(Ptr<UniqueId>::Ref entryId)
throw (std::invalid_argument)
= 0;
/**
* Reschedule an event to a different time.
*
* @param entryId the id of the entry to reschedule.
* @param playtime the new time for the schedule.
* @exception std::invalid_argument if there is something already
* scheduled for the new duration.
*/
virtual void
reschedule(Ptr<UniqueId>::Ref entryId,
Ptr<ptime>::Ref playtime)
throw (std::invalid_argument)
= 0;
};

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemon.cxx,v $
------------------------------------------------------------------------------*/
@ -166,6 +166,7 @@ SchedulerDaemon :: registerXmlRpcFunctions(
xmlRpcServer->addMethod(displayScheduleMethod.get());
xmlRpcServer->addMethod(displayPlaylistMethod.get());
xmlRpcServer->addMethod(removeFromScheduleMethod.get());
xmlRpcServer->addMethod(rescheduleMethod.get());
}

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.5 $
Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemon.h,v $
------------------------------------------------------------------------------*/
@ -64,6 +64,7 @@
#include "DisplayScheduleMethod.h"
#include "DisplayPlaylistMethod.h"
#include "RemoveFromScheduleMethod.h"
#include "RescheduleMethod.h"
#include "XmlRpcDaemon.h"
@ -119,7 +120,7 @@ using namespace LiveSupport::Core;
* </code></pre>
*
* @author $Author: maroy $
* @version $Revision: 1.5 $
* @version $Revision: 1.6 $
* @see ConnectionManagerFactory
* @see StorageClientFactory
* @see ScheduleFactory
@ -156,6 +157,11 @@ class SchedulerDaemon : public Installable,
*/
Ptr<RemoveFromScheduleMethod>::Ref removeFromScheduleMethod;
/**
* The RescheduleMethod the daemon is providing.
*/
Ptr<RescheduleMethod>::Ref rescheduleMethod;
/**
* Default constructor.
*/
@ -166,6 +172,7 @@ class SchedulerDaemon : public Installable,
displayScheduleMethod.reset(new DisplayScheduleMethod());
displayPlaylistMethod.reset(new DisplayPlaylistMethod());
removeFromScheduleMethod.reset(new RemoveFromScheduleMethod());
rescheduleMethod.reset(new RescheduleMethod());
}
protected:

View File

@ -0,0 +1,190 @@
/*------------------------------------------------------------------------------
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/products/scheduler/src/Attic/SchedulerDaemonRescheduleTest.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 <XmlRpcClient.h>
#include <XmlRpcValue.h>
#include "SchedulerDaemon.h"
#include "SchedulerDaemonRescheduleTest.h"
using namespace XmlRpc;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(SchedulerDaemonRescheduleTest);
/**
* The name of the configuration file for the scheduler daemon.
*/
static const std::string configFileName = "etc/scheduler.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
SchedulerDaemonRescheduleTest :: setUp(void) throw ()
{
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
if (!daemon->isConfigured()) {
try {
std::auto_ptr<xmlpp::DomParser>
parser(new xmlpp::DomParser(configFileName, true));
const xmlpp::Document * document = parser->get_document();
daemon->configure(*(document->get_root_node()));
} catch (std::invalid_argument &e) {
std::cerr << e.what() << std::endl;
CPPUNIT_FAIL("semantic error in configuration file");
} catch (xmlpp::exception &e) {
std::cerr << e.what() << std::endl;
CPPUNIT_FAIL("error parsing configuration file");
}
}
daemon->install();
// daemon->start();
// sleep(5);
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
SchedulerDaemonRescheduleTest :: tearDown(void) throw ()
{
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
// daemon->stop();
daemon->uninstall();
}
/*------------------------------------------------------------------------------
* A simple smoke test.
*----------------------------------------------------------------------------*/
void
SchedulerDaemonRescheduleTest :: simpleTest(void)
throw (CPPUNIT_NS::Exception)
{
XmlRpcValue parameters;
XmlRpcValue result;
struct tm time;
XmlRpcClient xmlRpcClient("localhost", 3344, "/RPC2", false);
// first schedule a playlist, so that there is something to reschedule
parameters["playlistId"] = 1;
time.tm_year = 2001;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 10;
time.tm_min = 0;
time.tm_sec = 0;
parameters["playtime"] = &time;
xmlRpcClient.execute("uploadPlaylist", parameters, result);
CPPUNIT_ASSERT(result.valid());
Ptr<UniqueId>::Ref entryId(new UniqueId((int) result));
// now reschedule it
parameters["scheduleEntryId"] = (int) entryId->getId();
time.tm_year = 2001;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 8;
time.tm_min = 0;
time.tm_sec = 0;
parameters["playtime"] = &time;
xmlRpcClient.execute("reschedule", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(((bool)result) == true);
// now reschedule it unto itself, should fail
parameters["scheduleEntryId"] = (int) entryId->getId();
time.tm_year = 2001;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 8;
time.tm_min = 30;
time.tm_sec = 0;
parameters["playtime"] = &time;
xmlRpcClient.execute("reschedule", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(((bool)result) == false);
}
/*------------------------------------------------------------------------------
* A simple negative test.
*----------------------------------------------------------------------------*/
void
SchedulerDaemonRescheduleTest :: negativeTest(void)
throw (CPPUNIT_NS::Exception)
{
XmlRpcValue parameters;
XmlRpcValue result;
XmlRpcClient xmlRpcClient("localhost", 3344, "/RPC2", false);
parameters["scheduleEntryId"] = 9999;
xmlRpcClient.execute("removeFromSchedule", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(((bool)result) == false);
}

View File

@ -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/products/scheduler/src/Attic/SchedulerDaemonRescheduleTest.h,v $
------------------------------------------------------------------------------*/
#ifndef SchedulerDaemonRescheduleTest_h
#define SchedulerDaemonRescheduleTest_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 Scheduler {
using namespace LiveSupport;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test to test the removeFromSchedule XML-RPC call.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @see SchedulerDaemon
*/
class SchedulerDaemonRescheduleTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(SchedulerDaemonRescheduleTest);
CPPUNIT_TEST(simpleTest);
CPPUNIT_TEST(negativeTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* Simple smoke test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
simpleTest(void) throw (CPPUNIT_NS::Exception);
/**
* Simple negative test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
negativeTest(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 Scheduler
} // namespace LiveSupport
#endif // SchedulerDaemonRescheduleTest_h