diff --git a/livesupport/products/scheduler/doc/model/SchedulerModel.zuml b/livesupport/products/scheduler/doc/model/SchedulerModel.zuml index f84cd246a..509d485d4 100644 Binary files a/livesupport/products/scheduler/doc/model/SchedulerModel.zuml and b/livesupport/products/scheduler/doc/model/SchedulerModel.zuml differ diff --git a/livesupport/products/scheduler/etc/Makefile.in b/livesupport/products/scheduler/etc/Makefile.in index bda7bc1ad..122c958bb 100644 --- a/livesupport/products/scheduler/etc/Makefile.in +++ b/livesupport/products/scheduler/etc/Makefile.in @@ -21,7 +21,7 @@ # # # Author : $Author: fgerlits $ -# Version : $Revision: 1.18 $ +# Version : $Revision: 1.19 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/etc/Makefile.in,v $ # # @configure_input@ @@ -131,7 +131,8 @@ SCHEDULER_OBJS = ${TMP_DIR}/SignalDispatcher.o \ ${TMP_DIR}/RevertEditedPlaylistMethod.o \ ${TMP_DIR}/SavePlaylistMethod.o \ ${TMP_DIR}/PlayLogFactory.o \ - ${TMP_DIR}/PostgresqlPlayLog.o + ${TMP_DIR}/PostgresqlPlayLog.o \ + ${TMP_DIR}/GeneratePlayReportMethod.o SCHEDULER_EXE_OBJS = ${SCHEDULER_OBJS} \ @@ -166,6 +167,7 @@ TEST_RUNNER_OBJS = ${SCHEDULER_OBJS} \ ${TMP_DIR}/SavePlaylistMethodTest.o \ ${TMP_DIR}/RevertEditedPlaylistMethodTest.o \ ${TMP_DIR}/PostgresqlPlayLogTest.o \ + ${TMP_DIR}/GeneratePlayReportMethodTest.o \ ${TMP_DIR}/TestRunner.o TEST_RUNNER_LIBS = ${SCHEDULER_EXE_LIBS} -lcppunit -ldl diff --git a/livesupport/products/scheduler/src/GeneratePlayReportMethod.cxx b/livesupport/products/scheduler/src/GeneratePlayReportMethod.cxx new file mode 100644 index 000000000..c30297146 --- /dev/null +++ b/livesupport/products/scheduler/src/GeneratePlayReportMethod.cxx @@ -0,0 +1,133 @@ +/*------------------------------------------------------------------------------ + + 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: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/GeneratePlayReportMethod.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 "PlayLogInterface.h" +#include "PlayLogFactory.h" +#include "XmlRpcTools.h" + +#include "GeneratePlayReportMethod.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 GeneratePlayReportMethod::methodName = "generatePlayReport"; + +/*------------------------------------------------------------------------------ + * The ID of this method for error reporting purposes. + *----------------------------------------------------------------------------*/ +const int GeneratePlayReportMethod::errorId = 1500; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Construct the method and register it right away. + *----------------------------------------------------------------------------*/ +GeneratePlayReportMethod :: GeneratePlayReportMethod ( + Ptr::Ref xmlRpcServer) throw() + : XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get()) +{ +} + + +/*------------------------------------------------------------------------------ + * Execute the stop XML-RPC function call. + *----------------------------------------------------------------------------*/ +void +GeneratePlayReportMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, + XmlRpc::XmlRpcValue & returnValue) + throw () +{ + if (!rootParameter.valid() || rootParameter.size() != 1) { + XmlRpcTools::markError(errorId+1, "invalid argument format", + returnValue); + return; + } + XmlRpc::XmlRpcValue parameters = rootParameter[0]; + + Ptr::Ref fromTime; + try { + fromTime = XmlRpcTools::extractFromTime(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+2, "missing or invalid 'from' argument", + returnValue); + return; + } + + Ptr::Ref toTime; + try { + toTime = XmlRpcTools::extractToTime(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+3, "missing or invalid 'to' argument", + returnValue); + return; + } + + Ptr::Ref plf = PlayLogFactory::getInstance(); + Ptr::Ref playLog = plf->getPlayLog(); + + Ptr::Ref> >::Ref playLogVector + = playLog->getPlayLogEntries(fromTime, toTime); + + XmlRpcTools::playLogVectorToXmlRpcValue(playLogVector, returnValue); +} diff --git a/livesupport/products/scheduler/src/GeneratePlayReportMethod.h b/livesupport/products/scheduler/src/GeneratePlayReportMethod.h new file mode 100644 index 000000000..62b19cd7c --- /dev/null +++ b/livesupport/products/scheduler/src/GeneratePlayReportMethod.h @@ -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: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/GeneratePlayReportMethod.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef GeneratePlayReportMethod_h +#define GeneratePlayReportMethod_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 "PlayLogEntry.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 list of audio clips which were + * played during a specified time interval. + * + * The name of the method when called through XML-RPC is "generatePlayReport". + * The expected parameter is an XML-RPC structure, with the following + * member: + *
    + *
  • from - datetime - the start of the interval to give the playlog + * from, inclusive.
  • + *
  • to - datetime - the end of the interval to give the playlog + * to, non-inclusive.
  • + *
