modified the WebStorageClient to keep a cache of the playlists which are
currently being edited
This commit is contained in:
parent
72387302c0
commit
5a749c7977
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: fgerlits $
|
Author : $Author: fgerlits $
|
||||||
Version : $Revision: 1.30 $
|
Version : $Revision: 1.31 $
|
||||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.cxx,v $
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.cxx,v $
|
||||||
|
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
@ -300,17 +300,19 @@ TestStorageClient :: savePlaylist(Ptr<SessionId>::Ref sessionId,
|
||||||
editIt = editedPlaylists.find(playlist->getId()->getId());
|
editIt = editedPlaylists.find(playlist->getId()->getId());
|
||||||
|
|
||||||
if ((editIt == editedPlaylists.end())
|
if ((editIt == editedPlaylists.end())
|
||||||
|| (*playlist->getToken() != *editIt->second->getToken())) {
|
|| (*playlist->getToken() != *editIt->second->getToken())) {
|
||||||
throw XmlRpcException("savePlaylist() called without editPlaylist()");
|
throw XmlRpcException("savePlaylist() called without editPlaylist()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ptr<std::string>::Ref nullPointer;
|
||||||
|
playlist->setToken(nullPointer);
|
||||||
|
|
||||||
PlaylistMapType::iterator
|
PlaylistMapType::iterator
|
||||||
storeIt = playlistMap.find(playlist->getId()->getId());
|
storeIt = playlistMap.find(playlist->getId()->getId());
|
||||||
|
|
||||||
if (storeIt == playlistMap.end()) {
|
if (storeIt == playlistMap.end()) {
|
||||||
throw XmlRpcException("playlist deleted while it was being edited???");
|
throw XmlRpcException("playlist deleted while it was being edited???");
|
||||||
}
|
}
|
||||||
|
|
||||||
storeIt->second = playlist;
|
storeIt->second = playlist;
|
||||||
|
|
||||||
editedPlaylists.erase(editIt);
|
editedPlaylists.erase(editIt);
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: fgerlits $
|
Author : $Author: fgerlits $
|
||||||
Version : $Revision: 1.26 $
|
Version : $Revision: 1.27 $
|
||||||
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 $
|
||||||
|
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
@ -693,6 +693,14 @@ WebStorageClient :: getPlaylist(Ptr<SessionId>::Ref sessionId,
|
||||||
Ptr<UniqueId>::Ref id) const
|
Ptr<UniqueId>::Ref id) const
|
||||||
throw (Core::XmlRpcException)
|
throw (Core::XmlRpcException)
|
||||||
{
|
{
|
||||||
|
EditedPlaylistsType::const_iterator
|
||||||
|
editIt = editedPlaylists.find(id->getId());
|
||||||
|
|
||||||
|
if (editIt != editedPlaylists.end() // is being edited
|
||||||
|
&& (*editIt->second.first == *sessionId)) { // by us
|
||||||
|
return editIt->second.second;
|
||||||
|
}
|
||||||
|
|
||||||
XmlRpcValue parameters;
|
XmlRpcValue parameters;
|
||||||
XmlRpcValue result;
|
XmlRpcValue result;
|
||||||
|
|
||||||
|
@ -808,11 +816,16 @@ WebStorageClient :: editPlaylist(Ptr<SessionId>::Ref sessionId,
|
||||||
Ptr<UniqueId>::Ref id)
|
Ptr<UniqueId>::Ref id)
|
||||||
throw (Core::XmlRpcException)
|
throw (Core::XmlRpcException)
|
||||||
{
|
{
|
||||||
Ptr<Playlist>::Ref playlist(new Playlist(id));
|
if (editedPlaylists.find(id->getId()) != editedPlaylists.end()) {
|
||||||
|
throw XmlRpcInvalidArgumentException("playlist is already"
|
||||||
|
" being edited");
|
||||||
|
}
|
||||||
|
|
||||||
Ptr<const std::string>::Ref url, token;
|
Ptr<const std::string>::Ref url, token;
|
||||||
|
|
||||||
editPlaylistGetUrl(sessionId, id, url, token);
|
editPlaylistGetUrl(sessionId, id, url, token);
|
||||||
|
|
||||||
|
Ptr<Playlist>::Ref playlist(new Playlist(id));
|
||||||
try {
|
try {
|
||||||
Ptr<xmlpp::DomParser>::Ref parser(new xmlpp::DomParser());
|
Ptr<xmlpp::DomParser>::Ref parser(new xmlpp::DomParser());
|
||||||
parser->parse_file(*url);
|
parser->parse_file(*url);
|
||||||
|
@ -830,6 +843,7 @@ WebStorageClient :: editPlaylist(Ptr<SessionId>::Ref sessionId,
|
||||||
}
|
}
|
||||||
|
|
||||||
playlist->setToken(token);
|
playlist->setToken(token);
|
||||||
|
editedPlaylists[id->getId()] = std::make_pair(sessionId, playlist);
|
||||||
|
|
||||||
return playlist;
|
return playlist;
|
||||||
}
|
}
|
||||||
|
@ -905,6 +919,16 @@ WebStorageClient :: savePlaylist(Ptr<SessionId>::Ref sessionId,
|
||||||
throw XmlRpcInvalidArgumentException("playlist has no token field");
|
throw XmlRpcInvalidArgumentException("playlist has no token field");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EditedPlaylistsType::iterator
|
||||||
|
editIt = editedPlaylists.find(playlist->getId()->getId());
|
||||||
|
|
||||||
|
if ((editIt == editedPlaylists.end())
|
||||||
|
|| *editIt->second.first != *sessionId) {
|
||||||
|
throw XmlRpcInvalidArgumentException("savePlaylist() called without "
|
||||||
|
"editPlaylist()");
|
||||||
|
}
|
||||||
|
editedPlaylists.erase(editIt);
|
||||||
|
|
||||||
XmlRpcValue parameters;
|
XmlRpcValue parameters;
|
||||||
XmlRpcValue result;
|
XmlRpcValue result;
|
||||||
|
|
||||||
|
@ -1238,6 +1262,7 @@ WebStorageClient :: createPlaylist(Ptr<SessionId>::Ref sessionId)
|
||||||
Ptr<Playlist>::Ref playlist(new Playlist(newId, playlength));
|
Ptr<Playlist>::Ref playlist(new Playlist(newId, playlength));
|
||||||
playlist->setToken(token);
|
playlist->setToken(token);
|
||||||
|
|
||||||
|
editedPlaylists[newId->getId()] = std::make_pair(sessionId, playlist);
|
||||||
savePlaylist(sessionId, playlist);
|
savePlaylist(sessionId, playlist);
|
||||||
|
|
||||||
token.reset();
|
token.reset();
|
||||||
|
|
|
@ -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.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.18 $
|
* @version $Revision: 1.19 $
|
||||||
*/
|
*/
|
||||||
class WebStorageClient :
|
class WebStorageClient :
|
||||||
virtual public Configurable,
|
virtual public Configurable,
|
||||||
|
@ -131,6 +131,18 @@ class WebStorageClient :
|
||||||
*/
|
*/
|
||||||
std::string storageServerPath;
|
std::string storageServerPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type for the list of playlists which are currently being edited
|
||||||
|
*/
|
||||||
|
typedef std::map<const UniqueId::IdType,
|
||||||
|
std::pair<Ptr<SessionId>::Ref, Ptr<Playlist>::Ref> >
|
||||||
|
EditedPlaylistsType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of playlists which are currently being edited
|
||||||
|
*/
|
||||||
|
EditedPlaylistsType editedPlaylists;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auxilliary method used by editPlaylist() and createPlaylist().
|
* Auxilliary method used by editPlaylist() and createPlaylist().
|
||||||
* Opens the playlist for editing, and returns its URL.
|
* Opens the playlist for editing, and returns its URL.
|
||||||
|
@ -215,7 +227,12 @@ class WebStorageClient :
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a playlist with the specified id to be displayed.
|
* Return a playlist with the specified id to be displayed.
|
||||||
* If the playlist is being edited, its last saved state is returned.
|
* 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 sessionId the session ID from the authentication client
|
||||||
* @param id the id of the playlist to return.
|
* @param id the id of the playlist to return.
|
||||||
|
@ -235,6 +252,10 @@ class WebStorageClient :
|
||||||
* This puts a lock on the playlist, and nobody else can edit it
|
* This puts a lock on the playlist, and nobody else can edit it
|
||||||
* until we release it using savePlaylist().
|
* until we release it using savePlaylist().
|
||||||
*
|
*
|
||||||
|
* This method creates a working copy of the playlist, which will
|
||||||
|
* be returned by getPlaylist() if it is called with the same
|
||||||
|
* sessionId and playlistId, until we call savePlaylist().
|
||||||
|
*
|
||||||
* @param sessionId the session ID from the authentication client
|
* @param sessionId the session ID from the authentication client
|
||||||
* @param id the id of the playlist to return.
|
* @param id the id of the playlist to return.
|
||||||
* @return the requested playlist.
|
* @return the requested playlist.
|
||||||
|
@ -252,6 +273,8 @@ class WebStorageClient :
|
||||||
* Can only be called after we obtained a lock on the playlist using
|
* Can only be called after we obtained a lock on the playlist using
|
||||||
* editPlaylist(); this method releases the lock.
|
* editPlaylist(); this method releases the lock.
|
||||||
*
|
*
|
||||||
|
* This method destroys the working copy created by editPlaylist().
|
||||||
|
*
|
||||||
* @param sessionId the session ID from the authentication client
|
* @param sessionId the session ID from the authentication client
|
||||||
* @param playlist the playlist to save.
|
* @param playlist the playlist to save.
|
||||||
* @exception XmlRpcException if there is a problem with the XML-RPC
|
* @exception XmlRpcException if there is a problem with the XML-RPC
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: fgerlits $
|
Author : $Author: fgerlits $
|
||||||
Version : $Revision: 1.28 $
|
Version : $Revision: 1.29 $
|
||||||
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 $
|
||||||
|
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
@ -239,7 +239,7 @@ WebStorageClientTest :: playlistTest(void)
|
||||||
try {
|
try {
|
||||||
playlist = wsc->editPlaylist(sessionId, playlistIdxx);
|
playlist = wsc->editPlaylist(sessionId, playlistIdxx);
|
||||||
CPPUNIT_FAIL("allowed to open playlist for editing twice");
|
CPPUNIT_FAIL("allowed to open playlist for editing twice");
|
||||||
} catch (Core::XmlRpcMethodFaultException &e) {
|
} catch (Core::XmlRpcInvalidArgumentException &e) {
|
||||||
} catch (XmlRpcException &e) {
|
} catch (XmlRpcException &e) {
|
||||||
std::string eMsg = "editPlaylist() threw unexpected exception:\n";
|
std::string eMsg = "editPlaylist() threw unexpected exception:\n";
|
||||||
CPPUNIT_FAIL(eMsg + e.what());
|
CPPUNIT_FAIL(eMsg + e.what());
|
||||||
|
@ -265,9 +265,21 @@ WebStorageClientTest :: playlistTest(void)
|
||||||
try {
|
try {
|
||||||
Ptr<Playlist>::Ref throwAwayPlaylist
|
Ptr<Playlist>::Ref throwAwayPlaylist
|
||||||
= wsc->getPlaylist(sessionId, playlistIdxx);
|
= wsc->getPlaylist(sessionId, playlistIdxx);
|
||||||
// this should be OK, get old copy
|
// we are editing it, get another working copy
|
||||||
|
CPPUNIT_ASSERT(throwAwayPlaylist->getPlaylength()
|
||||||
|
->total_seconds() == 9);
|
||||||
|
} catch (XmlRpcException &e) {
|
||||||
|
CPPUNIT_FAIL(e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Ptr<SessionId>::Ref newSessionId = authentication->login("root", "q");
|
||||||
|
Ptr<Playlist>::Ref throwAwayPlaylist
|
||||||
|
= wsc->getPlaylist(newSessionId, playlistIdxx);
|
||||||
|
// somebody else is editing it, get the old copy
|
||||||
CPPUNIT_ASSERT(throwAwayPlaylist->getPlaylength()
|
CPPUNIT_ASSERT(throwAwayPlaylist->getPlaylength()
|
||||||
->total_seconds() == 0);
|
->total_seconds() == 0);
|
||||||
|
authentication->logout(newSessionId);
|
||||||
} catch (XmlRpcException &e) {
|
} catch (XmlRpcException &e) {
|
||||||
CPPUNIT_FAIL(e.what());
|
CPPUNIT_FAIL(e.what());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue