From 8e121e1a4723bd67c11985ea5cea1a95599ba67d Mon Sep 17 00:00:00 2001 From: fgerlits Date: Wed, 27 Oct 2004 14:10:03 +0000 Subject: [PATCH] added FadeInfo methods --- livesupport/doc/model/Scheduler/index.html | 15 +- livesupport/modules/core/etc/Makefile.in | 4 +- livesupport/modules/core/etc/fadeInfo.xml | 9 + livesupport/modules/core/etc/playlist.xml | 17 +- .../modules/core/etc/playlistElement.xml | 12 +- .../core/include/LiveSupport/Core/AudioClip.h | 6 +- .../core/include/LiveSupport/Core/FadeInfo.h | 216 ++++++++++++++++++ .../core/include/LiveSupport/Core/Playlist.h | 42 +++- .../LiveSupport/Core/PlaylistElement.h | 52 ++++- livesupport/modules/core/src/FadeInfo.cxx | 116 ++++++++++ livesupport/modules/core/src/FadeInfoTest.cxx | 129 +++++++++++ livesupport/modules/core/src/FadeInfoTest.h | 107 +++++++++ livesupport/modules/core/src/Playlist.cxx | 26 ++- .../modules/core/src/PlaylistElement.cxx | 38 ++- .../modules/core/src/PlaylistElementTest.cxx | 13 +- livesupport/modules/core/src/PlaylistTest.cxx | 71 +++++- livesupport/modules/core/src/PlaylistTest.h | 13 +- .../products/scheduler/etc/Makefile.in | 6 +- .../products/scheduler/etc/storageClient.xml | 9 +- .../src/GeneratePlayReportMethod.cxx | 4 +- .../src/UpdateFadeInFadeOutMethod.cxx | 190 +++++++++++++++ .../scheduler/src/UpdateFadeInFadeOutMethod.h | 158 +++++++++++++ .../src/UpdateFadeInFadeOutMethodTest.cxx | 189 +++++++++++++++ .../src/UpdateFadeInFadeOutMethodTest.h | 135 +++++++++++ .../products/scheduler/src/XmlRpcTools.cxx | 54 ++++- .../products/scheduler/src/XmlRpcTools.h | 42 +++- 26 files changed, 1617 insertions(+), 56 deletions(-) create mode 100644 livesupport/modules/core/etc/fadeInfo.xml create mode 100644 livesupport/modules/core/include/LiveSupport/Core/FadeInfo.h create mode 100644 livesupport/modules/core/src/FadeInfo.cxx create mode 100644 livesupport/modules/core/src/FadeInfoTest.cxx create mode 100644 livesupport/modules/core/src/FadeInfoTest.h create mode 100644 livesupport/products/scheduler/src/UpdateFadeInFadeOutMethod.cxx create mode 100644 livesupport/products/scheduler/src/UpdateFadeInFadeOutMethod.h create mode 100644 livesupport/products/scheduler/src/UpdateFadeInFadeOutMethodTest.cxx create mode 100644 livesupport/products/scheduler/src/UpdateFadeInFadeOutMethodTest.h diff --git a/livesupport/doc/model/Scheduler/index.html b/livesupport/doc/model/Scheduler/index.html index 80b083dbc..2eeaea443 100644 --- a/livesupport/doc/model/Scheduler/index.html +++ b/livesupport/doc/model/Scheduler/index.html @@ -14,7 +14,7 @@ Development Loan Fund, under the GNU GPL.
@@ -3229,8 +3229,9 @@ with the Playlist is removed, with the related FadeInfo instances
Name
updateFadeInFadeOut
-(audioClip : AudioClip,
-playlist : Playlist)
+(playlist : Playlist,
+ relativeOffset: Time,
+ fadeInfo: FadeInfo)
: void
@@ -3238,7 +3239,8 @@ playlist : Playlist)
Responsibilities
Update the fade-in and -fade-out parameters for an audio clip playing in a playlist.
+fade-out parameters for an audio clip in a playlist, the start time of which +is at a given relative offset.
@@ -3262,8 +3264,9 @@ fade-out parameters for an audio clip playing in a playlist.
Exceptions
- If the Audio clip is not -in the playlist, indicate as an error.
+ If there is no Audio clip +with a start time at the given relative offset in the playlist, indicate +as an error.
diff --git a/livesupport/modules/core/etc/Makefile.in b/livesupport/modules/core/etc/Makefile.in index 6120e1446..0367b5c5e 100644 --- a/livesupport/modules/core/etc/Makefile.in +++ b/livesupport/modules/core/etc/Makefile.in @@ -21,7 +21,7 @@ # # # Author : $Author: fgerlits $ -# Version : $Revision: 1.8 $ +# Version : $Revision: 1.9 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/etc/Makefile.in,v $ # # @configure_input@ @@ -86,10 +86,12 @@ LDFLAGS = @LDFLAGS@ -L${USR_LIB_DIR} -L${LIB_DIR} #------------------------------------------------------------------------------- CORE_LIB_OBJS = ${TMP_DIR}/UniqueId.o \ ${TMP_DIR}/AudioClip.o \ + ${TMP_DIR}/FadeInfo.o \ ${TMP_DIR}/PlaylistElement.o \ ${TMP_DIR}/Playlist.o TEST_RUNNER_OBJS = ${TMP_DIR}/AudioClipTest.o \ + ${TMP_DIR}/FadeInfoTest.o \ ${TMP_DIR}/PlaylistElementTest.o \ ${TMP_DIR}/PlaylistTest.o \ ${TMP_DIR}/TestRunner.o diff --git a/livesupport/modules/core/etc/fadeInfo.xml b/livesupport/modules/core/etc/fadeInfo.xml new file mode 100644 index 000000000..f1050556f --- /dev/null +++ b/livesupport/modules/core/etc/fadeInfo.xml @@ -0,0 +1,9 @@ + + + + + +]> + diff --git a/livesupport/modules/core/etc/playlist.xml b/livesupport/modules/core/etc/playlist.xml index 1756dfb49..83a7670fd 100644 --- a/livesupport/modules/core/etc/playlist.xml +++ b/livesupport/modules/core/etc/playlist.xml @@ -5,20 +5,27 @@ - + + + + + + ]> - - + + - - + + + diff --git a/livesupport/modules/core/etc/playlistElement.xml b/livesupport/modules/core/etc/playlistElement.xml index 70fc1a6aa..2e8e2bccc 100644 --- a/livesupport/modules/core/etc/playlistElement.xml +++ b/livesupport/modules/core/etc/playlistElement.xml @@ -1,15 +1,21 @@ + + + + + + ]> - - + + + diff --git a/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h b/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h index c3c20deeb..71aaa14a1 100644 --- a/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h +++ b/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h,v $ ------------------------------------------------------------------------------*/ @@ -72,7 +72,7 @@ using namespace boost::posix_time; * in a Playlist. * * @author $Author: fgerlits $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ class AudioClip : public Configurable { @@ -169,7 +169,7 @@ class AudioClip : public Configurable /** * Return the total playing length for this audio clip. * - * @return the playing length of this audio clip, in milliseconds. + * @return the playing length of this audio clip, in microseconds. */ Ptr::Ref getPlaylength(void) const throw () diff --git a/livesupport/modules/core/include/LiveSupport/Core/FadeInfo.h b/livesupport/modules/core/include/LiveSupport/Core/FadeInfo.h new file mode 100644 index 000000000..ddb65a8d2 --- /dev/null +++ b/livesupport/modules/core/include/LiveSupport/Core/FadeInfo.h @@ -0,0 +1,216 @@ +/*------------------------------------------------------------------------------ + + 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/modules/core/include/LiveSupport/Core/FadeInfo.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef LiveSupport_Core_FadeInfo_h +#define LiveSupport_Core_FadeInfo_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/UniqueId.h" +#include "LiveSupport/Core/Configurable.h" + + +namespace LiveSupport { +namespace Core { + +using namespace std; +using namespace boost::posix_time; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * A class representing fade in / fade out information of a playlist element. + * These are contained in a PlaylistElement, a list of which, in turn, is + * contained in a Playlist. + * + * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + */ +class FadeInfo : public Configurable +{ + private: + /** + * The name of the configuration XML elmenent used by FadeInfo. + */ + static const std::string configElementNameStr; + + /** + * The unique id of the fade info. + */ + Ptr::Ref id; + + /** + * The length of fade in period. + */ + Ptr::Ref fadeIn; + + /** + * The length of fade out period. + */ + Ptr::Ref fadeOut; + + + public: + /** + * Default constructor. + */ + FadeInfo(void) throw () + { + } + + /** + * Create a fade info instance by specifying all details. + * This is used for testing purposes. + * + * @param id the id of the fade info. + * @param fadeIn the length of the fade in period. + * @param fadeOut the length of the fade in period. + */ + FadeInfo(Ptr::Ref id, + Ptr::Ref fadeIn, + Ptr::Ref fadeOut) throw() + { + this->id = id; + this->fadeIn = fadeIn; + this->fadeOut = fadeOut; + } + + /** + * Create a fade info instance by specifying the fade in and fade out. + * + * @param fadeIn the length of the fade in period. + * @param fadeOut the length of the fade in period. + */ + FadeInfo(Ptr::Ref fadeIn, + Ptr::Ref fadeOut) throw() + { + this->id = UniqueId::generateId(); + this->fadeIn = fadeIn; + this->fadeOut = fadeOut; + } + + /** + * A virtual destructor, as this class has virtual functions. + */ + virtual + ~FadeInfo(void) throw () + { + } + + /** + * Return the name of the XML element this object expects + * to be sent to a call to configure(). + * + * @return the name of the expected XML configuration element. + */ + static const std::string + getConfigElementName(void) throw () + { + return configElementNameStr; + } + + /** + * Configure the object based on the XML element supplied. + * The supplied element is expected to be of the name + * returned by configElementName(). + * + * @param element the XML element to configure the object from. + * @exception std::invalid_argument if the supplied XML element + * contains bad configuraiton information + */ + virtual void + configure(const xmlpp::Element & element) + throw (std::invalid_argument); + + /** + * Return the id of the fade info instance. + * + * @return the unique id of the fade info instance. + */ + Ptr::Ref + getId(void) const throw () + { + return id; + } + + /** + * Return the length of the fade in period. + * + * @return the length of the fade in period, in microseconds. + */ + Ptr::Ref + getFadeIn(void) const throw () + { + return fadeIn; + } + + /** + * Return the length of the fade in period. + * + * @return the length of the fade in period, in microseconds. + */ + Ptr::Ref + getFadeOut(void) const throw () + { + return fadeOut; + } +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Core +} // namespace LiveSupport + +#endif // LiveSupport_Core_FadeInfo_h + diff --git a/livesupport/modules/core/include/LiveSupport/Core/Playlist.h b/livesupport/modules/core/include/LiveSupport/Core/Playlist.h index 6a9c218a6..37e82a887 100644 --- a/livesupport/modules/core/include/LiveSupport/Core/Playlist.h +++ b/livesupport/modules/core/include/LiveSupport/Core/Playlist.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.8 $ + Version : $Revision: 1.9 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Playlist.h,v $ ------------------------------------------------------------------------------*/ @@ -71,7 +71,7 @@ using namespace boost::posix_time; * the playlist. * * @author $Author: fgerlits $ - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ */ class Playlist : public Configurable { @@ -203,7 +203,7 @@ class Playlist : public Configurable /** * Return the total playing length for this playlist. * - * @return the playling length of this playlist, in milliseconds. + * @return the playling length of this playlist, in microseconds. */ Ptr::Ref getPlaylength(void) const throw () @@ -278,18 +278,50 @@ class Playlist : public Configurable return elementList->end(); } + /** + * Get an iterator pointing to a playlist element at a given + * relative offset. + * @param relativeOffset (a pointer to) the relative offset where + * the playlist element is. + * @return a constant iterator to the playlist element if it exists, + * or playlist->end() if it does not. + */ + const_iterator + find(Ptr::Ref relativeOffset) const + throw () + { + return elementList->find(*relativeOffset); + } + /** * Add a new audio clip to the playlist. * + * @param audioClip the new audio clip to be added * @param relativeOffset the start of the audio clip, relative * to the start of the playlist - * @param audioClip the new audio clip to be added + * @param fadeInfo the fade in / fade out info (optional) * @exception std::invalid_argument if the playlist already contains * an audio clip with the same relative offset */ void addAudioClip(Ptr::Ref audioClip, - Ptr::Ref relativeOffset) + Ptr::Ref relativeOffset, + Ptr::Ref fadeInfo + = Ptr::Ref()) + throw (std::invalid_argument); + + /** + * Set the fade in / fade out info for a playlist element. + * + * @param relativeOffset the start of the playlist element, relative + * to the start of the playlist + * @param fadeInfo the new fade in / fade out info + * @exception std::invalid_argument if there is no playlist element + * at the given relative offset + */ + void + setFadeInfo(Ptr::Ref relativeOffset, + Ptr::Ref fadeInfo) throw (std::invalid_argument); /** diff --git a/livesupport/modules/core/include/LiveSupport/Core/PlaylistElement.h b/livesupport/modules/core/include/LiveSupport/Core/PlaylistElement.h index d6f930894..ad8fd94b8 100644 --- a/livesupport/modules/core/include/LiveSupport/Core/PlaylistElement.h +++ b/livesupport/modules/core/include/LiveSupport/Core/PlaylistElement.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/PlaylistElement.h,v $ ------------------------------------------------------------------------------*/ @@ -50,6 +50,7 @@ #include "LiveSupport/Core/UniqueId.h" #include "LiveSupport/Core/Configurable.h" #include "LiveSupport/Core/AudioClip.h" +#include "LiveSupport/Core/FadeInfo.h" namespace LiveSupport { @@ -73,7 +74,7 @@ using namespace LiveSupport::Core; * An item in a playlist. * * @author $Author: fgerlits $ - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ class PlaylistElement : public Configurable { @@ -98,6 +99,11 @@ class PlaylistElement : public Configurable */ Ptr::Ref audioClip; + /** + * The fade in / fade out info associated with the entry. + */ + Ptr::Ref fadeInfo; + public: @@ -112,38 +118,44 @@ class PlaylistElement : public Configurable * Create a playlist element by specifying all details. * This is used for testing purposes. * - * @param id the id of the entry. - * @param audioClipId the ID of the audio clip associated - * with the playlist element. + * @param id the id of the entry. * @param relativeOffset the start time of this element, relative to * the start of the playlist. + * @param audioClip (a pointer to) the audio clip associated + * with the playlist element. */ PlaylistElement(Ptr::Ref id, Ptr::Ref relativeOffset, - Ptr::Ref audioClip) + Ptr::Ref audioClip, + Ptr::Ref fadeInfo + = Ptr::Ref()) throw () { this->id = id; this->relativeOffset = relativeOffset; this->audioClip = audioClip; + this->fadeInfo = fadeInfo; } /** * Create a new playlist element, with a new UniqueId, * to be added to a playlist. * - * @param audioClipId the ID of the audio clip associated - * with the playlist element. * @param relativeOffset the start time of this element, relative to * the start of the playlist. + * @param audioClip (a pointer to) the audio clip associated + * with the playlist element. */ PlaylistElement(Ptr::Ref relativeOffset, - Ptr::Ref audioClip) + Ptr::Ref audioClip, + Ptr::Ref fadeInfo + = Ptr::Ref()) throw () { this->id = UniqueId::generateId(); this->relativeOffset = relativeOffset; this->audioClip = audioClip; + this->fadeInfo = fadeInfo; } /** @@ -212,6 +224,28 @@ class PlaylistElement : public Configurable return audioClip; } + /** + * Set the fade info associated with the playlist element. + * + * @param fadeInfo the fade info to be associated with the element. + */ + void + setFadeInfo(Ptr::Ref fadeInfo) throw () + { + this->fadeInfo = fadeInfo; + } + + /** + * Return the fade info associated with the playlist element. + * + * @return the fade info associated with the element. + */ + Ptr::Ref + getFadeInfo(void) const throw () + { + return fadeInfo; + } + }; diff --git a/livesupport/modules/core/src/FadeInfo.cxx b/livesupport/modules/core/src/FadeInfo.cxx new file mode 100644 index 000000000..f1f0f874e --- /dev/null +++ b/livesupport/modules/core/src/FadeInfo.cxx @@ -0,0 +1,116 @@ +/*------------------------------------------------------------------------------ + + 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/modules/core/src/FadeInfo.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include + +#include "LiveSupport/Core/FadeInfo.h" + +using namespace boost::posix_time; + +using namespace LiveSupport::Core; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * The name of the config element for this class + *----------------------------------------------------------------------------*/ +const std::string FadeInfo::configElementNameStr = "fadeInfo"; + +/** + * The name of the attribute to get the id of the audio clip. + */ +static const std::string idAttrName = "id"; + +/** + * The name of the attribute to get the fade in. + */ +static const std::string fadeInAttrName = "fadeIn"; + +/** + * The name of the attribute to get the fade out. + */ +static const std::string fadeOutAttrName = "fadeOut"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Create a fade info object based on an XML element. + *----------------------------------------------------------------------------*/ +void +FadeInfo :: configure(const xmlpp::Element & element) + throw (std::invalid_argument) +{ + if (element.get_name() != configElementNameStr) { + std::string eMsg = "bad configuration element "; + eMsg += element.get_name(); + throw std::invalid_argument(eMsg); + } + + const xmlpp::Attribute * attribute; + std::stringstream strStr; + unsigned long int idValue; + + if (!(attribute = element.get_attribute(idAttrName))) { + std::string eMsg = "missing attribute "; + eMsg += idAttrName; + throw std::invalid_argument(eMsg); + } + strStr.str(attribute->get_value()); + strStr >> idValue; + id.reset(new UniqueId(idValue)); + + if (!(attribute = element.get_attribute(fadeInAttrName))) { + std::string eMsg = "missing attribute "; + eMsg += idAttrName; + throw std::invalid_argument(eMsg); + } + fadeIn.reset(new time_duration( + duration_from_string(attribute->get_value()))); + + if (!(attribute = element.get_attribute(fadeOutAttrName))) { + std::string eMsg = "missing attribute "; + eMsg += idAttrName; + throw std::invalid_argument(eMsg); + } + fadeOut.reset(new time_duration( + duration_from_string(attribute->get_value()))); +} diff --git a/livesupport/modules/core/src/FadeInfoTest.cxx b/livesupport/modules/core/src/FadeInfoTest.cxx new file mode 100644 index 000000000..165896cff --- /dev/null +++ b/livesupport/modules/core/src/FadeInfoTest.cxx @@ -0,0 +1,129 @@ +/*------------------------------------------------------------------------------ + + 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/modules/core/src/FadeInfoTest.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 "LiveSupport/Core/FadeInfo.h" +#include "FadeInfoTest.h" + + +using namespace std; +using namespace LiveSupport::Core; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +CPPUNIT_TEST_SUITE_REGISTRATION(FadeInfoTest); + +/** + * The name of the configuration file for the audio clip. + */ +static const std::string configFileName = "etc/fadeInfo.xml"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Set up the test environment + *----------------------------------------------------------------------------*/ +void +FadeInfoTest :: setUp(void) throw () +{ +} + + +/*------------------------------------------------------------------------------ + * Clean up the test environment + *----------------------------------------------------------------------------*/ +void +FadeInfoTest :: tearDown(void) throw () +{ +} + + +/*------------------------------------------------------------------------------ + * Test to see if the singleton Hello object is accessible + *----------------------------------------------------------------------------*/ +void +FadeInfoTest :: firstTest(void) + throw (CPPUNIT_NS::Exception) +{ + try { + Ptr::Ref parser( + new xmlpp::DomParser(configFileName, true)); + const xmlpp::Document * document = parser->get_document(); + const xmlpp::Element * root = document->get_root_node(); + Ptr::Ref fadeInfo(new FadeInfo()); + + fadeInfo->configure(*root); + + CPPUNIT_ASSERT(fadeInfo->getId()->getId() == 9901); + + Ptr::Ref + fadeIn = fadeInfo->getFadeIn(); + CPPUNIT_ASSERT(fadeIn->hours() == 0); + CPPUNIT_ASSERT(fadeIn->minutes() == 0); + CPPUNIT_ASSERT(fadeIn->seconds() == 2); + + Ptr::Ref + fadeOut = fadeInfo->getFadeOut(); + CPPUNIT_ASSERT(fadeOut->hours() == 0); + CPPUNIT_ASSERT(fadeOut->minutes() == 0); + CPPUNIT_ASSERT(fadeOut->seconds() == 1); + CPPUNIT_ASSERT(fadeOut->fractional_seconds() == 500); + + } catch (std::invalid_argument &e) { + std::string eMsg = "semantic error in configuration file:\n"; + eMsg += e.what(); + CPPUNIT_FAIL(eMsg); + } catch (xmlpp::exception &e) { + std::string eMsg = "error parsing configuration file:\n"; + eMsg += e.what(); + CPPUNIT_FAIL(eMsg); + } +} diff --git a/livesupport/modules/core/src/FadeInfoTest.h b/livesupport/modules/core/src/FadeInfoTest.h new file mode 100644 index 000000000..af5879190 --- /dev/null +++ b/livesupport/modules/core/src/FadeInfoTest.h @@ -0,0 +1,107 @@ +/*------------------------------------------------------------------------------ + + 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/modules/core/src/FadeInfoTest.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef FadeInfoTest_h +#define FadeInfoTest_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 Core { + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * Unit test for the FadeInfo class. + * + * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + * @see FadeInfo + */ +class FadeInfoTest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(FadeInfoTest); + CPPUNIT_TEST(firstTest); + CPPUNIT_TEST_SUITE_END(); + + 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 Core +} // namespace LiveSupport + +#endif // FadeInfoTest_h + diff --git a/livesupport/modules/core/src/Playlist.cxx b/livesupport/modules/core/src/Playlist.cxx index c0be4a50f..8eb9dd461 100644 --- a/livesupport/modules/core/src/Playlist.cxx +++ b/livesupport/modules/core/src/Playlist.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.7 $ + Version : $Revision: 1.8 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/Playlist.cxx,v $ ------------------------------------------------------------------------------*/ @@ -149,7 +149,8 @@ Playlist::addPlaylistElement(Ptr::Ref playlistElement) *----------------------------------------------------------------------------*/ void Playlist::addAudioClip(Ptr::Ref audioClip, - Ptr::Ref relativeOffset) + Ptr::Ref relativeOffset, + Ptr::Ref fadeInfo) throw (std::invalid_argument) { if (elementList->find(*relativeOffset) != elementList->end()) { @@ -158,12 +159,31 @@ Playlist::addAudioClip(Ptr::Ref audioClip, } Ptr::Ref playlistElement(new PlaylistElement( - relativeOffset, audioClip)); + relativeOffset, audioClip, fadeInfo)); (*elementList)[*relativeOffset] = playlistElement; } +/*------------------------------------------------------------------------------ + * Change the fade in / fade out info of a playlist element. + *----------------------------------------------------------------------------*/ +void +Playlist::setFadeInfo(Ptr::Ref relativeOffset, + Ptr::Ref fadeInfo) + throw (std::invalid_argument) +{ + PlaylistElementListType::iterator it = elementList->find(*relativeOffset); + + if (it == elementList->end()) { + std::string eMsg = "no audio clip at this relative offset"; + throw std::invalid_argument(eMsg); + } + + it->second->setFadeInfo(fadeInfo); +} + + /*------------------------------------------------------------------------------ * Remove an audio clip from the playlist. *----------------------------------------------------------------------------*/ diff --git a/livesupport/modules/core/src/PlaylistElement.cxx b/livesupport/modules/core/src/PlaylistElement.cxx index c5baf03d1..e44831b67 100644 --- a/livesupport/modules/core/src/PlaylistElement.cxx +++ b/livesupport/modules/core/src/PlaylistElement.cxx @@ -20,9 +20,9 @@ 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.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistElement.cxx,v $ ------------------------------------------------------------------------------*/ @@ -35,7 +35,6 @@ #include -#include "LiveSupport/Core/UniqueId.h" #include "LiveSupport/Core/PlaylistElement.h" using namespace boost::posix_time; @@ -63,10 +62,15 @@ static const std::string idAttrName = "id"; static const std::string relativeOffsetAttrName = "relativeOffset"; /** - * The name of the (audio clip) child element of the playlist element. + * The name of the audio clip child element of the playlist element. */ static const std::string audioClipElementName = "audioClip"; +/** + * The name of the fade info child element of the playlist element. + */ +static const std::string fadeInfoElementName = "fadeInfo"; + /* =============================================== local function prototypes */ @@ -86,6 +90,7 @@ PlaylistElement :: configure(const xmlpp::Element & element) throw std::invalid_argument(eMsg); } + // set id const xmlpp::Attribute * attribute; std::stringstream strStr; UniqueId::IdType idValue; @@ -99,6 +104,7 @@ PlaylistElement :: configure(const xmlpp::Element & element) strStr >> idValue; id.reset(new UniqueId(idValue)); + // set relative offset if (!(attribute = element.get_attribute(relativeOffsetAttrName))) { std::string eMsg = "missing attribute "; eMsg += relativeOffsetAttrName; @@ -107,6 +113,7 @@ PlaylistElement :: configure(const xmlpp::Element & element) relativeOffset.reset(new time_duration( duration_from_string(attribute->get_value()))); + // set audio clip xmlpp::Node::NodeList childNodes = element.get_children(audioClipElementName); xmlpp::Node::NodeList::iterator it = childNodes.begin(); @@ -121,7 +128,7 @@ PlaylistElement :: configure(const xmlpp::Element & element) const xmlpp::Element * audioClipElement = dynamic_cast (*it); audioClip.reset(new AudioClip); - audioClip->configure(*audioClipElement); // may throw exception + audioClip->configure(*audioClipElement); // may throw exception ++it; if (it != childNodes.end()) { @@ -130,4 +137,25 @@ PlaylistElement :: configure(const xmlpp::Element & element) eMsg += " XML element"; throw std::invalid_argument(eMsg); } + + // set fade info + childNodes = element.get_children(fadeInfoElementName); + it = childNodes.begin(); + + if (it == childNodes.end()) { // no fade info is OK + return; + } + + const xmlpp::Element * fadeInfoElement + = dynamic_cast (*it); + fadeInfo.reset(new FadeInfo); + fadeInfo->configure(*fadeInfoElement); // may throw exception + + ++it; + if (it != childNodes.end()) { + std::string eMsg = "more than one "; + eMsg += fadeInfoElementName; + eMsg += " XML element"; + throw std::invalid_argument(eMsg); + } } diff --git a/livesupport/modules/core/src/PlaylistElementTest.cxx b/livesupport/modules/core/src/PlaylistElementTest.cxx index e104c0fa0..c060a873f 100644 --- a/livesupport/modules/core/src/PlaylistElementTest.cxx +++ b/livesupport/modules/core/src/PlaylistElementTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistElementTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -111,6 +111,17 @@ PlaylistElementTest :: firstTest(void) CPPUNIT_ASSERT(relativeOffset->total_seconds() == 12*60 + 34); CPPUNIT_ASSERT(playlistElement->getAudioClip()->getId()->getId() == 10001); + CPPUNIT_ASSERT(playlistElement->getFadeInfo()->getId()->getId() + == 9901); + Ptr::Ref fadeIn + = playlistElement->getFadeInfo() + ->getFadeIn(); + CPPUNIT_ASSERT(fadeIn->total_milliseconds() == 2000); + + Ptr::Ref fadeOut + = playlistElement->getFadeInfo() + ->getFadeOut(); + CPPUNIT_ASSERT(fadeOut->total_milliseconds() == 1500); } catch (std::invalid_argument &e) { std::string eMsg = "semantic error in configuration file:\n"; diff --git a/livesupport/modules/core/src/PlaylistTest.cxx b/livesupport/modules/core/src/PlaylistTest.cxx index 7faeb63b2..7f041771d 100644 --- a/livesupport/modules/core/src/PlaylistTest.cxx +++ b/livesupport/modules/core/src/PlaylistTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.8 $ + Version : $Revision: 1.9 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -285,3 +285,72 @@ PlaylistTest :: savedCopyTest(void) catch (std::logic_error &e) { } } + + +/*------------------------------------------------------------------------------ + * Test to see if we can add a fade info + *----------------------------------------------------------------------------*/ +void +PlaylistTest :: fadeInfoTest(void) + throw (CPPUNIT_NS::Exception) +{ + Playlist::const_iterator it = playlist->begin(); + CPPUNIT_ASSERT(it != playlist->end()); + Ptr::Ref playlistElement = it->second; + CPPUNIT_ASSERT(playlistElement->getFadeInfo().get() == 0); + + ++it; + CPPUNIT_ASSERT(it != playlist->end()); + playlistElement = it->second; + CPPUNIT_ASSERT(playlistElement->getFadeInfo()->getFadeIn() + ->total_milliseconds() == 2000); + CPPUNIT_ASSERT(playlistElement->getFadeInfo()->getFadeOut() + ->total_milliseconds() == 1500); + + ++it; + CPPUNIT_ASSERT(it == playlist->end()); + + Ptr::Ref relativeOffset (new time_duration(0,0,0,0)); + Ptr::Ref fadeIn (new time_duration(0,0,3,200000)); + Ptr::Ref fadeOut(new time_duration(0,0,4,0)); + Ptr::Ref fadeInfo(new FadeInfo(fadeIn, fadeOut)); + + try { + playlist->setFadeInfo(relativeOffset, fadeInfo); + } + catch (std::invalid_argument &e) { + CPPUNIT_FAIL("could not add new fade info"); + } + + it = playlist->begin(); + playlistElement = it->second; + CPPUNIT_ASSERT(playlistElement->getFadeInfo()->getFadeIn() + ->total_milliseconds() == 3200); + CPPUNIT_ASSERT(playlistElement->getFadeInfo()->getFadeOut() + ->total_milliseconds() == 4000); + + relativeOffset.reset(new time_duration(1,00,0,0)); + + try { + playlist->setFadeInfo(relativeOffset, fadeInfo); + } + catch (std::invalid_argument &e) { + CPPUNIT_FAIL("could not update fade info"); + } + + ++it; + playlistElement = it->second; + CPPUNIT_ASSERT(playlistElement->getFadeInfo()->getFadeIn() + ->total_milliseconds() == 3200); + CPPUNIT_ASSERT(playlistElement->getFadeInfo()->getFadeOut() + ->total_milliseconds() == 4000); + + relativeOffset.reset(new time_duration(0,18,0,0)); + + try { + playlist->setFadeInfo(relativeOffset, fadeInfo); + CPPUNIT_FAIL("allowed to set fade info for non-existent element"); + } + catch (std::invalid_argument &e) { + } +} diff --git a/livesupport/modules/core/src/PlaylistTest.h b/livesupport/modules/core/src/PlaylistTest.h index cec04972e..faef90865 100644 --- a/livesupport/modules/core/src/PlaylistTest.h +++ b/livesupport/modules/core/src/PlaylistTest.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/core/src/PlaylistTest.h,v $ ------------------------------------------------------------------------------*/ @@ -58,7 +58,7 @@ namespace Core { * Unit test for the UploadPlaylistMetohd class. * * @author $Author: fgerlits $ - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * @see Playlist */ class PlaylistTest : public CPPUNIT_NS::TestFixture @@ -68,6 +68,7 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(lockTest); CPPUNIT_TEST(audioClipTest); CPPUNIT_TEST(savedCopyTest); + CPPUNIT_TEST(fadeInfoTest); CPPUNIT_TEST_SUITE_END(); private: @@ -111,6 +112,14 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture void savedCopyTest(void) throw (CPPUNIT_NS::Exception); + /** + * Trying to add a new fade info. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + fadeInfoTest(void) throw (CPPUNIT_NS::Exception); + public: diff --git a/livesupport/products/scheduler/etc/Makefile.in b/livesupport/products/scheduler/etc/Makefile.in index 122c958bb..8980fe893 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.19 $ +# Version : $Revision: 1.20 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/etc/Makefile.in,v $ # # @configure_input@ @@ -132,7 +132,8 @@ SCHEDULER_OBJS = ${TMP_DIR}/SignalDispatcher.o \ ${TMP_DIR}/SavePlaylistMethod.o \ ${TMP_DIR}/PlayLogFactory.o \ ${TMP_DIR}/PostgresqlPlayLog.o \ - ${TMP_DIR}/GeneratePlayReportMethod.o + ${TMP_DIR}/GeneratePlayReportMethod.o \ + ${TMP_DIR}/UpdateFadeInFadeOutMethod.o SCHEDULER_EXE_OBJS = ${SCHEDULER_OBJS} \ @@ -168,6 +169,7 @@ TEST_RUNNER_OBJS = ${SCHEDULER_OBJS} \ ${TMP_DIR}/RevertEditedPlaylistMethodTest.o \ ${TMP_DIR}/PostgresqlPlayLogTest.o \ ${TMP_DIR}/GeneratePlayReportMethodTest.o \ + ${TMP_DIR}/UpdateFadeInFadeOutMethodTest.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 8bbb1f816..a3f707b97 100644 --- a/livesupport/products/scheduler/etc/storageClient.xml +++ b/livesupport/products/scheduler/etc/storageClient.xml @@ -9,13 +9,18 @@ - + + + + + + ]> @@ -25,6 +30,8 @@ + diff --git a/livesupport/products/scheduler/src/GeneratePlayReportMethod.cxx b/livesupport/products/scheduler/src/GeneratePlayReportMethod.cxx index c30297146..81602563a 100644 --- a/livesupport/products/scheduler/src/GeneratePlayReportMethod.cxx +++ b/livesupport/products/scheduler/src/GeneratePlayReportMethod.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/GeneratePlayReportMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -126,7 +126,7 @@ GeneratePlayReportMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, Ptr::Ref plf = PlayLogFactory::getInstance(); Ptr::Ref playLog = plf->getPlayLog(); - Ptr::Ref> >::Ref playLogVector + Ptr::Ref> >::Ref playLogVector = playLog->getPlayLogEntries(fromTime, toTime); XmlRpcTools::playLogVectorToXmlRpcValue(playLogVector, returnValue); diff --git a/livesupport/products/scheduler/src/UpdateFadeInFadeOutMethod.cxx b/livesupport/products/scheduler/src/UpdateFadeInFadeOutMethod.cxx new file mode 100644 index 000000000..a9011a6f1 --- /dev/null +++ b/livesupport/products/scheduler/src/UpdateFadeInFadeOutMethod.cxx @@ -0,0 +1,190 @@ +/*------------------------------------------------------------------------------ + + 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/UpdateFadeInFadeOutMethod.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 "LiveSupport/Core/Playlist.h" +#include "LiveSupport/Core/FadeInfo.h" +#include "ScheduleInterface.h" +#include "ScheduleFactory.h" +#include "XmlRpcTools.h" + +#include "UpdateFadeInFadeOutMethod.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 UpdateFadeInFadeOutMethod::methodName + = "updateFadeInFadeOut"; + +/*------------------------------------------------------------------------------ + * The ID of this method for error reporting purposes. + *----------------------------------------------------------------------------*/ +const int UpdateFadeInFadeOutMethod::errorId = 1600; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Construct the method and register it right away. + *----------------------------------------------------------------------------*/ +UpdateFadeInFadeOutMethod :: UpdateFadeInFadeOutMethod ( + Ptr::Ref xmlRpcServer) throw() + : XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get()) +{ +} + + +/*------------------------------------------------------------------------------ + * Execute the stop XML-RPC function call. + *----------------------------------------------------------------------------*/ +void +UpdateFadeInFadeOutMethod :: execute( + XmlRpc::XmlRpcValue & rootParameter, + XmlRpc::XmlRpcValue & returnValue) + throw () +{ + if (!rootParameter.valid() || rootParameter.size() != 1) { + XmlRpcTools::markError(errorId+1, "invalid argument format", + returnValue); + return; + } + XmlRpc::XmlRpcValue parameters = rootParameter[0]; + + Ptr::Ref playlistId; + try{ + playlistId = XmlRpcTools::extractPlaylistId(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+2, + "missing playlist ID argument", + returnValue); + return; + } + + Ptr::Ref relativeOffset; + try{ + relativeOffset = XmlRpcTools::extractRelativeOffset(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+3, + "missing relative offset argument", + returnValue); + return; + } + + Ptr::Ref fadeIn; + try{ + fadeIn = XmlRpcTools::extractFadeIn(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+4, + "missing fade in argument", + returnValue); + return; + } + + Ptr::Ref fadeOut; + try{ + fadeOut = XmlRpcTools::extractFadeOut(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+5, + "missing fade out argument", + returnValue); + return; + } + + Ptr::Ref scf; + Ptr::Ref storage; + scf = StorageClientFactory::getInstance(); + storage = scf->getStorageClient(); + + Ptr::Ref playlist; + try { + playlist = storage->getPlaylist(playlistId); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+6, "playlist does not exist", + returnValue); + return; + } + + if (!playlist->canBeEdited()) { + XmlRpcTools::markError(errorId+7, + "playlist has not been opened for editing", + returnValue); + return; + } + + Ptr::Ref fadeInfo(new FadeInfo(fadeIn, fadeOut)); + try { // and finally, the beef + playlist->setFadeInfo(relativeOffset, fadeInfo); + } + catch(std::invalid_argument &e) { + XmlRpcTools::markError(errorId+8, + "no audio clip at the specified " + "relative offset", + returnValue); + return; + } +} diff --git a/livesupport/products/scheduler/src/UpdateFadeInFadeOutMethod.h b/livesupport/products/scheduler/src/UpdateFadeInFadeOutMethod.h new file mode 100644 index 000000000..9d04522ba --- /dev/null +++ b/livesupport/products/scheduler/src/UpdateFadeInFadeOutMethod.h @@ -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/UpdateFadeInFadeOutMethod.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef UpdateFadeInFadeOutMethod_h +#define UpdateFadeInFadeOutMethod_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" + + +namespace LiveSupport { +namespace Scheduler { + +using namespace LiveSupport; +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * An XML-RPC method object to change the fade in / fade out info of an + * audio clip (specified by its relative offset) from a playlist (specified + * by its ID). + * + * The name of the method when called through XML-RPC is + * "updateFadeInFadeOut". + * The expected parameter is an XML-RPC structure, with the following + * members: + *
    + *
  • playlistId - int - the unique id of the playlist.
  • + *
  • relativeOffset - int - the number of seconds between the + * start of the playlist and the start of the audio clip + * to be removed.
  • + *
  • fadeIn - int - the length (in milliseconds) of the fade in.
  • + *
  • fadeOut - int - the length (in milliseconds) of the fade out.
  • + *