+ * + * The XML-RPC function returns an XML-RPC array, containing a structure + * for each play log item in the interval. An array of size 0 means there + * are no play log entries. Each structure is as follows: + *
    + *
  • audioClipId - int - the id of the audio clip played
  • + *
  • timestamp - datetime - the time the clip was played (started)
  • + *
+ * + * If there is an error, an XML-RPC structure is returned, with the following + * fields: + *
    + *
  • errorCode - int - a numerical code for the error
  • + *
  • errorMessage - string - a description of the error
  • + *
+ * The possible error codes are: + *
    + *
  • 1501 - invalid argument format
  • + *
  • 1502 - missing or invalid 'from' argument
  • + *
  • 1503 - missing or invalid 'to' argument
  • + *
+ * + * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + */ +class GeneratePlayReportMethod : 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 ID of this method for error reporting purposes. + */ + static const int errorId; + + + public: + /** + * A default constructor, for testing purposes. + */ + GeneratePlayReportMethod(void) throw () + : XmlRpc::XmlRpcServerMethod(methodName) + { + } + + /** + * Constuctor that registers the method with the server right away. + * + * @param xmlRpcServer the XML-RPC server to register with. + */ + GeneratePlayReportMethod( + Ptr::Ref xmlRpcServer) + throw (); + + /** + * Execute the generatePlayReport 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 // GeneratePlayReportMethod_h + diff --git a/livesupport/products/scheduler/src/GeneratePlayReportMethodTest.cxx b/livesupport/products/scheduler/src/GeneratePlayReportMethodTest.cxx new file mode 100644 index 000000000..6f39a3054 --- /dev/null +++ b/livesupport/products/scheduler/src/GeneratePlayReportMethodTest.cxx @@ -0,0 +1,354 @@ +/*------------------------------------------------------------------------------ + + 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: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/GeneratePlayReportMethodTest.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 "PlayLogFactory.h" +#include "UploadPlaylistMethod.h" +#include "GeneratePlayReportMethod.h" +#include "GeneratePlayReportMethodTest.h" + +using namespace std; + +using namespace LiveSupport::Db; +using namespace LiveSupport::Storage; +using namespace LiveSupport::Scheduler; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +CPPUNIT_TEST_SUITE_REGISTRATION(GeneratePlayReportMethodTest); + +/** + * The name of the configuration file for the storage client factory. + */ +const std::string GeneratePlayReportMethodTest::storageClientConfig = + "etc/storageClient.xml"; + +/** + * The name of the configuration file for the connection manager factory. + */ +const std::string GeneratePlayReportMethodTest::connectionManagerConfig = + "etc/connectionManagerFactory.xml"; + +/** + * The name of the configuration file for the play log factory. + */ +const std::string GeneratePlayReportMethodTest::playLogConfig = + "etc/playLogFactory.xml"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Configure a Configurable with an XML file. + *----------------------------------------------------------------------------*/ +void +GeneratePlayReportMethodTest :: 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 +GeneratePlayReportMethodTest :: setUp(void) throw () +{ + try { + Ptr::Ref scf + = StorageClientFactory::getInstance(); + configure(scf, storageClientConfig); + + Ptr::Ref cmf + = ConnectionManagerFactory::getInstance(); + configure(cmf, connectionManagerConfig); + + Ptr::Ref plf = PlayLogFactory::getInstance(); + configure(plf, playLogConfig); + + playLog = plf->getPlayLog(); + playLog->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 +GeneratePlayReportMethodTest :: tearDown(void) throw () +{ + playLog->uninstall(); +} + + +/*------------------------------------------------------------------------------ + * Just a very simple smoke test + *----------------------------------------------------------------------------*/ +void +GeneratePlayReportMethodTest :: firstTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::Ref method(new GeneratePlayReportMethod()); + XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); + 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; + + result.clear(); + method->execute(rootParameter, result); + CPPUNIT_ASSERT(result.size() == 0); +} + + +/*------------------------------------------------------------------------------ + * Insert some entries into the play log + *----------------------------------------------------------------------------*/ +void +GeneratePlayReportMethodTest :: insertEntries(void) + throw () +{ + Ptr::Ref audioClipId(new UniqueId(10001)); + Ptr::Ref timestamp(new ptime(time_from_string( + "2004-10-26 14:00:00"))); + playLog->addPlayLogEntry(audioClipId, timestamp); + + audioClipId.reset(new UniqueId(10017)); + timestamp.reset(new ptime(time_from_string("2004-10-26 15:30:00"))); + playLog->addPlayLogEntry(audioClipId, timestamp); + + audioClipId.reset(new UniqueId(10003)); + timestamp.reset(new ptime(time_from_string("2004-10-27 10:01:00"))); + playLog->addPlayLogEntry(audioClipId, timestamp); +} + + +/*------------------------------------------------------------------------------ + * Look at some intervals and check against test data + *----------------------------------------------------------------------------*/ +void +GeneratePlayReportMethodTest :: intervalTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::Ref method(new GeneratePlayReportMethod()); + XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); + XmlRpc::XmlRpcValue result; + struct tm time; + + // check for the interval 2004-10-26 between 13 and 15 o'clock + time.tm_year = 2004; + time.tm_mon = 10; + time.tm_mday = 26; + time.tm_hour = 13; + time.tm_min = 0; + time.tm_sec = 0; + parameters["from"] = &time; + time.tm_year = 2004; + time.tm_mon = 10; + time.tm_mday = 26; + time.tm_hour = 15; + time.tm_min = 0; + time.tm_sec = 0; + parameters["to"] = &time; + rootParameter[0] = parameters; + + result.clear(); + method->execute(rootParameter, result); + + // check the returned values + CPPUNIT_ASSERT(result.size() == 1); + CPPUNIT_ASSERT((int)(result[0]["audioClipId"]) == 10001); + time = result[0]["timestamp"]; + CPPUNIT_ASSERT(time.tm_year == 2004); + CPPUNIT_ASSERT(time.tm_mon == 10); + CPPUNIT_ASSERT(time.tm_mday == 26); + CPPUNIT_ASSERT(time.tm_hour == 14); + CPPUNIT_ASSERT(time.tm_min == 0); + CPPUNIT_ASSERT(time.tm_sec == 0); + + + // check for the interval 2004-10-26 between 14 o'clock and 15:30 + time.tm_year = 2004; + time.tm_mon = 10; + time.tm_mday = 26; + time.tm_hour = 14; + time.tm_min = 0; + time.tm_sec = 0; + parameters["from"] = &time; + time.tm_year = 2004; + time.tm_mon = 10; + time.tm_mday = 26; + time.tm_hour = 15; + time.tm_min = 30; + time.tm_sec = 0; + parameters["to"] = &time; + rootParameter[0] = parameters; + + result.clear(); + method->execute(rootParameter, result); + + // check the returned values + CPPUNIT_ASSERT(result.size() == 1); + CPPUNIT_ASSERT((int)(result[0]["audioClipId"]) == 10001); + time = result[0]["timestamp"]; + CPPUNIT_ASSERT(time.tm_year == 2004); + CPPUNIT_ASSERT(time.tm_mon == 10); + CPPUNIT_ASSERT(time.tm_mday == 26); + CPPUNIT_ASSERT(time.tm_hour == 14); + CPPUNIT_ASSERT(time.tm_min == 0); + CPPUNIT_ASSERT(time.tm_sec == 0); + + + // check for the interval 2004-10-26 15:00 to 2012-08-01 midnight + time.tm_year = 2004; + time.tm_mon = 10; + time.tm_mday = 26; + time.tm_hour = 15; + time.tm_min = 30; + time.tm_sec = 0; + parameters["from"] = &time; + time.tm_year = 2012; + time.tm_mon = 8; + time.tm_mday = 1; + time.tm_hour = 0; + time.tm_min = 0; + time.tm_sec = 0; + parameters["to"] = &time; + rootParameter[0] = parameters; + + result.clear(); + method->execute(rootParameter, result); + + // check the returned values + CPPUNIT_ASSERT(result.size() == 2); + CPPUNIT_ASSERT((int)(result[0]["audioClipId"]) == 10017); + time = result[0]["timestamp"]; + CPPUNIT_ASSERT(time.tm_year == 2004); + CPPUNIT_ASSERT(time.tm_mon == 10); + CPPUNIT_ASSERT(time.tm_mday == 26); + CPPUNIT_ASSERT(time.tm_hour == 15); + CPPUNIT_ASSERT(time.tm_min == 30); + CPPUNIT_ASSERT(time.tm_sec == 0); + + CPPUNIT_ASSERT((int)(result[1]["audioClipId"]) == 10003); + time = result[1]["timestamp"]; + CPPUNIT_ASSERT(time.tm_year == 2004); + CPPUNIT_ASSERT(time.tm_mon == 10); + CPPUNIT_ASSERT(time.tm_mday == 27); + CPPUNIT_ASSERT(time.tm_hour == 10); + CPPUNIT_ASSERT(time.tm_min == 01); + CPPUNIT_ASSERT(time.tm_sec == 0); + + + // check for the interval 2004-10-26 16 o'clock to 2004-10-27 10 o'clock + time.tm_year = 2004; + time.tm_mon = 10; + time.tm_mday = 26; + time.tm_hour = 16; + time.tm_min = 0; + time.tm_sec = 0; + parameters["from"] = &time; + time.tm_year = 2004; + time.tm_mon = 10; + time.tm_mday = 27; + time.tm_hour = 10; + time.tm_min = 0; + time.tm_sec = 0; + parameters["to"] = &time; + rootParameter[0] = parameters; + + result.clear(); + method->execute(rootParameter, result); + + // check the returned values + CPPUNIT_ASSERT(result.size() == 0); +} + + diff --git a/livesupport/products/scheduler/src/GeneratePlayReportMethodTest.h b/livesupport/products/scheduler/src/GeneratePlayReportMethodTest.h new file mode 100644 index 000000000..78ff3f978 --- /dev/null +++ b/livesupport/products/scheduler/src/GeneratePlayReportMethodTest.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: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/GeneratePlayReportMethodTest.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef GeneratePlayReportMethodTest_h +#define GeneratePlayReportMethodTest_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 GeneratePlayReportMethod class. + * + * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + * @see GeneratePlayReportMethod + */ +class GeneratePlayReportMethodTest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(GeneratePlayReportMethodTest); + 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 play log factory. + */ + static const std::string playLogConfig; + + /** + * The play log used during the test. + */ + Ptr::Ref playLog; + + /** + * 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 play log 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 // GeneratePlayReportMethodTest_h + diff --git a/livesupport/products/scheduler/src/PlayLogInterface.h b/livesupport/products/scheduler/src/PlayLogInterface.h index 9857dd9a4..ad6bde600 100644 --- a/livesupport/products/scheduler/src/PlayLogInterface.h +++ b/livesupport/products/scheduler/src/PlayLogInterface.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlayLogInterface.h,v $ ------------------------------------------------------------------------------*/ @@ -70,7 +70,7 @@ using namespace LiveSupport::Core; * The generic interface for the component scheduling events. * * @author $Author: fgerlits $ - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ class PlayLogInterface : virtual public Installable { @@ -82,7 +82,7 @@ class PlayLogInterface : virtual public Installable * @param timeStamp the time the clip was played (started). * @return the id of the newly created play log entry. */ - virtual Ptr::Ref + virtual Ptr::Ref addPlayLogEntry(Ptr::Ref audioClipId, Ptr::Ref timeStamp) throw (std::invalid_argument) @@ -97,7 +97,7 @@ class PlayLogInterface : virtual public Installable * non-inclusive * @return a vector of the play log entries for the time region. */ - virtual Ptr::Ref> >::Ref + virtual Ptr::Ref> >::Ref getPlayLogEntries(Ptr::Ref fromTime, Ptr::Ref toTime) throw (std::invalid_argument) diff --git a/livesupport/products/scheduler/src/PostgresqlPlayLog.cxx b/livesupport/products/scheduler/src/PostgresqlPlayLog.cxx index 1ad2b9d0e..fc6d82523 100644 --- a/livesupport/products/scheduler/src/PostgresqlPlayLog.cxx +++ b/livesupport/products/scheduler/src/PostgresqlPlayLog.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlPlayLog.cxx,v $ ------------------------------------------------------------------------------*/ @@ -165,19 +165,19 @@ PostgresqlPlayLog :: uninstall(void) throw (std::exception) /*------------------------------------------------------------------------------ * Add a new play log entry *----------------------------------------------------------------------------*/ -Ptr::Ref +Ptr::Ref PostgresqlPlayLog :: addPlayLogEntry( Ptr::Ref audioClipId, Ptr::Ref clipTimestamp) throw (std::invalid_argument) { - Ptr::Ref conn; - bool result = false; - Ptr::Ref id; + Ptr::Ref conn; + bool result = false; + Ptr::Ref id; try { conn = cm->getConnection(); - Ptr::Ref timestamp; + Ptr::Ref timestamp; Ptr::Ref pstmt(conn->prepareStatement( addPlayLogEntryStmt)); id = UniqueId::generateId(); @@ -209,15 +209,15 @@ PostgresqlPlayLog :: addPlayLogEntry( /*------------------------------------------------------------------------------ * Get the play log entries for a given time interval *----------------------------------------------------------------------------*/ -Ptr::Ref> >::Ref +Ptr::Ref> >::Ref PostgresqlPlayLog :: getPlayLogEntries( Ptr::Ref fromTime, Ptr::Ref toTime) throw (std::invalid_argument) { - Ptr::Ref conn; - Ptr::Ref> >::Ref result( - new std::vector::Ref>()); + Ptr::Ref conn; + Ptr::Ref> >::Ref result( + new std::vector::Ref>()); try { conn = cm->getConnection(); @@ -238,7 +238,7 @@ PostgresqlPlayLog :: getPlayLogEntries( Ptr::Ref clipTimestamp = Conversion::timestampToPtime(timestamp); - Ptr::Ref entry(new PlayLogEntry(id, + Ptr::Ref entry(new PlayLogEntry(id, audioClipId, clipTimestamp)); result->push_back(entry); diff --git a/livesupport/products/scheduler/src/PostgresqlPlayLog.h b/livesupport/products/scheduler/src/PostgresqlPlayLog.h index b7ee2dc27..9adf75f48 100644 --- a/livesupport/products/scheduler/src/PostgresqlPlayLog.h +++ b/livesupport/products/scheduler/src/PostgresqlPlayLog.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlPlayLog.h,v $ ------------------------------------------------------------------------------*/ @@ -81,7 +81,7 @@ using namespace LiveSupport::Core; * * * @author $Author: fgerlits $ - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ class PostgresqlPlayLog : public Configurable, public PlayLogInterface @@ -202,7 +202,7 @@ class PostgresqlPlayLog : public Configurable, * @param timeStamp the time the clip was played (started). * @return the id of the newly created play log entry. */ - virtual Ptr::Ref + virtual Ptr::Ref addPlayLogEntry(Ptr::Ref audioClipId, Ptr::Ref timeStamp) throw (std::invalid_argument); @@ -216,7 +216,7 @@ class PostgresqlPlayLog : public Configurable, * non-inclusive * @return a vector of the play log entries for the time region. */ - virtual Ptr::Ref> >::Ref + virtual Ptr::Ref> >::Ref getPlayLogEntries(Ptr::Ref fromTime, Ptr::Ref toTime) throw (std::invalid_argument); diff --git a/livesupport/products/scheduler/src/XmlRpcTools.cxx b/livesupport/products/scheduler/src/XmlRpcTools.cxx index 9bd1e9652..30c471f01 100644 --- a/livesupport/products/scheduler/src/XmlRpcTools.cxx +++ b/livesupport/products/scheduler/src/XmlRpcTools.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.7 $ + Version : $Revision: 1.8 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcTools.cxx,v $ ------------------------------------------------------------------------------*/ @@ -414,3 +414,47 @@ XmlRpcTools :: scheduleEntryIdToXmlRpcValue( returnValue[scheduleEntryIdName] = int(scheduleEntryId->getId()); } + +/*------------------------------------------------------------------------------ + * Convert a PlayLogEntry to an XmlRpcValue + *----------------------------------------------------------------------------*/ +void +XmlRpcTools :: playLogEntryToXmlRpcValue( + Ptr::Ref playLogEntry, + XmlRpc::XmlRpcValue & returnValue) + throw () +{ + returnValue["audioClipId"] = int(playLogEntry->getAudioClipId()->getId()); + + XmlRpc::XmlRpcValue timestamp; + ptimeToXmlRpcValue(playLogEntry->getTimestamp(), timestamp); + returnValue["timestamp"] = timestamp; +} + + +/*------------------------------------------------------------------------------ + * Convert a vector of PlayLogEntries into an XML-RPC value. + * This function returns an XML-RPC array of XML-RPC structures. + *----------------------------------------------------------------------------*/ +void +XmlRpcTools :: playLogVectorToXmlRpcValue( + Ptr::Ref> >::Ref + playLogVector, + XmlRpc::XmlRpcValue & returnValue) + throw () +{ + returnValue.setSize(playLogVector->size()); + // a call to setSize() makes sure it's an XML-RPC + // array + + std::vector::Ref>::const_iterator it = + playLogVector->begin(); + int arraySize = 0; + while (it != playLogVector->end()) { + Ptr::Ref playLog = *it; + XmlRpc::XmlRpcValue returnStruct; + playLogEntryToXmlRpcValue(playLog, returnStruct); + returnValue[arraySize++] = returnStruct; + ++it; + } +} diff --git a/livesupport/products/scheduler/src/XmlRpcTools.h b/livesupport/products/scheduler/src/XmlRpcTools.h index 847efff92..b8755288a 100644 --- a/livesupport/products/scheduler/src/XmlRpcTools.h +++ b/livesupport/products/scheduler/src/XmlRpcTools.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.6 $ + Version : $Revision: 1.7 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcTools.h,v $ ------------------------------------------------------------------------------*/ @@ -48,6 +48,7 @@ #include "LiveSupport/Core/Ptr.h" #include "LiveSupport/Core/Playlist.h" +#include "PlayLogEntry.h" #include "ScheduleEntry.h" @@ -71,7 +72,7 @@ using namespace LiveSupport::Core; * in the Scheduler. * * @author $Author: fgerlits $ - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ */ class XmlRpcTools { @@ -130,6 +131,17 @@ class XmlRpcTools XmlRpc::XmlRpcValue & xmlRpcValue) throw (); + /** + * Convert a PlayLogEntry to an XmlRpcValue + * + * @param playLogEntry the PlayLogEntry to convert. + * @param xmlRpcValue the output parameter holding the result of + * the conversion. + */ + static void + playLogEntryToXmlRpcValue(Ptr::Ref playLogEntry, + XmlRpc::XmlRpcValue & returnValue) + throw (); public: /** @@ -222,7 +234,7 @@ class XmlRpcTools * * @param audioClipVector a list of AudioClips. * @param returnValue the output parameter holding an XML-RPC - * representation of the list of Playlists. + * representation of the list of AudioClips. */ static void audioClipVectorToXmlRpcValue( @@ -315,6 +327,20 @@ class XmlRpcTools Ptr::Ref scheduleEntryId, XmlRpc::XmlRpcValue & returnValue) throw (); + /** + * Convert a vector of PlayLogEntries to an XML-RPC return value. + * + * @param playLogVector a list of PlayLogEntries. + * @param returnValue the output parameter holding an XML-RPC + * representation of the list of PlayLogEntries. + */ + static void + playLogVectorToXmlRpcValue( + Ptr::Ref> >::Ref + playLogVector, + XmlRpc::XmlRpcValue & returnValue) + throw (); + }; /* ================================================= external data structures */