added AudioClip constructor without ID, to be used before storeAudioClip()

added run-time type info to Playable: getType(), getAudioClip() and
    getPlaylist()
This commit is contained in:
fgerlits 2005-01-04 21:47:56 +00:00
parent 39acf9f58f
commit 7a56bbf8be
13 changed files with 333 additions and 35 deletions

View File

@ -21,7 +21,7 @@
# #
# #
# Author : $Author: fgerlits $ # Author : $Author: fgerlits $
# Version : $Revision: 1.19 $ # Version : $Revision: 1.20 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/etc/Makefile.in,v $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/etc/Makefile.in,v $
# #
# @configure_input@ # @configure_input@
@ -108,6 +108,7 @@ LDFLAGS = @LDFLAGS@ -pthread \
# Dependencies # Dependencies
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
CORE_LIB_OBJS = ${TMP_DIR}/UniqueId.o \ CORE_LIB_OBJS = ${TMP_DIR}/UniqueId.o \
${TMP_DIR}/Playable.o \
${TMP_DIR}/AudioClip.o \ ${TMP_DIR}/AudioClip.o \
${TMP_DIR}/FadeInfo.o \ ${TMP_DIR}/FadeInfo.o \
${TMP_DIR}/PlaylistElement.o \ ${TMP_DIR}/PlaylistElement.o \

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.15 $ Version : $Revision: 1.16 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -124,7 +124,7 @@ using namespace boost::posix_time;
* </code></pre> * </code></pre>
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.15 $ * @version $Revision: 1.16 $
*/ */
class AudioClip : public Configurable, class AudioClip : public Configurable,
public Playable public Playable
@ -171,6 +171,7 @@ class AudioClip : public Configurable,
* Default constructor. * Default constructor.
*/ */
AudioClip(void) throw () AudioClip(void) throw ()
: Playable(AudioClipType)
{ {
} }
@ -180,8 +181,8 @@ class AudioClip : public Configurable,
* *
* @param id the id of the audio clip. * @param id the id of the audio clip.
*/ */
AudioClip(Ptr<UniqueId>::Ref id) AudioClip(Ptr<UniqueId>::Ref id) throw ()
throw () : Playable(AudioClipType)
{ {
this->id = id; this->id = id;
} }
@ -216,6 +217,22 @@ class AudioClip : public Configurable,
Ptr<const std::string>::Ref uri = Ptr<string>::Ref()) Ptr<const std::string>::Ref uri = Ptr<string>::Ref())
throw (); throw ();
/**
* Create an audio clip by specifying all details which need
* to be set by the user.
* The ID is left blank, and can be set later using setId().
* This is used when a new audio clip is uploaded to storage.
*
* @param playlength the playing length of the audio clip.
* @param title the title of the audio clip.
* @param uri the location of the sound file corresponding to
* this audio clip object.
*/
AudioClip(Ptr<const Glib::ustring>::Ref title,
Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri)
throw ();
/** /**
* A virtual destructor, as this class has virtual functions. * A virtual destructor, as this class has virtual functions.
*/ */
@ -260,6 +277,23 @@ class AudioClip : public Configurable,
return id; return id;
} }
/**
* Set the ID of the object. This is only allowed if the ID was
* a null pointer; once the ID is set, it can not be changed.
*
* @param the new unique id of the audio clip.
*/
void
setId(Ptr<UniqueId>::Ref id) throw (std::invalid_argument)
{
if (!this->id) {
this->id = id;
}
else {
throw std::invalid_argument("can not set the ID twice");
}
}
/** /**
* Return the total playing length for this audio clip. * Return the total playing length for this audio clip.
* *

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.5 $ Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Playable.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Playable.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -44,6 +44,7 @@
#include <string> #include <string>
#include <libxml++/libxml++.h> #include <libxml++/libxml++.h>
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include "LiveSupport/Core/Ptr.h" #include "LiveSupport/Core/Ptr.h"
@ -54,6 +55,9 @@
namespace LiveSupport { namespace LiveSupport {
namespace Core { namespace Core {
class AudioClip; // forward declarations to avoid circularity
class Playlist;
using namespace boost::posix_time; using namespace boost::posix_time;
/* ================================================================ constants */ /* ================================================================ constants */
@ -65,16 +69,51 @@ using namespace boost::posix_time;
/* =============================================================== data types */ /* =============================================================== data types */
/** /**
* A purely abstract class which is extended by AudioClip and Playlist. * An abstract class which is extended by AudioClip and Playlist.
* It contains the methods which are common to these classes. * It contains the methods which are common to these classes.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.5 $ * @version $Revision: 1.6 $
*/ */
class Playable class Playable : public boost::enable_shared_from_this<Playable>
{ {
public: public:
/**
* The sub-types a Playable object can belong to.
*/
enum Type { AudioClipType, PlaylistType };
private:
/**
* The type of this playable object (audio clip or playlist).
*/
Type type;
protected:
/**
* Only my children are allowed to instantiate me.
*
* @param typeParam either AudioClipType or PlaylistType.
*/
Playable(Type typeParam) throw ()
: type(typeParam)
{
}
public:
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~Playable(void) throw ()
{
}
/** /**
* Return the id of the audio clip or playlist. * Return the id of the audio clip or playlist.
* *
@ -185,6 +224,37 @@ class Playable
virtual Ptr<Glib::ustring>::Ref virtual Ptr<Glib::ustring>::Ref
getXmlString(void) throw () = 0; getXmlString(void) throw () = 0;
/**
* Return the type of this object.
*
* @return either AudioClipType or PlaylistType.
*/
Type
getType(void) const throw ()
{
return type;
}
/**
* Return an audio clip pointer to this object. If the object's
* type is not AudioClipType, returns a zero pointer.
*
* @see getType()
* @return an audio clip pointer to this object.
*/
Ptr<AudioClip>::Ref
getAudioClip(void) throw ();
/**
* Return a playlist pointer to this object. If the object's
* type is not PlaylistType, returns a zero pointer.
*
* @see getType()
* @return a playlist pointer to this object.
*/
Ptr<Playlist>::Ref
getPlaylist(void) throw ();
}; };

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.24 $ Version : $Revision: 1.25 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Playlist.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Playlist.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -93,7 +93,7 @@ using namespace boost::posix_time;
* </code></pre> * </code></pre>
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.24 $ * @version $Revision: 1.25 $
*/ */
class Playlist : public Configurable, class Playlist : public Configurable,
public Playable public Playable
@ -185,6 +185,7 @@ class Playlist : public Configurable,
* Default constructor. * Default constructor.
*/ */
Playlist(void) throw () Playlist(void) throw ()
: Playable(PlaylistType)
{ {
elementList.reset(new PlaylistElementListType); elementList.reset(new PlaylistElementListType);
this->isLockedForPlaying = false; this->isLockedForPlaying = false;
@ -195,6 +196,7 @@ class Playlist : public Configurable,
* Create a playlist by specifying its ID only. * Create a playlist by specifying its ID only.
*/ */
Playlist(Ptr<UniqueId>::Ref id) throw () Playlist(Ptr<UniqueId>::Ref id) throw ()
: Playable(PlaylistType)
{ {
this->id = id; this->id = id;
@ -216,6 +218,7 @@ class Playlist : public Configurable,
Ptr<time_duration>::Ref playlength, Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri = Ptr<std::string>::Ref()) Ptr<const std::string>::Ref uri = Ptr<std::string>::Ref())
throw () throw ()
: Playable(PlaylistType)
{ {
this->id = id; this->id = id;
this->title.reset(new Glib::ustring("")); this->title.reset(new Glib::ustring(""));
@ -241,6 +244,7 @@ class Playlist : public Configurable,
Ptr<time_duration>::Ref playlength, Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri = Ptr<std::string>::Ref()) Ptr<const std::string>::Ref uri = Ptr<std::string>::Ref())
throw () throw ()
: Playable(PlaylistType)
{ {
this->id = id; this->id = id;
this->title = title; this->title = title;

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.14 $ Version : $Revision: 1.15 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/AudioClip.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/AudioClip.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -124,17 +124,18 @@ AudioClip :: AudioClip(Ptr<UniqueId>::Ref id,
Ptr<time_duration>::Ref playlength, Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri) Ptr<const std::string>::Ref uri)
throw () throw ()
: Playable(AudioClipType)
{ {
this->id = id; this->id = id;
this->title.reset(new Glib::ustring("")); this->title.reset(new Glib::ustring(""));
this->playlength = playlength; this->playlength = playlength;
this->uri = uri; this->uri = uri;
setMetadata(title, titleElementName, titleElementPrefix);
Ptr<const Glib::ustring>::Ref playlengthString(new const Glib::ustring( Ptr<const Glib::ustring>::Ref playlengthString(new const Glib::ustring(
to_simple_string(*playlength) )); to_simple_string(*playlength) ));
setMetadata(playlengthString, extentElementName, extentElementPrefix); setMetadata(playlengthString, extentElementName, extentElementPrefix);
setMetadata(title, titleElementName, titleElementPrefix);
} }
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
@ -145,20 +146,40 @@ AudioClip :: AudioClip(Ptr<UniqueId>::Ref id,
Ptr<time_duration>::Ref playlength, Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri) Ptr<const std::string>::Ref uri)
throw () throw ()
: Playable(AudioClipType)
{ {
this->id = id; this->id = id;
this->title = title; this->title = title;
this->playlength = playlength; this->playlength = playlength;
this->uri = uri; this->uri = uri;
setMetadata(title, titleElementName, titleElementPrefix);
Ptr<const Glib::ustring>::Ref playlengthString(new const Glib::ustring( Ptr<const Glib::ustring>::Ref playlengthString(new const Glib::ustring(
to_simple_string(*playlength) )); to_simple_string(*playlength) ));
setMetadata(playlengthString, extentElementName, extentElementPrefix); setMetadata(playlengthString, extentElementName, extentElementPrefix);
setMetadata(title, titleElementName, titleElementPrefix);
} }
/*------------------------------------------------------------------------------ * Constructor without ID.
*----------------------------------------------------------------------------*/AudioClip :: AudioClip(Ptr<const Glib::ustring>::Ref title,
Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri)
throw ()
: Playable(AudioClipType)
{
this->title = title;
this->playlength = playlength;
this->uri = uri;
setMetadata(title, titleElementName, titleElementPrefix);
Ptr<const Glib::ustring>::Ref playlengthString(new const Glib::ustring(
to_simple_string(*playlength) ));
setMetadata(playlengthString, extentElementName, extentElementPrefix);
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Set the value of the title field. * Set the value of the title field.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.7 $ Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/AudioClipTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/AudioClipTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -44,6 +44,7 @@
#include <iostream> #include <iostream>
#include "LiveSupport/Core/AudioClip.h" #include "LiveSupport/Core/AudioClip.h"
#include "LiveSupport/Core/Playlist.h"
#include "AudioClipTest.h" #include "AudioClipTest.h"
@ -140,3 +141,39 @@ AudioClipTest :: firstTest(void)
CPPUNIT_FAIL(eMsg); CPPUNIT_FAIL(eMsg);
} }
} }
/*------------------------------------------------------------------------------
* Test conversion to and from Playable
*----------------------------------------------------------------------------*/
void
AudioClipTest :: conversionTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<AudioClip>::Ref audioClip(new AudioClip());
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, false));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
audioClip->configure(*root);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (xmlpp::exception &e) {
std::string eMsg = "error parsing configuration file\n";
eMsg += e.what();
CPPUNIT_FAIL(eMsg);
}
Ptr<Playable>::Ref playable = audioClip;
CPPUNIT_ASSERT(playable->getType() == Playable::AudioClipType);
Ptr<AudioClip>::Ref otherAudioClip = playable->getAudioClip();
CPPUNIT_ASSERT(otherAudioClip == audioClip);
Ptr<Playlist>::Ref playlist = playable->getPlaylist();
CPPUNIT_ASSERT(!playlist);
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.1 $ Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/AudioClipTest.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/AudioClipTest.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -58,13 +58,14 @@ namespace Core {
* Unit test for the AudioClip class. * Unit test for the AudioClip class.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.1 $ * @version $Revision: 1.2 $
* @see AudioClip * @see AudioClip
*/ */
class AudioClipTest : public CPPUNIT_NS::TestFixture class AudioClipTest : public CPPUNIT_NS::TestFixture
{ {
CPPUNIT_TEST_SUITE(AudioClipTest); CPPUNIT_TEST_SUITE(AudioClipTest);
CPPUNIT_TEST(firstTest); CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(conversionTest);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
protected: protected:
@ -77,6 +78,14 @@ class AudioClipTest : public CPPUNIT_NS::TestFixture
void void
firstTest(void) throw (CPPUNIT_NS::Exception); firstTest(void) throw (CPPUNIT_NS::Exception);
/**
* Testing conversion to and from Playable.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
conversionTest(void) throw (CPPUNIT_NS::Exception);
public: public:

View File

@ -0,0 +1,78 @@
/*------------------------------------------------------------------------------
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/Playable.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#include "LiveSupport/Core/AudioClip.h"
#include "LiveSupport/Core/Playlist.h"
#include "LiveSupport/Core/Playable.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Return an audio clip pointer to this object.
*----------------------------------------------------------------------------*/
Ptr<AudioClip>::Ref
Playable :: getAudioClip(void) throw ()
{
Ptr<AudioClip>::Ref audioClip;
if (type == AudioClipType) {
audioClip = boost::dynamic_pointer_cast<AudioClip,Playable>
(shared_from_this());
}
return audioClip;
}
/*------------------------------------------------------------------------------
* Return a playlist pointer to this object.
*----------------------------------------------------------------------------*/
Ptr<Playlist>::Ref
Playable :: getPlaylist(void) throw ()
{
Ptr<Playlist>::Ref playlist;
if (type == PlaylistType) {
playlist = boost::dynamic_pointer_cast<Playlist,Playable>
(shared_from_this());
}
return playlist;
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.16 $ Version : $Revision: 1.17 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -389,3 +389,26 @@ PlaylistTest :: fadeInfoTest(void)
catch (std::invalid_argument &e) { catch (std::invalid_argument &e) {
} }
} }
/*------------------------------------------------------------------------------
* Test conversion to and from Playable
*----------------------------------------------------------------------------*/
void
PlaylistTest :: conversionTest(void)
throw (CPPUNIT_NS::Exception)
{
CPPUNIT_ASSERT(playlist.use_count() == 1);
Ptr<Playable>::Ref playable = playlist;
CPPUNIT_ASSERT(playable->getType() == Playable::PlaylistType);
CPPUNIT_ASSERT(playlist.use_count() == 2);
Ptr<Playlist>::Ref otherPlaylist = playable->getPlaylist();
CPPUNIT_ASSERT(otherPlaylist == playlist);
CPPUNIT_ASSERT(playlist.use_count() == 3);
Ptr<AudioClip>::Ref audioClip = playable->getAudioClip();
CPPUNIT_ASSERT(!audioClip);
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.8 $ Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.h,v $ 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. * Unit test for the UploadPlaylistMetohd class.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.8 $ * @version $Revision: 1.9 $
* @see Playlist * @see Playlist
*/ */
class PlaylistTest : public CPPUNIT_NS::TestFixture class PlaylistTest : public CPPUNIT_NS::TestFixture
@ -69,6 +69,7 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(audioClipTest); CPPUNIT_TEST(audioClipTest);
CPPUNIT_TEST(savedCopyTest); CPPUNIT_TEST(savedCopyTest);
CPPUNIT_TEST(fadeInfoTest); CPPUNIT_TEST(fadeInfoTest);
CPPUNIT_TEST(conversionTest);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
@ -120,6 +121,14 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture
void void
fadeInfoTest(void) throw (CPPUNIT_NS::Exception); fadeInfoTest(void) throw (CPPUNIT_NS::Exception);
/**
* Testing conversion to and from Playable.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
conversionTest(void) throw (CPPUNIT_NS::Exception);
public: public:

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.18 $ Version : $Revision: 1.19 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -1190,9 +1190,7 @@ WebStorageClient :: createPlaylist(Ptr<SessionId>::Ref sessionId)
parameters.clear(); parameters.clear();
parameters[createPlaylistSessionIdParamName] parameters[createPlaylistSessionIdParamName]
= sessionId->getId(); = sessionId->getId();
parameters[createPlaylistPlaylistIdParamName]
= std::string(*UniqueId::generateId()); // TODO: the server
// should generate the ID
result.clear(); result.clear();
if (!xmlRpcClient.execute(createPlaylistMethodName.c_str(), if (!xmlRpcClient.execute(createPlaylistMethodName.c_str(),
parameters, result)) { parameters, result)) {
@ -1443,8 +1441,8 @@ WebStorageClient :: storeAudioClip(Ptr<SessionId>::Ref sessionId,
parameters.clear(); parameters.clear();
parameters[storeAudioClipSessionIdParamName] parameters[storeAudioClipSessionIdParamName]
= sessionId->getId(); = sessionId->getId();
if (audioClip->getId()->getId() != 0) { // ID==0 means 'please if (audioClip->getId()) {
parameters[storeAudioClipAudioClipIdParamName] // generate new ID' parameters[storeAudioClipAudioClipIdParamName]
= std::string(*audioClip->getId()); = std::string(*audioClip->getId());
} }
parameters[storeAudioClipMetadataParamName] parameters[storeAudioClipMetadataParamName]
@ -1549,7 +1547,7 @@ WebStorageClient :: storeAudioClip(Ptr<SessionId>::Ref sessionId,
if (! result.hasMember(storeAudioClipAudioClipIdParamName) if (! result.hasMember(storeAudioClipAudioClipIdParamName)
|| result[storeAudioClipAudioClipIdParamName].getType() || result[storeAudioClipAudioClipIdParamName].getType()
!= XmlRpcValue::TypeString != XmlRpcValue::TypeString
|| (audioClip->getId()->getId() != 0 || (audioClip->getId()
&& &&
std::string(result[storeAudioClipAudioClipIdParamName]) std::string(result[storeAudioClipAudioClipIdParamName])
!= std::string(*audioClip->getId()))) { != std::string(*audioClip->getId()))) {
@ -1561,6 +1559,12 @@ WebStorageClient :: storeAudioClip(Ptr<SessionId>::Ref sessionId,
throw XmlRpcMethodResponseException(eMsg.str()); throw XmlRpcMethodResponseException(eMsg.str());
} }
if (!audioClip->getId()) {
Ptr<UniqueId>::Ref newId(new UniqueId(std::string(
result[storeAudioClipAudioClipIdParamName] )));
audioClip->setId(newId);
}
return true; return true;
} }

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.13 $ Version : $Revision: 1.14 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -99,7 +99,7 @@ using namespace LiveSupport::Core;
* </code></pre> * </code></pre>
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.13 $ * @version $Revision: 1.14 $
*/ */
class WebStorageClient : class WebStorageClient :
virtual public Configurable, virtual public Configurable,
@ -359,6 +359,9 @@ class WebStorageClient :
* Store an audio clip. The <code>uri</code> field of the audio clip * Store an audio clip. The <code>uri</code> field of the audio clip
* is expected to contain the valid URI of a binary audio file. * is expected to contain the valid URI of a binary audio file.
* *
* If the ID of the audio clip is UniqueId::NoId, a new globally unique
* ID is generated, and the audioClip ID is changed to the new ID.
*
* In this testing version, the audio clip URI is expected in the * In this testing version, the audio clip URI is expected in the
* form <code>file:relative_path/file_name.mp3</code>. Later this * form <code>file:relative_path/file_name.mp3</code>. Later this
* should be changed to an absolute URI. * should be changed to an absolute URI.

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.20 $ Version : $Revision: 1.21 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -430,10 +430,12 @@ WebStorageClientTest :: audioClipTest(void)
// test storeAudioClip() and getAudioClip() // test storeAudioClip() and getAudioClip()
Ptr<UniqueId>::Ref idxx = UniqueId::generateId(); Ptr<const Glib::ustring>::Ref title(new Glib::ustring(
"Muppet Show theme"));
Ptr<time_duration>::Ref playlength(new time_duration(0,0,11,0)); Ptr<time_duration>::Ref playlength(new time_duration(0,0,11,0));
Ptr<std::string>::Ref uri(new std::string("file:var/test10001.mp3")); Ptr<const std::string>::Ref uri(new std::string(
audioClip.reset(new AudioClip(idxx, playlength, uri)); "file:var/test10001.mp3"));
audioClip.reset(new AudioClip(title, playlength, uri));
try { try {
wsc->storeAudioClip(sessionId, audioClip); wsc->storeAudioClip(sessionId, audioClip);
@ -442,6 +444,9 @@ WebStorageClientTest :: audioClipTest(void)
CPPUNIT_FAIL(e.what()); CPPUNIT_FAIL(e.what());
} }
CPPUNIT_ASSERT(audioClip->getId());
Ptr<UniqueId>::Ref idxx = audioClip->getId();
try { try {
CPPUNIT_ASSERT( wsc->existsAudioClip(sessionId, idxx)); CPPUNIT_ASSERT( wsc->existsAudioClip(sessionId, idxx));
} }