diff --git a/livesupport/modules/core/etc/Makefile.in b/livesupport/modules/core/etc/Makefile.in index d27c18fef..6120e1446 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.7 $ +# Version : $Revision: 1.8 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/etc/Makefile.in,v $ # # @configure_input@ @@ -85,10 +85,12 @@ LDFLAGS = @LDFLAGS@ -L${USR_LIB_DIR} -L${LIB_DIR} # Dependencies #------------------------------------------------------------------------------- CORE_LIB_OBJS = ${TMP_DIR}/UniqueId.o \ + ${TMP_DIR}/AudioClip.o \ ${TMP_DIR}/PlaylistElement.o \ ${TMP_DIR}/Playlist.o -TEST_RUNNER_OBJS = ${TMP_DIR}/PlaylistElementTest.o \ +TEST_RUNNER_OBJS = ${TMP_DIR}/AudioClipTest.o \ + ${TMP_DIR}/PlaylistElementTest.o \ ${TMP_DIR}/PlaylistTest.o \ ${TMP_DIR}/TestRunner.o diff --git a/livesupport/modules/core/src/AudioClip.cxx b/livesupport/modules/core/src/AudioClip.cxx index 4c03f2621..48b18d261 100644 --- a/livesupport/modules/core/src/AudioClip.cxx +++ b/livesupport/modules/core/src/AudioClip.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/AudioClip.cxx,v $ ------------------------------------------------------------------------------*/ @@ -75,9 +75,8 @@ static const std::string playlengthAttrName = "playlength"; * Create an audio clip object based on an XML element. *----------------------------------------------------------------------------*/ void -AudioClip :: configure(const xmlpp::Element & element) - throw (std::logic_error, - std::invalid_argument) +AudioClip :: configure(const xmlpp::Element & element) + throw (std::invalid_argument) { if (element.get_name() != configElementNameStr) { std::string eMsg = "bad configuration element "; diff --git a/livesupport/products/scheduler/doc/model/SchedulerModel.zuml b/livesupport/products/scheduler/doc/model/SchedulerModel.zuml index add36b57c..00c7d4ed9 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 367b1cce0..8441b199f 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.16 $ +# Version : $Revision: 1.17 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/etc/Makefile.in,v $ # # @configure_input@ @@ -129,7 +129,8 @@ SCHEDULER_OBJS = ${TMP_DIR}/SignalDispatcher.o \ ${TMP_DIR}/DisplayAudioClipMethod.o \ ${TMP_DIR}/DisplayAudioClipsMethod.o \ ${TMP_DIR}/RevertEditedPlaylistMethod.o \ - ${TMP_DIR}/SavePlaylistMethod.o + ${TMP_DIR}/SavePlaylistMethod.o \ + ${TMP_DIR}/PlayLogEntry.o SCHEDULER_EXE_OBJS = ${SCHEDULER_OBJS} \ ${TMP_DIR}/main.o @@ -162,6 +163,7 @@ TEST_RUNNER_OBJS = ${SCHEDULER_OBJS} \ ${TMP_DIR}/DisplayAudioClipsMethodTest.o \ ${TMP_DIR}/SavePlaylistMethodTest.o \ ${TMP_DIR}/RevertEditedPlaylistMethodTest.o \ + ${TMP_DIR}/PlayLogEntryTest.o \ ${TMP_DIR}/TestRunner.o TEST_RUNNER_LIBS = ${SCHEDULER_EXE_LIBS} -lcppunit -ldl diff --git a/livesupport/products/scheduler/etc/playLogEntry.xml b/livesupport/products/scheduler/etc/playLogEntry.xml new file mode 100644 index 000000000..c6355e782 --- /dev/null +++ b/livesupport/products/scheduler/etc/playLogEntry.xml @@ -0,0 +1,9 @@ + + + + + +]> + diff --git a/livesupport/products/scheduler/src/PlayLogEntry.cxx b/livesupport/products/scheduler/src/PlayLogEntry.cxx new file mode 100644 index 000000000..d91d4bf7e --- /dev/null +++ b/livesupport/products/scheduler/src/PlayLogEntry.cxx @@ -0,0 +1,119 @@ +/*------------------------------------------------------------------------------ + + 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/Attic/PlayLogEntry.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include + +#include "PlayLogEntry.h" + +using namespace boost::posix_time; +using namespace LiveSupport::Core; +using namespace LiveSupport::Scheduler; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * The name of the config element for this class + *----------------------------------------------------------------------------*/ +const std::string PlayLogEntry::configElementNameStr = "playLogEntry"; + +/** + * 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 ID of the audio clip logged. + */ +static const std::string audioClipIdAttrName = "audioClipId"; + +/** + * The name of the attribute to get the time the audio clip was played. + */ +static const std::string timeStampAttrName = "timeStamp"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Create a play log entry object based on an XML element. + *----------------------------------------------------------------------------*/ +void +PlayLogEntry :: 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 idStrStream; + unsigned long int idValue; + + if (!(attribute = element.get_attribute(idAttrName))) { + std::string eMsg = "missing attribute "; + eMsg += idAttrName; + throw std::invalid_argument(eMsg); + } + idStrStream.str(attribute->get_value()); + idStrStream >> idValue; + id.reset(new UniqueId(idValue)); + + std::stringstream audioClipIdStrStream; + unsigned long int audioClipIdValue; + + if (!(attribute = element.get_attribute(audioClipIdAttrName))) { + std::string eMsg = "Missing attribute "; + eMsg += audioClipIdAttrName; + throw std::invalid_argument(eMsg); + } + audioClipIdStrStream.str(attribute->get_value()); + audioClipIdStrStream >> audioClipIdValue; + audioClipId.reset(new UniqueId(audioClipIdValue)); + + if (!(attribute = element.get_attribute(timeStampAttrName))) { + std::string eMsg = "missing attribute "; + eMsg += timeStampAttrName; + throw std::invalid_argument(eMsg); + } + timeStamp.reset(new ptime(time_from_string(attribute->get_value()))); +} diff --git a/livesupport/products/scheduler/src/PlayLogEntry.h b/livesupport/products/scheduler/src/PlayLogEntry.h new file mode 100644 index 000000000..b8b22670c --- /dev/null +++ b/livesupport/products/scheduler/src/PlayLogEntry.h @@ -0,0 +1,202 @@ +/*------------------------------------------------------------------------------ + + 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/Attic/PlayLogEntry.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef LiveSupport_Scheduler_PlayLogEntry_h +#define LiveSupport_Scheduler_PlayLogEntry_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 Scheduler { + +using namespace boost::posix_time; +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * A class representing a play log entry. + * PlayLogEntries contain information about the audio clips played. + * + * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + */ +class PlayLogEntry : public Configurable +{ + private: + /** + * The name of the configuration XML elmenent used by PlayLogEntry. + */ + static const std::string configElementNameStr; + + /** + * The unique id of the play log entry. + */ + Ptr::Ref id; + + /** + * The id of the audio clip referenced by this play log entry. + */ + Ptr::Ref audioClipId; + + /** + * The time this audio clip was played. + */ + Ptr::Ref timeStamp; + + + public: + /** + * Default constructor. + */ + PlayLogEntry(void) throw () + { + } + + /** + * Create a play log entry by specifying all details. + * This is used for testing purposes. + * + * @param id the ID of the play log entry. + * @param audioClipId the ID of the audio clip logged + * @param timeStamp the time this audio clip was played. + */ + PlayLogEntry(Ptr::Ref id, + Ptr::Ref audioClipId, + Ptr::Ref timeStamp) throw() + { + this->id = id; + this->audioClipId = audioClipId; + this->timeStamp = timeStamp; + } + + /** + * A virtual destructor, as this class has virtual functions. + */ + virtual + ~PlayLogEntry(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 configuration information + */ + virtual void + configure(const xmlpp::Element & element) + throw (std::invalid_argument); + + /** + * Return the ID of the play log entry. + * + * @return the unique ID of the play log entry. + */ + Ptr::Ref + getId(void) const throw () + { + return id; + } + + /** + * Return the ID of the audio clip referenced by this entry. + * + * @return the unique ID of the audio clip. + */ + Ptr::Ref + getAudioClipId(void) const throw () + { + return audioClipId; + } + + /** + * Return the time this audio clip was played. + * + * @return the the time the audio clip was played. + */ + Ptr::Ref + getTimeStamp(void) const throw () + { + return timeStamp; + } + +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Scheduler +} // namespace LiveSupport + +#endif // LiveSupport_Scheduler_PlayLogEntry_h + diff --git a/livesupport/products/scheduler/src/PlayLogEntryTest.cxx b/livesupport/products/scheduler/src/PlayLogEntryTest.cxx new file mode 100644 index 000000000..eb55697bd --- /dev/null +++ b/livesupport/products/scheduler/src/PlayLogEntryTest.cxx @@ -0,0 +1,124 @@ +/*------------------------------------------------------------------------------ + + 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/Attic/PlayLogEntryTest.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 "PlayLogEntry.h" +#include "PlayLogEntryTest.h" + + +using namespace std; +using namespace boost::posix_time; +using namespace LiveSupport::Core; +using namespace LiveSupport::Scheduler; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +CPPUNIT_TEST_SUITE_REGISTRATION(PlayLogEntryTest); + +/** + * The name of the configuration file for the audio clip. + */ +static const std::string configFileName = "etc/playLogEntry.xml"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Set up the test environment + *----------------------------------------------------------------------------*/ +void +PlayLogEntryTest :: setUp(void) throw () +{ +} + + +/*------------------------------------------------------------------------------ + * Clean up the test environment + *----------------------------------------------------------------------------*/ +void +PlayLogEntryTest :: tearDown(void) throw () +{ +} + + +/*------------------------------------------------------------------------------ + * Test to see if the singleton Hello object is accessible + *----------------------------------------------------------------------------*/ +void +PlayLogEntryTest :: 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 playLogEntry(new PlayLogEntry()); + + playLogEntry->configure(*root); + + CPPUNIT_ASSERT(playLogEntry->getId()->getId() == 1); + CPPUNIT_ASSERT(playLogEntry->getAudioClipId()->getId() == 10001); + + Ptr::Ref + timeStamp = playLogEntry->getTimeStamp(); + ptime beethovensBirthDay(time_from_string("1770-12-16 07:00:00")); + CPPUNIT_ASSERT(*timeStamp == beethovensBirthDay); + + } catch (std::invalid_argument &e) { + CPPUNIT_FAIL("semantic error in configuration file"); + } catch (xmlpp::exception &e) { + std::string eMsg = "error parsing configuration file: "; + eMsg += e.what(); + CPPUNIT_FAIL(eMsg); + } +} diff --git a/livesupport/products/scheduler/src/PlayLogEntryTest.h b/livesupport/products/scheduler/src/PlayLogEntryTest.h new file mode 100644 index 000000000..a5c988e55 --- /dev/null +++ b/livesupport/products/scheduler/src/PlayLogEntryTest.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/products/scheduler/src/Attic/PlayLogEntryTest.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef PlayLogEntryTest_h +#define PlayLogEntryTest_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 { + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * Unit test for the PlayLogEntry class. + * + * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + * @see PlayLogEntry + */ +class PlayLogEntryTest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(PlayLogEntryTest); + 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 Scheduler +} // namespace LiveSupport + +#endif // PlayLogEntryTest_h +