added PlaylistElement
This commit is contained in:
parent
4bcf8acfb6
commit
9411445823
|
@ -21,7 +21,7 @@
|
|||
#
|
||||
#
|
||||
# Author : $Author: fgerlits $
|
||||
# Version : $Revision: 1.6 $
|
||||
# Version : $Revision: 1.7 $
|
||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/etc/Makefile.in,v $
|
||||
#
|
||||
# @configure_input@
|
||||
|
@ -85,9 +85,11 @@ LDFLAGS = @LDFLAGS@ -L${USR_LIB_DIR} -L${LIB_DIR}
|
|||
# Dependencies
|
||||
#-------------------------------------------------------------------------------
|
||||
CORE_LIB_OBJS = ${TMP_DIR}/UniqueId.o \
|
||||
${TMP_DIR}/PlaylistElement.o \
|
||||
${TMP_DIR}/Playlist.o
|
||||
|
||||
TEST_RUNNER_OBJS = ${TMP_DIR}/PlaylistTest.o \
|
||||
TEST_RUNNER_OBJS = ${TMP_DIR}/PlaylistElementTest.o \
|
||||
${TMP_DIR}/PlaylistTest.o \
|
||||
${TMP_DIR}/TestRunner.o
|
||||
|
||||
TEST_RUNNER_LIBS = -l${CORE_LIB} -lxml++-1.0 -lcppunit -ldl
|
||||
|
|
|
@ -0,0 +1,211 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/PlaylistElement.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef PlaylistElement_h
|
||||
#define PlaylistElement_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include <libxml++/libxml++.h>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include "LiveSupport/Core/Ptr.h"
|
||||
#include "LiveSupport/Core/UniqueId.h"
|
||||
#include "LiveSupport/Core/Configurable.h"
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace Core {
|
||||
|
||||
using namespace boost::posix_time;
|
||||
|
||||
using namespace LiveSupport;
|
||||
using namespace LiveSupport::Core;
|
||||
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* An item in a playlist.
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
class PlaylistElement : public Configurable
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* The name of the configuration XML element used by Playlist.
|
||||
*/
|
||||
static const std::string configElementNameStr;
|
||||
|
||||
/**
|
||||
* The id of the playlist element.
|
||||
*/
|
||||
Ptr<UniqueId>::Ref id;
|
||||
|
||||
/**
|
||||
* The starting time of the event.
|
||||
*/
|
||||
Ptr<time_duration>::Ref relativeOffset;
|
||||
|
||||
/**
|
||||
* The id of the audio clip associated with the entry.
|
||||
*/
|
||||
Ptr<UniqueId>::Ref audioClipId;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* The default constructor.
|
||||
*/
|
||||
PlaylistElement(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 relativeOffset the start time of this element, relative to
|
||||
* the start of the playlist.
|
||||
*/
|
||||
PlaylistElement(Ptr<UniqueId>::Ref id,
|
||||
Ptr<time_duration>::Ref relativeOffset,
|
||||
Ptr<UniqueId>::Ref audioClipId)
|
||||
throw ()
|
||||
{
|
||||
this->id = id;
|
||||
this->relativeOffset = relativeOffset;
|
||||
this->audioClipId = audioClipId;
|
||||
}
|
||||
|
||||
/**
|
||||
* A virtual destructor, as this class has virtual functions.
|
||||
*/
|
||||
virtual
|
||||
~PlaylistElement(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
|
||||
* @exception std::logic_error if the object has already
|
||||
* been configured, and can not be reconfigured.
|
||||
*/
|
||||
virtual void
|
||||
configure(const xmlpp::Element & element)
|
||||
throw (std::invalid_argument);
|
||||
|
||||
/**
|
||||
* Return the id of the playlist element.
|
||||
*
|
||||
* @return the id of the playlist element.
|
||||
*/
|
||||
Ptr<const UniqueId>::Ref
|
||||
getId(void) const throw ()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the relative offset of the element.
|
||||
*
|
||||
* @return the relative offset of the element.
|
||||
*/
|
||||
Ptr<const time_duration>::Ref
|
||||
getRelativeOffset(void) const throw ()
|
||||
{
|
||||
return relativeOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the id of the audio clip associated with the element.
|
||||
*
|
||||
* @return the id of the audio clip associated with the element.
|
||||
*/
|
||||
Ptr<const UniqueId>::Ref
|
||||
getAudioClipId(void) const throw ()
|
||||
{
|
||||
return audioClipId;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace Core
|
||||
} // namespace LiveSupport
|
||||
|
||||
#endif // PlaylistElement_h
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/PlaylistElement.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "LiveSupport/Core/UniqueId.h"
|
||||
#include "LiveSupport/Core/PlaylistElement.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 PlaylistElement::configElementNameStr = "playlistElement";
|
||||
|
||||
/**
|
||||
* The name of the attribute of the id of the playlist element.
|
||||
*/
|
||||
static const std::string idAttrName = "id";
|
||||
|
||||
/**
|
||||
* The name of the attribute of the relative offset of the playlist element.
|
||||
*/
|
||||
static const std::string relativeOffsetAttrName = "relativeOffset";
|
||||
|
||||
/**
|
||||
* The name of the (audio clip) child element of the playlist element.
|
||||
*/
|
||||
static const std::string audioClipElementName = "audioClip";
|
||||
|
||||
/**
|
||||
* The name of the attribute of the id of the audio clip element.
|
||||
*/
|
||||
static const std::string audioClipIdAttrName = "id";
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Create a playlist object based on an XML element.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
PlaylistElement :: 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;
|
||||
UniqueId::IdType 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(relativeOffsetAttrName))) {
|
||||
std::string eMsg = "Missing attribute ";
|
||||
eMsg += relativeOffsetAttrName;
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
relativeOffset.reset(new time_duration(
|
||||
duration_from_string(attribute->get_value())));
|
||||
|
||||
xmlpp::Node::NodeList childNodes
|
||||
= element.get_children(audioClipElementName);
|
||||
xmlpp::Node::NodeList::iterator it = childNodes.begin();
|
||||
|
||||
if (it == childNodes.end()) {
|
||||
std::string eMsg = "Missing ";
|
||||
eMsg += audioClipElementName;
|
||||
eMsg += " XML element";
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
|
||||
// this is not really a new allocation, but a new pointer into the inside
|
||||
// of the parameter '& element' -- so no delete is needed (nor allowed)
|
||||
xmlpp::Element * audioClipElement
|
||||
= new xmlpp::Element( (*it)->cobj() );
|
||||
|
||||
if (!(attribute= audioClipElement->get_attribute(audioClipIdAttrName))) {
|
||||
std::string eMsg = "Missing ";
|
||||
eMsg += audioClipElementName;
|
||||
eMsg += "attribute ";
|
||||
eMsg += audioClipIdAttrName;
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
|
||||
std::stringstream audioClipStrStr;
|
||||
UniqueId::IdType audioClipIdValue;
|
||||
audioClipStrStr.str(attribute->get_value());
|
||||
audioClipStrStr >> audioClipIdValue;
|
||||
audioClipId.reset(new UniqueId(audioClipIdValue));
|
||||
|
||||
++it;
|
||||
if (it != childNodes.end()) {
|
||||
std::string eMsg = "More than one ";
|
||||
eMsg += audioClipElementName;
|
||||
eMsg += " XML element";
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/PlaylistElementTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#error "Need unistd.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "LiveSupport/Core/Playlist.h"
|
||||
#include "LiveSupport/Core/PlaylistElement.h"
|
||||
|
||||
#include "PlaylistElementTest.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace LiveSupport::Core;
|
||||
using namespace boost::posix_time;
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(PlaylistElementTest);
|
||||
|
||||
/**
|
||||
* The name of the configuration file for the playlist element.
|
||||
*/
|
||||
static const std::string configFileName = "etc/playlistElement.xml";
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Set up the test environment
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
PlaylistElementTest :: setUp(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Clean up the test environment
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
PlaylistElementTest :: tearDown(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test to see if the singleton Hello object is accessible
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
PlaylistElementTest :: firstTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
Ptr<PlaylistElement>::Ref playlistElement(new PlaylistElement);
|
||||
try {
|
||||
|
||||
Ptr<xmlpp::DomParser>::Ref parser(
|
||||
new xmlpp::DomParser(configFileName, true));
|
||||
const xmlpp::Document * document = parser->get_document();
|
||||
const xmlpp::Element * root = document->get_root_node();
|
||||
|
||||
playlistElement->configure(*root);
|
||||
|
||||
CPPUNIT_ASSERT(playlistElement->getId()->getId() == 707);
|
||||
Ptr<const time_duration>::Ref relativeOffset
|
||||
= playlistElement->getRelativeOffset();
|
||||
CPPUNIT_ASSERT(relativeOffset->total_seconds() == 12*60 + 34);
|
||||
CPPUNIT_ASSERT(playlistElement->getAudioClipId()->getId() == 10001);
|
||||
|
||||
} 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);
|
||||
}
|
||||
}
|
|
@ -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/PlaylistElementTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef PlaylistElementTest_h
|
||||
#define PlaylistElementTest_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace Core {
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* Unit test for the PlaylistElement class.
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.1 $
|
||||
* @see PlaylistElement
|
||||
*/
|
||||
class PlaylistElementTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(PlaylistElementTest);
|
||||
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 // PlaylistElementTest_h
|
||||
|
Loading…
Reference in New Issue