incorporated changes for recursive acquiring of playlists

see issue http://bugs.campware.org/view.php?id=1438
This commit is contained in:
maroy 2005-09-06 12:52:31 +00:00
parent 89bcc935e5
commit b3b80d424f
2 changed files with 126 additions and 45 deletions

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.48 $
Version : $Revision: 1.49 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $
------------------------------------------------------------------------------*/
@ -43,7 +43,6 @@
#include <fstream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <XmlRpcClient.h>
#include <XmlRpcValue.h>
#include <XmlRpcUtil.h>
#include <curl/curl.h>
#include <curl/easy.h>
@ -64,6 +63,7 @@ using namespace XmlRpc;
using namespace LiveSupport::Core;
using namespace LiveSupport::Storage;
/* =================================================== local data structures */
@ -409,6 +409,11 @@ static const std::string getPlaylistUrlParamName = "url";
*----------------------------------------------------------------------------*/
static const std::string getPlaylistTokenParamName = "token";
/*------------------------------------------------------------------------------
* The name of the content parameter returned (for open) or input (for close)
*----------------------------------------------------------------------------*/
static const std::string getPlaylistContentParamName = "content";
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: editPlaylist */
@ -914,7 +919,8 @@ WebStorageClient :: existsPlaylist(Ptr<SessionId>::Ref sessionId,
*----------------------------------------------------------------------------*/
Ptr<Playlist>::Ref
WebStorageClient :: getPlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id) const
Ptr<UniqueId>::Ref id,
bool deep) const
throw (Core::XmlRpcException)
{
EditedPlaylistsType::const_iterator
@ -932,12 +938,9 @@ WebStorageClient :: getPlaylist(Ptr<SessionId>::Ref sessionId,
storageServerPath.c_str(), false);
parameters.clear();
parameters[getPlaylistSessionIdParamName]
= sessionId->getId();
parameters[getPlaylistPlaylistIdParamName]
= std::string(*id);
parameters[getPlaylistRecursiveParamName]
= false;
parameters[getPlaylistSessionIdParamName] = sessionId->getId();
parameters[getPlaylistPlaylistIdParamName] = std::string(*id);
parameters[getPlaylistRecursiveParamName] = deep;
result.clear();
if (!xmlRpcClient.execute(getPlaylistOpenMethodName.c_str(),
@ -957,7 +960,6 @@ WebStorageClient :: getPlaylist(Ptr<SessionId>::Ref sessionId,
<< result;
throw Core::XmlRpcMethodFaultException(eMsg.str());
}
if (! result.hasMember(getPlaylistUrlParamName)
|| result[getPlaylistUrlParamName].getType()
!= XmlRpcValue::TypeString
@ -993,6 +995,10 @@ WebStorageClient :: getPlaylist(Ptr<SessionId>::Ref sessionId,
"error parsing playlist metafile");
}
if (deep) {
playlist = acquirePlaylist(playlist, result);
}
parameters.clear();
parameters[getPlaylistSessionIdParamName] = sessionId->getId();
parameters[getPlaylistTokenParamName] = token;
@ -1075,6 +1081,9 @@ WebStorageClient :: editPlaylist(Ptr<SessionId>::Ref sessionId,
}
/*------------------------------------------------------------------------------
* Opens the playlist for editing, and returns its URL.
*----------------------------------------------------------------------------*/
void
WebStorageClient :: editPlaylistGetUrl(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id,
@ -1267,12 +1276,12 @@ WebStorageClient :: revertPlaylist(Ptr<const std::string>::Ref playlistToken)
* Acquire resources for a playlist.
*----------------------------------------------------------------------------*/
Ptr<Playlist>::Ref
WebStorageClient :: acquirePlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id) const
WebStorageClient :: acquirePlaylist(Ptr<Playlist>::Ref oldPlaylist,
XmlRpcValue & result) const
throw (Core::XmlRpcException)
{
Ptr<Playlist>::Ref oldPlaylist = getPlaylist(sessionId, id);
XmlRpcValue content;
int index;
Ptr<time_duration>::Ref playlength = oldPlaylist->getPlaylength();
Ptr<Playlist>::Ref newPlaylist(new Playlist(oldPlaylist->getId(),
playlength));
@ -1293,31 +1302,53 @@ WebStorageClient :: acquirePlaylist(Ptr<SessionId>::Ref sessionId,
= smilBodyNode->add_child(smilParNodeName);
Playlist::const_iterator it = oldPlaylist->begin();
if (result.hasMember(getPlaylistContentParamName)) {
content = result[getPlaylistContentParamName];
}
// if there is no content parameter, leave the original, empty content
index = 0;
// assume that it is as long as the size of the content array
while (it != oldPlaylist->end()) {
Ptr<PlaylistElement>::Ref plElement = it->second;
Ptr<time_duration>::Ref relativeOffset
= plElement->getRelativeOffset();
Ptr<FadeInfo>::Ref fadeInfo = plElement->getFadeInfo();
Ptr<Playable>::Ref playable;
if (index >= content.size()) {
break;
}
XmlRpcValue contents = content[index];
++index;
if (!contents.hasMember(getPlaylistUrlParamName)) {
// TODO: maybe signal error?
continue;
}
Ptr<Playable>::Ref playable;
Ptr<const std::string>::Ref url;
Ptr<AudioClip>::Ref audioClip;
Ptr<Playlist>::Ref playlist;
switch (plElement->getType()) {
case PlaylistElement::AudioClipType :
playable = acquireAudioClip(sessionId, plElement
->getAudioClip()
->getId());
url.reset(new std::string(contents[getPlaylistUrlParamName]));
audioClip.reset(new AudioClip(*plElement->getAudioClip()));
audioClip->setUri(url);
url.reset();
newPlaylist->addPlayable(audioClip, relativeOffset, fadeInfo);
playable = audioClip;
break;
case PlaylistElement::PlaylistType :
playable = acquirePlaylist(sessionId, plElement
->getPlaylist()
->getId());
playlist.reset(new Playlist(*plElement->getPlaylist()));
playlist = acquirePlaylist(playlist, contents);
newPlaylist->addPlayable(playlist, relativeOffset, fadeInfo);
playable = playlist;
break;
default : // this should never happen
throw XmlRpcInvalidArgumentException(
"unexpected playlist element type "
"(neither audio clip nor playlist)");
}
newPlaylist->addPlayable(playable, relativeOffset, fadeInfo);
xmlpp::Element* smilPlayableNode
= smilParNode->add_child(smilPlayableNodeName);
@ -1440,13 +1471,8 @@ WebStorageClient :: releasePlaylist(Ptr<Playlist>::Ref playlist) const
while (it != playlist->end()) {
Ptr<PlaylistElement>::Ref plElement = it->second;
if (plElement->getType() == PlaylistElement::AudioClipType) {
try {
releaseAudioClip(it->second->getAudioClip());
}
catch (XmlRpcException &e) {
eMsg += e.what();
eMsg += "\n";
}
// don't have to release, as it will be done by the storage server
// for clips inside the playlist
++it;
} else if (plElement->getType() == PlaylistElement::PlaylistType) {
try {
@ -1457,8 +1483,9 @@ WebStorageClient :: releasePlaylist(Ptr<Playlist>::Ref playlist) const
eMsg += "\n";
}
++it;
} else { // this should never happen
eMsg += "unexpected playlist element type\n";
} else {
// this should never happen
eMsg += "unexpected playlist element type\n";
}
}
@ -2230,7 +2257,7 @@ WebStorageClient :: getAllPlaylists(Ptr<SessionId>::Ref sessionId,
playlists->push_back(getPlaylist(sessionId, *it));
++it;
}
return playlists;
}

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.32 $
Author : $Author: maroy $
Version : $Revision: 1.33 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.h,v $
------------------------------------------------------------------------------*/
@ -42,6 +42,8 @@
#include <stdexcept>
#include <XmlRpcValue.h>
#include "LiveSupport/Core/Playlist.h"
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Storage/StorageClientInterface.h"
@ -50,6 +52,8 @@
namespace LiveSupport {
namespace Storage {
using namespace XmlRpc;
using namespace LiveSupport;
using namespace LiveSupport::Core;
@ -95,8 +99,8 @@ using namespace LiveSupport::Core;
* &lt;!ATTLIST location path CDATA #REQUIRED &gt;
* </code></pre>
*
* @author $Author: fgerlits $
* @version $Revision: 1.32 $
* @author $Author: maroy $
* @version $Revision: 1.33 $
*/
class WebStorageClient :
virtual public Configurable,
@ -140,6 +144,18 @@ class WebStorageClient :
*/
EditedPlaylistsType editedPlaylists;
/**
* A vector containing the unique IDs of the audio clips returned
* by reset() (for testing) or by search().
*/
Ptr<std::vector<Ptr<UniqueId>::Ref> >::Ref audioClipIds;
/**
* A vector containing the unique IDs of the playlists returned
* by reset() (for testing) or by search().
*/
Ptr<std::vector<Ptr<UniqueId>::Ref> >::Ref playlistIds;
/**
* Auxilliary method used by editPlaylist() and createPlaylist().
* Opens the playlist for editing, and returns its URL.
@ -160,16 +176,47 @@ class WebStorageClient :
throw (XmlRpcException);
/**
* A vector containing the unique IDs of the audio clips returned
* by reset() (for testing) or by search().
* Return a playlist with the specified id to be displayed.
* If the playlist is being edited, and this method is called
* by the same user who is editing the playlist,
* (i.e., the method is called with the same sessionId and playlistId
* that editPlaylist() was), then the working copy of the playlist
* is returned.
* Any other user gets the old (pre-editPlaylist()) copy from storage.
*
* @param sessionId the session ID from the authentication client
* @param id the id of the playlist to return.
* @param deep signal if all playable objects are to be accessed
* and locked, that are referenced by this playlist, or
* any playlist contained in this one.
* @return the requested playlist.
* @exception XmlRpcInvalidDataException if the audio clip we got
* from the storage is invalid.
* @exception XmlRpcException if there is a problem with the XML-RPC
* call or no playlist with the specified id exists.
*/
Ptr<std::vector<Ptr<UniqueId>::Ref> >::Ref audioClipIds;
Ptr<Playlist>::Ref
getPlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id,
bool deep) const
throw (XmlRpcException);
/**
* A vector containing the unique IDs of the playlists returned
* by reset() (for testing) or by search().
* Do the final stages of acquring a playlist: generate SMIL
* files, etc.
*
* @param oldPlaylist the playlist to work on.
* @param result the XML-RPC result from getPlaylist() call
* with deep == true
* @return a playlist which has a URI filed, and all things below
* it are openned properly and processed as well.
* @exception XmlRpcException if there is a problem with the XML-RPC
* call or no playlist with the specified id exists.
*/
Ptr<std::vector<Ptr<UniqueId>::Ref> >::Ref playlistIds;
Ptr<Playlist>::Ref
acquirePlaylist(Ptr<Playlist>::Ref oldPlaylist,
XmlRpcValue & result) const
throw (XmlRpcException);
public:
@ -266,8 +313,10 @@ class WebStorageClient :
virtual Ptr<Playlist>::Ref
getPlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id) const
throw (XmlRpcException);
throw (XmlRpcException)
{
return getPlaylist(sessionId, id, false);
}
/**
* Return a playlist with the specified id to be edited.
@ -352,7 +401,12 @@ class WebStorageClient :
virtual Ptr<Playlist>::Ref
acquirePlaylist(Ptr<SessionId>::Ref sessionId,
Ptr<UniqueId>::Ref id) const
throw (XmlRpcException);
throw (XmlRpcException)
{
// FIXME: silently, with deep == true, getPlaylist will also
// generate all related SMIL files, etc.
return getPlaylist(sessionId, id, true);
}
/**
* Release the resources (audio clips, other playlists) used