added save current state / revert to previous state mechanism to Playlist

This commit is contained in:
fgerlits 2004-10-18 12:30:34 +00:00
parent acd6329cac
commit 555294c0a5
7 changed files with 4346 additions and 5793 deletions

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.6 $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Playlist.h,v $
------------------------------------------------------------------------------*/
@ -71,7 +71,7 @@ using namespace boost::posix_time;
* the playlist.
*
* @author $Author: fgerlits $
* @version $Revision: 1.6 $
* @version $Revision: 1.7 $
*/
class Playlist : public Configurable
{
@ -124,6 +124,11 @@ class Playlist : public Configurable
addPlaylistElement(Ptr<PlaylistElement>::Ref playlistElement)
throw (std::invalid_argument);
/**
* A saved copy of this playlist.
*/
Ptr<Playlist>::Ref savedCopy;
public:
/**
@ -308,6 +313,30 @@ class Playlist : public Configurable
bool
valid(void) throw ();
/**
* Create a saved copy of this playlist. If a saved copy exists
* already, it is replaced by the current state.
*/
void
createSavedCopy(void) throw ();
/**
* Delete the saved copy of the playlist, if exists (or do nothing).
*/
void
deleteSavedCopy(void) throw ()
{
savedCopy.reset();
}
/**
* Revert to the saved copy of this playlist. If there is no
* saved copy, do nothing and throw an exception.
*/
void
revertToSavedCopy(void) throw (std::logic_error);
};

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.6 $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/Playlist.cxx,v $
------------------------------------------------------------------------------*/
@ -253,3 +253,44 @@ Playlist::valid(void) throw ()
playlength = runningTime; // fix playlength, if everything else is OK
return true;
}
/*------------------------------------------------------------------------------
* Create a saved copy of the playlist.
*----------------------------------------------------------------------------*/
void
Playlist::createSavedCopy(void) throw ()
{
savedCopy = Ptr<Playlist>::Ref(new Playlist);
savedCopy->id = this->id;
savedCopy->playlength = this->playlength;
savedCopy->isLockedForPlaying = this->isLockedForPlaying;
savedCopy->isLockedForEditing = this->isLockedForEditing;
// note: we create a new copy of the playlist element map, but not of the
// individual playlist elements, which (i think) are immutable
savedCopy->elementList.reset(new PlaylistElementListType(*elementList));
savedCopy->savedCopy.reset();
}
/*------------------------------------------------------------------------------
* Revert to a saved copy of the playlist.
*----------------------------------------------------------------------------*/
void
Playlist::revertToSavedCopy(void) throw (std::logic_error)
{
if (savedCopy == 0) {
throw (std::logic_error("playlist has no saved copy"));
}
this->id = savedCopy->id;
this->playlength = savedCopy->playlength;
this->isLockedForPlaying = savedCopy->isLockedForPlaying;
this->isLockedForEditing = savedCopy->isLockedForEditing;
this->elementList = savedCopy->elementList;
savedCopy.reset();
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.6 $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.cxx,v $
------------------------------------------------------------------------------*/
@ -233,3 +233,49 @@ PlaylistTest :: audioClipTest(void)
CPPUNIT_FAIL("removeAudioClip allowed to remove "
"non-existent audio clip");
}
/*------------------------------------------------------------------------------
* Test the "save/revert to current state" mechanism
*----------------------------------------------------------------------------*/
void
PlaylistTest :: savedCopyTest(void)
throw (CPPUNIT_NS::Exception)
{
try {
playlist->revertToSavedCopy();
CPPUNIT_FAIL("allowed to revert to non-existent state");
}
catch (std::logic_error &e) {
}
playlist->createSavedCopy();
playlist->removeAudioClip(Ptr<time_duration>::Ref(
new time_duration(0,0,0,0)));
playlist->removeAudioClip(Ptr<time_duration>::Ref(
new time_duration(1,0,0,0)));
CPPUNIT_ASSERT(playlist->begin() == playlist->end());
try {
playlist->revertToSavedCopy();
}
catch (std::logic_error &e) {
CPPUNIT_FAIL("could not revert to saved state");
}
Playlist::const_iterator it = playlist->begin();
CPPUNIT_ASSERT(it != playlist->end());
++it;
CPPUNIT_ASSERT(it != playlist->end());
CPPUNIT_ASSERT(it->second->getAudioClip()->getId()->getId() == 10002);
++it;
CPPUNIT_ASSERT(it == playlist->end());
playlist->deleteSavedCopy();
try {
playlist->revertToSavedCopy();
CPPUNIT_FAIL("allowed to revert to deleted state");
}
catch (std::logic_error &e) {
}
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
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.4 $
* @version $Revision: 1.5 $
* @see Playlist
*/
class PlaylistTest : public CPPUNIT_NS::TestFixture
@ -67,6 +67,7 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(lockTest);
CPPUNIT_TEST(audioClipTest);
CPPUNIT_TEST(savedCopyTest);
CPPUNIT_TEST_SUITE_END();
private:
@ -102,6 +103,14 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture
void
audioClipTest(void) throw (CPPUNIT_NS::Exception);
/**
* Testing the "save/revert to current state" mechanism.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
savedCopyTest(void) throw (CPPUNIT_NS::Exception);
public:

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.5 $
Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -145,7 +145,8 @@ OpenPlaylistForEditingMethod :: execute(XmlRpc::XmlRpcValue & parameters,
return;
}
XmlRpcTools::playlistToXmlRpcValue(playlist, returnValue);
playlist->createSavedCopy();
XmlRpcTools::playlistToXmlRpcValue(playlist, returnValue);
return;
}