diff --git a/livesupport/modules/core/include/LiveSupport/Core/StorageClientInterface.h b/livesupport/modules/core/include/LiveSupport/Core/StorageClientInterface.h index 1d5d8d5b4..089994ef2 100644 --- a/livesupport/modules/core/include/LiveSupport/Core/StorageClientInterface.h +++ b/livesupport/modules/core/include/LiveSupport/Core/StorageClientInterface.h @@ -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::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::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::Ref> >::Ref + getAllAudioClips(void) const throw () = 0; + + }; diff --git a/livesupport/modules/storage/etc/testStorage.xml b/livesupport/modules/storage/etc/testStorage.xml index a0ac06fc6..9d768ddad 100644 --- a/livesupport/modules/storage/etc/testStorage.xml +++ b/livesupport/modules/storage/etc/testStorage.xml @@ -1,7 +1,7 @@ + @@ -21,7 +21,9 @@ - + + + diff --git a/livesupport/modules/storage/src/TestStorageClient.cxx b/livesupport/modules/storage/src/TestStorageClient.cxx index 8e93a5b69..540328b5d 100644 --- a/livesupport/modules/storage/src/TestStorageClient.cxx +++ b/livesupport/modules/storage/src/TestStorageClient.cxx @@ -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::Ref playlist(new Playlist()); + Ptr::Ref playlist(new Playlist); const xmlpp::Element * element = dynamic_cast (*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::Ref audioClip(new AudioClip); + const xmlpp::Element * element = + dynamic_cast (*it); + audioClip->configure(*element); + audioClipMap[audioClip->getId()->getId()] = audioClip; + ++it; + } } @@ -125,13 +140,10 @@ void TestStorageClient :: deletePlaylist(Ptr::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::Ref id) const + throw () +{ + return audioClipMap.count(id->getId()) == 1 ? true : false; +} + + +/*------------------------------------------------------------------------------ + * Return an audio clip. + *----------------------------------------------------------------------------*/ +Ptr::Ref +TestStorageClient :: getAudioClip(Ptr::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::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::Ref> >::Ref +TestStorageClient :: getAllAudioClips(void) const + throw () +{ + AudioClipMap::const_iterator it = audioClipMap.begin(); + Ptr::Ref> >::Ref + audioClipVector (new std::vector::Ref>); + + while (it != audioClipMap.end()) { + audioClipVector->push_back(it->second); + ++it; + } + + return audioClipVector; +} + diff --git a/livesupport/modules/storage/src/TestStorageClient.h b/livesupport/modules/storage/src/TestStorageClient.h index 8f7bed3e7..7d48eba1e 100644 --- a/livesupport/modules/storage/src/TestStorageClient.h +++ b/livesupport/modules/storage/src/TestStorageClient.h @@ -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::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::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::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::Ref> >::Ref getAllPlaylists(void) const throw (); - /** * Create a new playlist. * @@ -178,22 +187,16 @@ class TestStorageClient : virtual Ptr::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::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::Ref getAudioClip(Ptr::Ref id) const - throw (std::invalid_argument) - { - Ptr::Ref nonConstId(new UniqueId(id->getId())); - Ptr::Ref length(new time_duration(0,30,0,0)); - Ptr::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::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::Ref> >::Ref + getAllAudioClips(void) const throw (); }; diff --git a/livesupport/modules/storage/src/TestStorageClientTest.cxx b/livesupport/modules/storage/src/TestStorageClientTest.cxx index 71711647d..1c46e959a 100644 --- a/livesupport/modules/storage/src/TestStorageClientTest.cxx +++ b/livesupport/modules/storage/src/TestStorageClientTest.cxx @@ -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::Ref id(new UniqueId(rand())); + Ptr::Ref id2(new UniqueId(10002)); + Ptr::Ref id7(new UniqueId(10077)); - CPPUNIT_ASSERT(tsc->existsAudioClip(id)); + CPPUNIT_ASSERT(tsc->existsAudioClip(id2)); + CPPUNIT_ASSERT(!tsc->existsAudioClip(id7)); - Ptr::Ref audioClip = tsc->getAudioClip(id); - CPPUNIT_ASSERT(audioClip->getId()->getId() == id->getId()); - CPPUNIT_ASSERT(audioClip->getPlaylength()->total_seconds() + Ptr::Ref audioClip = tsc->getAudioClip(id2); + CPPUNIT_ASSERT(audioClip->getId()->getId() == id2->getId()); + CPPUNIT_ASSERT(audioClip->getPlaylength()->total_seconds() == 30*60); + + Ptr::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)); } diff --git a/livesupport/modules/storage/src/TestStorageClientTest.h b/livesupport/modules/storage/src/TestStorageClientTest.h index 1713316ca..c8e8b4ae7 100644 --- a/livesupport/modules/storage/src/TestStorageClientTest.h +++ b/livesupport/modules/storage/src/TestStorageClientTest.h @@ -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. */ diff --git a/livesupport/products/scheduler/doc/model/SchedulerModel.zuml b/livesupport/products/scheduler/doc/model/SchedulerModel.zuml index 7c63756e6..c91d3b208 100644 Binary files a/livesupport/products/scheduler/doc/model/SchedulerModel.zuml and b/livesupport/products/scheduler/doc/model/SchedulerModel.zuml differ diff --git a/livesupport/products/scheduler/etc/Makefile.in b/livesupport/products/scheduler/etc/Makefile.in index 549730c6c..e070f4eea 100644 --- a/livesupport/products/scheduler/etc/Makefile.in +++ b/livesupport/products/scheduler/etc/Makefile.in @@ -21,7 +21,7 @@ # # # Author : $Author: fgerlits $ -# Version : $Revision: 1.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 diff --git a/livesupport/products/scheduler/etc/storageClient.xml b/livesupport/products/scheduler/etc/storageClient.xml index 8b7e72a2d..8bbb1f816 100644 --- a/livesupport/products/scheduler/etc/storageClient.xml +++ b/livesupport/products/scheduler/etc/storageClient.xml @@ -3,7 +3,7 @@ - + @@ -27,5 +27,7 @@ + + diff --git a/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethodTest.cxx b/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethodTest.cxx index 3302963b2..9987116db 100644 --- a/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethodTest.cxx +++ b/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethodTest.cxx @@ -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")); diff --git a/livesupport/products/scheduler/src/DisplayAudioClipMethod.cxx b/livesupport/products/scheduler/src/DisplayAudioClipMethod.cxx new file mode 100644 index 000000000..f79145467 --- /dev/null +++ b/livesupport/products/scheduler/src/DisplayAudioClipMethod.cxx @@ -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 +#else +#error need time.h +#endif + + +#include + +#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::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::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::Ref scf; + Ptr::Ref storage; + + scf = StorageClientFactory::getInstance(); + storage = scf->getStorageClient(); + + Ptr::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); +} diff --git a/livesupport/products/scheduler/src/DisplayAudioClipMethod.h b/livesupport/products/scheduler/src/DisplayAudioClipMethod.h new file mode 100644 index 000000000..a028a4ae2 --- /dev/null +++ b/livesupport/products/scheduler/src/DisplayAudioClipMethod.h @@ -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 +#include +#include +#include + +#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: + *
    + *
  • audioClipId - int - the unique id of the audio clip requested.
  • + *
+ * + * The XML-RPC function returns an XML-RPC structure, containing the following + * fields: + *
    + *
  • id - int - the unique id of the audio clip
  • + *
  • playlength - int - the length of the audio clip, in seconds + *
  • + *
+ * + * If there is an error, an XML-RPC structure is returned, with the following + * fields: + *
    + *
  • errorCode - int - a numerical code for the error
  • + *
  • errorMessage - string - a description of the error
  • + *
+ * The possible error codes are: + *
    + *
  • 601 - invalid argument format
  • + *
  • 602 - argument is not an audio clip ID
  • + *
  • 603 - audio clip not found
  • + *
+ * + * @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::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 + diff --git a/livesupport/products/scheduler/src/DisplayAudioClipMethodTest.cxx b/livesupport/products/scheduler/src/DisplayAudioClipMethodTest.cxx new file mode 100644 index 000000000..66859b18f --- /dev/null +++ b/livesupport/products/scheduler/src/DisplayAudioClipMethodTest.cxx @@ -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 +#else +#error "Need unistd.h" +#endif + + +#include +#include +#include + +#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::Ref configurable, + const std::string fileName) + throw (std::invalid_argument, + xmlpp::exception) +{ + Ptr::Ref parser(new xmlpp::DomParser(fileName, true)); + const xmlpp::Document * document = parser->get_document(); + const xmlpp::Element * root = document->get_root_node(); + + configurable->configure(*root); +} + + +/*------------------------------------------------------------------------------ + * Set up the test environment + *----------------------------------------------------------------------------*/ +void +DisplayAudioClipMethodTest :: setUp(void) throw () +{ + try { + Ptr::Ref scf + = StorageClientFactory::getInstance(); + configure(scf, storageClientConfig); + + Ptr::Ref cmf + = ConnectionManagerFactory::getInstance(); + configure(cmf, connectionManagerConfig); + + } catch (std::invalid_argument &e) { + CPPUNIT_FAIL("semantic error in configuration file"); + } catch (xmlpp::exception &e) { + CPPUNIT_FAIL("error parsing configuration file"); + } catch (std::exception &e) { + CPPUNIT_FAIL(e.what()); + } +} + + +/*------------------------------------------------------------------------------ + * Clean up the test environment + *----------------------------------------------------------------------------*/ +void +DisplayAudioClipMethodTest :: tearDown(void) throw () +{ +} + + +/*------------------------------------------------------------------------------ + * Just a very simple smoke test + *----------------------------------------------------------------------------*/ +void +DisplayAudioClipMethodTest :: firstTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::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::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 +} diff --git a/livesupport/products/scheduler/src/DisplayAudioClipMethodTest.h b/livesupport/products/scheduler/src/DisplayAudioClipMethodTest.h new file mode 100644 index 000000000..bcf51b727 --- /dev/null +++ b/livesupport/products/scheduler/src/DisplayAudioClipMethodTest.h @@ -0,0 +1,144 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: 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 + + +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::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 + diff --git a/livesupport/products/scheduler/src/DisplayAudioClipsMethod.cxx b/livesupport/products/scheduler/src/DisplayAudioClipsMethod.cxx new file mode 100644 index 000000000..e54374049 --- /dev/null +++ b/livesupport/products/scheduler/src/DisplayAudioClipsMethod.cxx @@ -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 + +#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::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::Ref scf; + Ptr::Ref storage; + + scf = StorageClientFactory::getInstance(); + storage = scf->getStorageClient(); + + Ptr::Ref> >::Ref audioClipVector = + storage->getAllAudioClips(); + + XmlRpcTools::audioClipVectorToXmlRpcValue(audioClipVector, returnValue); +} diff --git a/livesupport/products/scheduler/src/DisplayAudioClipsMethod.h b/livesupport/products/scheduler/src/DisplayAudioClipsMethod.h new file mode 100644 index 000000000..22ba33af0 --- /dev/null +++ b/livesupport/products/scheduler/src/DisplayAudioClipsMethod.h @@ -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 +#include +#include +#include +#include + +#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: + *
    + *
  • id - int - the unique id of the audio clip
  • + *
  • playlength - int - the length of the audio clip, in seconds + *
  • + *
+ * + * @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::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 + diff --git a/livesupport/products/scheduler/src/DisplayAudioClipsMethodTest.cxx b/livesupport/products/scheduler/src/DisplayAudioClipsMethodTest.cxx new file mode 100644 index 000000000..99d85c0a0 --- /dev/null +++ b/livesupport/products/scheduler/src/DisplayAudioClipsMethodTest.cxx @@ -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 +#else +#error "Need unistd.h" +#endif + + +#include +#include +#include +#include + +#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::Ref configurable, + const std::string fileName) + throw (std::invalid_argument, + xmlpp::exception) +{ + Ptr::Ref parser(new xmlpp::DomParser(fileName, true)); + const xmlpp::Document * document = parser->get_document(); + const xmlpp::Element * root = document->get_root_node(); + + configurable->configure(*root); +} + + +/*------------------------------------------------------------------------------ + * Set up the test environment + *----------------------------------------------------------------------------*/ +void +DisplayAudioClipsMethodTest :: setUp(void) throw () +{ + try { + Ptr::Ref scf + = StorageClientFactory::getInstance(); + configure(scf, storageClientConfig); + + Ptr::Ref cmf + = ConnectionManagerFactory::getInstance(); + configure(cmf, connectionManagerConfig); + + } catch (std::invalid_argument &e) { + CPPUNIT_FAIL("semantic error in configuration file"); + } catch (xmlpp::exception &e) { + CPPUNIT_FAIL("error parsing configuration file"); + } catch (std::exception &e) { + CPPUNIT_FAIL(e.what()); + } +} + + +/*------------------------------------------------------------------------------ + * Clean up the test environment + *----------------------------------------------------------------------------*/ +void +DisplayAudioClipsMethodTest :: tearDown(void) throw () +{ +} + + +/*------------------------------------------------------------------------------ + * Just a very simple smoke test + *----------------------------------------------------------------------------*/ +void +DisplayAudioClipsMethodTest :: firstTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::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); + +} diff --git a/livesupport/products/scheduler/src/DisplayAudioClipsMethodTest.h b/livesupport/products/scheduler/src/DisplayAudioClipsMethodTest.h new file mode 100644 index 000000000..1c5200d47 --- /dev/null +++ b/livesupport/products/scheduler/src/DisplayAudioClipsMethodTest.h @@ -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 + + +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::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 + diff --git a/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethodTest.cxx b/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethodTest.cxx index ca96cf39f..338d635c2 100644 --- a/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethodTest.cxx +++ b/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/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); diff --git a/livesupport/products/scheduler/src/XmlRpcTools.cxx b/livesupport/products/scheduler/src/XmlRpcTools.cxx index 1dad6ef45..a32574845 100644 --- a/livesupport/products/scheduler/src/XmlRpcTools.cxx +++ b/livesupport/products/scheduler/src/XmlRpcTools.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.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::Ref playlist = *it; - XmlRpc::XmlRpcValue returnStruct; - returnStruct["id"] = (int) (playlist->getId()->getId()); - returnStruct["playlength"] = playlist->getPlaylength()->total_seconds(); - returnValue[arraySize++] = returnStruct; + Ptr::Ref playlist = *it; + XmlRpc::XmlRpcValue returnStruct; + playlistToXmlRpcValue(playlist, returnStruct); + returnValue[arraySize++] = returnStruct; + ++it; + } +} + + +/*------------------------------------------------------------------------------ + * Convert an AudioClip to an XmlRpcValue + *----------------------------------------------------------------------------*/ +void +XmlRpcTools :: audioClipToXmlRpcValue( + Ptr::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::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::Ref>::const_iterator it = + audioClipVector->begin(); + int arraySize = 0; + while (it != audioClipVector->end()) { + Ptr::Ref audioClip = *it; + XmlRpc::XmlRpcValue returnStruct; + audioClipToXmlRpcValue(audioClip, returnStruct); + returnValue[arraySize++] = returnStruct; ++it; } } diff --git a/livesupport/products/scheduler/src/XmlRpcTools.h b/livesupport/products/scheduler/src/XmlRpcTools.h index 99ba46739..341116fed 100644 --- a/livesupport/products/scheduler/src/XmlRpcTools.h +++ b/livesupport/products/scheduler/src/XmlRpcTools.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.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::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::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::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::Ref> >::Ref playlistVector, - XmlRpc::XmlRpcValue & returnValue) - throw (); - /** * Extract the from time parameter from the XML-RPC parameters. * diff --git a/livesupport/products/scheduler/src/XmlRpcToolsTest.cxx b/livesupport/products/scheduler/src/XmlRpcToolsTest.cxx index 7d58b539a..6e4dd941c 100644 --- a/livesupport/products/scheduler/src/XmlRpcToolsTest.cxx +++ b/livesupport/products/scheduler/src/XmlRpcToolsTest.cxx @@ -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::Ref playlist = Ptr::Ref(new Playlist); + XmlRpcValue xmlRpcPlaylist; + XmlRpcValue xmlRpcAudioClip; + Ptr::Ref playlist = Ptr::Ref(new Playlist); + Ptr::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::Ref playlistId;