now we save the playlist token, to be used in revertPlaylist(), to unlock

any stuck edited playlist in case of a crash
This commit is contained in:
fgerlits 2005-07-28 17:24:47 +00:00
parent 8427aae7ac
commit 2f4b978834
6 changed files with 219 additions and 17 deletions

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $ Author : $Author: fgerlits $
Version : $Revision: 1.17 $ Version : $Revision: 1.18 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientInterface.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientInterface.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -65,8 +65,8 @@ using namespace Core;
/** /**
* An interface for storage clients. * An interface for storage clients.
* *
* @author $Author: maroy $ * @author $Author: fgerlits $
* @version $Revision: 1.17 $ * @version $Revision: 1.18 $
*/ */
class StorageClientInterface class StorageClientInterface
{ {
@ -176,6 +176,23 @@ class StorageClientInterface
throw (XmlRpcException) throw (XmlRpcException)
= 0; = 0;
/**
* Revert a playlist to its pre-editing state.
* This is only used for clean-up after crashes. If the GUI
* crashed while editing a playlist, it can release the lock on
* the playlist (and lose all changes) at the next login using
* this method.
*
* @param playlistToken the token of the edited playlist
* @exception XmlRpcException if there is a problem with the XML-RPC
* call or no playlist with the specified
* token exists.
*/
virtual void
revertPlaylist(Ptr<const std::string>::Ref playlistToken)
throw (XmlRpcException)
= 0;
/** /**
* Acquire the resources for the playlist. * Acquire the resources for the playlist.
* The last saved copy of the playlist is read, and a local copy * The last saved copy of the playlist is read, and a local copy

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.41 $ Version : $Revision: 1.42 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -430,6 +430,18 @@ TestStorageClient :: savePlaylist(Ptr<SessionId>::Ref sessionId,
} }
/*------------------------------------------------------------------------------
* Revert a playlist to its pre-editing state.
*----------------------------------------------------------------------------*/
void
TestStorageClient :: revertPlaylist(Ptr<const std::string>::Ref playlistToken)
throw (XmlRpcException)
{
std::cerr << "TestStorageClient :: revertPlaylist"
<< " is NOT IMPLEMENTED." << std::endl;
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Acquire resources for a playlist. * Acquire resources for a playlist.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $ Author : $Author: fgerlits $
Version : $Revision: 1.36 $ Version : $Revision: 1.37 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -85,8 +85,8 @@ using namespace LiveSupport::Core;
* &lt;!ATTLIST testStorage tempFiles CDATA #REQUIRED &gt; * &lt;!ATTLIST testStorage tempFiles CDATA #REQUIRED &gt;
* </code></pre> * </code></pre>
* *
* @author $Author: maroy $ * @author $Author: fgerlits $
* @version $Revision: 1.36 $ * @version $Revision: 1.37 $
*/ */
class TestStorageClient : class TestStorageClient :
virtual public Configurable, virtual public Configurable,
@ -314,6 +314,22 @@ class TestStorageClient :
Ptr<Playlist>::Ref playlist) Ptr<Playlist>::Ref playlist)
throw (XmlRpcException); throw (XmlRpcException);
/**
* Revert a playlist to its pre-editing state.
* This is only used for clean-up after crashes. If the GUI
* crashed while editing a playlist, it can release the lock on
* the playlist (and lose all changes) at the next login using
* this method.
*
* @param playlistToken the token of the edited playlist
* @exception XmlRpcException if there is a problem with the XML-RPC
* call or no playlist with the specified
* token exists.
*/
virtual void
revertPlaylist(Ptr<const std::string>::Ref playlistToken)
throw (XmlRpcException);
/** /**
* Acquire the resources for the playlist. * Acquire the resources for the playlist.

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.45 $ Version : $Revision: 1.46 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -463,6 +463,30 @@ static const std::string savePlaylistNewPlaylistParamName = "newPlaylist";
static const std::string savePlaylistResultParamName = "plid"; static const std::string savePlaylistResultParamName = "plid";
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: revertPlaylist */
/*------------------------------------------------------------------------------
* The name of the 'revert playlist' method on the storage server
*----------------------------------------------------------------------------*/
static const std::string revertPlaylistMethodName
= "locstor.revertEditedPlaylist";
/*------------------------------------------------------------------------------
* The name of the session ID parameter in the input structure
*----------------------------------------------------------------------------*/
static const std::string revertPlaylistSessionIdParamName = "sessid";
/*------------------------------------------------------------------------------
* The name of the token parameter in the input structure
*----------------------------------------------------------------------------*/
static const std::string revertPlaylistTokenParamName = "token";
/*------------------------------------------------------------------------------
* The name of the result parameter returned by the method
*----------------------------------------------------------------------------*/
static const std::string revertPlaylistResultParamName = "plid";
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ audio clip methods */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ audio clip methods */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: existsAudioClip */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: existsAudioClip */
@ -1176,6 +1200,62 @@ WebStorageClient :: savePlaylist(Ptr<SessionId>::Ref sessionId,
} }
/*------------------------------------------------------------------------------
* Revert a playlist to its pre-editing state.
*----------------------------------------------------------------------------*/
void
WebStorageClient :: revertPlaylist(Ptr<const Glib::ustring>::Ref playlistToken)
throw (XmlRpcException)
{
if (!playlistToken) {
throw XmlRpcInvalidArgumentException("null pointer in argument");
}
XmlRpcValue parameters;
XmlRpcValue result;
XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort,
storageServerPath.c_str(), false);
parameters.clear();
parameters[revertPlaylistSessionIdParamName] // dummy parameter
= "";
parameters[revertPlaylistTokenParamName]
= *playlistToken;
result.clear();
if (!xmlRpcClient.execute(revertPlaylistMethodName.c_str(),
parameters, result)) {
xmlRpcClient.close();
std::string eMsg = "cannot execute XML-RPC method '";
eMsg += revertPlaylistMethodName;
eMsg += "'";
throw XmlRpcCommunicationException(eMsg);
}
xmlRpcClient.close();
if (xmlRpcClient.isFault()) {
std::stringstream eMsg;
eMsg << "XML-RPC method '"
<< revertPlaylistMethodName
<< "' returned error message:\n"
<< result;
throw Core::XmlRpcMethodFaultException(eMsg.str());
}
if (! result.hasMember(revertPlaylistResultParamName)
|| result[revertPlaylistResultParamName].getType()
!= XmlRpcValue::TypeString) {
std::stringstream eMsg;
eMsg << "XML-RPC method '"
<< revertPlaylistMethodName
<< "' returned unexpected value:\n"
<< result;
throw XmlRpcMethodResponseException(eMsg.str());
}
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Acquire resources for a playlist. * Acquire resources for a playlist.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $ Author : $Author: fgerlits $
Version : $Revision: 1.31 $ Version : $Revision: 1.32 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -95,8 +95,8 @@ using namespace LiveSupport::Core;
* &lt;!ATTLIST location path CDATA #REQUIRED &gt; * &lt;!ATTLIST location path CDATA #REQUIRED &gt;
* </code></pre> * </code></pre>
* *
* @author $Author: maroy $ * @author $Author: fgerlits $
* @version $Revision: 1.31 $ * @version $Revision: 1.32 $
*/ */
class WebStorageClient : class WebStorageClient :
virtual public Configurable, virtual public Configurable,
@ -308,6 +308,22 @@ class WebStorageClient :
Ptr<Playlist>::Ref playlist) Ptr<Playlist>::Ref playlist)
throw (XmlRpcException); throw (XmlRpcException);
/**
* Revert a playlist to its pre-editing state.
* This is only used for clean-up after crashes. If the GUI
* crashed while editing a playlist, it can release the lock on
* the playlist (and lose all changes) at the next login using
* this method.
*
* @param playlistToken the token of the edited playlist
* @exception XmlRpcException if there is a problem with the XML-RPC
* call or no playlist with the specified
* token exists.
*/
virtual void
revertPlaylist(Ptr<const std::string>::Ref playlistToken)
throw (XmlRpcException);
/** /**
* Acquire the resources for the playlist. * Acquire the resources for the playlist.

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.62 $ Version : $Revision: 1.63 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -110,6 +110,11 @@ static const std::string stationLogoConfigElementName = "stationLogo";
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
static const std::string scratchpadContentsKey = "scratchpadContents"; static const std::string scratchpadContentsKey = "scratchpadContents";
/*------------------------------------------------------------------------------
* The name of the user preference for storing the token of the edited p.l.
*----------------------------------------------------------------------------*/
static const std::string editedPlaylistTokenKey = "editedPlaylistToken";
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Static constant for the key of the scheduler not available key * Static constant for the key of the scheduler not available key
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
@ -427,11 +432,32 @@ GLiveSupport :: login(const std::string & login,
{ {
try { try {
sessionId = authentication->login(login, password); sessionId = authentication->login(login, password);
loadScratchpadContents();
return true;
} catch (XmlRpcException &e) { } catch (XmlRpcException &e) {
return false; return false;
} }
try {
Ptr<const Glib::ustring>::Ref editedPlaylistToken;
editedPlaylistToken = authentication->loadPreferencesItem(
sessionId,
editedPlaylistTokenKey);
Ptr<const std::string>::Ref editedPlaylistTokenString(
new const std::string(
*editedPlaylistToken ));
storage->revertPlaylist(editedPlaylistTokenString);
} catch (std::invalid_argument &e) {
// no stuck playlist token found; that's OK
} catch (XmlRpcException &e) {
std::cerr << "Problem loading "
<< editedPlaylistTokenKey
<< " user preference item:"
<< std::endl
<< e.what();
}
loadScratchpadContents();
return true;
} }
@ -643,6 +669,21 @@ GLiveSupport :: openPlaylistForEditing(Ptr<UniqueId>::Ref playlistId)
} }
editedPlaylist = storage->editPlaylist(sessionId, playlistId); editedPlaylist = storage->editPlaylist(sessionId, playlistId);
try {
Ptr<const Glib::ustring>::Ref token(new const Glib::ustring(
*editedPlaylist->getToken() ));
authentication->savePreferencesItem(sessionId,
editedPlaylistTokenKey,
token);
} catch (XmlRpcException &e) {
std::cerr << "Problem saving "
<< editedPlaylistTokenKey
<< " user preference item:"
<< std::endl
<< e.what();
}
editedPlaylist->createSavedCopy(); editedPlaylist->createSavedCopy();
masterPanel->updateSimplePlaylistMgmtWindow(); masterPanel->updateSimplePlaylistMgmtWindow();
@ -663,6 +704,16 @@ GLiveSupport :: cancelEditedPlaylist(void)
if (editedPlaylist->isLocked()) { if (editedPlaylist->isLocked()) {
editedPlaylist->revertToSavedCopy(); editedPlaylist->revertToSavedCopy();
storage->savePlaylist(sessionId, editedPlaylist); storage->savePlaylist(sessionId, editedPlaylist);
try {
authentication->deletePreferencesItem(sessionId,
editedPlaylistTokenKey);
} catch (XmlRpcException &e) {
std::cerr << "Problem deleting "
<< editedPlaylistTokenKey
<< " user preference item:"
<< std::endl
<< e.what();
}
} }
editedPlaylist.reset(); editedPlaylist.reset();
} }
@ -711,6 +762,16 @@ GLiveSupport :: savePlaylist(void)
if (editedPlaylist->isLocked()) { if (editedPlaylist->isLocked()) {
editedPlaylist->deleteSavedCopy(); editedPlaylist->deleteSavedCopy();
storage->savePlaylist(sessionId, editedPlaylist); storage->savePlaylist(sessionId, editedPlaylist);
try {
authentication->deletePreferencesItem(sessionId,
editedPlaylistTokenKey);
} catch (XmlRpcException &e) {
std::cerr << "Problem deleting "
<< editedPlaylistTokenKey
<< " user preference item:"
<< std::endl
<< e.what();
}
addToScratchpad(editedPlaylist); // update with new version addToScratchpad(editedPlaylist); // update with new version
} }
editedPlaylist.reset(); editedPlaylist.reset();