diff --git a/livesupport/modules/storage/src/WebStorageClient.cxx b/livesupport/modules/storage/src/WebStorageClient.cxx index 734010f6b..266d4a997 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.27 $ + Version : $Revision: 1.28 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $ ------------------------------------------------------------------------------*/ @@ -187,13 +187,42 @@ static const std::string resetStorageMethodName = "locstor.resetStorage"; /*------------------------------------------------------------------------------ - * The name of the result parameter returned by the method + * The name of the audio clips result parameter returned by the method *----------------------------------------------------------------------------*/ -static const std::string resetStorageResultParamName = "gunids"; +static const std::string resetStorageAudioClipResultParamName = "audioclips"; + +/*------------------------------------------------------------------------------ + * The name of the playlists result parameter returned by the method + *----------------------------------------------------------------------------*/ +static const std::string resetStoragePlaylistResultParamName = "playlists"; /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ playlist methods */ +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: createPlaylist */ + +/*------------------------------------------------------------------------------ + * The name of the create playlist method on the storage server + *----------------------------------------------------------------------------*/ +static const std::string createPlaylistMethodName + = "locstor.createPlaylist"; + +/*------------------------------------------------------------------------------ + * The name of the session ID parameter in the input structure + *----------------------------------------------------------------------------*/ +static const std::string createPlaylistSessionIdParamName = "sessid"; + +/*------------------------------------------------------------------------------ + * The name of the playlist unique ID parameter in the input structure + *----------------------------------------------------------------------------*/ +static const std::string createPlaylistPlaylistIdParamName = "plid"; + +/*------------------------------------------------------------------------------ + * The name of the result parameter returned by the method + *----------------------------------------------------------------------------*/ +static const std::string createPlaylistResultParamName = "plid"; + + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: existsPlaylist */ /*------------------------------------------------------------------------------ @@ -314,7 +343,7 @@ static const std::string savePlaylistNewPlaylistParamName = "newPlaylist"; /*------------------------------------------------------------------------------ * The name of the result parameter returned by the method *----------------------------------------------------------------------------*/ -static const std::string savePlaylistResultParamName = "status"; +static const std::string savePlaylistResultParamName = "plid"; /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: deletePlaylist */ @@ -341,30 +370,6 @@ static const std::string deletePlaylistPlaylistIdParamName = "plid"; static const std::string deletePlaylistResultParamName = "status"; -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: createPlaylist */ - -/*------------------------------------------------------------------------------ - * The name of the create playlist method on the storage server - *----------------------------------------------------------------------------*/ -static const std::string createPlaylistMethodName - = "locstor.createPlaylist"; - -/*------------------------------------------------------------------------------ - * The name of the session ID parameter in the input structure - *----------------------------------------------------------------------------*/ -static const std::string createPlaylistSessionIdParamName = "sessid"; - -/*------------------------------------------------------------------------------ - * The name of the playlist unique ID parameter in the input structure - *----------------------------------------------------------------------------*/ -static const std::string createPlaylistPlaylistIdParamName = "plid"; - -/*------------------------------------------------------------------------------ - * The name of the result parameter returned by the method - *----------------------------------------------------------------------------*/ -static const std::string createPlaylistResultParamName = "plid"; - - /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ audio clip methods */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: existsAudioClip */ @@ -630,6 +635,75 @@ WebStorageClient :: configure(const xmlpp::Element & element) } +/*------------------------------------------------------------------------------ + * Create a new playlist. + *----------------------------------------------------------------------------*/ +Ptr::Ref +WebStorageClient :: createPlaylist(Ptr::Ref sessionId) + throw (Core::XmlRpcException) +{ + XmlRpcValue parameters; + XmlRpcValue result; + + XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort, + storageServerPath.c_str(), false); + + parameters.clear(); + parameters[createPlaylistSessionIdParamName] + = sessionId->getId(); + + result.clear(); + if (!xmlRpcClient.execute(createPlaylistMethodName.c_str(), + parameters, result)) { + xmlRpcClient.close(); + std::string eMsg = "cannot execute XML-RPC method '"; + eMsg += createPlaylistMethodName; + eMsg += "'"; + throw XmlRpcCommunicationException(eMsg); + } + xmlRpcClient.close(); + + if (xmlRpcClient.isFault()) { + std::stringstream eMsg; + eMsg << "XML-RPC method '" + << createPlaylistMethodName + << "' returned error message:\n" + << result; + throw XmlRpcMethodFaultException(eMsg.str()); + } + + if (! result.hasMember(createPlaylistResultParamName) + || result[createPlaylistResultParamName].getType() + != XmlRpcValue::TypeString) { + std::stringstream eMsg; + eMsg << "XML-RPC method '" + << createPlaylistMethodName + << "' returned unexpected value:\n" + << result; + throw XmlRpcMethodResponseException(eMsg.str()); + } + + Ptr::Ref newId(new UniqueId(std::string( + result[createPlaylistResultParamName] ))); + + Ptr::Ref url, token; + + editPlaylistGetUrl(sessionId, newId, url, token); + + Ptr::Ref playlength(new time_duration(0,0,0,0)); + Ptr::Ref playlist(new Playlist(newId, playlength)); + playlist->setToken(token); + + editedPlaylists[newId->getId()] = std::make_pair(sessionId, playlist); + savePlaylist(sessionId, playlist); + + token.reset(); + playlist->setToken(token); + + return playlist->getId(); +} + + /*------------------------------------------------------------------------------ * Tell if a playlist exists. *----------------------------------------------------------------------------*/ @@ -965,7 +1039,9 @@ WebStorageClient :: savePlaylist(Ptr::Ref sessionId, if (! result.hasMember(savePlaylistResultParamName) || result[savePlaylistResultParamName].getType() - != XmlRpcValue::TypeBoolean) { + != XmlRpcValue::TypeString + || std::string(result[savePlaylistResultParamName]) + != std::string(*playlist->getId())) { std::stringstream eMsg; eMsg << "XML-RPC method '" << savePlaylistMethodName @@ -974,14 +1050,6 @@ WebStorageClient :: savePlaylist(Ptr::Ref sessionId, throw XmlRpcMethodResponseException(eMsg.str()); } - if (! bool(result[savePlaylistResultParamName])) { - std::stringstream eMsg; - eMsg << "XML-RPC method '" - << savePlaylistMethodName - << "' returned 'false'"; - throw XmlRpcMethodResponseException(eMsg.str()); - } - Ptr::Ref nullpointer; playlist->setToken(nullpointer); } @@ -1201,77 +1269,6 @@ WebStorageClient :: getAllPlaylists(Ptr::Ref sessionId) const } -/*------------------------------------------------------------------------------ - * Create a new playlist. - *----------------------------------------------------------------------------*/ -Ptr::Ref -WebStorageClient :: createPlaylist(Ptr::Ref sessionId) - throw (Core::XmlRpcException) -{ - XmlRpcValue parameters; - XmlRpcValue result; - - XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort, - storageServerPath.c_str(), false); - - parameters.clear(); - parameters[createPlaylistSessionIdParamName] - = sessionId->getId(); - - result.clear(); - if (!xmlRpcClient.execute(createPlaylistMethodName.c_str(), - parameters, result)) { - xmlRpcClient.close(); - std::string eMsg = "cannot execute XML-RPC method '"; - eMsg += createPlaylistMethodName; - eMsg += "'"; - throw XmlRpcCommunicationException(eMsg); - } - xmlRpcClient.close(); - - if (xmlRpcClient.isFault()) { - std::stringstream eMsg; - eMsg << "XML-RPC method '" - << createPlaylistMethodName - << "' returned error message:\n" - << result; - throw XmlRpcMethodFaultException(eMsg.str()); - } - - if (! result.hasMember(createPlaylistResultParamName) - || result[createPlaylistResultParamName].getType() - != XmlRpcValue::TypeString) { - std::stringstream eMsg; - eMsg << "XML-RPC method '" - << createPlaylistMethodName - << "' returned unexpected value:\n" - << result; - throw XmlRpcMethodResponseException(eMsg.str()); - } - - Ptr::Ref newId(new UniqueId(std::string( - result[createPlaylistResultParamName] ))); -// std::cerr << "\nnew id: " -// << std::string(result[createPlaylistResultParamName]) << "\n"; - - Ptr::Ref url, token; - - editPlaylistGetUrl(sessionId, newId, url, token); - - Ptr::Ref playlength(new time_duration(0,0,0,0)); - Ptr::Ref playlist(new Playlist(newId, playlength)); - playlist->setToken(token); - - editedPlaylists[newId->getId()] = std::make_pair(sessionId, playlist); - savePlaylist(sessionId, playlist); - - token.reset(); - playlist->setToken(token); - - return playlist->getId(); -} - - /*------------------------------------------------------------------------------ * Tell if an audio clip exists. *----------------------------------------------------------------------------*/ @@ -1819,7 +1816,7 @@ WebStorageClient :: getAllAudioClips(Ptr::Ref sessionId) /*------------------------------------------------------------------------------ * Reset the storage to its initial state. *----------------------------------------------------------------------------*/ -Ptr::Ref> >::Ref +void WebStorageClient :: reset(void) throw (Core::XmlRpcException) { @@ -1852,8 +1849,11 @@ WebStorageClient :: reset(void) throw XmlRpcMethodFaultException(eMsg.str()); } - if (! result.hasMember(resetStorageResultParamName) - || result[resetStorageResultParamName].getType() + if (! result.hasMember(resetStorageAudioClipResultParamName) + || result[resetStorageAudioClipResultParamName].getType() + != XmlRpcValue::TypeArray + || ! result.hasMember(resetStoragePlaylistResultParamName) + || result[resetStoragePlaylistResultParamName].getType() != XmlRpcValue::TypeArray) { std::stringstream eMsg; eMsg << "XML-RPC method '" @@ -1863,23 +1863,38 @@ WebStorageClient :: reset(void) throw XmlRpcMethodResponseException(eMsg.str()); } - XmlRpcValue uniqueIdArray = result[resetStorageResultParamName]; - Ptr::Ref> >::Ref returnValue( - new std::vector::Ref>); + XmlRpcValue audioClipArray = result[resetStorageAudioClipResultParamName]; + testAudioClipIds.reset(new std::vector::Ref>); - for (int i=0; i < uniqueIdArray.size(); i++) { - if (uniqueIdArray[i].getType() != XmlRpcValue::TypeString) { + for (int i=0; i < audioClipArray.size(); i++) { + if (audioClipArray[i].getType() != XmlRpcValue::TypeString) { std::stringstream eMsg; - eMsg << "Non-string gunid returned by XML-RPC method '" + eMsg << "Non-string audio clip gunid returned by XML-RPC method '" << resetStorageMethodName << "':\n" << result; throw XmlRpcMethodResponseException(eMsg.str()); } - Ptr::Ref uniqueId(new UniqueId(std::string(uniqueIdArray[i]))); - returnValue->push_back(uniqueId); + Ptr::Ref uniqueId(new UniqueId(std::string( + audioClipArray[i]))); + testAudioClipIds->push_back(uniqueId); } + + XmlRpcValue playlistArray = result[resetStoragePlaylistResultParamName]; + testPlaylistIds.reset(new std::vector::Ref>); - return returnValue; + for (int i=0; i < playlistArray.size(); i++) { + if (playlistArray[i].getType() != XmlRpcValue::TypeString) { + std::stringstream eMsg; + eMsg << "Non-string audio clip gunid returned by XML-RPC method '" + << resetStorageMethodName + << "':\n" + << result; + throw XmlRpcMethodResponseException(eMsg.str()); + } + Ptr::Ref uniqueId(new UniqueId(std::string( + playlistArray[i]))); + testPlaylistIds->push_back(uniqueId); + } } diff --git a/livesupport/modules/storage/src/WebStorageClient.h b/livesupport/modules/storage/src/WebStorageClient.h index a485828fa..7825c6965 100644 --- a/livesupport/modules/storage/src/WebStorageClient.h +++ b/livesupport/modules/storage/src/WebStorageClient.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.19 $ + Version : $Revision: 1.20 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.h,v $ ------------------------------------------------------------------------------*/ @@ -99,7 +99,7 @@ using namespace LiveSupport::Core; * * * @author $Author: fgerlits $ - * @version $Revision: 1.19 $ + * @version $Revision: 1.20 $ */ class WebStorageClient : virtual public Configurable, @@ -506,13 +506,25 @@ class WebStorageClient : /** - * Reset the storage to its initial state. Used for testing. + * A vector containing the unique IDs of the audio clips in the + * storage. Set by reset(). Used for testing. + */ + Ptr::Ref> >::Ref testAudioClipIds; + + /** + * A vector containing the unique IDs of the playlists in the + * storage. Set by reset(). Used for testing. + */ + Ptr::Ref> >::Ref testPlaylistIds; + + /** + * Reset the storage to its initial state. + * Calls locstor.resetStorage, and puts the unique IDs returned + * into testAudioClipIds and testPlaylistIds. Used for testing. * - * @return a vector containing the UniqueId's of the audio clips - * in the storage after the reset. * @exception XmlRpcException if the server returns an error. */ - Ptr::Ref> >::Ref + void reset(void) throw (XmlRpcException); }; diff --git a/livesupport/modules/storage/src/WebStorageClientTest.cxx b/livesupport/modules/storage/src/WebStorageClientTest.cxx index 3508e5242..0ff30f5cc 100644 --- a/livesupport/modules/storage/src/WebStorageClientTest.cxx +++ b/livesupport/modules/storage/src/WebStorageClientTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.29 $ + Version : $Revision: 1.30 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -181,14 +181,13 @@ void WebStorageClientTest :: playlistTest(void) throw (CPPUNIT_NS::Exception) { - Ptr::Ref> >::Ref uniqueIdVector; try { - uniqueIdVector = wsc->reset(); + wsc->reset(); } catch (XmlRpcException &e) { CPPUNIT_FAIL(e.what()); } - CPPUNIT_ASSERT(uniqueIdVector->size() >= 3); - Ptr::Ref audioClipId = uniqueIdVector->at(0); + CPPUNIT_ASSERT(wsc->testAudioClipIds->size() >= 3); + Ptr::Ref audioClipId = wsc->testAudioClipIds->at(0); Ptr::Ref sessionId; try { @@ -361,18 +360,18 @@ void WebStorageClientTest :: audioClipTest(void) throw (CPPUNIT_NS::Exception) { - Ptr::Ref> >::Ref uniqueIdVector; try { - uniqueIdVector = wsc->reset(); + wsc->reset(); } catch (XmlRpcException &e) { CPPUNIT_FAIL(e.what()); } - CPPUNIT_ASSERT(uniqueIdVector->size() >= 2); - Ptr::Ref id01 = uniqueIdVector->at(1); + CPPUNIT_ASSERT(wsc->testAudioClipIds->size() >= 2); + Ptr::Ref id01 = wsc->testAudioClipIds->at(1); // std::cout << "\nReset storage result:\n"; -// for (unsigned i=0; isize(); i++) { -// std::cout << std::hex << std::string(*uniqueIdVector->at(i)) << std::endl; +// for (unsigned i=0; i < wsc->testAudioClipIds->size(); i++) { +// std::cout << std::hex << std::string(*wsc->testAudioClipIds->at(i)) +// << std::endl; // } Ptr::Ref sessionId; @@ -500,14 +499,13 @@ void WebStorageClientTest :: simplePlaylistTest(void) throw (CPPUNIT_NS::Exception) { - Ptr::Ref> >::Ref uniqueIdVector; try { - uniqueIdVector = wsc->reset(); + wsc->reset(); } catch (XmlRpcException &e) { CPPUNIT_FAIL(e.what()); } - CPPUNIT_ASSERT(uniqueIdVector->size() >= 3); - Ptr::Ref audioClipId = uniqueIdVector->at(0); + CPPUNIT_ASSERT(wsc->testAudioClipIds->size() >= 3); + Ptr::Ref audioClipId = wsc->testAudioClipIds->at(0); Ptr::Ref sessionId; try {