From 2f4b978834e7daca31fa48e2f5294b4b5190f96b Mon Sep 17 00:00:00 2001 From: fgerlits Date: Thu, 28 Jul 2005 17:24:47 +0000 Subject: [PATCH] now we save the playlist token, to be used in revertPlaylist(), to unlock any stuck edited playlist in case of a crash --- .../Storage/StorageClientInterface.h | 25 +++++- .../modules/storage/src/TestStorageClient.cxx | 14 +++- .../modules/storage/src/TestStorageClient.h | 24 +++++- .../modules/storage/src/WebStorageClient.cxx | 82 ++++++++++++++++++- .../modules/storage/src/WebStorageClient.h | 24 +++++- .../gLiveSupport/src/GLiveSupport.cxx | 67 ++++++++++++++- 6 files changed, 219 insertions(+), 17 deletions(-) diff --git a/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientInterface.h b/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientInterface.h index b9817763c..c75a8bef7 100644 --- a/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientInterface.h +++ b/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientInterface.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.17 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.18 $ 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. * - * @author $Author: maroy $ - * @version $Revision: 1.17 $ + * @author $Author: fgerlits $ + * @version $Revision: 1.18 $ */ class StorageClientInterface { @@ -176,6 +176,23 @@ class StorageClientInterface throw (XmlRpcException) = 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::Ref playlistToken) + throw (XmlRpcException) + = 0; + /** * Acquire the resources for the playlist. * The last saved copy of the playlist is read, and a local copy diff --git a/livesupport/modules/storage/src/TestStorageClient.cxx b/livesupport/modules/storage/src/TestStorageClient.cxx index 7eb3811d1..7db536950 100644 --- a/livesupport/modules/storage/src/TestStorageClient.cxx +++ b/livesupport/modules/storage/src/TestStorageClient.cxx @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -430,6 +430,18 @@ TestStorageClient :: savePlaylist(Ptr::Ref sessionId, } +/*------------------------------------------------------------------------------ + * Revert a playlist to its pre-editing state. + *----------------------------------------------------------------------------*/ +void +TestStorageClient :: revertPlaylist(Ptr::Ref playlistToken) + throw (XmlRpcException) +{ + std::cerr << "TestStorageClient :: revertPlaylist" + << " is NOT IMPLEMENTED." << std::endl; +} + + /*------------------------------------------------------------------------------ * Acquire resources for a playlist. *----------------------------------------------------------------------------*/ diff --git a/livesupport/modules/storage/src/TestStorageClient.h b/livesupport/modules/storage/src/TestStorageClient.h index ddc797cd3..147bdfa55 100644 --- a/livesupport/modules/storage/src/TestStorageClient.h +++ b/livesupport/modules/storage/src/TestStorageClient.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.36 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.37 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.h,v $ ------------------------------------------------------------------------------*/ @@ -85,8 +85,8 @@ using namespace LiveSupport::Core; * <!ATTLIST testStorage tempFiles CDATA #REQUIRED > * * - * @author $Author: maroy $ - * @version $Revision: 1.36 $ + * @author $Author: fgerlits $ + * @version $Revision: 1.37 $ */ class TestStorageClient : virtual public Configurable, @@ -314,6 +314,22 @@ class TestStorageClient : Ptr::Ref playlist) 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::Ref playlistToken) + throw (XmlRpcException); + /** * Acquire the resources for the playlist. diff --git a/livesupport/modules/storage/src/WebStorageClient.cxx b/livesupport/modules/storage/src/WebStorageClient.cxx index 11a7214eb..4929c99fb 100644 --- a/livesupport/modules/storage/src/WebStorageClient.cxx +++ b/livesupport/modules/storage/src/WebStorageClient.cxx @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -463,6 +463,30 @@ static const std::string savePlaylistNewPlaylistParamName = "newPlaylist"; 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 */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: existsAudioClip */ @@ -1176,6 +1200,62 @@ WebStorageClient :: savePlaylist(Ptr::Ref sessionId, } +/*------------------------------------------------------------------------------ + * Revert a playlist to its pre-editing state. + *----------------------------------------------------------------------------*/ +void +WebStorageClient :: revertPlaylist(Ptr::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. *----------------------------------------------------------------------------*/ diff --git a/livesupport/modules/storage/src/WebStorageClient.h b/livesupport/modules/storage/src/WebStorageClient.h index 9f2f7db3a..ace16b4f6 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: maroy $ - Version : $Revision: 1.31 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.32 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.h,v $ ------------------------------------------------------------------------------*/ @@ -95,8 +95,8 @@ using namespace LiveSupport::Core; * <!ATTLIST location path CDATA #REQUIRED > * * - * @author $Author: maroy $ - * @version $Revision: 1.31 $ + * @author $Author: fgerlits $ + * @version $Revision: 1.32 $ */ class WebStorageClient : virtual public Configurable, @@ -308,6 +308,22 @@ class WebStorageClient : Ptr::Ref playlist) 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::Ref playlistToken) + throw (XmlRpcException); + /** * Acquire the resources for the playlist. diff --git a/livesupport/products/gLiveSupport/src/GLiveSupport.cxx b/livesupport/products/gLiveSupport/src/GLiveSupport.cxx index e47cfcbe6..8b93dfa0d 100644 --- a/livesupport/products/gLiveSupport/src/GLiveSupport.cxx +++ b/livesupport/products/gLiveSupport/src/GLiveSupport.cxx @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -110,6 +110,11 @@ static const std::string stationLogoConfigElementName = "stationLogo"; *----------------------------------------------------------------------------*/ 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 *----------------------------------------------------------------------------*/ @@ -427,11 +432,32 @@ GLiveSupport :: login(const std::string & login, { try { sessionId = authentication->login(login, password); - loadScratchpadContents(); - return true; } catch (XmlRpcException &e) { return false; } + + try { + Ptr::Ref editedPlaylistToken; + editedPlaylistToken = authentication->loadPreferencesItem( + sessionId, + editedPlaylistTokenKey); + Ptr::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::Ref playlistId) } editedPlaylist = storage->editPlaylist(sessionId, playlistId); + + try { + Ptr::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(); masterPanel->updateSimplePlaylistMgmtWindow(); @@ -663,6 +704,16 @@ GLiveSupport :: cancelEditedPlaylist(void) if (editedPlaylist->isLocked()) { editedPlaylist->revertToSavedCopy(); 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(); } @@ -711,6 +762,16 @@ GLiveSupport :: savePlaylist(void) if (editedPlaylist->isLocked()) { editedPlaylist->deleteSavedCopy(); 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 } editedPlaylist.reset();