libretime/livesupport/modules/storage/src/TestStorageClient.cxx
fgerlits a815a437d9 added XmlRpcTools utility class
implemented createPlaylist and openPlaylistForEditing methods
2004-10-08 17:56:37 +00:00

179 lines
6.3 KiB
C++

/*------------------------------------------------------------------------------
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.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <boost/date_time/posix_time/posix_time.hpp>
#include "TestStorageClient.h"
using namespace boost::posix_time;
using namespace LiveSupport::Core;
using namespace LiveSupport::Storage;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* The name of the config element for this class
*----------------------------------------------------------------------------*/
const std::string TestStorageClient::configElementNameStr = "testStorage";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Configure the test storage client.
*----------------------------------------------------------------------------*/
void
TestStorageClient :: configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error)
{
if (element.get_name() != configElementNameStr) {
std::string eMsg = "Bad configuration element ";
eMsg += element.get_name();
throw std::invalid_argument(eMsg);
}
// iterate through the playlist elements
xmlpp::Node::NodeList nodes =
element.get_children(Playlist::getConfigElementName());
xmlpp::Node::NodeList::iterator it = nodes.begin();
playlistMap.clear();
while (it != nodes.end()) {
Ptr<Playlist>::Ref playlist(new Playlist());
const xmlpp::Element * element =
dynamic_cast<const xmlpp::Element*> (*it);
playlist->configure(*element);
playlistMap[playlist->getId()->getId()] = playlist;
++it;
}
}
/*------------------------------------------------------------------------------
* Tell if a playlist exists.
*----------------------------------------------------------------------------*/
const bool
TestStorageClient :: existsPlaylist(Ptr<const UniqueId>::Ref id) const
throw ()
{
return playlistMap.count(id->getId()) == 1 ? true : false;
}
/*------------------------------------------------------------------------------
* Return a playlist.
*----------------------------------------------------------------------------*/
Ptr<Playlist>::Ref
TestStorageClient :: getPlaylist(Ptr<const UniqueId>::Ref id) const
throw (std::invalid_argument)
{
PlaylistMap::const_iterator it = playlistMap.find(id->getId());
if (it == playlistMap.end()) {
throw std::invalid_argument("no such playlist");
}
return it->second;
}
/*------------------------------------------------------------------------------
* Delete a playlist.
*----------------------------------------------------------------------------*/
void
TestStorageClient :: deletePlaylist(Ptr<const UniqueId>::Ref id)
throw (std::invalid_argument)
{
PlaylistMap::iterator it = playlistMap.find(id->getId());
if (it == playlistMap.end()) {
throw std::invalid_argument("no such playlist");
}
playlistMap.erase(it);
}
/*------------------------------------------------------------------------------
* Return a listing of all the playlists in the playlist store.
*----------------------------------------------------------------------------*/
Ptr<std::vector<Ptr<Playlist>::Ref> >::Ref
TestStorageClient :: getAllPlaylists(void) const
throw ()
{
PlaylistMap::const_iterator it = playlistMap.begin();
Ptr<std::vector<Ptr<Playlist>::Ref> >::Ref
playlistVector (new std::vector<Ptr<Playlist>::Ref>);
while (it != playlistMap.end()) {
playlistVector->push_back(it->second);
++it;
}
return playlistVector;
}
/*------------------------------------------------------------------------------
* Create a new playlist.
*----------------------------------------------------------------------------*/
Ptr<Playlist>::Ref
TestStorageClient :: createPlaylist() throw ()
{
// generate a new UniqueId -- TODO: fix UniqueId to make sure
// this is really unique; not checked here!
Ptr<UniqueId>::Ref playlistId =
Ptr<UniqueId>::Ref(UniqueId :: generateId());
Ptr<time_duration>::Ref playLength =
Ptr<time_duration>::Ref(new time_duration(0,0,0));
Ptr<Playlist>::Ref playlist =
Ptr<Playlist>::Ref(new Playlist(playlistId, playLength));
playlistMap[playlistId->getId()] = playlist;
return playlist;
}