added XML-RPC functions displaySchedule and displayPlaylist to

the Scheduler Daemon
This commit is contained in:
maroy 2004-08-01 03:14:24 +00:00
parent cb11baaeef
commit 0b445bac8a
32 changed files with 2648 additions and 49 deletions

View file

@ -13,7 +13,7 @@ Development Loan Fund</a>, under the GNU <a
href="http://www.gnu.org/licenses/gpl.html">GPL</a>.<br>
<ul>
<li>Author: $Author: maroy $</li>
<li>Version: $Revision: 1.2 $</li>
<li>Version: $Revision: 1.3 $</li>
<li>Location: $Source:
/home/cvs/livesupport/doc/gettingStarted.html,v $</li>
</ul>
@ -28,7 +28,7 @@ control system, but some preparation and setup has to be made on system
used to develop LiveSupport as well.<br>
<h1>Steps<br>
</h1>
The following steps need to be taken for setting up the LiveSupport
The following steps needed to be taken for setting up the LiveSupport
development environment.<br>
<ul>
<li>set up additional system resources</li>

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/modules/core/include/LiveSupport/Core/UniqueId.h,v $
------------------------------------------------------------------------------*/
@ -58,7 +58,7 @@ namespace Core {
* A class representing globally unique identifiers.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
class UniqueId
{
@ -93,6 +93,19 @@ class UniqueId
this->id = id;
}
/**
* Compare this is with an other one.
*
* @param otherId the other unqiue id to compare to.
* @return true if this an otherId have the same ID value,
* false otherwise.
*/
bool
operator==(const UniqueId & otherId) const throw ()
{
return this->id == otherId.id;
}
/**
* Compare this id with an other one.
*

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/modules/db/include/LiveSupport/Db/Conversion.h,v $
------------------------------------------------------------------------------*/
@ -68,7 +68,7 @@ using namespace LiveSupport::Core;
* helpful when accessing databases.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
class Conversion
{
@ -76,7 +76,7 @@ class Conversion
/**
* The default constructor.
*/
Conversion(void) throw()
Conversion(void) throw ()
{
}
@ -89,7 +89,16 @@ class Conversion
* @return an odbc::Timestamp, holding the same time.
*/
static Ptr<odbc::Timestamp>::Ref
ptimeToTimestamp(Ptr<const posix_time::ptime>::Ref ptime) throw();
ptimeToTimestamp(Ptr<const posix_time::ptime>::Ref ptime) throw ();
/**
* Convert an odbc::Timestamp to a boost::ptime.
*
* @param timestamp an odbc::Timestamp to convert.
* @return a boost ptime, holding the same time.
*/
static Ptr<posix_time::ptime>::Ref
timestampToPtime(Ptr<odbc::Timestamp>::Ref timestamp) throw ();
};

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/modules/db/src/Conversion.cxx,v $
------------------------------------------------------------------------------*/
@ -71,3 +71,20 @@ Conversion :: ptimeToTimestamp(Ptr<const posix_time::ptime>::Ref ptime)
return timestamp;
}
/*------------------------------------------------------------------------------
* Convert an odbc::Timestamp to a boost::ptime
*----------------------------------------------------------------------------*/
Ptr<posix_time::ptime>::Ref
Conversion :: timestampToPtime(Ptr<odbc::Timestamp>::Ref timestamp)
throw()
{
// don't convert through the time_t format, as probably because of
// timezone settings, boost::posix_time::from_time_t() ruins the
// actual value
std::string timeStr = timestamp->toString();
Ptr<posix_time::ptime>::Ref ptime(new posix_time::ptime(
posix_time::time_from_string(timeStr)));
return ptime;
}

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientFactory.h,v $
------------------------------------------------------------------------------*/
@ -76,6 +76,7 @@ using namespace LiveSupport::Core;
* ...
* &lt;/testStorage&gt;
* &lt;/storageClientFactory&gt;
* </code></pre>
*
* For detais of the testStorage element, see the documentation for the
* TestStorageClient class.
@ -87,7 +88,7 @@ using namespace LiveSupport::Core;
* </code></pre>
*
* @author $Author: maroy $
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
* @see TestStorageClient
*/
class StorageClientFactory :

View file

@ -21,7 +21,7 @@
#
#
# Author : $Author: maroy $
# Version : $Revision: 1.3 $
# Version : $Revision: 1.4 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/etc/Makefile.in,v $
#
# @configure_input@
@ -110,6 +110,8 @@ SCHEDULER_OBJS = ${TMP_DIR}/SignalDispatcher.o \
${TMP_DIR}/XmlRpcDaemon.o \
${TMP_DIR}/SchedulerDaemon.o \
${TMP_DIR}/UploadPlaylistMethod.o \
${TMP_DIR}/DisplayScheduleMethod.o \
${TMP_DIR}/DisplayPlaylistMethod.o \
${TMP_DIR}/ScheduleFactory.o \
${TMP_DIR}/PostgresqlSchedule.o
@ -122,7 +124,11 @@ SCHEDULER_EXE_LIBS = -l${STORAGE_LIB} -l${DB_LIB} -l${CORE_LIB} \
TEST_RUNNER_OBJS = ${SCHEDULER_OBJS} \
${TMP_DIR}/SchedulerDaemonTest.o \
${TMP_DIR}/SchedulerDaemonUploadTest.o \
${TMP_DIR}/SchedulerDaemonDisplayScheduleTest.o \
${TMP_DIR}/SchedulerDaemonDisplayPlaylistTest.o \
${TMP_DIR}/UploadPlaylistMethodTest.o \
${TMP_DIR}/DisplayScheduleMethodTest.o \
${TMP_DIR}/DisplayPlaylistMethodTest.o \
${TMP_DIR}/PostgresqlScheduleTest.o \
${TMP_DIR}/TestRunner.o
TEST_RUNNER_LIBS = ${SCHEDULER_EXE_LIBS} -lcppunit -ldl

View file

@ -40,7 +40,7 @@
<storageClientFactory>
<testStorage>
<playlist id="1" playlength="01:30:00.00"/>
<playlist id="1" playlength="01:00:00.00"/>
</testStorage>
</storageClientFactory>

View file

