added fake audio clip retrieval methods to TestStorageClient

added displayAudioClip and displayAudioClips XML-RPC server methods
This commit is contained in:
fgerlits 2004-10-19 08:09:56 +00:00
parent 555294c0a5
commit ee413579a4
22 changed files with 1428 additions and 90 deletions

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.6 $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Attic/StorageClientInterface.h,v $
------------------------------------------------------------------------------*/
@ -61,7 +61,7 @@ namespace Core {
* An interface for storage clients.
*
* @author $Author: fgerlits $
* @version $Revision: 1.6 $
* @version $Revision: 1.7 $
*/
class StorageClientInterface
{
@ -105,7 +105,6 @@ class StorageClientInterface
/**
* Return a list of all playlists in the playlist store.
*
* @param (none).
* @return a vector containing the playlists.
*/
virtual Ptr<std::vector<Ptr<Playlist>::Ref> >::Ref
@ -143,6 +142,27 @@ class StorageClientInterface
throw (std::invalid_argument)
= 0;
/**
* Delete an audio clip with the specified id.
*
* @param id the id of the audio clip to be deleted.
* @exception std::invalid_argument if no audio clip with the
* specified id exists.
*/
virtual void
deleteAudioClip(Ptr<const UniqueId>::Ref id)
throw (std::invalid_argument)
= 0;
/**
* Return a list of all audio clips in the playlist store.
*
* @return a vector containing the playlists.
*/
virtual Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref
getAllAudioClips(void) const throw () = 0;
};

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE testStorage [
<!ELEMENT testStorage (playlist*) >
<!ELEMENT testStorage (playlist*, audioClip*) >
<!ELEMENT playlist (playlistElement*) >
<!ATTLIST playlist id NMTOKEN #REQUIRED >
@ -21,7 +21,9 @@
<audioClip id="10001" playlength="01:00:00.000"/>
</playlistElement>
<playlistElement id="102" relativeOffset="01:00:00.000" >
<audioClip id="10002" playlength="00:30:00.000"/>
<audioClip id="10002" playlength="00:30:00.000"/>
</playlistElement>
</playlist>
<audioClip id="10001" playlength="01:00:00.000"/>
<audioClip id="10002" playlength="00:30:00.000"/>
</testStorage>

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.cxx,v $
------------------------------------------------------------------------------*/
@ -73,20 +73,35 @@ TestStorageClient :: configure(const xmlpp::Element & element)
throw std::invalid_argument(eMsg);
}
// iterate through the playlist elements
xmlpp::Node::NodeList nodes =
element.get_children(Playlist::getConfigElementName());
xmlpp::Node::NodeList::iterator it = nodes.begin();
// iterate through the playlist elements ...
xmlpp::Node::NodeList nodes
= element.get_children(Playlist::getConfigElementName());
xmlpp::Node::NodeList::iterator it
= nodes.begin();
playlistMap.clear();
while (it != nodes.end()) {
Ptr<Playlist>::Ref playlist(new Playlist());
Ptr<Playlist>::Ref playlist(new Playlist);
const xmlpp::Element * element =
dynamic_cast<const xmlpp::Element*> (*it);
playlist->configure(*element);
playlistMap[playlist->getId()->getId()] = playlist;
++it;
}
// ... and the the audio clip elements
nodes = element.get_children(AudioClip::getConfigElementName());
it = nodes.begin();
audioClipMap.clear();
while (it != nodes.end()) {
Ptr<AudioClip>::Ref audioClip(new AudioClip);
const xmlpp::Element * element =
dynamic_cast<const xmlpp::Element*> (*it);
audioClip->configure(*element);
audioClipMap[audioClip->getId()->getId()] = audioClip;
++it;
}
}
@ -125,13 +140,10 @@ void
TestStorageClient :: deletePlaylist(Ptr<const UniqueId>::Ref id)
throw (std::invalid_argument)
{
PlaylistMap::iterator it = playlistMap.find(id->getId());
if (it == playlistMap.end()) {
// erase() returns the number of entries found & erased
if (!playlistMap.erase(id->getId())) {
throw std::invalid_argument("no such playlist");
}
playlistMap.erase(it);
}
@ -176,3 +188,66 @@ TestStorageClient :: createPlaylist() throw ()
return playlist;
}
/*------------------------------------------------------------------------------
* Tell if an audio clip exists.
*----------------------------------------------------------------------------*/
const bool
TestStorageClient :: existsAudioClip(Ptr<const UniqueId>::Ref id) const
throw ()
{
return audioClipMap.count(id->getId()) == 1 ? true : false;
}
/*------------------------------------------------------------------------------
* Return an audio clip.
*----------------------------------------------------------------------------*/
Ptr<AudioClip>::Ref
TestStorageClient :: getAudioClip(Ptr<const UniqueId>::Ref id) const
throw (std::invalid_argument)
{
AudioClipMap::const_iterator it = audioClipMap.find(id->getId());
if (it == audioClipMap.end()) {
throw std::invalid_argument("no such audio clip");
}
return it->second;
}
/*------------------------------------------------------------------------------
* Delete an audio clip.
*----------------------------------------------------------------------------*/
void
TestStorageClient :: deleteAudioClip(Ptr<const UniqueId>::Ref id)
throw (std::invalid_argument)
{
// erase() returns the number of entries found & erased
if (!audioClipMap.erase(id->getId())) {
throw std::invalid_argument("no such audio clip");
}
}
/*------------------------------------------------------------------------------
* Return a listing of all the audio clips in the audio clip store.
*----------------------------------------------------------------------------*/
Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref
TestStorageClient :: getAllAudioClips(void) const
throw ()
{
AudioClipMap::const_iterator it = audioClipMap.begin();
Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref
audioClipVector (new std::vector<Ptr<AudioClip>::Ref>);
while (it != audioClipMap.end()) {
audioClipVector->push_back(it->second);
++it;
}
return audioClipVector;
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.6 $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.h,v $
------------------------------------------------------------------------------*/
@ -67,29 +67,40 @@ using namespace LiveSupport::Core;
* A dummy storage client, only used for test purposes.
*
* @author $Author: fgerlits $
* @version $Revision: 1.6 $
* @version $Revision: 1.7 $
*/
class TestStorageClient :
virtual public Configurable,
virtual public StorageClientInterface
{
private:
/**
* The map type containing the playlists by their ids.
*/
typedef std::map<const UniqueId::IdType, Ptr<Playlist>::Ref>
PlaylistMap;
/**
* The name of the configuration XML elmenent used by TestStorageClient
*/
static const std::string configElementNameStr;
/**
* The map type containing the playlists by their ids.
*/
typedef std::map<const UniqueId::IdType, Ptr<Playlist>::Ref>
PlaylistMap;
/**
* The map holding all contained playlists, by ids.
*/
PlaylistMap playlistMap;
/**
* The map type containing the audio clips by their ids.
*/
typedef std::map<const UniqueId::IdType, Ptr<AudioClip>::Ref>
AudioClipMap;
/**
* The map holding all contained audio clips, by ids.
*/
AudioClipMap audioClipMap;
public:
/**
@ -163,13 +174,11 @@ class TestStorageClient :
/**
* Return a list of all playlists in the playlist store.
*
* @param (none).
* @return a vector containing the playlists.
*/
virtual Ptr<std::vector<Ptr<Playlist>::Ref> >::Ref
getAllPlaylists(void) const throw ();
/**
* Create a new playlist.
*
@ -178,22 +187,16 @@ class TestStorageClient :
virtual Ptr<Playlist>::Ref
createPlaylist() throw ();
/**
* Tell if an audio clip with a given id exists.
*
* @param id the id of the audio clip to check for.
* @return true if an audio clip with the specified id exists,
* false otherwise.
* Note: at this point, this function always returns 'true'.
*/
virtual const bool
existsAudioClip(Ptr<const UniqueId>::Ref id) const
throw ()
{
return true;
}
throw ();
/**
* Return an audio clip with the specified id.
@ -202,19 +205,29 @@ class TestStorageClient :
* @return the requested audio clip.
* @exception std::invalid_argument if no audio clip with the
* specified id exists.
* Note: at this point, this function returns a fake new audio
* clip with play length 30 minutes.
*/
virtual Ptr<AudioClip>::Ref
getAudioClip(Ptr<const UniqueId>::Ref id) const
throw (std::invalid_argument)
{
Ptr<UniqueId>::Ref nonConstId(new UniqueId(id->getId()));
Ptr<time_duration>::Ref length(new time_duration(0,30,0,0));
Ptr<AudioClip>::Ref audioClip(new AudioClip(nonConstId,
length));
return audioClip;
}
throw (std::invalid_argument);
/**
* Delete the audio clip with the specified id.
*
* @param id the id of the audio clip to be deleted.
* @exception std::invalid_argument if no audio clip with the
* specified id exists.
*/
virtual void
deleteAudioClip(Ptr<const UniqueId>::Ref id)
throw (std::invalid_argument);
/**
* Return a list of all audio clips in the playlist store.
*
* @return a vector containing the audio clips.
*/
virtual Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref
getAllAudioClips(void) const throw ();
};

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.5 $
Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClientTest.cxx,v $
------------------------------------------------------------------------------*/
@ -47,6 +47,7 @@
#include "TestStorageClientTest.h"
using namespace std;
using namespace LiveSupport::Core;
using namespace LiveSupport::Storage;
@ -176,18 +177,30 @@ TestStorageClientTest :: createPlaylistTest(void)
/*------------------------------------------------------------------------------
* Test to see if the fake audio clips are correctly counterfeited
* Testing the audio clip operations
*----------------------------------------------------------------------------*/
void
TestStorageClientTest :: audioClipTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<const UniqueId>::Ref id(new UniqueId(rand()));
Ptr<const UniqueId>::Ref id2(new UniqueId(10002));
Ptr<const UniqueId>::Ref id7(new UniqueId(10077));
CPPUNIT_ASSERT(tsc->existsAudioClip(id));
CPPUNIT_ASSERT(tsc->existsAudioClip(id2));
CPPUNIT_ASSERT(!tsc->existsAudioClip(id7));
Ptr<AudioClip>::Ref audioClip = tsc->getAudioClip(id);
CPPUNIT_ASSERT(audioClip->getId()->getId() == id->getId());
CPPUNIT_ASSERT(audioClip->getPlaylength()->total_seconds()
Ptr<AudioClip>::Ref audioClip = tsc->getAudioClip(id2);
CPPUNIT_ASSERT(audioClip->getId()->getId() == id2->getId());
CPPUNIT_ASSERT(audioClip->getPlaylength()->total_seconds()
== 30*60);
Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref audioClipVector =
tsc->getAllAudioClips();
CPPUNIT_ASSERT(audioClipVector->size() == 2);
audioClip = (*audioClipVector)[0];
CPPUNIT_ASSERT((int) (audioClip->getId()->getId()) == 10001);
tsc->deleteAudioClip(id2);
CPPUNIT_ASSERT(!tsc->existsAudioClip(id2));
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.5 $
Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClientTest.h,v $
------------------------------------------------------------------------------*/
@ -58,7 +58,7 @@ namespace Storage {
* Unit test for the UploadPlaylistMetohd class.
*
* @author $Author: fgerlits $
* @version $Revision: 1.5 $
* @version $Revision: 1.6 $
* @see TestStorageClient
*/
class TestStorageClientTest : public CPPUNIT_NS::TestFixture
@ -68,6 +68,7 @@ class TestStorageClientTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(getAllPlaylistsTest);
CPPUNIT_TEST(deletePlaylistTest);
CPPUNIT_TEST(createPlaylistTest);
CPPUNIT_TEST(audioClipTest);
CPPUNIT_TEST_SUITE_END();
private:
@ -111,7 +112,7 @@ class TestStorageClientTest : public CPPUNIT_NS::TestFixture
createPlaylistTest(void) throw (CPPUNIT_NS::Exception);
/**
* Testing existsAudioClip() and getAudioClip().
* Testing the audio clip operations.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/

View File

@ -21,7 +21,7 @@
#
#
# Author : $Author: fgerlits $
# Version : $Revision: 1.14 $
# Version : $Revision: 1.15 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/etc/Makefile.in,v $
#
# @configure_input@
@ -125,7 +125,9 @@ SCHEDULER_OBJS = ${TMP_DIR}/SignalDispatcher.o \
${TMP_DIR}/CreatePlaylistMethod.o \
${TMP_DIR}/AddAudioClipToPlaylistMethod.o \
${TMP_DIR}/RemoveAudioClipFromPlaylistMethod.o \
${TMP_DIR}/ValidatePlaylistMethod.o
${TMP_DIR}/ValidatePlaylistMethod.o \
${TMP_DIR}/DisplayAudioClipMethod.o \
${TMP_DIR}/DisplayAudioClipsMethod.o
SCHEDULER_EXE_OBJS = ${SCHEDULER_OBJS} \
${TMP_DIR}/main.o
@ -154,6 +156,8 @@ TEST_RUNNER_OBJS = ${SCHEDULER_OBJS} \
${TMP_DIR}/AddAudioClipToPlaylistMethodTest.o \
${TMP_DIR}/RemoveAudioClipFromPlaylistMethodTest.o \
${TMP_DIR}/ValidatePlaylistMethodTest.o \
${TMP_DIR}/DisplayAudioClipMethodTest.o \
${TMP_DIR}/DisplayAudioClipsMethodTest.o \
${TMP_DIR}/TestRunner.o
TEST_RUNNER_LIBS = ${SCHEDULER_EXE_LIBS} -lcppunit -ldl

View File

@ -3,7 +3,7 @@
<!ELEMENT storageClientFactory (testStorage?) >
<!ELEMENT testStorage (playlist*) >
<!ELEMENT testStorage (playlist*, audioClip*) >
<!ELEMENT playlist (playlistElement*) >
<!ATTLIST playlist id NMTOKEN #REQUIRED >
@ -27,5 +27,7 @@
<audioClip id="10002" playlength="00:30:00.000"/>
</playlistElement>
</playlist>
<audioClip id="10001" playlength="01:00:00.000"/>
<audioClip id="10002" playlength="00:30:00.000"/>
</testStorage>
</storageClientFactory>

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.3 $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -151,7 +151,7 @@ AddAudioClipToPlaylistMethodTest :: firstTest(void)
XmlRpc::XmlRpcValue result;
parameter["playlistId"] = 1;
parameter["audioClipId"] = 20002;
parameter["audioClipId"] = 10001;
parameter["relativeOffset"] = 60*60;
openPlaylistMethod->execute(parameter, result);
@ -162,7 +162,7 @@ AddAudioClipToPlaylistMethodTest :: firstTest(void)
parameter.clear();
result.clear();
parameter["playlistId"] = 1;
parameter["audioClipId"] = 20003;
parameter["audioClipId"] = 10001;
parameter["relativeOffset"] = 90*60;
addAudioClipMethod->execute(parameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));

View File

@ -0,0 +1,135 @@
/*------------------------------------------------------------------------------
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/DisplayAudioClipMethod.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_TIME_H
#include <time.h>
#else
#error need time.h
#endif
#include <string>
#include "LiveSupport/Core/StorageClientInterface.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "ScheduleInterface.h"
#include "ScheduleFactory.h"
#include "XmlRpcTools.h"
#include "DisplayAudioClipMethod.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 DisplayAudioClipMethod::methodName = "displayAudioClip";
/*------------------------------------------------------------------------------
* The ID of this method for error reporting purposes.
*----------------------------------------------------------------------------*/
const int DisplayAudioClipMethod::errorId = 600;
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Construct the method and register it right away.
*----------------------------------------------------------------------------*/
DisplayAudioClipMethod :: DisplayAudioClipMethod (
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer) throw()
: XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get())
{
}
/*------------------------------------------------------------------------------
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
DisplayAudioClipMethod :: execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
if (!parameters.valid()) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
Ptr<UniqueId>::Ref id;
try{
id = XmlRpcTools::extractAudioClipId(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+2, "argument is not an audio clip ID",
returnValue);
return;
}
Ptr<StorageClientFactory>::Ref scf;
Ptr<StorageClientInterface>::Ref storage;
scf = StorageClientFactory::getInstance();
storage = scf->getStorageClient();
Ptr<AudioClip>::Ref audioClip;
try {
audioClip = storage->getAudioClip(id);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+3, "audio clip not found",
returnValue);
return;
}
XmlRpcTools::audioClipToXmlRpcValue(audioClip, returnValue);
}

View File

@ -0,0 +1,156 @@
/*------------------------------------------------------------------------------
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/DisplayAudioClipMethod.h,v $
------------------------------------------------------------------------------*/
#ifndef DisplayAudioClipMethod_h
#define DisplayAudioClipMethod_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <string>
#include <XmlRpcServerMethod.h>
#include <XmlRpcValue.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/AudioClip.h"
namespace LiveSupport {
namespace Scheduler {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An XML-RPC method object to return a audio clip for a specified
* audio clip id.
*
* The name of the method when called through XML-RPC is "displayAudioClip".
* The expected parameter is an XML-RPC structure, with the following
* member:
* <ul>
* <li>audioClipId - int - the unique id of the audio clip requested.</li>
* </ul>
*
* The XML-RPC function returns an XML-RPC structure, containing the following
* fields:
* <ul>
* <li>id - int - the unique id of the audio clip</li>
* <li>playlength - int - the length of the audio clip, in seconds
* </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>601 - invalid argument format </li>
* <li>602 - argument is not an audio clip ID </li>
* <li>603 - audio clip not found </li>
* </ul>
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
*/
class DisplayAudioClipMethod : 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.
*/
DisplayAudioClipMethod(void) throw ()
: XmlRpc::XmlRpcServerMethod(methodName)
{
}
/**
* Constuctor that registers the method with the server right away.
*
* @param xmlRpcServer the XML-RPC server to register with.
*/
DisplayAudioClipMethod(
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer)
throw ();
/**
* Execute the display schedule command on the Scheduler daemon.
*
* @param parameters XML-RPC function call parameters
* @param returnValue the return value of the call (out parameter)
*/
void
execute( XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Scheduler
} // namespace LiveSupport
#endif // DisplayAudioClipMethod_h

View File

@ -0,0 +1,171 @@
/*------------------------------------------------------------------------------
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/DisplayAudioClipMethodTest.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 "DisplayAudioClipMethod.h"
#include "DisplayAudioClipMethodTest.h"
using namespace LiveSupport::Db;
using namespace LiveSupport::Storage;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(DisplayAudioClipMethodTest);
/**
* The name of the configuration file for the storage client factory.
*/
const std::string DisplayAudioClipMethodTest::storageClientConfig =
"etc/storageClient.xml";
/**
* The name of the configuration file for the connection manager factory.
*/
const std::string DisplayAudioClipMethodTest::connectionManagerConfig =
"etc/connectionManagerFactory.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Configure a Configurable with an XML file.
*----------------------------------------------------------------------------*/
void
DisplayAudioClipMethodTest :: 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
DisplayAudioClipMethodTest :: setUp(void) throw ()
{
try {
Ptr<StorageClientFactory>::Ref scf
= StorageClientFactory::getInstance();
configure(scf, storageClientConfig);
Ptr<ConnectionManagerFactory>::Ref cmf
= ConnectionManagerFactory::getInstance();
configure(cmf, connectionManagerConfig);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (xmlpp::exception &e) {
CPPUNIT_FAIL("error parsing configuration file");
} catch (std::exception &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
DisplayAudioClipMethodTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Just a very simple smoke test
*----------------------------------------------------------------------------*/
void
DisplayAudioClipMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DisplayAudioClipMethod>::Ref method(new DisplayAudioClipMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue result;
// set up a structure for the parameter
parameter["audioClipId"] = 10001;
method->execute(parameter, result);
CPPUNIT_ASSERT(int(result["id"]) == 10001);
CPPUNIT_ASSERT(int(result["playlength"]) == (60 * 60));
}
/*------------------------------------------------------------------------------
* A very simple negative test
*----------------------------------------------------------------------------*/
void
DisplayAudioClipMethodTest :: negativeTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DisplayAudioClipMethod>::Ref method(new DisplayAudioClipMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue result;
// set up a structure for the parameter
parameter["audioClipId"] = 9999;
method->execute(parameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT(int(result["errorCode"]) == 603); // audio clip not found
}

View File

@ -0,0 +1,144 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayAudioClipMethodTest.h,v $
------------------------------------------------------------------------------*/
#ifndef DisplayAudioClipMethodTest_h
#define DisplayAudioClipMethodTest_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 DisplayAudioClipMethod class.
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
* @see DisplayAudioClipMethod
*/
class DisplayAudioClipMethodTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(DisplayAudioClipMethodTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(negativeTest);
CPPUNIT_TEST_SUITE_END();
/**
* The name of the configuration file for the storage client factory.
*/
static const std::string storageClientConfig;
/**
* The name of the configuration file for the connection manager
* factory.
*/
static const std::string connectionManagerConfig;
/**
* Configure a configurable with an XML file.
*
* @param configurable configure this
* @param fileName the name of the XML file to configure with.
* @exception std::invalid_argument on configuration errors.
* @exception xmlpp::exception on XML parsing errors.
*/
void
configure(Ptr<Configurable>::Ref configurable,
std::string fileName)
throw (std::invalid_argument,
xmlpp::exception);
protected:
/**
* A simple test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
/**
* A simple negative test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
negativeTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Scheduler
} // namespace LiveSupport
#endif // DisplayAudioClipMethodTest_h

View File

@ -0,0 +1,98 @@
/*------------------------------------------------------------------------------
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/DisplayAudioClipsMethod.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <string>
#include "LiveSupport/Core/StorageClientInterface.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "XmlRpcTools.h"
#include "DisplayAudioClipsMethod.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 DisplayAudioClipsMethod::methodName = "displayAudioClips";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Construct the method and register it right away.
*----------------------------------------------------------------------------*/
DisplayAudioClipsMethod :: DisplayAudioClipsMethod (
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer) throw()
: XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get())
{
}
/*------------------------------------------------------------------------------
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
DisplayAudioClipsMethod :: execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
Ptr<StorageClientFactory>::Ref scf;
Ptr<StorageClientInterface>::Ref storage;
scf = StorageClientFactory::getInstance();
storage = scf->getStorageClient();
Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref audioClipVector =
storage->getAllAudioClips();
XmlRpcTools::audioClipVectorToXmlRpcValue(audioClipVector, returnValue);
}

View File

@ -0,0 +1,138 @@
/*------------------------------------------------------------------------------
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/DisplayAudioClipsMethod.h,v $
------------------------------------------------------------------------------*/
#ifndef DisplayAudioClipsMethod_h
#define DisplayAudioClipsMethod_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 <XmlRpcServerMethod.h>
#include <XmlRpcValue.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/AudioClip.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 a listing of the audio clips contained
* in the audio clip store.
*
* The name of the method when called through XML-RPC is "displayAudioClips".
* No input parameters are expected.
*
* The XML-RPC function returns an XML-RPC array, containing a structure
* for each audio clip in the audio clip store. An array of size 0 means the
* audio clip store is empty. Each structure is as follows:
* <ul>
* <li>id - int - the unique id of the audio clip</li>
* <li>playlength - int - the length of the audio clip, in seconds
* </li>
* </ul>
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
*/
class DisplayAudioClipsMethod : public XmlRpc::XmlRpcServerMethod
{
private:
/**
* The name of this method, as it will be registered into the
* XML-RPC server.
*/
static const std::string methodName;
public:
/**
* A default constructor, for testing purposes.
*/
DisplayAudioClipsMethod(void) throw ()
: XmlRpc::XmlRpcServerMethod(methodName)
{
}
/**
* Constuctor that registers the method with the server right away.
*
* @param xmlRpcServer the XML-RPC server to register with.
*/
DisplayAudioClipsMethod(
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer)
throw ();
/**
* Execute the displayAudioClips 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 // DisplayAudioClipsMethod_h

View File

@ -0,0 +1,158 @@
/*------------------------------------------------------------------------------
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/DisplayAudioClipsMethodTest.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 <vector>
#include <XmlRpcValue.h>
#include "LiveSupport/Db/ConnectionManagerFactory.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "DisplayAudioClipsMethod.h"
#include "DisplayAudioClipsMethodTest.h"
using namespace LiveSupport::Db;
using namespace LiveSupport::Storage;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(DisplayAudioClipsMethodTest);
/**
* The name of the configuration file for the storage client factory.
*/
const std::string DisplayAudioClipsMethodTest::storageClientConfig =
"etc/storageClient.xml";
/**
* The name of the configuration file for the connection manager factory.
*/
const std::string DisplayAudioClipsMethodTest::connectionManagerConfig =
"etc/connectionManagerFactory.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Configure a Configurable with an XML file.
*----------------------------------------------------------------------------*/
void
DisplayAudioClipsMethodTest :: 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
DisplayAudioClipsMethodTest :: setUp(void) throw ()
{
try {
Ptr<StorageClientFactory>::Ref scf
= StorageClientFactory::getInstance();
configure(scf, storageClientConfig);
Ptr<ConnectionManagerFactory>::Ref cmf
= ConnectionManagerFactory::getInstance();
configure(cmf, connectionManagerConfig);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (xmlpp::exception &e) {
CPPUNIT_FAIL("error parsing configuration file");
} catch (std::exception &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
DisplayAudioClipsMethodTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Just a very simple smoke test
*----------------------------------------------------------------------------*/
void
DisplayAudioClipsMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DisplayAudioClipsMethod>::Ref method(new DisplayAudioClipsMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue result;
XmlRpc::XmlRpcValue audioClip;
method->execute(parameter, result);
CPPUNIT_ASSERT(result.size() == 2);
audioClip = result[0];
CPPUNIT_ASSERT(int(audioClip["id"]) == 10001);
CPPUNIT_ASSERT(int(audioClip["playlength"]) == 60 * 60);
audioClip = result[1];
CPPUNIT_ASSERT(int(audioClip["id"]) == 10002);
CPPUNIT_ASSERT(int(audioClip["playlength"]) == 30 * 60);
}

View File

@ -0,0 +1,136 @@
/*------------------------------------------------------------------------------
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/DisplayAudioClipsMethodTest.h,v $
------------------------------------------------------------------------------*/
#ifndef DisplayAudioClipsMethodTest_h
#define DisplayAudioClipsMethodTest_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 DisplayAudioClipsMethod class.
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
* @see DisplayAudioClipsMethod
*/
class DisplayAudioClipsMethodTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(DisplayAudioClipsMethodTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST_SUITE_END();
/**
* The name of the configuration file for the storage client factory.
*/
static const std::string storageClientConfig;
/**
* The name of the configuration file for the connection manager
* factory.
*/
static const std::string connectionManagerConfig;
/**
* Configure a configurable with an XML file.
*
* @param configurable configure this
* @param fileName the name of the XML file to configure with.
* @exception std::invalid_argument on configuration errors.
* @exception xmlpp::exception on XML parsing errors.
*/
void
configure(Ptr<Configurable>::Ref configurable,
std::string fileName)
throw (std::invalid_argument,
xmlpp::exception);
protected:
/**
* A simple test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
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 // DisplayAudioClipsMethodTest_h

View File

@ -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/RemoveAudioClipFromPlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -155,7 +155,7 @@ RemoveAudioClipFromPlaylistMethodTest :: firstTest(void)
XmlRpc::XmlRpcValue result;
parameter["playlistId"] = 1;
parameter["audioClipId"] = 20002;
parameter["audioClipId"] = 10001;
parameter["relativeOffset"] = 90*60;
removeAudioClipMethod->execute(parameter, result);
@ -166,8 +166,8 @@ RemoveAudioClipFromPlaylistMethodTest :: firstTest(void)
openPlaylistMethod->execute(parameter, result);
removeAudioClipMethod->execute(parameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT((int)(result["errorCode"]) == 406); // no such audio clip
CPPUNIT_ASSERT((int)(result["errorCode"]) == 406); // no audio clip at
// this rel offset
result.clear();
addAudioClipMethod->execute(parameter, result);
removeAudioClipMethod->execute(parameter, result);

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.5 $
Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcTools.cxx,v $
------------------------------------------------------------------------------*/
@ -202,11 +202,51 @@ XmlRpcTools :: playlistVectorToXmlRpcValue(
playlistVector->begin();
int arraySize = 0;
while (it != playlistVector->end()) {
Ptr<Playlist>::Ref playlist = *it;
XmlRpc::XmlRpcValue returnStruct;
returnStruct["id"] = (int) (playlist->getId()->getId());
returnStruct["playlength"] = playlist->getPlaylength()->total_seconds();
returnValue[arraySize++] = returnStruct;
Ptr<Playlist>::Ref playlist = *it;
XmlRpc::XmlRpcValue returnStruct;
playlistToXmlRpcValue(playlist, returnStruct);
returnValue[arraySize++] = returnStruct;
++it;
}
}
/*------------------------------------------------------------------------------
* Convert an AudioClip to an XmlRpcValue
*----------------------------------------------------------------------------*/
void
XmlRpcTools :: audioClipToXmlRpcValue(
Ptr<const AudioClip>::Ref audioClip,
XmlRpc::XmlRpcValue & xmlRpcValue)
throw ()
{
xmlRpcValue["id"] = (int) (audioClip->getId()->getId());
xmlRpcValue["playlength"] = audioClip->getPlaylength()->total_seconds();
}
/*------------------------------------------------------------------------------
* Convert a vector of AudioClips into an XML-RPC value.
* This function returns an XML-RPC array of XML-RPC structures.
*----------------------------------------------------------------------------*/
void
XmlRpcTools :: audioClipVectorToXmlRpcValue(
const Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref audioClipVector,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
returnValue.setSize(audioClipVector->size());
// a call to setSize() makes sure it's an XML-RPC
// array
std::vector<Ptr<AudioClip>::Ref>::const_iterator it =
audioClipVector->begin();
int arraySize = 0;
while (it != audioClipVector->end()) {
Ptr<AudioClip>::Ref audioClip = *it;
XmlRpc::XmlRpcValue returnStruct;
audioClipToXmlRpcValue(audioClip, returnStruct);
returnValue[arraySize++] = returnStruct;
++it;
}
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcTools.h,v $
------------------------------------------------------------------------------*/
@ -71,7 +71,7 @@ using namespace LiveSupport::Core;
* in the Scheduler.
*
* @author $Author: fgerlits $
* @version $Revision: 1.4 $
* @version $Revision: 1.5 $
*/
class XmlRpcTools
{
@ -192,6 +192,44 @@ class XmlRpcTools
XmlRpc::XmlRpcValue & xmlRpcValue)
throw ();
/**
* Convert a vector of Playlists to an XML-RPC return value.
*
* @param playlistVector a list of Playlists.
* @param returnValue the output parameter holding an XML-RPC
* representation of the list of Playlists.
*/
static void
playlistVectorToXmlRpcValue(
const Ptr<std::vector<Ptr<Playlist>::Ref> >::Ref playlistVector,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Convert an AudioClip to an XmlRpcValue
*
* @param audioClip the AudioClip to convert.
* @param xmlRpcValue the output parameter holding the result of
* the conversion.
*/
static void
audioClipToXmlRpcValue(Ptr<const AudioClip>::Ref audioClip,
XmlRpc::XmlRpcValue & xmlRpcValue)
throw ();
/**
* Convert a vector of AudioClips to an XML-RPC return value.
*
* @param audioClipVector a list of AudioClips.
* @param returnValue the output parameter holding an XML-RPC
* representation of the list of Playlists.
*/
static void
audioClipVectorToXmlRpcValue(
const Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref audioClipVector,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Convert an error code, message pair to an XmlRpcValue
*
@ -216,19 +254,6 @@ class XmlRpcTools
XmlRpc::XmlRpcValue & xmlRpcValue)
throw ();
/**
* Convert a vector of Playlists to an XML-RPC return value.
*
* @param playlistVector a list of Playlists.
* @param returnValue the output parameter holding an XML-RPC
* representation of the list of Playlists.
*/
static void
playlistVectorToXmlRpcValue(
const Ptr<std::vector<Ptr<Playlist>::Ref> >::Ref playlistVector,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Extract the from time parameter from the XML-RPC parameters.
*

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcToolsTest.cxx,v $
------------------------------------------------------------------------------*/
@ -124,17 +124,24 @@ void
XmlRpcToolsTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
XmlRpcValue xmlRpcPlaylist;
Ptr<Playlist>::Ref playlist = Ptr<Playlist>::Ref(new Playlist);
XmlRpcValue xmlRpcPlaylist;
XmlRpcValue xmlRpcAudioClip;
Ptr<Playlist>::Ref playlist = Ptr<Playlist>::Ref(new Playlist);
Ptr<const AudioClip>::Ref audioClip;
// set up a playlist instance
configure(playlist, configFileName);
audioClip = playlist->begin()->second->getAudioClip();
// run the packing method
// run the packing methods
XmlRpcTools :: playlistToXmlRpcValue(playlist, xmlRpcPlaylist);
XmlRpcTools :: audioClipToXmlRpcValue(audioClip, xmlRpcAudioClip);
CPPUNIT_ASSERT(((int) xmlRpcPlaylist["id"]) == 1);
CPPUNIT_ASSERT(((int) xmlRpcPlaylist["playlength"]) == (90 * 60));
CPPUNIT_ASSERT(int(xmlRpcPlaylist["id"]) == 1);
CPPUNIT_ASSERT(int(xmlRpcPlaylist["playlength"]) == 90 * 60);
CPPUNIT_ASSERT(int(xmlRpcAudioClip["id"]) == 10001);
CPPUNIT_ASSERT(int(xmlRpcAudioClip["playlength"]) == 60 * 60);
XmlRpcValue xmlRpcPlaylistId;
Ptr<UniqueId>::Ref playlistId;