added generatePlayReport XML-RPC server method
This commit is contained in:
parent
b219059333
commit
5a49ab5223
Binary file not shown.
|
@ -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
|
||||
|
||||
|
|
|
@ -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 <time.h>
|
||||
#else
|
||||
#error need time.h
|
||||
#endif
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
#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<XmlRpc::XmlRpcServer>::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<ptime>::Ref fromTime;
|
||||
try {
|
||||
fromTime = XmlRpcTools::extractFromTime(parameters);
|
||||
}
|
||||
catch (std::invalid_argument &e) {
|
||||
XmlRpcTools::markError(errorId+2, "missing or invalid 'from' argument",
|
||||
returnValue);
|
||||
return;
|
||||
}
|
||||
|
||||
Ptr<ptime>::Ref toTime;
|
||||
try {
|
||||
toTime = XmlRpcTools::extractToTime(parameters);
|
||||
}
|
||||
catch (std::invalid_argument &e) {
|
||||
XmlRpcTools::markError(errorId+3, "missing or invalid 'to' argument",
|
||||
returnValue);
|
||||
return;
|
||||
}
|
||||
|
||||
Ptr<PlayLogFactory>::Ref plf = PlayLogFactory::getInstance();
|
||||
Ptr<PlayLogInterface>::Ref playLog = plf->getPlayLog();
|
||||
|
||||
Ptr<std::vector<Ptr<const PlayLogEntry>::Ref> >::Ref playLogVector
|
||||
= playLog->getPlayLogEntries(fromTime, toTime);
|
||||
|
||||
XmlRpcTools::playLogVectorToXmlRpcValue(playLogVector, returnValue);
|
||||
}
|
|
@ -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 <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <XmlRpcServerMethod.h>
|
||||
#include <XmlRpcValue.h>
|
||||
|
||||
#include "LiveSupport/Core/Ptr.h"
|
||||
#include "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:
|
||||
* <ul>
|
||||
* <li>from - datetime - the start of the interval to give the playlog
|
||||
* from, inclusive.</li>
|
||||
* <li>to - datetime - the end of the interval to give the playlog
|
||||
* to, non-inclusive.</li>
|
||||
* </ul>
|
||||
*
|
||||
* 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:
|
||||
* <ul>
|
||||
* <li>audioClipId - int - the id of the audio clip played </li>
|
||||
* <li>timestamp - datetime - the time the clip was played (started) </li>
|
||||
* </ul>
|
||||
*
|
||||
* If there is an error, an XML-RPC structure is returned, with the following
|
||||
* fields:
|
||||
* <ul>
|
||||
* <li>errorCode - int - a numerical code for the error</li>
|
||||
* <li>errorMessage - string - a description of the error</li>
|
||||
* </ul>
|
||||
* The possible error codes are:
|
||||
* <ul>
|
||||
* <li>1501 - invalid argument format </li>
|
||||
* <li>1502 - missing or invalid 'from' argument </li>
|
||||
* <li>1503 - missing or invalid 'to' argument </li>
|
||||
* </ul>
|
||||
*
|
||||
* @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<XmlRpc::XmlRpcServer>::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
|
||||
|
|
@ -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 <unistd.h>
|
||||
#else
|
||||
#error "Need unistd.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <XmlRpcValue.h>
|
||||
|
||||
#include "LiveSupport/Db/ConnectionManagerFactory.h"
|
||||
#include "LiveSupport/Storage/StorageClientFactory.h"
|
||||
#include "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<Configurable>::Ref configurable,
|
||||
const std::string fileName)
|
||||
throw (std::invalid_argument,
|
||||
xmlpp::exception)
|
||||
{
|
||||
Ptr<xmlpp::DomParser>::Ref parser(new xmlpp::DomParser(fileName, true));
|
||||
const xmlpp::Document * document = parser->get_document();
|
||||
const xmlpp::Element * root = document->get_root_node();
|
||||
|
||||
configurable->configure(*root);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Set up the test environment
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
GeneratePlayReportMethodTest :: setUp(void) throw ()
|
||||
{
|
||||
try {
|
||||
Ptr<StorageClientFactory>::Ref scf
|
||||
= StorageClientFactory::getInstance();
|
||||
configure(scf, storageClientConfig);
|
||||
|
||||
Ptr<ConnectionManagerFactory>::Ref cmf
|
||||
= ConnectionManagerFactory::getInstance();
|
||||
configure(cmf, connectionManagerConfig);
|
||||
|
||||
Ptr<PlayLogFactory>::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<GeneratePlayReportMethod>::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<const UniqueId>::Ref audioClipId(new UniqueId(10001));
|
||||
Ptr<const ptime>::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<GeneratePlayReportMethod>::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);
|
||||
}
|
||||
|
||||
|
|
@ -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 <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
||||
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<PlayLogInterface>::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<Configurable>::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
|
||||
|
|
@ -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<UniqueId>::Ref
|
||||
virtual Ptr<const UniqueId>::Ref
|
||||
addPlayLogEntry(Ptr<const UniqueId>::Ref audioClipId,
|
||||
Ptr<const ptime>::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<std::vector<Ptr<PlayLogEntry>::Ref> >::Ref
|
||||
virtual Ptr<std::vector<Ptr<const PlayLogEntry>::Ref> >::Ref
|
||||
getPlayLogEntries(Ptr<const ptime>::Ref fromTime,
|
||||
Ptr<const ptime>::Ref toTime)
|
||||
throw (std::invalid_argument)
|
||||
|
|
|
@ -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<UniqueId>::Ref
|
||||
Ptr<const UniqueId>::Ref
|
||||
PostgresqlPlayLog :: addPlayLogEntry(
|
||||
Ptr<const UniqueId>::Ref audioClipId,
|
||||
Ptr<const ptime>::Ref clipTimestamp)
|
||||
throw (std::invalid_argument)
|
||||
{
|
||||
Ptr<Connection>::Ref conn;
|
||||
bool result = false;
|
||||
Ptr<UniqueId>::Ref id;
|
||||
Ptr<Connection>::Ref conn;
|
||||
bool result = false;
|
||||
Ptr<const UniqueId>::Ref id;
|
||||
|
||||
try {
|
||||
conn = cm->getConnection();
|
||||
Ptr<Timestamp>::Ref timestamp;
|
||||
Ptr<Timestamp>::Ref timestamp;
|
||||
Ptr<PreparedStatement>::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<std::vector<Ptr<PlayLogEntry>::Ref> >::Ref
|
||||
Ptr<std::vector<Ptr<const PlayLogEntry>::Ref> >::Ref
|
||||
PostgresqlPlayLog :: getPlayLogEntries(
|
||||
Ptr<const ptime>::Ref fromTime,
|
||||
Ptr<const ptime>::Ref toTime)
|
||||
throw (std::invalid_argument)
|
||||
{
|
||||
Ptr<Connection>::Ref conn;
|
||||
Ptr<std::vector<Ptr<PlayLogEntry>::Ref> >::Ref result(
|
||||
new std::vector<Ptr<PlayLogEntry>::Ref>());
|
||||
Ptr<Connection>::Ref conn;
|
||||
Ptr<std::vector<Ptr<const PlayLogEntry>::Ref> >::Ref result(
|
||||
new std::vector<Ptr<const PlayLogEntry>::Ref>());
|
||||
|
||||
try {
|
||||
conn = cm->getConnection();
|
||||
|
@ -238,7 +238,7 @@ PostgresqlPlayLog :: getPlayLogEntries(
|
|||
Ptr<ptime>::Ref clipTimestamp
|
||||
= Conversion::timestampToPtime(timestamp);
|
||||
|
||||
Ptr<PlayLogEntry>::Ref entry(new PlayLogEntry(id,
|
||||
Ptr<const PlayLogEntry>::Ref entry(new PlayLogEntry(id,
|
||||
audioClipId,
|
||||
clipTimestamp));
|
||||
result->push_back(entry);
|
||||
|
|
|
@ -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;
|
|||
* </code></pre>
|
||||
*
|
||||
* @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<UniqueId>::Ref
|
||||
virtual Ptr<const UniqueId>::Ref
|
||||
addPlayLogEntry(Ptr<const UniqueId>::Ref audioClipId,
|
||||
Ptr<const ptime>::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<std::vector<Ptr<PlayLogEntry>::Ref> >::Ref
|
||||
virtual Ptr<std::vector<Ptr<const PlayLogEntry>::Ref> >::Ref
|
||||
getPlayLogEntries(Ptr<const ptime>::Ref fromTime,
|
||||
Ptr<const ptime>::Ref toTime)
|
||||
throw (std::invalid_argument);
|
||||
|
|
|
@ -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<const PlayLogEntry>::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<const std::vector<Ptr<const PlayLogEntry>::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<Ptr<const PlayLogEntry>::Ref>::const_iterator it =
|
||||
playLogVector->begin();
|
||||
int arraySize = 0;
|
||||
while (it != playLogVector->end()) {
|
||||
Ptr<const PlayLogEntry>::Ref playLog = *it;
|
||||
XmlRpc::XmlRpcValue returnStruct;
|
||||
playLogEntryToXmlRpcValue(playLog, returnStruct);
|
||||
returnValue[arraySize++] = returnStruct;
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<const PlayLogEntry>::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<const UniqueId>::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<const std::vector<Ptr<const PlayLogEntry>::Ref> >::Ref
|
||||
playLogVector,
|
||||
XmlRpc::XmlRpcValue & returnValue)
|
||||
throw ();
|
||||
|
||||
};
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
|
Loading…
Reference in New Issue