From b3b80d424ffffc4f1b41048a9411537d2a5cbf7a Mon Sep 17 00:00:00 2001 From: maroy Date: Tue, 6 Sep 2005 12:52:31 +0000 Subject: [PATCH] incorporated changes for recursive acquiring of playlists see issue http://bugs.campware.org/view.php?id=1438 --- .../modules/storage/src/WebStorageClient.cxx | 91 ++++++++++++------- .../modules/storage/src/WebStorageClient.h | 80 +++++++++++++--- 2 files changed, 126 insertions(+), 45 deletions(-) diff --git a/livesupport/modules/storage/src/WebStorageClient.cxx b/livesupport/modules/storage/src/WebStorageClient.cxx index d8dffa862..992bba1fd 100644 --- a/livesupport/modules/storage/src/WebStorageClient.cxx +++ b/livesupport/modules/storage/src/WebStorageClient.cxx @@ -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 #include #include -#include #include #include #include @@ -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::Ref sessionId, *----------------------------------------------------------------------------*/ Ptr::Ref WebStorageClient :: getPlaylist(Ptr::Ref sessionId, - Ptr::Ref id) const + Ptr::Ref id, + bool deep) const throw (Core::XmlRpcException) { EditedPlaylistsType::const_iterator @@ -932,12 +938,9 @@ WebStorageClient :: getPlaylist(Ptr::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::Ref sessionId, << result; throw Core::XmlRpcMethodFaultException(eMsg.str()); } - if (! result.hasMember(getPlaylistUrlParamName) || result[getPlaylistUrlParamName].getType() != XmlRpcValue::TypeString @@ -993,6 +995,10 @@ WebStorageClient :: getPlaylist(Ptr::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::Ref sessionId, } +/*------------------------------------------------------------------------------ + * Opens the playlist for editing, and returns its URL. + *----------------------------------------------------------------------------*/ void WebStorageClient :: editPlaylistGetUrl(Ptr::Ref sessionId, Ptr::Ref id, @@ -1267,12 +1276,12 @@ WebStorageClient :: revertPlaylist(Ptr::Ref playlistToken) * Acquire resources for a playlist. *----------------------------------------------------------------------------*/ Ptr::Ref -WebStorageClient :: acquirePlaylist(Ptr::Ref sessionId, - Ptr::Ref id) const +WebStorageClient :: acquirePlaylist(Ptr::Ref oldPlaylist, + XmlRpcValue & result) const throw (Core::XmlRpcException) { - Ptr::Ref oldPlaylist = getPlaylist(sessionId, id); - + XmlRpcValue content; + int index; Ptr::Ref playlength = oldPlaylist->getPlaylength(); Ptr::Ref newPlaylist(new Playlist(oldPlaylist->getId(), playlength)); @@ -1293,31 +1302,53 @@ WebStorageClient :: acquirePlaylist(Ptr::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::Ref plElement = it->second; Ptr::Ref relativeOffset = plElement->getRelativeOffset(); Ptr::Ref fadeInfo = plElement->getFadeInfo(); - Ptr::Ref playable; + if (index >= content.size()) { + break; + } + XmlRpcValue contents = content[index]; + ++index; + if (!contents.hasMember(getPlaylistUrlParamName)) { + // TODO: maybe signal error? + continue; + } + + Ptr::Ref playable; + Ptr::Ref url; + Ptr::Ref audioClip; + Ptr::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::Ref playlist) const while (it != playlist->end()) { Ptr::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::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::Ref sessionId, playlists->push_back(getPlaylist(sessionId, *it)); ++it; } - + return playlists; } diff --git a/livesupport/modules/storage/src/WebStorageClient.h b/livesupport/modules/storage/src/WebStorageClient.h index ace16b4f6..64f2d576b 100644 --- a/livesupport/modules/storage/src/WebStorageClient.h +++ b/livesupport/modules/storage/src/WebStorageClient.h @@ -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 +#include + #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; * <!ATTLIST location path CDATA #REQUIRED > * * - * @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::Ref> >::Ref audioClipIds; + + /** + * A vector containing the unique IDs of the playlists returned + * by reset() (for testing) or by search(). + */ + Ptr::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::Ref> >::Ref audioClipIds; + Ptr::Ref + getPlaylist(Ptr::Ref sessionId, + Ptr::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::Ref> >::Ref playlistIds; + Ptr::Ref + acquirePlaylist(Ptr::Ref oldPlaylist, + XmlRpcValue & result) const + throw (XmlRpcException); public: @@ -266,8 +313,10 @@ class WebStorageClient : virtual Ptr::Ref getPlaylist(Ptr::Ref sessionId, Ptr::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::Ref acquirePlaylist(Ptr::Ref sessionId, Ptr::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