@ -0,0 +1,163 @@
/*------------------------------------------------------------------------------
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/DisplayPlaylistMethod.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 "LiveSupport/Core/StorageClientInterface.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "ScheduleInterface.h"
#include "ScheduleFactory.h"
#include "DisplayPlaylistMethod.h"
using namespace boost;
using namespace boost::posix_time;
using namespace LiveSupport;
using namespace LiveSupport::Core;
using namespace LiveSupport::Storage;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* The name of this XML-RPC method.
*----------------------------------------------------------------------------*/
const std::string DisplayPlaylistMethod::methodName = "displayPlaylist";
/*------------------------------------------------------------------------------
* The name of the playlistId member in the XML-RPC parameter
* structure.
*----------------------------------------------------------------------------*/
const std::string DisplayPlaylistMethod::playlistIdName = "playlistId";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Construct the method and register it right away.
*----------------------------------------------------------------------------*/
DisplayPlaylistMethod :: DisplayPlaylistMethod (
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer) throw()
: XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get())
{
}
/*------------------------------------------------------------------------------
* Extract the UniqueId from an XML-RPC function call parameter
*----------------------------------------------------------------------------*/
Ptr<UniqueId>::Ref
DisplayPlaylistMethod :: extractPlaylistId(
XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument)
{
if (!xmlRpcValue.hasMember(playlistIdName)) {
throw std::invalid_argument("no playlist id in parameter structure");
}
Ptr<UniqueId>::Ref id(new UniqueId((int) xmlRpcValue[playlistIdName]));
return id;
}
/*------------------------------------------------------------------------------
* Convert a Playlist to an XmlRpcValue
*----------------------------------------------------------------------------*/
void
DisplayPlaylistMethod :: playlistToXmlRpcValue(
Ptr<const Playlist>::Ref playlist,
XmlRpc::XmlRpcValue & xmlRpcValue)
throw ()
{
xmlRpcValue["id"] = (int) (playlist->getId()->getId());
xmlRpcValue["playlength"] = playlist->getPlaylength()->total_seconds();
}
/*------------------------------------------------------------------------------
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
DisplayPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
try {
if (!parameters.valid()) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
Ptr<UniqueId>::Ref id = extractPlaylistId(parameters[0]);
Ptr<StorageClientFactory>::Ref scf;
Ptr<StorageClientInterface>::Ref storage;
scf = StorageClientFactory::getInstance();
storage = scf->getStorageClient();
if (!storage->existsPlaylist(id)) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
Ptr<Playlist>::Ref playlist = storage->getPlaylist(id);
playlistToXmlRpcValue(playlist, returnValue);
} catch (std::invalid_argument &e) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
}

View file

@ -0,0 +1,168 @@
/*------------------------------------------------------------------------------
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/DisplayPlaylistMethod.h,v $
------------------------------------------------------------------------------*/
#ifndef DisplayPlaylistMethod_h
#define DisplayPlaylistMethod_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 <XmlRpcServerMethod.h>
#include <XmlRpcValue.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Playlist.h"
namespace LiveSupport {
namespace Scheduler {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An XML-RPC method object to return a playlist for a specified
* playlist id.
*
* The name of the method when called through XML-RPC is "displayPlaylist".
* The expected parameter is an XML-RPC structure, with the following
* member:
* <ul>
* <li>playlistId - int - the unique id of the playlist requested.</li>
* </ul>
*
* The XML-RPC function returns an XML-RPC structure, containing the following
* fields:
* <ul>
* <li>id - int - the unique id of the playlist</li>
* <li>playlength - int - the playlist length of the playlist, in seconds
* </li>
* </ul>
* In case of an error, a simple false value is returned.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class DisplayPlaylistMethod : 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 playlistId member in the XML-RPC parameter
* structure.
*/
static const std::string playlistIdName;
/**
* Extract the playlist 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
extractPlaylistId(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Convert a Playlist to an XmlRpcValue
*
* @param playlist the Playlist to convert.
* @param xmlRpcValue the output parameter holding the value of
* the conversion.
*/
static void
playlistToXmlRpcValue(Ptr<const Playlist>::Ref playlist,
XmlRpc::XmlRpcValue & xmlRpcValue)
throw ();
public:
/**
* A default constructor, for testing purposes.
*/
DisplayPlaylistMethod(void) throw ()
: XmlRpc::XmlRpcServerMethod(methodName)
{
}
/**
* Constuctor that registers the method with the server right away.
*
* @param xmlRpcServer the XML-RPC server to register with.
*/
DisplayPlaylistMethod(
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer)
throw ();
/**
* Execute the display schedule 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 // DisplayPlaylistMethod_h

View file

@ -0,0 +1,175 @@
/*------------------------------------------------------------------------------
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/DisplayPlaylistMethodTest.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 "DisplayPlaylistMethod.h"
#include "DisplayPlaylistMethodTest.h"
using namespace LiveSupport::Db;
using namespace LiveSupport::Storage;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(DisplayPlaylistMethodTest);
/**
* The name of the configuration file for the storage client factory.
*/
const std::string DisplayPlaylistMethodTest::storageClientConfig =
"etc/storageClient.xml";
/**
* The name of the configuration file for the connection manager factory.
*/
const std::string DisplayPlaylistMethodTest::connectionManagerConfig =
"etc/connectionManagerFactory.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Configure a Configurable with an XML file.
*----------------------------------------------------------------------------*/
void
DisplayPlaylistMethodTest :: 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
DisplayPlaylistMethodTest :: setUp(void) throw ()
{
try {
Ptr<StorageClientFactory>::Ref scf
= StorageClientFactory::getInstance();
configure(scf, storageClientConfig);
Ptr<ConnectionManagerFactory>::Ref cmf
= ConnectionManagerFactory::getInstance();
configure(cmf, connectionManagerConfig);
} 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
DisplayPlaylistMethodTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Just a very simple smoke test
*----------------------------------------------------------------------------*/
void
DisplayPlaylistMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DisplayPlaylistMethod>::Ref method(new DisplayPlaylistMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result;
// set up a structure for the parameters
parameters["playlistId"] = 1;
rootParameter[0] = parameters;
method->execute(rootParameter, result);
CPPUNIT_ASSERT(((int) result["id"]) == 1);
CPPUNIT_ASSERT(((int) result["playlength"]) == (60 * 60));
}
/*------------------------------------------------------------------------------
* A very simple negative test
*----------------------------------------------------------------------------*/
void
DisplayPlaylistMethodTest :: negativeTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DisplayPlaylistMethod>::Ref method(new DisplayPlaylistMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result;
// set up a structure for the parameters
parameters["playlistId"] = 9999;
rootParameter[0] = parameters;
method->execute(rootParameter, result);
CPPUNIT_ASSERT(((bool)result) == false);
}

View file

@ -0,0 +1,144 @@
/*------------------------------------------------------------------------------
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/DisplayPlaylistMethodTest.h,v $
------------------------------------------------------------------------------*/
#ifndef DisplayPlaylistMethodTest_h
#define DisplayPlaylistMethodTest_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 DisplayPlaylistMethod class.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @see DisplayPlaylistMethod
*/
class DisplayPlaylistMethodTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(DisplayPlaylistMethodTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(negativeTest);
CPPUNIT_TEST_SUITE_END();
/**
* The name of the configuration file for the storage client factory.
*/
static const std::string storageClientConfig;
/**
* The name of the configuration file for the connection manager
* factory.
*/
static const std::string connectionManagerConfig;
/**
* 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);
/**
* A 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 // DisplayPlaylistMethodTest_h

View file

@ -0,0 +1,231 @@
/*------------------------------------------------------------------------------
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/DisplayScheduleMethod.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 "DisplayScheduleMethod.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 DisplayScheduleMethod::methodName = "displaySchedule";
/*------------------------------------------------------------------------------
* The name of the from member in the XML-RPC parameter
* structure.
*----------------------------------------------------------------------------*/
const std::string DisplayScheduleMethod::fromName = "from";
/*------------------------------------------------------------------------------
* The name of the to member in the XML-RPC parameter
* structure.
*----------------------------------------------------------------------------*/
const std::string DisplayScheduleMethod::toName = "to";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Construct the method and register it right away.
*----------------------------------------------------------------------------*/
DisplayScheduleMethod :: DisplayScheduleMethod (
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer) throw()
: XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get())
{
}
/*------------------------------------------------------------------------------
* Extract the from time from an XML-RPC function call parameter
*----------------------------------------------------------------------------*/
Ptr<ptime>::Ref
DisplayScheduleMethod :: extractFrom(
XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument)
{
if (!xmlRpcValue.hasMember(fromName)) {
throw std::invalid_argument("no from part in parameter structure");
}
struct tm tm = (struct tm) xmlRpcValue[fromName];
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;
}
/*------------------------------------------------------------------------------
* Extract the to time from an XML-RPC function call parameter
*----------------------------------------------------------------------------*/
Ptr<ptime>::Ref
DisplayScheduleMethod :: extractTo(
XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument)
{
if (!xmlRpcValue.hasMember(toName)) {
throw std::invalid_argument("no to part in parameter structure");
}
struct tm tm = (struct tm) xmlRpcValue[toName];
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;
}
/*------------------------------------------------------------------------------
* Convert a boost::posix_time::ptime to an XmlRpcValue
*----------------------------------------------------------------------------*/
void
DisplayScheduleMethod :: ptimeToXmlRpcValue(
Ptr<const ptime>::Ref ptime,
XmlRpc::XmlRpcValue & xmlRpcValue)
throw ()
{
gregorian::date date = ptime->date();
posix_time::time_duration hours = ptime->time_of_day();
struct tm time;
time.tm_year = date.year();
time.tm_mon = date.month();
time.tm_mday = date.day();
time.tm_hour = hours.hours();
time.tm_min = hours.minutes();
time.tm_sec = hours.seconds();
// TODO: set tm_wday, tm_yday and tm_isdst fields as well
xmlRpcValue = XmlRpc::XmlRpcValue(&time);
}
/*------------------------------------------------------------------------------
* Convert a vector of ScheduleEntries into an XML-RPC value.
* This function returns an XML-RPC array of XML-RPC structures.
*----------------------------------------------------------------------------*/
void
DisplayScheduleMethod :: scheduleEntriesToXmlRpcValue(
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref scheduleEntries,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
returnValue.setSize(scheduleEntries->size());
// a call to setSize() makes sure it's an XML-RPC
// array
std::vector<Ptr<ScheduleEntry>::Ref>::iterator it
= scheduleEntries->begin();
int arraySize = 0;
while (it != scheduleEntries->end()) {
Ptr<ScheduleEntry>::Ref entry = *it;
XmlRpc::XmlRpcValue returnStruct;
returnStruct["id"] = (int) (entry->getId()->getId());
returnStruct["playlistId"] = (int) (entry->getPlaylistId()->getId());
XmlRpc::XmlRpcValue time;
ptimeToXmlRpcValue(entry->getStartTime(), time);
returnStruct["start"] = time;
ptimeToXmlRpcValue(entry->getEndTime(), time);
returnStruct["end"] = time;
returnValue[arraySize++] = returnStruct;
++it;
}
}
/*------------------------------------------------------------------------------
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
DisplayScheduleMethod :: execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
try {
if (!parameters.valid()) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
Ptr<ptime>::Ref fromTime = extractFrom(parameters[0]);
Ptr<ptime>::Ref toTime = extractTo(parameters[0]);
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule();
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref scheduleEntries
= schedule->getScheduleEntries(fromTime, toTime);
scheduleEntriesToXmlRpcValue(scheduleEntries, returnValue);
} catch (std::invalid_argument &e) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
}

View file

@ -0,0 +1,208 @@
/*------------------------------------------------------------------------------
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/DisplayScheduleMethod.h,v $
------------------------------------------------------------------------------*/
#ifndef DisplayScheduleMethod_h
#define DisplayScheduleMethod_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 <vector>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <XmlRpcServerMethod.h>
#include <XmlRpcValue.h>
#include "LiveSupport/Core/Ptr.h"
#include "ScheduleEntry.h"
namespace LiveSupport {
namespace Scheduler {
using namespace boost::posix_time;
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An XML-RPC method object to return the schedule for a specified
* time interval.
*
* The name of the method when called through XML-RPC is "displaySchedule".
* The expected parameter is an XML-RPC structure, with the following
* member:
* <ul>
* <li>from - datetime - the start of the interval to list schedule from,
* inclusive.</li>
* <li>to - datetime - the end of the interval to list schedule from,
* non-inclusive.</li>
* </ul>
*
* The XML-RPC function returns an XML-RPC array, containing a structure
* for each scheduled item in the interval. An array of size 0 means there
* are not scheduled entries. Each structure is as follows:
* <ul>
* <li>id - int - the id of the scheduled entry</li>
* <li>playlistId - int - the id of the playlist associated with the entry
* </li>
* <li>start - datetime - the start of the scheduled item</li>
* <li>end - datetime - the end of the scheduled item</li>
* </ul>
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class DisplayScheduleMethod : 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 from member in the XML-RPC parameter
* structure.
*/
static const std::string fromName;
/**
* The name of the to member in the XML-RPC parameter
* structure.
*/
static const std::string toName;
/**
* Extract the from time parameter from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return the time value for the from parameter
* @exception std::invalid_argument if there was no from parameter
* in xmlRpcValue
*/
Ptr<boost::posix_time::ptime>::Ref
extractFrom(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the to parameter from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return the time value for the to parameter
* @exception std::invalid_argument if there was no to parameter
* in xmlRpcValue
*/
Ptr<boost::posix_time::ptime>::Ref
extractTo(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Convert a boost::posix_time::ptime to an XmlRpcValue
*
* @param ptime the ptime to convert
* @param xmlRpcValue the output parameter holding the value of
* the conversion.
*/
static void
ptimeToXmlRpcValue(Ptr<const ptime>::Ref ptime,
XmlRpc::XmlRpcValue & xmlRpcValue)
throw ();
/**
* Convert a vector of ScheduleEntries to an XML-RPC return value.
*
* @param scheduleEntries a list of ScheduleEntries.
* @param returnValue the output parameter holding an XML-RPC
* representation of the suppied schedule entires.
*/
void
scheduleEntriesToXmlRpcValue(
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref scheduleEntries,
XmlRpc::XmlRpcValue & returnValue)
throw ();
public:
/**
* A default constructor, for testing purposes.
*/
DisplayScheduleMethod(void) throw ()
: XmlRpc::XmlRpcServerMethod(methodName)
{
}
/**
* Constuctor that registers the method with the server right away.
*
* @param xmlRpcServer the XML-RPC server to register with.
*/
DisplayScheduleMethod(
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer)
throw ();
/**
* Execute the display schedule 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 // DisplayScheduleMethod_h

View file

@ -0,0 +1,362 @@
/*------------------------------------------------------------------------------
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/DisplayScheduleMethodTest.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 "DisplayScheduleMethod.h"
#include "DisplayScheduleMethodTest.h"
using namespace LiveSupport::Db;
using namespace LiveSupport::Storage;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(DisplayScheduleMethodTest);
/**
* The name of the configuration file for the storage client factory.
*/
const std::string DisplayScheduleMethodTest::storageClientConfig =
"etc/storageClient.xml";
/**
* The name of the configuration file for the connection manager factory.
*/
const std::string DisplayScheduleMethodTest::connectionManagerConfig =
"etc/connectionManagerFactory.xml";
/**
* The name of the configuration file for the schedule factory.
*/
const std::string DisplayScheduleMethodTest::scheduleConfig =
"etc/scheduleFactory.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Configure a Configurable with an XML file.
*----------------------------------------------------------------------------*/
void
DisplayScheduleMethodTest :: 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
DisplayScheduleMethodTest :: setUp(void) throw ()
{
try {
Ptr<StorageClientFactory>::Ref scf
= StorageClientFactory::getInstance();
configure(scf, storageClientConfig);
Ptr<ConnectionManagerFactory>::Ref cmf
= ConnectionManagerFactory::getInstance();
configure(cmf, connectionManagerConfig);
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
configure(sf, scheduleConfig);
schedule = sf->getSchedule();
schedule->install();
insertEntries();
} 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
DisplayScheduleMethodTest :: tearDown(void) throw ()
{
schedule->uninstall();
}
/*------------------------------------------------------------------------------
* Just a very simple smoke test
*----------------------------------------------------------------------------*/
void
DisplayScheduleMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DisplayScheduleMethod>::Ref method(new DisplayScheduleMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result;
struct tm time;
// set up a structure for the parameters
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["from"] = &time;
time.tm_year = 2001;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 19;
time.tm_min = 31;
time.tm_sec = 1;
parameters["to"] = &time;
rootParameter[0] = parameters;
method->execute(rootParameter, result);
CPPUNIT_ASSERT(result.size() == 0);
}
/*------------------------------------------------------------------------------
* Insert some entries into the schedule
*----------------------------------------------------------------------------*/
void
DisplayScheduleMethodTest :: insertEntries(void)
throw ()
{
Ptr<UploadPlaylistMethod>::Ref method(new UploadPlaylistMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result;
struct tm time;
// insert a playlist for 2004-07-31, at 10 o'clock
parameters["playlistId"] = 1;
time.tm_year = 2004;
time.tm_mon = 7;
time.tm_mday = 31;
time.tm_hour = 10;
time.tm_min = 0;
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
method->execute(rootParameter, result);
// insert a playlist for 2004-07-31, at 12 o'clock
parameters["playlistId"] = 1;
time.tm_year = 2004;
time.tm_mon = 7;
time.tm_mday = 31;
time.tm_hour = 12;
time.tm_min = 0;
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
method->execute(rootParameter, result);
// insert a playlist for 2004-07-31, at 14 o'clock
parameters["playlistId"] = 1;
time.tm_year = 2004;
time.tm_mon = 7;
time.tm_mday = 31;
time.tm_hour = 14;
time.tm_min = 0;
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
method->execute(rootParameter, result);
}
/*------------------------------------------------------------------------------
* Look at some intervals and check against test data
*----------------------------------------------------------------------------*/
void
DisplayScheduleMethodTest :: intervalTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DisplayScheduleMethod>::Ref method(new DisplayScheduleMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result;
struct tm time;
// check for the interval 2004-07-31 between 9 and 11 o'clock
time.tm_year = 2004;
time.tm_mon = 7;
time.tm_mday = 31;
time.tm_hour = 9;
time.tm_min = 0;
time.tm_sec = 0;
parameters["from"] = &time;
time.tm_year = 2004;
time.tm_mon = 7;
time.tm_mday = 31;
time.tm_hour = 11;
time.tm_min = 0;
time.tm_sec = 0;
parameters["to"] = &time;
rootParameter[0] = parameters;
result = XmlRpc::XmlRpcValue();
method->execute(rootParameter, result);
// check the returned values
CPPUNIT_ASSERT(result.size() == 1);
CPPUNIT_ASSERT((int)(result[0]["playlistId"]) == 1);
time = result[0]["start"];
CPPUNIT_ASSERT(time.tm_year == 2004);
CPPUNIT_ASSERT(time.tm_mon == 7);
CPPUNIT_ASSERT(time.tm_mday == 31);
CPPUNIT_ASSERT(time.tm_hour == 10);
CPPUNIT_ASSERT(time.tm_min == 0);
CPPUNIT_ASSERT(time.tm_sec == 0);
time = result[0]["end"];
CPPUNIT_ASSERT(time.tm_year == 2004);
CPPUNIT_ASSERT(time.tm_mon == 7);
CPPUNIT_ASSERT(time.tm_mday == 31);
CPPUNIT_ASSERT(time.tm_hour == 11);
CPPUNIT_ASSERT(time.tm_min == 0);
CPPUNIT_ASSERT(time.tm_sec == 0);
// check for the interval 2004-07-31 between 9 and 13 o'clock
time.tm_year = 2004;
time.tm_mon = 7;
time.tm_mday = 31;
time.tm_hour = 9;
time.tm_min = 0;
time.tm_sec = 0;
parameters["from"] = &time;
time.tm_year = 2004;
time.tm_mon = 7;
time.tm_mday = 31;
time.tm_hour = 13;
time.tm_min = 0;
time.tm_sec = 0;
parameters["to"] = &time;
rootParameter[0] = parameters;
result = XmlRpc::XmlRpcValue();
method->execute(rootParameter, result);
// check the returned values
CPPUNIT_ASSERT(result.size() == 2);
CPPUNIT_ASSERT((int)(result[0]["playlistId"]) == 1);
time = result[0]["start"];
CPPUNIT_ASSERT(time.tm_year == 2004);
CPPUNIT_ASSERT(time.tm_mon == 7);
CPPUNIT_ASSERT(time.tm_mday == 31);
CPPUNIT_ASSERT(time.tm_hour == 10);
CPPUNIT_ASSERT(time.tm_min == 0);
CPPUNIT_ASSERT(time.tm_sec == 0);
time = result[0]["end"];
CPPUNIT_ASSERT(time.tm_year == 2004);
CPPUNIT_ASSERT(time.tm_mon == 7);
CPPUNIT_ASSERT(time.tm_mday == 31);
CPPUNIT_ASSERT(time.tm_hour == 11);
CPPUNIT_ASSERT(time.tm_min == 0);
CPPUNIT_ASSERT(time.tm_sec == 0);
CPPUNIT_ASSERT((int)(result[1]["playlistId"]) == 1);
time = result[1]["start"];
CPPUNIT_ASSERT(time.tm_year == 2004);
CPPUNIT_ASSERT(time.tm_mon == 7);
CPPUNIT_ASSERT(time.tm_mday == 31);
CPPUNIT_ASSERT(time.tm_hour == 12);
CPPUNIT_ASSERT(time.tm_min == 0);
CPPUNIT_ASSERT(time.tm_sec == 0);
time = result[1]["end"];
CPPUNIT_ASSERT(time.tm_year == 2004);
CPPUNIT_ASSERT(time.tm_mon == 7);
CPPUNIT_ASSERT(time.tm_mday == 31);
CPPUNIT_ASSERT(time.tm_hour == 13);
CPPUNIT_ASSERT(time.tm_min == 0);
CPPUNIT_ASSERT(time.tm_sec == 0);
// check for the interval 2004-07-31 between 8 and 9 o'clock
time.tm_year = 2004;
time.tm_mon = 7;
time.tm_mday = 31;
time.tm_hour = 8;
time.tm_min = 0;
time.tm_sec = 0;
parameters["from"] = &time;
time.tm_year = 2004;
time.tm_mon = 7;
time.tm_mday = 31;
time.tm_hour = 9;
time.tm_min = 0;
time.tm_sec = 0;
parameters["to"] = &time;
rootParameter[0] = parameters;
result = XmlRpc::XmlRpcValue();
method->execute(rootParameter, result);
// check the returned values
CPPUNIT_ASSERT(result.size() == 0);
}

View file

@ -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/products/scheduler/src/DisplayScheduleMethodTest.h,v $
------------------------------------------------------------------------------*/
#ifndef DisplayScheduleMethodTest_h
#define DisplayScheduleMethodTest_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 DisplayScheduleMethod class.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @see DisplayScheduleMethod
*/
class DisplayScheduleMethodTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(DisplayScheduleMethodTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(intervalTest);
CPPUNIT_TEST_SUITE_END();
/**
* The name of the configuration file for the storage client factory.
*/
static const std::string storageClientConfig;
/**
* The name of the configuration file for the connection manager
* factory.
*/
static const std::string connectionManagerConfig;
/**
* 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);
/**
* Insert some entries into the schedule to provide test data.
*/
void
insertEntries(void) throw ();
protected:
/**
* A simple test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
/**
* Look at some intervals, and check them against the test data.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
intervalTest(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 // DisplayScheduleMethodTest_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/PostgresqlSchedule.cxx,v $
------------------------------------------------------------------------------*/
@ -96,6 +96,19 @@ const std::string PostgresqlSchedule::isTimeframaAvailableStmt =
const std::string PostgresqlSchedule::schedulePlaylistStmt =
"INSERT INTO schedule(id, playlist, starts, ends) VALUES(?, ?, ?, ?)";
/*------------------------------------------------------------------------------
* The SQL statement for querying scheduled entries for a time interval
* The parameters for this call are: from, to
* and returns the properties: id, playlist, starts, ends for all
* schedule entries between from and to, ordered by starts.
* TODO: the below query only lists entries starting inside [from:to[
* but what about entries starting before, but flowing into [from:to[ ?
*----------------------------------------------------------------------------*/
const std::string PostgresqlSchedule::getScheduleEntriesStmt =
"SELECT id, playlist, starts, ends FROM schedule WHERE "
"(? <= starts) AND (starts < ?) "
"ORDER BY starts";
/* =============================================== local function prototypes */
@ -249,3 +262,57 @@ PostgresqlSchedule :: schedulePlaylist(
}
}
/*------------------------------------------------------------------------------
* Get the scheduled entries for a given timepoint
*----------------------------------------------------------------------------*/
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref
PostgresqlSchedule :: getScheduleEntries(
Ptr<ptime>::Ref fromTime,
Ptr<ptime>::Ref toTime)
throw ()
{
Ptr<Connection>::Ref conn;
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref result(
new std::vector<Ptr<ScheduleEntry>::Ref>());
try {
conn = cm->getConnection();
Ptr<Timestamp>::Ref timestamp;
Ptr<PreparedStatement>::Ref pstmt(conn->prepareStatement(
getScheduleEntriesStmt));
timestamp = Conversion::ptimeToTimestamp(fromTime);
pstmt->setTimestamp(1, *timestamp);
timestamp = Conversion::ptimeToTimestamp(toTime);
pstmt->setTimestamp(2, *timestamp);
Ptr<ResultSet>::Ref rs(pstmt->executeQuery());
while (rs->next()) {
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);
Ptr<ScheduleEntry>::Ref entry(new ScheduleEntry(id,
playlistId,
startTime,
endTime));
result->push_back(entry);
}
cm->returnConnection(conn);
} catch (std::exception &e) {
if (conn) {
cm->returnConnection(conn);
}
// TODO: report error
return result;
}
return result;
}

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
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.2 $
* @version $Revision: 1.3 $
*/
class PostgresqlSchedule : public Configurable,
public ScheduleInterface
@ -112,6 +112,11 @@ class PostgresqlSchedule : public Configurable,
*/
static const std::string schedulePlaylistStmt;
/**
* The SQL statement for getting the schedules for a time interval
*/
static const std::string getScheduleEntriesStmt;
/**
* The database connection manager to use for connecting the
* database.
@ -218,6 +223,20 @@ class PostgresqlSchedule : public Configurable,
schedulePlaylist(Ptr<Playlist>::Ref playlist,
Ptr<ptime>::Ref playtime)
throw (std::invalid_argument);
/**
* Return the list of scheduled entries for a specified time interval.
*
* @param fromTime the start of the time of the interval queried,
* inclusive
* @param toTime to end of the time of the interval queried,
* non-inclusive
* @return a vector of the scheduled entries for the time region.
*/
virtual Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref
getScheduleEntries(Ptr<ptime>::Ref fromTime,
Ptr<ptime>::Ref toTime)
throw ();
};

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx,v $
------------------------------------------------------------------------------*/
@ -226,3 +226,76 @@ PostgresqlScheduleTest :: scheduleAndQueryTest(void)
CPPUNIT_ASSERT(schedule->isTimeframeAvailable(from, to));
}
/*------------------------------------------------------------------------------
* See if getScheduleEntries() returns correct lists
*----------------------------------------------------------------------------*/
void
PostgresqlScheduleTest :: getScheduleEntriesTest(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<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref entries;
Ptr<ScheduleEntry>::Ref entry;
try {
// schedule our playlist for 2004-07-23, 10 o'clock
from.reset(new ptime(time_from_string("2004-07-23 10:00:00")));
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")));
schedule->schedulePlaylist(playlist, from);
// schedule our playlist for 2004-07-23, 14 o'clock
from.reset(new ptime(time_from_string("2004-07-23 14:00:00")));
schedule->schedulePlaylist(playlist, from);
// and now let's see what's scheduled for 2004-07-23 between
// 9:00 and 11:00
from.reset(new ptime(time_from_string("2004-07-23 09:00:00")));
to.reset(new ptime(time_from_string("2004-07-23 11:00:00")));
entries = schedule->getScheduleEntries(from, to);
// see that it is a single entry starting from 10 to 11 o'clock
CPPUNIT_ASSERT(entries->size() == 1);
entry = (*entries)[0];
CPPUNIT_ASSERT(*(entry->getPlaylistId()) == *(playlist->getId()));
from.reset(new ptime(time_from_string("2004-07-23 10:00:00")));
CPPUNIT_ASSERT(*(entry->getStartTime()) == *from);
to.reset(new ptime(time_from_string("2004-07-23 11:00:00")));
CPPUNIT_ASSERT(*(entry->getEndTime()) == *to);
// let's see what's scheduled for 2004-07-23 between
// 9:00 and 13:00
from.reset(new ptime(time_from_string("2004-07-23 09:00:00")));
to.reset(new ptime(time_from_string("2004-07-23 13:00:00")));
entries = schedule->getScheduleEntries(from, to);
// see that it is 2 entries, the one at 10 and the other at 12 o'clock
CPPUNIT_ASSERT(entries->size() == 2);
// see the one at 10 o'clock
entry = (*entries)[0];
CPPUNIT_ASSERT(*(entry->getPlaylistId()) == *(playlist->getId()));
from.reset(new ptime(time_from_string("2004-07-23 10:00:00")));
CPPUNIT_ASSERT(*(entry->getStartTime()) == *from);
to.reset(new ptime(time_from_string("2004-07-23 11:00:00")));
CPPUNIT_ASSERT(*(entry->getEndTime()) == *to);
// see the other at 12 o'clock
entry = (*entries)[1];
CPPUNIT_ASSERT(*(entry->getPlaylistId()) == *(playlist->getId()));
from.reset(new ptime(time_from_string("2004-07-23 12:00:00")));
CPPUNIT_ASSERT(*(entry->getStartTime()) == *from);
to.reset(new ptime(time_from_string("2004-07-23 13:00:00")));
CPPUNIT_ASSERT(*(entry->getEndTime()) == *to);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
}

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/PostgresqlScheduleTest.h,v $
------------------------------------------------------------------------------*/
@ -64,7 +64,7 @@ using namespace LiveSupport::Core;
* Unit test for the PostgresqlSchedule class.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
* @see PostgresqlSchedule
*/
class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture
@ -73,6 +73,7 @@ class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(simpleScheduleTest);
CPPUNIT_TEST(scheduleAndQueryTest);
CPPUNIT_TEST(getScheduleEntriesTest);
CPPUNIT_TEST_SUITE_END();
private:
@ -113,6 +114,15 @@ class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture
void
scheduleAndQueryTest(void) throw (CPPUNIT_NS::Exception);
/**
* Schedule some playlists, then get the list of scheduled playlists
* for different time intervals.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
getScheduleEntriesTest(void) throw (CPPUNIT_NS::Exception);
public:
/**

View file

@ -0,0 +1,182 @@
/*------------------------------------------------------------------------------
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/ScheduleEntry.h,v $
------------------------------------------------------------------------------*/
#ifndef ScheduleEntry_h
#define ScheduleEntry_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 "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/UniqueId.h"
namespace LiveSupport {
namespace Scheduler {
using namespace boost::posix_time;
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A scheduled event.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class ScheduleEntry
{
private:
/**
* The id of the schedule entry.
*/
Ptr<UniqueId>::Ref id;
/**
* The id of the playlist associated with the entry.
*/
Ptr<UniqueId>::Ref playlistId;
/**
* The starting time of the event.
*/
Ptr<ptime>::Ref startTime;
/**
* The end time for the event.
*/
Ptr<ptime>::Ref endTime;
/**
* The default constructor.
*/
ScheduleEntry(void) throw ()
{
}
public:
/**
* A constructor with initialization values.
*
* @param id the id of the entry.
* @param playlistId the id of the playlist associated with the entry.
* @param startTime the starting time for the entry.
* @param endTime the ending time for the entry.
*/
ScheduleEntry(Ptr<UniqueId>::Ref id,
Ptr<UniqueId>::Ref playlistId,
Ptr<ptime>::Ref startTime,
Ptr<ptime>::Ref endTime)
throw ()
{
this->id = id;
this->playlistId = playlistId;
this->startTime = startTime;
this->endTime = endTime;
}
/**
* Return the id of the entry.
*
* @return the id of the entry.
*/
Ptr<const UniqueId>::Ref
getId(void) const throw ()
{
return id;
}
/**
* Return the id of the playlist associated with the entry.
*
* @return the id of the playlist associated with the entry.
*/
Ptr<const UniqueId>::Ref
getPlaylistId(void) const throw ()
{
return playlistId;
}
/**
* Return the starting time for the entry.
*
* @return the starting time for the entry.
*/
Ptr<const ptime>::Ref
getStartTime(void) const throw ()
{
return startTime;
}
/**
* Return the ending time for the entry.
*
* @return the ending time for the entry.
*/
Ptr<const ptime>::Ref
getEndTime(void) const throw ()
{
return endTime;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Scheduler
} // namespace LiveSupport
#endif // ScheduleEntry_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/ScheduleInterface.h,v $
------------------------------------------------------------------------------*/
@ -46,6 +46,7 @@
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Installable.h"
#include "LiveSupport/Core/Playlist.h"
#include "ScheduleEntry.h"
namespace LiveSupport {
@ -69,7 +70,7 @@ using namespace LiveSupport::Core;
* The generic interface for the component scheduling events.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
class ScheduleInterface : virtual public Installable
{
@ -99,6 +100,21 @@ class ScheduleInterface : virtual public Installable
Ptr<ptime>::Ref playtime)
throw (std::invalid_argument)
= 0;
/**
* Return the list of scheduled entries for a specified time interval.
*
* @param fromTime the start of the time of the interval queried,
* inclusive
* @param toTime to end of the time of the interval queried,
* non-inclusive
* @return a vector of the scheduled entries for the time region.
*/
virtual Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref
getScheduleEntries(Ptr<ptime>::Ref fromTime,
Ptr<ptime>::Ref toTime)
throw ()
= 0;
};

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemon.cxx,v $
------------------------------------------------------------------------------*/
@ -163,6 +163,8 @@ SchedulerDaemon :: registerXmlRpcFunctions(
throw (std::logic_error)
{
xmlRpcServer->addMethod(uploadPlaylistMethod.get());
xmlRpcServer->addMethod(displayScheduleMethod.get());
xmlRpcServer->addMethod(displayPlaylistMethod.get());
}

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/SchedulerDaemon.h,v $
------------------------------------------------------------------------------*/
@ -61,6 +61,8 @@
#include "LiveSupport/Core/Installable.h"
#include "LiveSupport/Core/Configurable.h"
#include "UploadPlaylistMethod.h"
#include "DisplayScheduleMethod.h"
#include "DisplayPlaylistMethod.h"
#include "XmlRpcDaemon.h"
@ -116,7 +118,7 @@ using namespace LiveSupport::Core;
* </code></pre>
*
* @author $Author: maroy $
* @version $Revision: 1.3 $
* @version $Revision: 1.4 $
* @see ConnectionManagerFactory
* @see StorageClientFactory
* @see ScheduleFactory
@ -138,6 +140,16 @@ class SchedulerDaemon : public Installable,
*/
Ptr<UploadPlaylistMethod>::Ref uploadPlaylistMethod;
/**
* The DisplayScheduleMethod the daemon is providing.
*/
Ptr<DisplayScheduleMethod>::Ref displayScheduleMethod;
/**
* The DisplayPlaylistMethod the daemon is providing.
*/
Ptr<DisplayPlaylistMethod>::Ref displayPlaylistMethod;
/**
* Default constructor.
*/
@ -145,6 +157,8 @@ class SchedulerDaemon : public Installable,
: XmlRpcDaemon()
{
uploadPlaylistMethod.reset(new UploadPlaylistMethod());
displayScheduleMethod.reset(new DisplayScheduleMethod());
displayPlaylistMethod.reset(new DisplayPlaylistMethod());
}
protected:

View file

@ -0,0 +1,153 @@
/*------------------------------------------------------------------------------
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/SchedulerDaemonDisplayPlaylistTest.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 "SchedulerDaemonDisplayPlaylistTest.h"
using namespace XmlRpc;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(SchedulerDaemonDisplayPlaylistTest);
/**
* 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
SchedulerDaemonDisplayPlaylistTest :: 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
SchedulerDaemonDisplayPlaylistTest :: tearDown(void) throw ()
{
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
// daemon->stop();
daemon->uninstall();
}
/*------------------------------------------------------------------------------
* A simple smoke test.
*----------------------------------------------------------------------------*/
void
SchedulerDaemonDisplayPlaylistTest :: simpleTest(void)
throw (CPPUNIT_NS::Exception)
{
XmlRpcValue parameters;
XmlRpcValue result;
XmlRpcClient xmlRpcClient("localhost", 3344, "/RPC2", false);
parameters["playlistId"] = 1;
xmlRpcClient.execute("displayPlaylist", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(((int) result["id"]) == 1);
CPPUNIT_ASSERT(((int) result["playlength"]) == (60 * 60));
}
/*------------------------------------------------------------------------------
* A simple negative test.
*----------------------------------------------------------------------------*/
void
SchedulerDaemonDisplayPlaylistTest :: negativeTest(void)
throw (CPPUNIT_NS::Exception)
{
XmlRpcValue parameters;
XmlRpcValue result;
XmlRpcClient xmlRpcClient("localhost", 3344, "/RPC2", false);
parameters["playlistId"] = 9999;
xmlRpcClient.execute("displayPlaylist", 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/SchedulerDaemonDisplayPlaylistTest.h,v $
------------------------------------------------------------------------------*/
#ifndef SchedulerDaemonDisplayPlaylistTest_h
#define SchedulerDaemonDisplayPlaylistTest_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 displayPlaylist XML-RPC call.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @see SchedulerDaemon
*/
class SchedulerDaemonDisplayPlaylistTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(SchedulerDaemonDisplayPlaylistTest);
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 // SchedulerDaemonDisplayPlaylistTest_h

View file

@ -0,0 +1,148 @@
/*------------------------------------------------------------------------------
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/SchedulerDaemonDisplayScheduleTest.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 "SchedulerDaemonDisplayScheduleTest.h"
using namespace XmlRpc;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(SchedulerDaemonDisplayScheduleTest);
/**
* 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
SchedulerDaemonDisplayScheduleTest :: 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
SchedulerDaemonDisplayScheduleTest :: tearDown(void) throw ()
{
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
// daemon->stop();
daemon->uninstall();
}
/*------------------------------------------------------------------------------
* Test a simple query, resulting in an empty result set.
*----------------------------------------------------------------------------*/
void
SchedulerDaemonDisplayScheduleTest :: simpleTest(void)
throw (CPPUNIT_NS::Exception)
{
XmlRpcValue parameters;
XmlRpcValue result;
struct tm time;
XmlRpcClient xmlRpcClient("localhost", 3344, "/RPC2", false);
// list the schedules for an interval (as the database is empty,
// it's going to return an empty result set)
time.tm_year = 2004;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 10;
time.tm_min = 0;
time.tm_sec = 0;
parameters["from"] = &time;
time.tm_year = 2004;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 11;
time.tm_min = 0;
time.tm_sec = 0;
parameters["to"] = &time;
xmlRpcClient.execute("displaySchedule", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(result.size() == 0);
}

View file

@ -0,0 +1,108 @@
/*------------------------------------------------------------------------------
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/SchedulerDaemonDisplayScheduleTest.h,v $
------------------------------------------------------------------------------*/
#ifndef SchedulerDaemonDisplayScheduleTest_h
#define SchedulerDaemonDisplayScheduleTest_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 displaySchedule XML-RPC call.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @see SchedulerDaemon
*/
class SchedulerDaemonDisplayScheduleTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(SchedulerDaemonDisplayScheduleTest);
CPPUNIT_TEST(simpleTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* Simple test for an empty query.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
simpleTest(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 // SchedulerDaemonDisplayScheduleTest_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/SchedulerDaemonUploadTest.cxx,v $
------------------------------------------------------------------------------*/
@ -126,7 +126,12 @@ SchedulerDaemonUploadTest :: simpleTest(void)
// try to schedule playlist #1 for the time below
parameters["playlistId"] = 1;
strptime("2001-11-12 10:00:00", "%Y-%m-%d %H:%M:%S", &time);
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);

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -49,6 +49,7 @@
#include "UploadPlaylistMethod.h"
using namespace boost;
using namespace boost::posix_time;
using namespace LiveSupport;
@ -86,7 +87,7 @@ const std::string UploadPlaylistMethod::playtimeName = "playtime";
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Construct the StopXmlRpcMethod and register it right away.
* Construct the method and register it right away.
*----------------------------------------------------------------------------*/
UploadPlaylistMethod :: UploadPlaylistMethod (
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer) throw()
@ -124,9 +125,10 @@ UploadPlaylistMethod :: extractPlayschedule(
throw std::invalid_argument("no playtime in parameter structure");
}
struct tm & tm = (struct tm &) xmlRpcValue[playtimeName];
time_t time = mktime(&tm);
Ptr<ptime>::Ref ptime(new ptime(from_time_t(time)));
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;
}

View file

@ -22,11 +22,11 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/UploadPlaylistMethod.h,v $
------------------------------------------------------------------------------*/
#ifndef UploadPlaylistMetohd_h
#ifndef UploadPlaylistMethod_h
#define UploadPlaylistMethod_h
#ifndef __cplusplus
@ -70,7 +70,7 @@ using namespace LiveSupport::Core;
*
* The name of the method when called through XML-RPC is "uploadPlaylist".
* The expected parameter is an XML-RPC structure, with the following
* member:
* members:
* <ul>
* <li>playlistId - int, the id of the playlist to upload</li>
* <li>playtime - the time when the playlist should be scheduled,
@ -78,7 +78,7 @@ using namespace LiveSupport::Core;
* </ul>
*
* @author $Author: maroy $
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
class UploadPlaylistMethod : public XmlRpc::XmlRpcServerMethod
{
@ -165,5 +165,5 @@ class UploadPlaylistMethod : public XmlRpc::XmlRpcServerMethod
} // namespace Scheduler
} // namespace LiveSupport
#endif // UploadPlaylistMetohd_h
#endif // UploadPlaylistMethod_h

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -145,7 +145,7 @@ UploadPlaylistMethodTest :: tearDown(void) throw ()
/*------------------------------------------------------------------------------
* Test to see if the singleton Hello object is accessible
* Just a very simple smoke test
*----------------------------------------------------------------------------*/
void
UploadPlaylistMethodTest :: firstTest(void)
@ -159,7 +159,12 @@ UploadPlaylistMethodTest :: firstTest(void)
// set up a structure for the parameters
parameters["playlistId"] = 1;
strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &time);
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;
@ -183,7 +188,12 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void)
// load the first playlist, this will succeed
parameters["playlistId"] = 1;
strptime("2001-11-12 10:00:00", "%Y-%m-%d %H:%M:%S", &time);
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;
rootParameter[0] = parameters;
@ -193,7 +203,12 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void)
// try to load the same one, but in an overlapping time region
// (we know that playlist with id 1 in 1 hour long)
parameters["playlistId"] = 1;
strptime("2001-11-12 10:30:00", "%Y-%m-%d %H:%M:%S", &time);
time.tm_year = 2001;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 10;
time.tm_min = 30;
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
@ -202,7 +217,12 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void)
// try to load the same one, but now in good timing
parameters["playlistId"] = 1;
strptime("2001-11-12 11:30:00", "%Y-%m-%d %H:%M:%S", &time);
time.tm_year = 2001;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 11;
time.tm_min = 30;
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
@ -211,7 +231,12 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void)
// try to load the same one, this time overlapping both previos instnaces
parameters["playlistId"] = 1;
strptime("2001-11-12 10:45:00", "%Y-%m-%d %H:%M:%S", &time);
time.tm_year = 2001;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 10;
time.tm_min = 45;
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;

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/UploadPlaylistMethodTest.h,v $
------------------------------------------------------------------------------*/
@ -58,10 +58,10 @@ using namespace LiveSupport::Core;
/* =============================================================== data types */
/**
* Unit test for the UploadPlaylistMetohd class.
* Unit test for the UploadPlaylistMethod class.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
* @see UploadPlaylistMethod
*/
class UploadPlaylistMethodTest : public CPPUNIT_NS::TestFixture