diff --git a/livesupport/doc/gettingStarted.html b/livesupport/doc/gettingStarted.html
index a1f0177bf..165908b20 100644
--- a/livesupport/doc/gettingStarted.html
+++ b/livesupport/doc/gettingStarted.html
@@ -13,7 +13,7 @@ Development Loan Fund, under the GNU GPL.
- Author: $Author: maroy $
- - Version: $Revision: 1.2 $
+ - Version: $Revision: 1.3 $
- Location: $Source:
/home/cvs/livesupport/doc/gettingStarted.html,v $
@@ -28,7 +28,7 @@ control system, but some preparation and setup has to be made on system
used to develop LiveSupport as well.
Steps
-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.
- set up additional system resources
diff --git a/livesupport/modules/core/include/LiveSupport/Core/UniqueId.h b/livesupport/modules/core/include/LiveSupport/Core/UniqueId.h
index 0bee06408..54baf7e16 100644
--- a/livesupport/modules/core/include/LiveSupport/Core/UniqueId.h
+++ b/livesupport/modules/core/include/LiveSupport/Core/UniqueId.h
@@ -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.
*
diff --git a/livesupport/modules/db/include/LiveSupport/Db/Conversion.h b/livesupport/modules/db/include/LiveSupport/Db/Conversion.h
index 0a898f295..0d8832962 100644
--- a/livesupport/modules/db/include/LiveSupport/Db/Conversion.h
+++ b/livesupport/modules/db/include/LiveSupport/Db/Conversion.h
@@ -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::Ref
- ptimeToTimestamp(Ptr::Ref ptime) throw();
+ ptimeToTimestamp(Ptr::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::Ref
+ timestampToPtime(Ptr::Ref timestamp) throw ();
};
diff --git a/livesupport/modules/db/src/Conversion.cxx b/livesupport/modules/db/src/Conversion.cxx
index 76ef535c7..f482ecd1d 100644
--- a/livesupport/modules/db/src/Conversion.cxx
+++ b/livesupport/modules/db/src/Conversion.cxx
@@ -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::Ref ptime)
return timestamp;
}
+
+/*------------------------------------------------------------------------------
+ * Convert an odbc::Timestamp to a boost::ptime
+ *----------------------------------------------------------------------------*/
+Ptr::Ref
+Conversion :: timestampToPtime(Ptr::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::Ref ptime(new posix_time::ptime(
+ posix_time::time_from_string(timeStr)));
+ return ptime;
+}
+
diff --git a/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientFactory.h b/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientFactory.h
index 24c328343..adca925aa 100644
--- a/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientFactory.h
+++ b/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientFactory.h
@@ -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;
* ...
* </testStorage>
* </storageClientFactory>
+ *
*
* For detais of the testStorage element, see the documentation for the
* TestStorageClient class.
@@ -87,7 +88,7 @@ using namespace LiveSupport::Core;
*
*
* @author $Author: maroy $
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
* @see TestStorageClient
*/
class StorageClientFactory :
diff --git a/livesupport/products/scheduler/etc/Makefile.in b/livesupport/products/scheduler/etc/Makefile.in
index 5c00a0711..31e5a8980 100644
--- a/livesupport/products/scheduler/etc/Makefile.in
+++ b/livesupport/products/scheduler/etc/Makefile.in
@@ -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
diff --git a/livesupport/products/scheduler/etc/scheduler.xml b/livesupport/products/scheduler/etc/scheduler.xml
index 528be1a75..a9d403f44 100644
--- a/livesupport/products/scheduler/etc/scheduler.xml
+++ b/livesupport/products/scheduler/etc/scheduler.xml
@@ -40,7 +40,7 @@
-
+
diff --git a/livesupport/products/scheduler/src/DisplayPlaylistMethod.cxx b/livesupport/products/scheduler/src/DisplayPlaylistMethod.cxx
new file mode 100644
index 000000000..6e0a6f18c
--- /dev/null
+++ b/livesupport/products/scheduler/src/DisplayPlaylistMethod.cxx
@@ -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
+#else
+#error need time.h
+#endif
+
+
+#include
+
+#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::Ref xmlRpcServer) throw()
+ : XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get())
+{
+}
+
+
+/*------------------------------------------------------------------------------
+ * Extract the UniqueId from an XML-RPC function call parameter
+ *----------------------------------------------------------------------------*/
+Ptr::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::Ref id(new UniqueId((int) xmlRpcValue[playlistIdName]));
+ return id;
+}
+
+
+/*------------------------------------------------------------------------------
+ * Convert a Playlist to an XmlRpcValue
+ *----------------------------------------------------------------------------*/
+void
+DisplayPlaylistMethod :: playlistToXmlRpcValue(
+ Ptr::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::Ref id = extractPlaylistId(parameters[0]);
+
+ Ptr::Ref scf;
+ Ptr::Ref storage;
+
+ scf = StorageClientFactory::getInstance();
+ storage = scf->getStorageClient();
+
+ if (!storage->existsPlaylist(id)) {
+ // TODO: mark error
+ returnValue = XmlRpc::XmlRpcValue(false);
+ return;
+ }
+
+ Ptr::Ref playlist = storage->getPlaylist(id);
+
+ playlistToXmlRpcValue(playlist, returnValue);
+
+ } catch (std::invalid_argument &e) {
+ // TODO: mark error
+ returnValue = XmlRpc::XmlRpcValue(false);
+ return;
+ }
+}
+
diff --git a/livesupport/products/scheduler/src/DisplayPlaylistMethod.h b/livesupport/products/scheduler/src/DisplayPlaylistMethod.h
new file mode 100644
index 000000000..03aa65779
--- /dev/null
+++ b/livesupport/products/scheduler/src/DisplayPlaylistMethod.h
@@ -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
+#include
+#include
+#include
+
+#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:
+ *
+ * - playlistId - int - the unique id of the playlist requested.
+ *
+ *
+ * The XML-RPC function returns an XML-RPC structure, containing the following
+ * fields:
+ *
+ * - id - int - the unique id of the playlist
+ * - playlength - int - the playlist length of the playlist, in seconds
+ *
+ *
+ * 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::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::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::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
+
diff --git a/livesupport/products/scheduler/src/DisplayPlaylistMethodTest.cxx b/livesupport/products/scheduler/src/DisplayPlaylistMethodTest.cxx
new file mode 100644
index 000000000..893f9e7cb
--- /dev/null
+++ b/livesupport/products/scheduler/src/DisplayPlaylistMethodTest.cxx
@@ -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
+#else
+#error "Need unistd.h"
+#endif
+
+
+#include
+#include
+#include
+
+#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::Ref configurable,
+ const std::string fileName)
+ throw (std::invalid_argument,
+ xmlpp::exception)
+{
+ Ptr::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::Ref scf
+ = StorageClientFactory::getInstance();
+ configure(scf, storageClientConfig);
+
+ Ptr::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::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::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);
+}
+
diff --git a/livesupport/products/scheduler/src/DisplayPlaylistMethodTest.h b/livesupport/products/scheduler/src/DisplayPlaylistMethodTest.h
new file mode 100644
index 000000000..a7539307e
--- /dev/null
+++ b/livesupport/products/scheduler/src/DisplayPlaylistMethodTest.h
@@ -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
+
+
+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::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
+
diff --git a/livesupport/products/scheduler/src/DisplayScheduleMethod.cxx b/livesupport/products/scheduler/src/DisplayScheduleMethod.cxx
new file mode 100644
index 000000000..270743730
--- /dev/null
+++ b/livesupport/products/scheduler/src/DisplayScheduleMethod.cxx
@@ -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
+#else
+#error need time.h
+#endif
+
+
+#include
+
+#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::Ref xmlRpcServer) throw()
+ : XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get())
+{
+}
+
+
+/*------------------------------------------------------------------------------
+ * Extract the from time from an XML-RPC function call parameter
+ *----------------------------------------------------------------------------*/
+Ptr::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::Ref ptime(new ptime(date, hours));
+
+ return ptime;
+}
+
+
+/*------------------------------------------------------------------------------
+ * Extract the to time from an XML-RPC function call parameter
+ *----------------------------------------------------------------------------*/
+Ptr::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::Ref ptime(new ptime(date, hours));
+
+ return ptime;
+}
+
+
+/*------------------------------------------------------------------------------
+ * Convert a boost::posix_time::ptime to an XmlRpcValue
+ *----------------------------------------------------------------------------*/
+void
+DisplayScheduleMethod :: ptimeToXmlRpcValue(
+ Ptr::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::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::Ref>::iterator it
+ = scheduleEntries->begin();
+ int arraySize = 0;
+ while (it != scheduleEntries->end()) {
+ Ptr::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::Ref fromTime = extractFrom(parameters[0]);
+ Ptr::Ref toTime = extractTo(parameters[0]);
+
+ Ptr::Ref sf = ScheduleFactory::getInstance();
+ Ptr::Ref schedule = sf->getSchedule();
+
+ Ptr::Ref> >::Ref scheduleEntries
+ = schedule->getScheduleEntries(fromTime, toTime);
+
+ scheduleEntriesToXmlRpcValue(scheduleEntries, returnValue);
+
+ } catch (std::invalid_argument &e) {
+ // TODO: mark error
+ returnValue = XmlRpc::XmlRpcValue(false);
+ return;
+ }
+}
+
diff --git a/livesupport/products/scheduler/src/DisplayScheduleMethod.h b/livesupport/products/scheduler/src/DisplayScheduleMethod.h
new file mode 100644
index 000000000..e749532d2
--- /dev/null
+++ b/livesupport/products/scheduler/src/DisplayScheduleMethod.h
@@ -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
+#include
+#include
+#include
+#include
+#include
+
+#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:
+ *
+ * - from - datetime - the start of the interval to list schedule from,
+ * inclusive.
+ * - to - datetime - the end of the interval to list schedule from,
+ * non-inclusive.
+ *
+ *
+ * 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:
+ *
+ * - id - int - the id of the scheduled entry
+ * - playlistId - int - the id of the playlist associated with the entry
+ *
+ * - start - datetime - the start of the scheduled item
+ * - end - datetime - the end of the scheduled item
+ *
+ *
+ * @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::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::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::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::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::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
+
diff --git a/livesupport/products/scheduler/src/DisplayScheduleMethodTest.cxx b/livesupport/products/scheduler/src/DisplayScheduleMethodTest.cxx
new file mode 100644
index 000000000..be8ee91e4
--- /dev/null
+++ b/livesupport/products/scheduler/src/DisplayScheduleMethodTest.cxx
@@ -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
+#else
+#error "Need unistd.h"
+#endif
+
+
+#include
+#include
+#include
+
+#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::Ref configurable,
+ const std::string fileName)
+ throw (std::invalid_argument,
+ xmlpp::exception)
+{
+ Ptr::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::Ref scf
+ = StorageClientFactory::getInstance();
+ configure(scf, storageClientConfig);
+
+ Ptr::Ref cmf
+ = ConnectionManagerFactory::getInstance();
+ configure(cmf, connectionManagerConfig);
+
+ Ptr::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::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::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::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);
+}
+
+
diff --git a/livesupport/products/scheduler/src/DisplayScheduleMethodTest.h b/livesupport/products/scheduler/src/DisplayScheduleMethodTest.h
new file mode 100644
index 000000000..b08903945
--- /dev/null
+++ b/livesupport/products/scheduler/src/DisplayScheduleMethodTest.h
@@ -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
+
+
+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::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::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
+
diff --git a/livesupport/products/scheduler/src/PostgresqlSchedule.cxx b/livesupport/products/scheduler/src/PostgresqlSchedule.cxx
index ac2d79820..684988679 100644
--- a/livesupport/products/scheduler/src/PostgresqlSchedule.cxx
+++ b/livesupport/products/scheduler/src/PostgresqlSchedule.cxx
@@ -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 */
@@ -224,12 +237,12 @@ PostgresqlSchedule :: schedulePlaylist(
schedulePlaylistStmt));
id = UniqueId::generateId();
pstmt->setInt(1, id->getId());
-
+
pstmt->setInt(2, playlist->getId()->getId());
-
+
timestamp = Conversion::ptimeToTimestamp(playtime);
pstmt->setTimestamp(3, *timestamp);
-
+
ends.reset(new ptime((*playtime) + *(playlist->getPlaylength())));
timestamp = Conversion::ptimeToTimestamp(ends);
pstmt->setTimestamp(4, *timestamp);
@@ -249,3 +262,57 @@ PostgresqlSchedule :: schedulePlaylist(
}
}
+
+/*------------------------------------------------------------------------------
+ * Get the scheduled entries for a given timepoint
+ *----------------------------------------------------------------------------*/
+Ptr::Ref> >::Ref
+PostgresqlSchedule :: getScheduleEntries(
+ Ptr::Ref fromTime,
+ Ptr::Ref toTime)
+ throw ()
+{
+ Ptr::Ref conn;
+ Ptr::Ref> >::Ref result(
+ new std::vector::Ref>());
+
+ try {
+ conn = cm->getConnection();
+ Ptr::Ref timestamp;
+ Ptr::Ref pstmt(conn->prepareStatement(
+ getScheduleEntriesStmt));
+ timestamp = Conversion::ptimeToTimestamp(fromTime);
+ pstmt->setTimestamp(1, *timestamp);
+ timestamp = Conversion::ptimeToTimestamp(toTime);
+ pstmt->setTimestamp(2, *timestamp);
+
+ Ptr::Ref rs(pstmt->executeQuery());
+ while (rs->next()) {
+ Ptr::Ref id(new UniqueId(rs->getInt(1)));
+ Ptr::Ref playlistId(new UniqueId(rs->getInt(2)));
+
+ *timestamp = rs->getTimestamp(3);
+ Ptr::Ref startTime = Conversion::timestampToPtime(timestamp);
+
+ *timestamp = rs->getTimestamp(4);
+ Ptr::Ref endTime = Conversion::timestampToPtime(timestamp);
+
+ Ptr::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;
+}
+
diff --git a/livesupport/products/scheduler/src/PostgresqlSchedule.h b/livesupport/products/scheduler/src/PostgresqlSchedule.h
index 0ba269556..579c9e7df 100644
--- a/livesupport/products/scheduler/src/PostgresqlSchedule.h
+++ b/livesupport/products/scheduler/src/PostgresqlSchedule.h
@@ -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;
*
*
* @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::Ref playlist,
Ptr::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::Ref> >::Ref
+ getScheduleEntries(Ptr::Ref fromTime,
+ Ptr::Ref toTime)
+ throw ();
};
diff --git a/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx b/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx
index 8792dfec6..dc637f589 100644
--- a/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx
+++ b/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx
@@ -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::Ref playlistId = UniqueId::generateId();
+ Ptr::Ref playlength(new time_duration(1, 0, 0));
+ Ptr::Ref playlist(new Playlist(playlistId, playlength));
+
+ Ptr::Ref from;
+ Ptr::Ref to;
+
+ Ptr::Ref> >::Ref entries;
+ Ptr::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());
+ }
+}
+
+
diff --git a/livesupport/products/scheduler/src/PostgresqlScheduleTest.h b/livesupport/products/scheduler/src/PostgresqlScheduleTest.h
index fddef5bce..a2401e2d2 100644
--- a/livesupport/products/scheduler/src/PostgresqlScheduleTest.h
+++ b/livesupport/products/scheduler/src/PostgresqlScheduleTest.h
@@ -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:
/**
diff --git a/livesupport/products/scheduler/src/ScheduleEntry.h b/livesupport/products/scheduler/src/ScheduleEntry.h
new file mode 100644
index 000000000..52b8787ef
--- /dev/null
+++ b/livesupport/products/scheduler/src/ScheduleEntry.h
@@ -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
+#include
+#include
+#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::Ref id;
+
+ /**
+ * The id of the playlist associated with the entry.
+ */
+ Ptr::Ref playlistId;
+
+ /**
+ * The starting time of the event.
+ */
+ Ptr::Ref startTime;
+
+ /**
+ * The end time for the event.
+ */
+ Ptr::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::Ref id,
+ Ptr::Ref playlistId,
+ Ptr::Ref startTime,
+ Ptr::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::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::Ref
+ getPlaylistId(void) const throw ()
+ {
+ return playlistId;
+ }
+
+ /**
+ * Return the starting time for the entry.
+ *
+ * @return the starting time for the entry.
+ */
+ Ptr::Ref
+ getStartTime(void) const throw ()
+ {
+ return startTime;
+ }
+
+ /**
+ * Return the ending time for the entry.
+ *
+ * @return the ending time for the entry.
+ */
+ Ptr::Ref
+ getEndTime(void) const throw ()
+ {
+ return endTime;
+ }
+};
+
+
+/* ================================================= external data structures */
+
+
+/* ====================================================== function prototypes */
+
+
+} // namespace Scheduler
+} // namespace LiveSupport
+
+#endif // ScheduleEntry_h
+
diff --git a/livesupport/products/scheduler/src/ScheduleInterface.h b/livesupport/products/scheduler/src/ScheduleInterface.h
index 426b06344..a9af21ad3 100644
--- a/livesupport/products/scheduler/src/ScheduleInterface.h
+++ b/livesupport/products/scheduler/src/ScheduleInterface.h
@@ -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::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::Ref> >::Ref
+ getScheduleEntries(Ptr::Ref fromTime,
+ Ptr::Ref toTime)
+ throw ()
+ = 0;
};
diff --git a/livesupport/products/scheduler/src/SchedulerDaemon.cxx b/livesupport/products/scheduler/src/SchedulerDaemon.cxx
index e29be8a1b..c6cd96cc7 100644
--- a/livesupport/products/scheduler/src/SchedulerDaemon.cxx
+++ b/livesupport/products/scheduler/src/SchedulerDaemon.cxx
@@ -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());
}
diff --git a/livesupport/products/scheduler/src/SchedulerDaemon.h b/livesupport/products/scheduler/src/SchedulerDaemon.h
index 2e1fadc31..87f2b83d5 100644
--- a/livesupport/products/scheduler/src/SchedulerDaemon.h
+++ b/livesupport/products/scheduler/src/SchedulerDaemon.h
@@ -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;
*
*
* @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::Ref uploadPlaylistMethod;
+ /**
+ * The DisplayScheduleMethod the daemon is providing.
+ */
+ Ptr::Ref displayScheduleMethod;
+
+ /**
+ * The DisplayPlaylistMethod the daemon is providing.
+ */
+ Ptr::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:
diff --git a/livesupport/products/scheduler/src/SchedulerDaemonDisplayPlaylistTest.cxx b/livesupport/products/scheduler/src/SchedulerDaemonDisplayPlaylistTest.cxx
new file mode 100644
index 000000000..95f29eff7
--- /dev/null
+++ b/livesupport/products/scheduler/src/SchedulerDaemonDisplayPlaylistTest.cxx
@@ -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
+#else
+#error "Need unistd.h"
+#endif
+
+
+#include
+#include
+#include
+
+#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::Ref daemon = SchedulerDaemon::getInstance();
+
+ if (!daemon->isConfigured()) {
+ try {
+ std::auto_ptr
+ 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::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);
+}
+
diff --git a/livesupport/products/scheduler/src/SchedulerDaemonDisplayPlaylistTest.h b/livesupport/products/scheduler/src/SchedulerDaemonDisplayPlaylistTest.h
new file mode 100644
index 000000000..b766b0b6c
--- /dev/null
+++ b/livesupport/products/scheduler/src/SchedulerDaemonDisplayPlaylistTest.h
@@ -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
+
+
+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
+
diff --git a/livesupport/products/scheduler/src/SchedulerDaemonDisplayScheduleTest.cxx b/livesupport/products/scheduler/src/SchedulerDaemonDisplayScheduleTest.cxx
new file mode 100644
index 000000000..46ea5b08d
--- /dev/null
+++ b/livesupport/products/scheduler/src/SchedulerDaemonDisplayScheduleTest.cxx
@@ -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
+#else
+#error "Need unistd.h"
+#endif
+
+
+#include
+#include
+#include
+
+#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::Ref daemon = SchedulerDaemon::getInstance();
+
+ if (!daemon->isConfigured()) {
+ try {
+ std::auto_ptr
+ 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::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);
+}
+
diff --git a/livesupport/products/scheduler/src/SchedulerDaemonDisplayScheduleTest.h b/livesupport/products/scheduler/src/SchedulerDaemonDisplayScheduleTest.h
new file mode 100644
index 000000000..6aaaf21cd
--- /dev/null
+++ b/livesupport/products/scheduler/src/SchedulerDaemonDisplayScheduleTest.h
@@ -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
+
+
+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
+
diff --git a/livesupport/products/scheduler/src/SchedulerDaemonUploadTest.cxx b/livesupport/products/scheduler/src/SchedulerDaemonUploadTest.cxx
index be5f7ac65..50aa9cb36 100644
--- a/livesupport/products/scheduler/src/SchedulerDaemonUploadTest.cxx
+++ b/livesupport/products/scheduler/src/SchedulerDaemonUploadTest.cxx
@@ -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);
diff --git a/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx b/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx
index 308fe717f..14c0ba240 100644
--- a/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx
+++ b/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx
@@ -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::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::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::Ref ptime(new ptime(date, hours));
return ptime;
}
diff --git a/livesupport/products/scheduler/src/UploadPlaylistMethod.h b/livesupport/products/scheduler/src/UploadPlaylistMethod.h
index 4a6b3ae82..ab2cdf94b 100644
--- a/livesupport/products/scheduler/src/UploadPlaylistMethod.h
+++ b/livesupport/products/scheduler/src/UploadPlaylistMethod.h
@@ -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:
*
* - playlistId - int, the id of the playlist to upload
* - playtime - the time when the playlist should be scheduled,
@@ -78,7 +78,7 @@ using namespace LiveSupport::Core;
*
*
* @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
diff --git a/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx b/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx
index 41ad917c7..b501c38fe 100644
--- a/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx
+++ b/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx
@@ -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;
diff --git a/livesupport/products/scheduler/src/UploadPlaylistMethodTest.h b/livesupport/products/scheduler/src/UploadPlaylistMethodTest.h
index 299344d11..ac58677f0 100644
--- a/livesupport/products/scheduler/src/UploadPlaylistMethodTest.h
+++ b/livesupport/products/scheduler/src/UploadPlaylistMethodTest.h
@@ -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