+ * + * In case of an error, an XML-RPC structure is returned, with the following + * fields: + *
    + *
  • errorCode - int - the id of the error condition
  • + *
  • errorMessage - string - a description of the error
  • + *
+ * The possible error codes are: + *
    + *
  • 1601 - invalid argument format
  • + *
  • 1602 - missing playlist ID argument
  • + *
  • 1603 - missing relative offset argument
  • + *
  • 1604 - missing fade in argument
  • + *
  • 1605 - missing fade out argument
  • + *
  • 1606 - playlist does not exist
  • + *
  • 1607 - playlist has not been opened for editing
  • + *
  • 1608 - no audio clip at the specified relative offset
  • + *
+ * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + */ +class UpdateFadeInFadeOutMethod : 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. + */ + UpdateFadeInFadeOutMethod(void) throw () + : XmlRpc::XmlRpcServerMethod(methodName) + { + } + + /** + * Constuctor that registers the method with the server right away. + * + * @param xmlRpcServer the XML-RPC server to register with. + */ + UpdateFadeInFadeOutMethod( + 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 // UpdateFadeInFadeOutMethod_h + diff --git a/livesupport/products/scheduler/src/UpdateFadeInFadeOutMethodTest.cxx b/livesupport/products/scheduler/src/UpdateFadeInFadeOutMethodTest.cxx new file mode 100644 index 000000000..659677b73 --- /dev/null +++ b/livesupport/products/scheduler/src/UpdateFadeInFadeOutMethodTest.cxx @@ -0,0 +1,189 @@ +/*------------------------------------------------------------------------------ + + 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/UpdateFadeInFadeOutMethodTest.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 "XmlRpcTools.h" + +#include "OpenPlaylistForEditingMethod.h" +#include "AddAudioClipToPlaylistMethod.h" +#include "UpdateFadeInFadeOutMethod.h" + +#include "UpdateFadeInFadeOutMethodTest.h" + + +using namespace std; +using namespace LiveSupport::Db; +using namespace LiveSupport::Storage; +using namespace LiveSupport::Scheduler; + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +CPPUNIT_TEST_SUITE_REGISTRATION(UpdateFadeInFadeOutMethodTest); + +/** + * The name of the configuration file for the storage client factory. + */ +const std::string UpdateFadeInFadeOutMethodTest::storageClientConfig = + "etc/storageClient.xml"; + +/** + * The name of the configuration file for the connection manager factory. + */ +const std::string UpdateFadeInFadeOutMethodTest::connectionManagerConfig = + "etc/connectionManagerFactory.xml"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Configure a Configurable with an XML file. + *----------------------------------------------------------------------------*/ +void +UpdateFadeInFadeOutMethodTest :: 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 +UpdateFadeInFadeOutMethodTest :: 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 +UpdateFadeInFadeOutMethodTest :: tearDown(void) throw () +{ +} + + +/*------------------------------------------------------------------------------ + * Just a very simple smoke test + *----------------------------------------------------------------------------*/ +void +UpdateFadeInFadeOutMethodTest :: firstTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::Ref + openPlaylistMethod(new OpenPlaylistForEditingMethod()); + Ptr::Ref + updateFadeMethod(new UpdateFadeInFadeOutMethod()); + XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); + XmlRpc::XmlRpcValue result; + + parameters["playlistId"] = 1; + parameters["relativeOffset"] = 90*60; + parameters["fadeIn"] = 0; + rootParameter[0] = parameters; + + result.clear(); + updateFadeMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(result.hasMember("errorCode")); + CPPUNIT_ASSERT((int)(result["errorCode"]) == 1605); // missing fade out + + parameters["fadeOut"] = 2100; + rootParameter[0] = parameters; + + result.clear(); + updateFadeMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(result.hasMember("errorCode")); + CPPUNIT_ASSERT((int)(result["errorCode"]) == 1607); // not open for editing + + result.clear(); + openPlaylistMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); + result.clear(); + updateFadeMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(result.hasMember("errorCode")); + CPPUNIT_ASSERT((int)(result["errorCode"]) == 1608); // no audio clip at + // this rel offset + parameters["relativeOffset"] = 0; + rootParameter[0] = parameters; + + result.clear(); + updateFadeMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); +} diff --git a/livesupport/products/scheduler/src/UpdateFadeInFadeOutMethodTest.h b/livesupport/products/scheduler/src/UpdateFadeInFadeOutMethodTest.h new file mode 100644 index 000000000..c50217638 --- /dev/null +++ b/livesupport/products/scheduler/src/UpdateFadeInFadeOutMethodTest.h @@ -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/UpdateFadeInFadeOutMethodTest.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef UpdateFadeInFadeOutMethodTest_h +#define UpdateFadeInFadeOutMethodTest_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 UpdateFadeInFadeOutMethod class. + * + * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + * @see UpdateFadeInFadeOutMethod + */ +class UpdateFadeInFadeOutMethodTest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(UpdateFadeInFadeOutMethodTest); + 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 // UpdateFadeInFadeOutMethodTest_h + diff --git a/livesupport/products/scheduler/src/XmlRpcTools.cxx b/livesupport/products/scheduler/src/XmlRpcTools.cxx index 30c471f01..6b9e8f699 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.8 $ + Version : $Revision: 1.9 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcTools.cxx,v $ ------------------------------------------------------------------------------*/ @@ -95,6 +95,18 @@ const std::string XmlRpcTools::scheduleEntryIdName = *----------------------------------------------------------------------------*/ const std::string XmlRpcTools::playtimeName = "playtime"; +/*------------------------------------------------------------------------------ + * The name of the fade in member in the XML-RPC parameter + * structure. + *----------------------------------------------------------------------------*/ +const std::string XmlRpcTools::fadeInName = "fadeIn"; + +/*------------------------------------------------------------------------------ + * The name of the fade out member in the XML-RPC parameter + * structure. + *----------------------------------------------------------------------------*/ +const std::string XmlRpcTools::fadeOutName = "fadeOut"; + /* ================================================ local constants & macros */ @@ -402,6 +414,40 @@ XmlRpcTools :: extractPlayschedule( } +/*------------------------------------------------------------------------------ + * Extract the fade in time from an XML-RPC function call parameter + *----------------------------------------------------------------------------*/ +Ptr::Ref +XmlRpcTools :: extractFadeIn(XmlRpc::XmlRpcValue & xmlRpcValue) + throw (std::invalid_argument) +{ + if (!xmlRpcValue.hasMember(fadeInName)) { + throw std::invalid_argument("missing fade in argument"); + } + + Ptr::Ref fadeIn(new time_duration(0,0, + (int) xmlRpcValue[fadeInName], 0)); + return fadeIn; +} + + +/*------------------------------------------------------------------------------ + * Extract the fade out time from an XML-RPC function call parameter + *----------------------------------------------------------------------------*/ +Ptr::Ref +XmlRpcTools :: extractFadeOut(XmlRpc::XmlRpcValue & xmlRpcValue) + throw (std::invalid_argument) +{ + if (!xmlRpcValue.hasMember(fadeOutName)) { + throw std::invalid_argument("missing fade out argument"); + } + + Ptr::Ref fadeOut(new time_duration(0,0, + (int) xmlRpcValue[fadeOutName], 0)); + return fadeOut; +} + + /*------------------------------------------------------------------------------ * Convert a schedule entry ID (a UniqueId) to an XmlRpcValue *----------------------------------------------------------------------------*/ @@ -438,7 +484,7 @@ XmlRpcTools :: playLogEntryToXmlRpcValue( *----------------------------------------------------------------------------*/ void XmlRpcTools :: playLogVectorToXmlRpcValue( - Ptr::Ref> >::Ref + Ptr::Ref> >::Ref playLogVector, XmlRpc::XmlRpcValue & returnValue) throw () @@ -447,11 +493,11 @@ XmlRpcTools :: playLogVectorToXmlRpcValue( // a call to setSize() makes sure it's an XML-RPC // array - std::vector::Ref>::const_iterator it = + std::vector::Ref>::const_iterator it = playLogVector->begin(); int arraySize = 0; while (it != playLogVector->end()) { - Ptr::Ref playLog = *it; + Ptr::Ref playLog = *it; XmlRpc::XmlRpcValue returnStruct; playLogEntryToXmlRpcValue(playLog, returnStruct); returnValue[arraySize++] = returnStruct; diff --git a/livesupport/products/scheduler/src/XmlRpcTools.h b/livesupport/products/scheduler/src/XmlRpcTools.h index 538946acb..1b92a2925 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.8 $ + Version : $Revision: 1.9 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcTools.h,v $ ------------------------------------------------------------------------------*/ @@ -72,7 +72,7 @@ using namespace LiveSupport::Core; * in the Scheduler. * * @author $Author: fgerlits $ - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ */ class XmlRpcTools { @@ -119,6 +119,18 @@ class XmlRpcTools */ static const std::string playtimeName; + /** + * The name of the fade in member in the XML-RPC parameter + * structure. + */ + static const std::string fadeInName; + + /** + * The name of the fade out member in the XML-RPC parameter + * structure. + */ + static const std::string fadeOutName; + /** * Convert a boost::posix_time::ptime to an XmlRpcValue * @@ -303,6 +315,30 @@ class XmlRpcTools extractPlayschedule(XmlRpc::XmlRpcValue & xmlRpcValue) throw (std::invalid_argument); + /** + * Extract the fade in time from the XML-RPC parameters. + * + * @param xmlRpcValue the XML-RPC parameter to extract from. + * @return a time_duration that was found in the XML-RPC parameter. + * @exception std::invalid_argument if there was no fadeIn + * member in xmlRpcValue + */ + static Ptr::Ref + extractFadeIn(XmlRpc::XmlRpcValue & xmlRpcValue) + throw (std::invalid_argument); + + /** + * Extract the fade out time from the XML-RPC parameters. + * + * @param xmlRpcValue the XML-RPC parameter to extract from. + * @return a time_duration that was found in the XML-RPC parameter. + * @exception std::invalid_argument if there was no fadeOut + * member in xmlRpcValue + */ + static Ptr::Ref + extractFadeOut(XmlRpc::XmlRpcValue & xmlRpcValue) + throw (std::invalid_argument); + /** * Convert a vector of ScheduleEntries to an XML-RPC return value. * @@ -337,7 +373,7 @@ class XmlRpcTools */ static void playLogVectorToXmlRpcValue( - Ptr::Ref> >::Ref + Ptr::Ref> >::Ref playLogVector, XmlRpc::XmlRpcValue & returnValue) throw ();