From 680d7eccf9782c8a7bd1320f7c1b9a745c2cbecc Mon Sep 17 00:00:00 2001 From: fgerlits Date: Fri, 22 Oct 2004 12:48:58 +0000 Subject: [PATCH] ugh - cleaned up the mess I made earlier when I added the error reporting to the XML-RPC server methods... it works now, I think --- .../src/AddAudioClipToPlaylistMethod.cxx | 20 +-- .../src/AddAudioClipToPlaylistMethod.h | 7 +- .../src/AddAudioClipToPlaylistMethodTest.cxx | 32 +++-- .../src/CreatePlaylistMethodTest.cxx | 13 +- .../scheduler/src/DeletePlaylistMethod.cxx | 84 +++++++------ .../scheduler/src/DeletePlaylistMethod.h | 24 ++-- .../src/DeletePlaylistMethodTest.cxx | 52 ++++++-- .../scheduler/src/DisplayAudioClipMethod.cxx | 9 +- .../src/DisplayAudioClipMethodTest.cxx | 14 ++- .../src/DisplayAudioClipsMethodTest.cxx | 3 +- .../scheduler/src/DisplayPlaylistMethod.cxx | 70 ++++++----- .../scheduler/src/DisplayPlaylistMethod.h | 23 +++- .../src/DisplayPlaylistMethodTest.cxx | 29 +++-- .../src/DisplayPlaylistsMethodTest.cxx | 3 +- .../scheduler/src/DisplayScheduleMethod.cxx | 66 ++++++---- .../scheduler/src/DisplayScheduleMethod.h | 22 +++- .../src/DisplayScheduleMethodTest.cxx | 28 +++-- .../src/OpenPlaylistForEditingMethod.cxx | 9 +- .../src/OpenPlaylistForEditingMethodTest.cxx | 18 ++- .../src/RemoveAudioClipFromPlaylistMethod.cxx | 10 +- .../RemoveAudioClipFromPlaylistMethodTest.cxx | 28 +++-- .../src/RemoveFromScheduleMethod.cxx | 61 ++++----- .../scheduler/src/RemoveFromScheduleMethod.h | 22 +++- .../src/RemoveFromScheduleMethodTest.cxx | 39 +++--- .../scheduler/src/RescheduleMethod.cxx | 79 +++++++----- .../products/scheduler/src/RescheduleMethod.h | 26 +++- .../scheduler/src/RescheduleMethodTest.cxx | 31 ++--- .../src/RevertEditedPlaylistMethod.cxx | 7 +- .../src/RevertEditedPlaylistMethodTest.cxx | 28 +++-- .../scheduler/src/SavePlaylistMethod.cxx | 7 +- .../scheduler/src/SavePlaylistMethodTest.cxx | 15 ++- .../SchedulerDaemonDisplayPlaylistTest.cxx | 12 +- .../SchedulerDaemonDisplayScheduleTest.cxx | 12 +- .../SchedulerDaemonRemoveFromScheduleTest.cxx | 22 ++-- .../src/SchedulerDaemonRescheduleTest.cxx | 22 ++-- .../scheduler/src/SchedulerDaemonTest.cxx | 6 +- .../src/SchedulerDaemonUploadTest.cxx | 10 +- .../scheduler/src/UploadPlaylistMethod.cxx | 118 +++++++++++------- .../scheduler/src/UploadPlaylistMethod.h | 34 ++++- .../src/UploadPlaylistMethodTest.cxx | 42 ++++--- .../scheduler/src/ValidatePlaylistMethod.cxx | 9 +- .../src/ValidatePlaylistMethodTest.cxx | 18 ++- .../products/scheduler/src/XmlRpcTools.cxx | 15 ++- .../products/scheduler/src/XmlRpcTools.h | 16 ++- 44 files changed, 769 insertions(+), 446 deletions(-) diff --git a/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethod.cxx b/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethod.cxx index 9e6c0a262..15951a934 100644 --- a/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethod.cxx +++ b/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.4 $ + Version : $Revision: 1.5 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -96,22 +96,24 @@ AddAudioClipToPlaylistMethod :: AddAudioClipToPlaylistMethod ( * Execute the stop XML-RPC function call. *----------------------------------------------------------------------------*/ void -AddAudioClipToPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, +AddAudioClipToPlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, XmlRpc::XmlRpcValue & returnValue) - throw () + throw () { - if (!parameters.valid()) { + if (!rootParameter.valid() || rootParameter.size() != 1) { XmlRpcTools::markError(errorId+1, "invalid argument format", returnValue); return; } + XmlRpc::XmlRpcValue parameters = rootParameter[0]; Ptr::Ref playlistId; try{ playlistId = XmlRpcTools::extractPlaylistId(parameters); } catch (std::invalid_argument &e) { - XmlRpcTools::markError(errorId+2, e.what(), returnValue); + XmlRpcTools::markError(errorId+2, "missing playlist ID argument", + returnValue); return; } @@ -120,7 +122,8 @@ AddAudioClipToPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, audioClipId = XmlRpcTools::extractAudioClipId(parameters); } catch (std::invalid_argument &e) { - XmlRpcTools::markError(errorId+3, e.what(), returnValue); + XmlRpcTools::markError(errorId+3, "missing audio clip ID argument", + returnValue); return; } @@ -129,7 +132,8 @@ AddAudioClipToPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, relativeOffset = XmlRpcTools::extractRelativeOffset(parameters); } catch (std::invalid_argument &e) { - XmlRpcTools::markError(errorId+4, e.what(), returnValue); + XmlRpcTools::markError(errorId+4, "missing relative offset argument", + returnValue); return; } @@ -143,7 +147,7 @@ AddAudioClipToPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, playlist = storage->getPlaylist(playlistId); } catch (std::invalid_argument &e) { - XmlRpcTools::markError(errorId+5, "playlist does not exist", + XmlRpcTools::markError(errorId+5, "playlist not found", returnValue); return; } diff --git a/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethod.h b/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethod.h index d2680d48f..1cc8616bf 100644 --- a/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethod.h +++ b/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethod.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethod.h,v $ ------------------------------------------------------------------------------*/ @@ -91,13 +91,14 @@ using namespace LiveSupport::Core; *
  • 302 - missing playlist ID argument
  • *
  • 303 - missing audio clip ID argument
  • *
  • 304 - missing relative offset argument
  • - *
  • 305 - playlist does not exist
  • + *
  • 305 - playlist not found
  • *
  • 306 - playlist has not been opened for editing
  • *
  • 307 - audio clip does not exist
  • *
  • 308 - two audio clips at the same relative offset
  • * + * * @author $Author: fgerlits $ - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ class AddAudioClipToPlaylistMethod : public XmlRpc::XmlRpcServerMethod { diff --git a/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethodTest.cxx b/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethodTest.cxx index 9987116db..6a2bcc5e9 100644 --- a/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethodTest.cxx +++ b/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.4 $ + Version : $Revision: 1.5 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -147,23 +147,31 @@ AddAudioClipToPlaylistMethodTest :: firstTest(void) openPlaylistMethod(new OpenPlaylistForEditingMethod()); Ptr::Ref addAudioClipMethod(new AddAudioClipToPlaylistMethod()); - XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; - parameter["playlistId"] = 1; - parameter["audioClipId"] = 10001; - parameter["relativeOffset"] = 60*60; + parameters["playlistId"] = 1; + parameters["audioClipId"] = 10001; + parameters["relativeOffset"] = 60*60; + rootParameter[0] = parameters; - openPlaylistMethod->execute(parameter, result); - addAudioClipMethod->execute(parameter, result); + result.clear(); + openPlaylistMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); + result.clear(); + addAudioClipMethod->execute(rootParameter, result); CPPUNIT_ASSERT(result.hasMember("errorCode")); CPPUNIT_ASSERT((int)(result["errorCode"]) == 308); - parameter.clear(); + parameters.clear(); + parameters["playlistId"] = 1; + parameters["audioClipId"] = 10001; + parameters["relativeOffset"] = 90*60; + rootParameter[0] = parameters; + result.clear(); - parameter["playlistId"] = 1; - parameter["audioClipId"] = 10001; - parameter["relativeOffset"] = 90*60; - addAudioClipMethod->execute(parameter, result); + addAudioClipMethod->execute(rootParameter, result); CPPUNIT_ASSERT(!result.hasMember("errorCode")); } diff --git a/livesupport/products/scheduler/src/CreatePlaylistMethodTest.cxx b/livesupport/products/scheduler/src/CreatePlaylistMethodTest.cxx index e2edd6a60..aa1bcaa2b 100644 --- a/livesupport/products/scheduler/src/CreatePlaylistMethodTest.cxx +++ b/livesupport/products/scheduler/src/CreatePlaylistMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.6 $ + Version : $Revision: 1.7 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/CreatePlaylistMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -142,19 +142,24 @@ CreatePlaylistMethodTest :: firstTest(void) { Ptr::Ref method(new CreatePlaylistMethod()); XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; - method->execute(parameter, result); + result.clear(); + method->execute(rootParameter, result); CPPUNIT_ASSERT(result.hasMember("id")); CPPUNIT_ASSERT(((int) result["playlength"]) == 0); int playlistId = (int) result["id"]; method.reset(new OpenPlaylistForEditingMethod()); parameter.clear(); - result.clear(); parameter["playlistId"] = playlistId; + rootParameter[0] = parameter; // should not allow to open the same playlist for editing again - method->execute(parameter, result); + result.clear(); + method->execute(rootParameter, result); + CPPUNIT_ASSERT(result.hasMember("errorCode")); CPPUNIT_ASSERT((int) result["errorCode"] == 105); } diff --git a/livesupport/products/scheduler/src/DeletePlaylistMethod.cxx b/livesupport/products/scheduler/src/DeletePlaylistMethod.cxx index dd1a89a4e..9f7e0957b 100644 --- a/livesupport/products/scheduler/src/DeletePlaylistMethod.cxx +++ b/livesupport/products/scheduler/src/DeletePlaylistMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/DeletePlaylistMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -61,10 +61,9 @@ using namespace LiveSupport::Scheduler; const std::string DeletePlaylistMethod::methodName = "deletePlaylist"; /*------------------------------------------------------------------------------ - * The name of the playlistId member in the XML-RPC parameter - * structure. + * The ID of this method for error reporting purposes. *----------------------------------------------------------------------------*/ -const std::string DeletePlaylistMethod::playlistIdName = "playlistId"; +const int DeletePlaylistMethod::errorId = 900; /* =============================================== local function prototypes */ @@ -87,48 +86,53 @@ DeletePlaylistMethod :: DeletePlaylistMethod ( * (Overrides 'execute' in XmlRpcServerMethod.) *----------------------------------------------------------------------------*/ void -DeletePlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, +DeletePlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, XmlRpc::XmlRpcValue & returnValue) throw () { + if (!rootParameter.valid() || rootParameter.size() != 1) { + XmlRpcTools::markError(errorId+1, "invalid argument format", + returnValue); + return; + } + XmlRpc::XmlRpcValue parameters = rootParameter[0]; + + Ptr::Ref playlistId; + try{ + playlistId = XmlRpcTools::extractPlaylistId(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+2, "missing playlist ID argument", + returnValue); + return; + } + + Ptr::Ref scf + = StorageClientFactory::getInstance(); + Ptr::Ref storage + = scf->getStorageClient(); + Ptr::Ref playlist; try { - if (!parameters.valid()) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); - return; - } + playlist = storage->getPlaylist(playlistId); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+3, "playlist not found", + returnValue); + return; + } - Ptr::Ref id = XmlRpcTools::extractPlaylistId(parameters[0]); + if (playlist->isLocked()) { + XmlRpcTools::markError(errorId+4, "playlist is locked", + returnValue); + return; + } - Ptr::Ref scf; - Ptr::Ref storage; - - scf = StorageClientFactory::getInstance(); - storage = scf->getStorageClient(); - - Ptr::Ref playlist; - try { - playlist = storage->getPlaylist(id); - } - catch (std::invalid_argument &e) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); - return; - } - - if (playlist->isLocked()) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); - return; - } - - storage->deletePlaylist(id); - - returnValue = XmlRpc::XmlRpcValue(true); - - } catch (std::invalid_argument &e) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); + try { + storage->deletePlaylist(playlistId); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+5, "playlist could not be deleted", + returnValue); return; } } diff --git a/livesupport/products/scheduler/src/DeletePlaylistMethod.h b/livesupport/products/scheduler/src/DeletePlaylistMethod.h index 1549dc0ea..b6d896af5 100644 --- a/livesupport/products/scheduler/src/DeletePlaylistMethod.h +++ b/livesupport/products/scheduler/src/DeletePlaylistMethod.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/DeletePlaylistMethod.h,v $ ------------------------------------------------------------------------------*/ @@ -74,14 +74,23 @@ using namespace LiveSupport::Core; * to be deleted. * * - * The XML-RPC function returns the XML-RPC value: + * If there is an error, an XML-RPC structure is returned, with the following + * fields: *
      - *
    • true if the operation completed successfully,
    • - *
    • false if playlist is not found or there was some other error.
    • + *
    • errorCode - int - a numerical code for the error
    • + *
    • errorMessage - string - a description of the error
    • + *
    + * The possible error codes are: + *
      + *
    • 901 - invalid argument format
    • + *
    • 902 - missing playlist ID argument
    • + *
    • 903 - playlist not found
    • + *
    • 904 - playlist is locked
    • + *
    • 905 - playlist could not be deleted
    • *
    * * @author $Author: fgerlits $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ class DeletePlaylistMethod : public XmlRpc::XmlRpcServerMethod { @@ -93,10 +102,9 @@ class DeletePlaylistMethod : public XmlRpc::XmlRpcServerMethod static const std::string methodName; /** - * The name of the playlistId member in the XML-RPC parameter - * structure. + * The ID of this method for error reporting purposes. */ - static const std::string playlistIdName; + static const int errorId; public: diff --git a/livesupport/products/scheduler/src/DeletePlaylistMethodTest.cxx b/livesupport/products/scheduler/src/DeletePlaylistMethodTest.cxx index ee34ba6b5..66f83bb9b 100644 --- a/livesupport/products/scheduler/src/DeletePlaylistMethodTest.cxx +++ b/livesupport/products/scheduler/src/DeletePlaylistMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/DeletePlaylistMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -46,6 +46,9 @@ #include "LiveSupport/Db/ConnectionManagerFactory.h" #include "LiveSupport/Storage/StorageClientFactory.h" +#include "OpenPlaylistForEditingMethod.h" +#include "SavePlaylistMethod.h" + #include "DeletePlaylistMethod.h" #include "DeletePlaylistMethodTest.h" @@ -138,17 +141,37 @@ void DeletePlaylistMethodTest :: firstTest(void) throw (CPPUNIT_NS::Exception) { - Ptr::Ref method(new DeletePlaylistMethod()); - XmlRpc::XmlRpcValue rootParameter; - XmlRpc::XmlRpcValue parameters; - XmlRpc::XmlRpcValue result; + Ptr::Ref + openMethod (new OpenPlaylistForEditingMethod); + Ptr::Ref + saveMethod (new SavePlaylistMethod); + Ptr::Ref + deleteMethod(new DeletePlaylistMethod); + XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); + XmlRpc::XmlRpcValue result; // set up a structure for the parameters - parameters["playlistId"] = 1; - rootParameter[0] = parameters; + parameter["playlistId"] = 1; + rootParameter[0] = parameter; - method->execute(rootParameter, result); - CPPUNIT_ASSERT(((bool) result) == true); + result.clear(); + openMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); + + result.clear(); + deleteMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(result.hasMember("errorCode")); + CPPUNIT_ASSERT(int(result["errorCode"]) == 904); // playlist is locked + + result.clear(); + saveMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); + + result.clear(); + deleteMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); // OK } @@ -160,15 +183,18 @@ DeletePlaylistMethodTest :: negativeTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref method(new DeletePlaylistMethod()); + XmlRpc::XmlRpcValue parameter; XmlRpc::XmlRpcValue rootParameter; - XmlRpc::XmlRpcValue parameters; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; // set up a structure for the parameters - parameters["playlistId"] = 9999; - rootParameter[0] = parameters; + parameter["playlistId"] = 9999; + rootParameter[0] = parameter; + result.clear(); method->execute(rootParameter, result); - CPPUNIT_ASSERT(((bool)result) == false); + CPPUNIT_ASSERT(result.hasMember("errorCode")); + CPPUNIT_ASSERT(int(result["errorCode"]) == 903); // playlist not found } diff --git a/livesupport/products/scheduler/src/DisplayAudioClipMethod.cxx b/livesupport/products/scheduler/src/DisplayAudioClipMethod.cxx index f79145467..a61cdffa9 100644 --- a/livesupport/products/scheduler/src/DisplayAudioClipMethod.cxx +++ b/livesupport/products/scheduler/src/DisplayAudioClipMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayAudioClipMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -95,15 +95,16 @@ DisplayAudioClipMethod :: DisplayAudioClipMethod ( * Execute the stop XML-RPC function call. *----------------------------------------------------------------------------*/ void -DisplayAudioClipMethod :: execute(XmlRpc::XmlRpcValue & parameters, - XmlRpc::XmlRpcValue & returnValue) +DisplayAudioClipMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, + XmlRpc::XmlRpcValue & returnValue) throw () { - if (!parameters.valid()) { + if (!rootParameter.valid() || rootParameter.size() != 1) { XmlRpcTools::markError(errorId+1, "invalid argument format", returnValue); return; } + XmlRpc::XmlRpcValue parameters = rootParameter[0]; Ptr::Ref id; try{ diff --git a/livesupport/products/scheduler/src/DisplayAudioClipMethodTest.cxx b/livesupport/products/scheduler/src/DisplayAudioClipMethodTest.cxx index 66859b18f..3a15bd11e 100644 --- a/livesupport/products/scheduler/src/DisplayAudioClipMethodTest.cxx +++ b/livesupport/products/scheduler/src/DisplayAudioClipMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayAudioClipMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -140,12 +140,16 @@ DisplayAudioClipMethodTest :: firstTest(void) { Ptr::Ref method(new DisplayAudioClipMethod()); XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; // set up a structure for the parameter parameter["audioClipId"] = 10001; + rootParameter[0] = parameter; - method->execute(parameter, result); + result.clear(); + method->execute(rootParameter, result); CPPUNIT_ASSERT(int(result["id"]) == 10001); CPPUNIT_ASSERT(int(result["playlength"]) == (60 * 60)); } @@ -160,12 +164,16 @@ DisplayAudioClipMethodTest :: negativeTest(void) { Ptr::Ref method(new DisplayAudioClipMethod()); XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; // set up a structure for the parameter parameter["audioClipId"] = 9999; + rootParameter[0] = parameter; - method->execute(parameter, result); + result.clear(); + method->execute(rootParameter, result); CPPUNIT_ASSERT(result.hasMember("errorCode")); CPPUNIT_ASSERT(int(result["errorCode"]) == 603); // audio clip not found } diff --git a/livesupport/products/scheduler/src/DisplayAudioClipsMethodTest.cxx b/livesupport/products/scheduler/src/DisplayAudioClipsMethodTest.cxx index 99d85c0a0..eba298a6c 100644 --- a/livesupport/products/scheduler/src/DisplayAudioClipsMethodTest.cxx +++ b/livesupport/products/scheduler/src/DisplayAudioClipsMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayAudioClipsMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -144,6 +144,7 @@ DisplayAudioClipsMethodTest :: firstTest(void) XmlRpc::XmlRpcValue result; XmlRpc::XmlRpcValue audioClip; + result.clear(); method->execute(parameter, result); CPPUNIT_ASSERT(result.size() == 2); diff --git a/livesupport/products/scheduler/src/DisplayPlaylistMethod.cxx b/livesupport/products/scheduler/src/DisplayPlaylistMethod.cxx index 41ce2c1ff..c3338c97d 100644 --- a/livesupport/products/scheduler/src/DisplayPlaylistMethod.cxx +++ b/livesupport/products/scheduler/src/DisplayPlaylistMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayPlaylistMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -71,10 +71,9 @@ using namespace LiveSupport::Scheduler; const std::string DisplayPlaylistMethod::methodName = "displayPlaylist"; /*------------------------------------------------------------------------------ - * The name of the playlistId member in the XML-RPC parameter - * structure. + * The ID of this method for error reporting purposes. *----------------------------------------------------------------------------*/ -const std::string DisplayPlaylistMethod::playlistIdName = "playlistId"; +const int DisplayPlaylistMethod::errorId = 1000; /* =============================================== local function prototypes */ @@ -96,39 +95,42 @@ DisplayPlaylistMethod :: DisplayPlaylistMethod ( * Execute the stop XML-RPC function call. *----------------------------------------------------------------------------*/ void -DisplayPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, +DisplayPlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, XmlRpc::XmlRpcValue & returnValue) throw () { - try { - if (!parameters.valid()) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); - return; - } - - Ptr::Ref id = XmlRpcTools::extractPlaylistId(parameters[0]); - - Ptr::Ref scf; - Ptr::Ref storage; - - scf = StorageClientFactory::getInstance(); - storage = scf->getStorageClient(); - - if (!storage->existsPlaylist(id)) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); - return; - } - - Ptr::Ref playlist = storage->getPlaylist(id); - - XmlRpcTools::playlistToXmlRpcValue(playlist, returnValue); - - } catch (std::invalid_argument &e) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); + if (!rootParameter.valid() || rootParameter.size() != 1) { + XmlRpcTools::markError(errorId+1, "invalid argument format", + returnValue); return; } -} + XmlRpc::XmlRpcValue parameters = rootParameter[0]; + Ptr::Ref id; + try{ + id = XmlRpcTools::extractPlaylistId(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+2, "argument is not a Playlist ID", + returnValue); + return; + } + + Ptr::Ref scf; + Ptr::Ref storage; + + scf = StorageClientFactory::getInstance(); + storage = scf->getStorageClient(); + + Ptr::Ref playlist; + try { + playlist = storage->getPlaylist(id); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+3, "playlist not found", + returnValue); + return; + } + + XmlRpcTools::playlistToXmlRpcValue(playlist, returnValue); +} diff --git a/livesupport/products/scheduler/src/DisplayPlaylistMethod.h b/livesupport/products/scheduler/src/DisplayPlaylistMethod.h index fbacbc2b9..9363f2110 100644 --- a/livesupport/products/scheduler/src/DisplayPlaylistMethod.h +++ b/livesupport/products/scheduler/src/DisplayPlaylistMethod.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayPlaylistMethod.h,v $ ------------------------------------------------------------------------------*/ @@ -81,10 +81,22 @@ using namespace LiveSupport::Core; *
  • playlength - int - the playlist length of the playlist, in seconds *
  • * - * In case of an error, a simple false value is returned. + * + * If there is an error, an XML-RPC structure is returned, with the following + * fields: + *
      + *
    • errorCode - int - a numerical code for the error
    • + *
    • errorMessage - string - a description of the error
    • + *
    + * The possible error codes are: + *
      + *
    • 1001 - invalid argument format
    • + *
    • 1002 - argument is not a playlist ID
    • + *
    • 1003 - playlist not found
    • + *
    * * @author $Author: fgerlits $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ class DisplayPlaylistMethod : public XmlRpc::XmlRpcServerMethod { @@ -96,10 +108,9 @@ class DisplayPlaylistMethod : public XmlRpc::XmlRpcServerMethod static const std::string methodName; /** - * The name of the playlistId member in the XML-RPC parameter - * structure. + * The ID of this method for error reporting purposes. */ - static const std::string playlistIdName; + static const int errorId; public: diff --git a/livesupport/products/scheduler/src/DisplayPlaylistMethodTest.cxx b/livesupport/products/scheduler/src/DisplayPlaylistMethodTest.cxx index dbc0711ff..5cf2ea506 100644 --- a/livesupport/products/scheduler/src/DisplayPlaylistMethodTest.cxx +++ b/livesupport/products/scheduler/src/DisplayPlaylistMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayPlaylistMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -139,17 +139,19 @@ DisplayPlaylistMethodTest :: firstTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref method(new DisplayPlaylistMethod()); + XmlRpc::XmlRpcValue parameter; XmlRpc::XmlRpcValue rootParameter; - XmlRpc::XmlRpcValue parameters; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; - // set up a structure for the parameters - parameters["playlistId"] = 1; - rootParameter[0] = parameters; + // set up a structure for the parameter + parameter["playlistId"] = 1; + rootParameter[0] = parameter; + result.clear(); method->execute(rootParameter, result); - CPPUNIT_ASSERT(((int) result["id"]) == 1); - CPPUNIT_ASSERT(((int) result["playlength"]) == (90 * 60)); + CPPUNIT_ASSERT(int(result["id"]) == 1); + CPPUNIT_ASSERT(int(result["playlength"]) == 90 * 60); } @@ -161,15 +163,18 @@ DisplayPlaylistMethodTest :: negativeTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref method(new DisplayPlaylistMethod()); + XmlRpc::XmlRpcValue parameter; XmlRpc::XmlRpcValue rootParameter; - XmlRpc::XmlRpcValue parameters; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; - // set up a structure for the parameters - parameters["playlistId"] = 9999; - rootParameter[0] = parameters; + // set up a structure for the parameter + parameter["playlistId"] = 9999; + rootParameter[0] = parameter; + result.clear(); method->execute(rootParameter, result); - CPPUNIT_ASSERT(((bool)result) == false); + CPPUNIT_ASSERT(result.hasMember("errorCode")); + CPPUNIT_ASSERT(int(result["errorCode"]) == 1003); // playlist not found } diff --git a/livesupport/products/scheduler/src/DisplayPlaylistsMethodTest.cxx b/livesupport/products/scheduler/src/DisplayPlaylistsMethodTest.cxx index 9a3f3c645..98e6c73da 100644 --- a/livesupport/products/scheduler/src/DisplayPlaylistsMethodTest.cxx +++ b/livesupport/products/scheduler/src/DisplayPlaylistsMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayPlaylistsMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -144,6 +144,7 @@ DisplayPlaylistsMethodTest :: firstTest(void) XmlRpc::XmlRpcValue result; XmlRpc::XmlRpcValue playlist; + result.clear(); method->execute(parameters, result); CPPUNIT_ASSERT(result.size() == 1); diff --git a/livesupport/products/scheduler/src/DisplayScheduleMethod.cxx b/livesupport/products/scheduler/src/DisplayScheduleMethod.cxx index 38fa67046..e2f6f29bd 100644 --- a/livesupport/products/scheduler/src/DisplayScheduleMethod.cxx +++ b/livesupport/products/scheduler/src/DisplayScheduleMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayScheduleMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -67,6 +67,11 @@ using namespace LiveSupport::Scheduler; *----------------------------------------------------------------------------*/ const std::string DisplayScheduleMethod::methodName = "displaySchedule"; +/*------------------------------------------------------------------------------ + * The ID of this method for error reporting purposes. + *----------------------------------------------------------------------------*/ +const int DisplayScheduleMethod::errorId = 1100; + /* =============================================== local function prototypes */ @@ -87,35 +92,42 @@ DisplayScheduleMethod :: DisplayScheduleMethod ( * Execute the stop XML-RPC function call. *----------------------------------------------------------------------------*/ void -DisplayScheduleMethod :: execute(XmlRpc::XmlRpcValue & parameters, +DisplayScheduleMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, XmlRpc::XmlRpcValue & returnValue) throw () { - try { - if (!parameters.valid()) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); - return; - } - - Ptr::Ref fromTime - = XmlRpcTools::extractFromTime(parameters[0]); - Ptr::Ref toTime - = XmlRpcTools::extractToTime(parameters[0]); - - Ptr::Ref sf = ScheduleFactory::getInstance(); - Ptr::Ref schedule = sf->getSchedule(); - - Ptr::Ref> >::Ref scheduleEntries - = schedule->getScheduleEntries(fromTime, toTime); - - XmlRpcTools::scheduleEntriesToXmlRpcValue(scheduleEntries, - returnValue); - - } catch (std::invalid_argument &e) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); + if (!rootParameter.valid() || rootParameter.size() != 1) { + XmlRpcTools::markError(errorId+1, "invalid argument format", + returnValue); return; } -} + XmlRpc::XmlRpcValue parameters = rootParameter[0]; + Ptr::Ref fromTime; + try { + fromTime = XmlRpcTools::extractFromTime(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+2, "missing or invalid 'from' argument", + returnValue); + return; + } + + Ptr::Ref toTime; + try { + toTime = XmlRpcTools::extractToTime(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+3, "missing or invalid 'to' argument", + returnValue); + return; + } + + Ptr::Ref sf = ScheduleFactory::getInstance(); + Ptr::Ref schedule = sf->getSchedule(); + + Ptr::Ref> >::Ref scheduleEntries + = schedule->getScheduleEntries(fromTime, toTime); + + XmlRpcTools::scheduleEntriesToXmlRpcValue(scheduleEntries, returnValue); +} diff --git a/livesupport/products/scheduler/src/DisplayScheduleMethod.h b/livesupport/products/scheduler/src/DisplayScheduleMethod.h index e24769cf9..665a84e1b 100644 --- a/livesupport/products/scheduler/src/DisplayScheduleMethod.h +++ b/livesupport/products/scheduler/src/DisplayScheduleMethod.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayScheduleMethod.h,v $ ------------------------------------------------------------------------------*/ @@ -92,8 +92,21 @@ using namespace LiveSupport::Core; *
  • end - datetime - the end of the scheduled item
  • * * + * If there is an error, an XML-RPC structure is returned, with the following + * fields: + *
      + *
    • errorCode - int - a numerical code for the error
    • + *
    • errorMessage - string - a description of the error
    • + *
    + * The possible error codes are: + *
      + *
    • 1101 - invalid argument format
    • + *
    • 1102 - missing or invalid 'from' argument
    • + *
    • 1103 - missing or invalid 'to' argument
    • + *
    + * * @author $Author: fgerlits $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ class DisplayScheduleMethod : public XmlRpc::XmlRpcServerMethod { @@ -104,6 +117,11 @@ class DisplayScheduleMethod : public XmlRpc::XmlRpcServerMethod */ static const std::string methodName; + /** + * The ID of this method for error reporting purposes. + */ + static const int errorId; + public: /** diff --git a/livesupport/products/scheduler/src/DisplayScheduleMethodTest.cxx b/livesupport/products/scheduler/src/DisplayScheduleMethodTest.cxx index cd4c31bb1..d7a37369b 100644 --- a/livesupport/products/scheduler/src/DisplayScheduleMethodTest.cxx +++ b/livesupport/products/scheduler/src/DisplayScheduleMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayScheduleMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -51,6 +51,7 @@ #include "DisplayScheduleMethod.h" #include "DisplayScheduleMethodTest.h" +using namespace std; using namespace LiveSupport::Db; using namespace LiveSupport::Storage; @@ -155,8 +156,9 @@ DisplayScheduleMethodTest :: firstTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref method(new DisplayScheduleMethod()); - XmlRpc::XmlRpcValue rootParameter; XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; struct tm time; @@ -177,6 +179,7 @@ DisplayScheduleMethodTest :: firstTest(void) parameters["to"] = &time; rootParameter[0] = parameters; + result.clear(); method->execute(rootParameter, result); CPPUNIT_ASSERT(result.size() == 0); } @@ -190,8 +193,9 @@ DisplayScheduleMethodTest :: insertEntries(void) throw () { Ptr::Ref method(new UploadPlaylistMethod()); - XmlRpc::XmlRpcValue rootParameter; XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; struct tm time; @@ -205,6 +209,8 @@ DisplayScheduleMethodTest :: insertEntries(void) time.tm_sec = 0; parameters["playtime"] = &time; rootParameter[0] = parameters; + + result.clear(); method->execute(rootParameter, result); // insert a playlist for 2004-07-31, at 12 o'clock @@ -217,6 +223,8 @@ DisplayScheduleMethodTest :: insertEntries(void) time.tm_sec = 0; parameters["playtime"] = &time; rootParameter[0] = parameters; + + result.clear(); method->execute(rootParameter, result); // insert a playlist for 2004-07-31, at 14 o'clock @@ -229,6 +237,8 @@ DisplayScheduleMethodTest :: insertEntries(void) time.tm_sec = 0; parameters["playtime"] = &time; rootParameter[0] = parameters; + + result.clear(); method->execute(rootParameter, result); } @@ -241,8 +251,9 @@ DisplayScheduleMethodTest :: intervalTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref method(new DisplayScheduleMethod()); - XmlRpc::XmlRpcValue rootParameter; XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; struct tm time; @@ -262,7 +273,8 @@ DisplayScheduleMethodTest :: intervalTest(void) time.tm_sec = 0; parameters["to"] = &time; rootParameter[0] = parameters; - result = XmlRpc::XmlRpcValue(); + + result.clear(); method->execute(rootParameter, result); // check the returned values @@ -299,7 +311,8 @@ DisplayScheduleMethodTest :: intervalTest(void) time.tm_sec = 0; parameters["to"] = &time; rootParameter[0] = parameters; - result = XmlRpc::XmlRpcValue(); + + result.clear(); method->execute(rootParameter, result); // check the returned values @@ -352,7 +365,8 @@ DisplayScheduleMethodTest :: intervalTest(void) time.tm_sec = 0; parameters["to"] = &time; rootParameter[0] = parameters; - result = XmlRpc::XmlRpcValue(); + + result.clear(); method->execute(rootParameter, result); // check the returned values diff --git a/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.cxx b/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.cxx index 888e4c501..7151490f5 100644 --- a/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.cxx +++ b/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.7 $ + Version : $Revision: 1.8 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -96,15 +96,16 @@ OpenPlaylistForEditingMethod :: OpenPlaylistForEditingMethod ( * Execute the stop XML-RPC function call. *----------------------------------------------------------------------------*/ void -OpenPlaylistForEditingMethod :: execute(XmlRpc::XmlRpcValue & parameters, +OpenPlaylistForEditingMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, XmlRpc::XmlRpcValue & returnValue) - throw () + throw () { - if (!parameters.valid()) { + if (!rootParameter.valid() || rootParameter.size() != 1) { XmlRpcTools::markError(errorId+1, "invalid argument format", returnValue); return; } + XmlRpc::XmlRpcValue parameters = rootParameter[0]; Ptr::Ref id; try{ diff --git a/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.cxx b/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.cxx index 67d9ca2ed..09f0d581f 100644 --- a/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.cxx +++ b/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.6 $ + Version : $Revision: 1.7 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -143,29 +143,35 @@ OpenPlaylistForEditingMethodTest :: firstTest(void) Ptr::Ref method(new OpenPlaylistForEditingMethod()); XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; parameter["playlistId"] = 1; + rootParameter[0] = parameter; - method->execute(parameter, result); + result.clear(); + method->execute(rootParameter, result); CPPUNIT_ASSERT((int) result["id"] == 1); CPPUNIT_ASSERT((int) result["playlength"] == (90 * 60)); parameter.clear(); - result.clear(); parameter["playlistId"] = 6376; + rootParameter[0] = parameter; // no such playlist - method->execute(parameter, result); + result.clear(); + method->execute(rootParameter, result); CPPUNIT_ASSERT((int) result["errorCode"] == 104); CPPUNIT_ASSERT((const std::string) result["errorMessage"] == "playlist not found"); parameter.clear(); - result.clear(); parameter["playlistId"] = 1; + rootParameter[0] = parameter; // should not allow to open the same playlist for editing again - method->execute(parameter, result); + result.clear(); + method->execute(rootParameter, result); CPPUNIT_ASSERT((int) result["errorCode"] == 105); CPPUNIT_ASSERT((const std::string) result["errorMessage"] == "could not open playlist"); diff --git a/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethod.cxx b/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethod.cxx index d767163c8..73639cf9d 100644 --- a/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethod.cxx +++ b/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -96,15 +96,17 @@ RemoveAudioClipFromPlaylistMethod :: RemoveAudioClipFromPlaylistMethod ( * Execute the stop XML-RPC function call. *----------------------------------------------------------------------------*/ void -RemoveAudioClipFromPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, - XmlRpc::XmlRpcValue & returnValue) +RemoveAudioClipFromPlaylistMethod :: execute( + XmlRpc::XmlRpcValue & rootParameter, + XmlRpc::XmlRpcValue & returnValue) throw () { - if (!parameters.valid()) { + if (!rootParameter.valid() || rootParameter.size() != 1) { XmlRpcTools::markError(errorId+1, "invalid argument format", returnValue); return; } + XmlRpc::XmlRpcValue parameters = rootParameter[0]; Ptr::Ref playlistId; try{ diff --git a/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethodTest.cxx b/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethodTest.cxx index 338d635c2..61cc5ee46 100644 --- a/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethodTest.cxx +++ b/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -151,25 +151,33 @@ RemoveAudioClipFromPlaylistMethodTest :: firstTest(void) addAudioClipMethod(new AddAudioClipToPlaylistMethod()); Ptr::Ref removeAudioClipMethod(new RemoveAudioClipFromPlaylistMethod()); - XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; - parameter["playlistId"] = 1; - parameter["audioClipId"] = 10001; - parameter["relativeOffset"] = 90*60; + parameters["playlistId"] = 1; + parameters["audioClipId"] = 10001; + parameters["relativeOffset"] = 90*60; + rootParameter[0] = parameters; - removeAudioClipMethod->execute(parameter, result); + result.clear(); + removeAudioClipMethod->execute(rootParameter, result); CPPUNIT_ASSERT(result.hasMember("errorCode")); CPPUNIT_ASSERT((int)(result["errorCode"]) == 405); // not open for editing result.clear(); - openPlaylistMethod->execute(parameter, result); - removeAudioClipMethod->execute(parameter, result); + openPlaylistMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); + result.clear(); + removeAudioClipMethod->execute(rootParameter, result); CPPUNIT_ASSERT(result.hasMember("errorCode")); CPPUNIT_ASSERT((int)(result["errorCode"]) == 406); // no audio clip at // this rel offset result.clear(); - addAudioClipMethod->execute(parameter, result); - removeAudioClipMethod->execute(parameter, result); + addAudioClipMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); + result.clear(); + removeAudioClipMethod->execute(rootParameter, result); CPPUNIT_ASSERT(!result.hasMember("errorCode")); } diff --git a/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx b/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx index a18a4e392..46ff1b73c 100644 --- a/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx +++ b/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -64,6 +64,11 @@ using namespace LiveSupport::Scheduler; *----------------------------------------------------------------------------*/ const std::string RemoveFromScheduleMethod::methodName = "removeFromSchedule"; +/*------------------------------------------------------------------------------ + * The ID of this method for error reporting purposes. + *----------------------------------------------------------------------------*/ +const int RemoveFromScheduleMethod::errorId = 1200; + /* =============================================== local function prototypes */ @@ -84,37 +89,37 @@ RemoveFromScheduleMethod :: RemoveFromScheduleMethod ( * Execute the remove from schedule XML-RPC function call. *----------------------------------------------------------------------------*/ void -RemoveFromScheduleMethod :: execute(XmlRpc::XmlRpcValue & parameters, +RemoveFromScheduleMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, XmlRpc::XmlRpcValue & returnValue) - throw () + throw () { - try { - if (!parameters.valid()) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); - return; - } + if (!rootParameter.valid() || rootParameter.size() != 1) { + XmlRpcTools::markError(errorId+1, "invalid argument format", + returnValue); + return; + } + XmlRpc::XmlRpcValue parameters = rootParameter[0]; - Ptr::Ref entryId - = XmlRpcTools::extractScheduleEntryId(parameters[0]); - - Ptr::Ref sf = ScheduleFactory::getInstance(); - Ptr::Ref schedule = sf->getSchedule(); - - if (!schedule->scheduleEntryExists(entryId)) { - // TODO: mark error; - returnValue = XmlRpc::XmlRpcValue(false); - return; - } - - schedule->removeFromSchedule(entryId); - - } catch (std::invalid_argument &e) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); + Ptr::Ref entryId; + try { + entryId = XmlRpcTools::extractScheduleEntryId(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+2, "missing schedule entry ID argument", + returnValue); return; } - returnValue = XmlRpc::XmlRpcValue(true); -} + Ptr::Ref sf = ScheduleFactory::getInstance(); + Ptr::Ref schedule = sf->getSchedule(); + + try { + schedule->removeFromSchedule(entryId); + + } catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+3, "schedule entry not found", + returnValue); + return; + } +} diff --git a/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h b/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h index 77765e49c..0d0cc6d19 100644 --- a/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h +++ b/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h,v $ ------------------------------------------------------------------------------*/ @@ -74,8 +74,21 @@ using namespace LiveSupport::Core; *
  • scheduleEntryId - int - the id of the scheduled entry to remove
  • * * + * In case of an error, an XML-RPC structure is returned, with the following + * fields: + *
      + *
    • errorCode - int - the id of the error condition
    • + *
    • errorMessage - string - a description of the error
    • + *
    + * The possible error codes are: + *
      + *
    • 1201 - invalid argument format
    • + *
    • 1202 - missing argument
    • + *
    • 1203 - not found
    • + *
    + * * @author $Author: fgerlits $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ class RemoveFromScheduleMethod : public XmlRpc::XmlRpcServerMethod { @@ -86,6 +99,11 @@ class RemoveFromScheduleMethod : public XmlRpc::XmlRpcServerMethod */ static const std::string methodName; + /** + * The ID of this method for error reporting purposes. + */ + static const int errorId; + public: /** diff --git a/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx b/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx index 6fec577db..5f2c40116 100644 --- a/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx +++ b/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -129,16 +129,17 @@ RemoveFromScheduleMethodTest :: firstTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref uploadMethod( - new UploadPlaylistMethod()); + new UploadPlaylistMethod()); Ptr::Ref removeMethod( - new RemoveFromScheduleMethod()); - XmlRpc::XmlRpcValue rootParameter; + new RemoveFromScheduleMethod()); XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; struct tm time; Ptr::Ref entryId; - // first schedule (upload) a playlist) + // first schedule (upload) a playlist parameters["playlistId"] = 1; time.tm_year = 2001; time.tm_mon = 11; @@ -147,18 +148,20 @@ RemoveFromScheduleMethodTest :: firstTest(void) time.tm_min = 0; time.tm_sec = 0; parameters["playtime"] = &time; - rootParameter[0] = parameters; + rootParameter[0] = parameters; + result.clear(); uploadMethod->execute(rootParameter, result); - entryId.reset(new UniqueId((int) result)); + CPPUNIT_ASSERT(result.hasMember("scheduleEntryId")); + entryId.reset(new UniqueId(int(result["scheduleEntryId"]))); parameters.clear(); - result.clear(); - parameters["scheduleEntryId"] = (int) entryId->getId(); - rootParameter[0] = parameters; + parameters["scheduleEntryId"] = int(entryId->getId()); + rootParameter[0] = parameters; + result.clear(); removeMethod->execute(rootParameter, result); - CPPUNIT_ASSERT(result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); } @@ -170,16 +173,18 @@ RemoveFromScheduleMethodTest :: negativeTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref removeMethod( - new RemoveFromScheduleMethod()); - XmlRpc::XmlRpcValue rootParameter; + new RemoveFromScheduleMethod()); XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; Ptr::Ref entryId(new UniqueId(9999)); - parameters["scheduleEntryId"] = (int) entryId->getId(); - rootParameter[0] = parameters; + parameters["scheduleEntryId"] = int(entryId->getId()); + rootParameter[0] = parameters; + result.clear(); removeMethod->execute(rootParameter, result); - CPPUNIT_ASSERT(!result); + CPPUNIT_ASSERT(result.hasMember("errorCode")); } diff --git a/livesupport/products/scheduler/src/RescheduleMethod.cxx b/livesupport/products/scheduler/src/RescheduleMethod.cxx index 1c066f6b9..0b9081d77 100644 --- a/livesupport/products/scheduler/src/RescheduleMethod.cxx +++ b/livesupport/products/scheduler/src/RescheduleMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -67,6 +67,11 @@ using namespace LiveSupport::Scheduler; *----------------------------------------------------------------------------*/ const std::string RescheduleMethod::methodName = "reschedule"; +/*------------------------------------------------------------------------------ + * The ID of this method for error reporting purposes. + *----------------------------------------------------------------------------*/ +const int RescheduleMethod::errorId = 1300; + /* =============================================== local function prototypes */ @@ -87,40 +92,54 @@ RescheduleMethod :: RescheduleMethod ( * Execute the upload playlist method XML-RPC function call. *----------------------------------------------------------------------------*/ void -RescheduleMethod :: execute(XmlRpc::XmlRpcValue & parameters, +RescheduleMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, XmlRpc::XmlRpcValue & returnValue) - throw () + throw () { + if (!rootParameter.valid() || rootParameter.size() != 1) { + XmlRpcTools::markError(errorId+1, "invalid argument format", + returnValue); + return; + } + XmlRpc::XmlRpcValue parameters = rootParameter[0]; + + Ptr::Ref entryId; try { - if (!parameters.valid()) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); - return; - } - - Ptr::Ref entryId - = XmlRpcTools::extractScheduleEntryId(parameters[0]); - Ptr::Ref playschedule - = XmlRpcTools::extractPlayschedule(parameters[0]); - Ptr::Ref scheduleEntryId; - - Ptr::Ref sf = ScheduleFactory::getInstance(); - Ptr::Ref schedule = sf->getSchedule(); - - if (!schedule->scheduleEntryExists(entryId)) { - // TODO: mark error; - returnValue = XmlRpc::XmlRpcValue(false); - return; - } - - schedule->reschedule(entryId, playschedule); - - } catch (std::invalid_argument &e) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); + entryId = XmlRpcTools::extractScheduleEntryId(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+2, "missing schedule entry ID argument", + returnValue); return; } - returnValue = XmlRpc::XmlRpcValue(true); + Ptr::Ref playschedule; + try { + playschedule = XmlRpcTools::extractPlayschedule(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+3, "missing playtime argument", + returnValue); + return; + } + + Ptr::Ref scheduleEntryId; + + Ptr::Ref sf = ScheduleFactory::getInstance(); + Ptr::Ref schedule = sf->getSchedule(); + + if (!schedule->scheduleEntryExists(entryId)) { + XmlRpcTools::markError(errorId+4, "schedule entry not found", + returnValue); + return; + } + try { + schedule->reschedule(entryId, playschedule); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+5, e.what(), + returnValue); + return; + } } diff --git a/livesupport/products/scheduler/src/RescheduleMethod.h b/livesupport/products/scheduler/src/RescheduleMethod.h index bb6e96de3..61a5f6214 100644 --- a/livesupport/products/scheduler/src/RescheduleMethod.h +++ b/livesupport/products/scheduler/src/RescheduleMethod.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethod.h,v $ ------------------------------------------------------------------------------*/ @@ -75,11 +75,24 @@ using namespace LiveSupport::Core; * *
  • playtime - datetime - the new playing time for the entry
  • * - * The return value is true if all went well, - * or a boolean false, if there were errors. + * + * In case of an error, an XML-RPC structure is returned, with the following + * fields: + *
      + *
    • errorCode - int - the id of the error condition
    • + *
    • errorMessage - string - a description of the error
    • + *
    + * The possible error codes are: + *
      + *
    • 1301 - invalid argument format
    • + *
    • 1302 - missing schedule entry ID argument
    • + *
    • 1303 - missing playtime argument
    • + *
    • 1304 - schedule entry not found
    • + *
    • 1305 - could not reschedule entry
    • + *
    * * @author $Author: fgerlits $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ class RescheduleMethod : public XmlRpc::XmlRpcServerMethod { @@ -90,6 +103,11 @@ class RescheduleMethod : public XmlRpc::XmlRpcServerMethod */ static const std::string methodName; + /** + * The ID of this method for error reporting purposes. + */ + static const int errorId; + public: /** diff --git a/livesupport/products/scheduler/src/RescheduleMethodTest.cxx b/livesupport/products/scheduler/src/RescheduleMethodTest.cxx index 43f979caa..be6d07883 100644 --- a/livesupport/products/scheduler/src/RescheduleMethodTest.cxx +++ b/livesupport/products/scheduler/src/RescheduleMethodTest.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -133,8 +133,9 @@ RescheduleMethodTest :: firstTest(void) { Ptr::Ref uploadMethod(new UploadPlaylistMethod()); Ptr::Ref rescheduleMethod(new RescheduleMethod()); - XmlRpc::XmlRpcValue rootParameter; XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; struct tm time; Ptr::Ref entryId; @@ -148,15 +149,16 @@ RescheduleMethodTest :: firstTest(void) time.tm_min = 31; time.tm_sec = 1; parameters["playtime"] = &time; - rootParameter[0] = parameters; + rootParameter[0] = parameters; + result.clear(); uploadMethod->execute(rootParameter, result); - CPPUNIT_ASSERT(result.valid()); - entryId.reset(new UniqueId((int) result)); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); + CPPUNIT_ASSERT(result.hasMember("scheduleEntryId")); + entryId.reset(new UniqueId(int(result["scheduleEntryId"]))); // now let's reschedule it parameters.clear(); - result.clear(); parameters["scheduleEntryId"] = (int) entryId->getId(); time.tm_year = 2001; time.tm_mon = 11; @@ -165,15 +167,14 @@ RescheduleMethodTest :: firstTest(void) time.tm_min = 31; time.tm_sec = 1; parameters["playtime"] = &time; - rootParameter[0] = parameters; + rootParameter[0] = parameters; + result.clear(); rescheduleMethod->execute(rootParameter, result); - CPPUNIT_ASSERT(result.valid()); - CPPUNIT_ASSERT((bool) result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); // now let's reschedule unto itself, should fail parameters.clear(); - result.clear(); parameters["scheduleEntryId"] = (int) entryId->getId(); time.tm_year = 2001; time.tm_mon = 11; @@ -182,10 +183,12 @@ RescheduleMethodTest :: firstTest(void) time.tm_min = 51; time.tm_sec = 1; parameters["playtime"] = &time; - rootParameter[0] = parameters; + rootParameter[0] = parameters; + result.clear(); rescheduleMethod->execute(rootParameter, result); - CPPUNIT_ASSERT(result.valid()); - CPPUNIT_ASSERT(!((bool) result)); + CPPUNIT_ASSERT(result.hasMember("errorCode")); + + CPPUNIT_ASSERT(int(result["errorCode"]) == 1305); } diff --git a/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.cxx b/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.cxx index b663f86be..878477e55 100644 --- a/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.cxx +++ b/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -91,15 +91,16 @@ RevertEditedPlaylistMethod :: RevertEditedPlaylistMethod ( * Execute the stop XML-RPC function call. *----------------------------------------------------------------------------*/ void -RevertEditedPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, +RevertEditedPlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, XmlRpc::XmlRpcValue & returnValue) throw () { - if (!parameters.valid()) { + if (!rootParameter.valid() || rootParameter.size() != 1) { XmlRpcTools::markError(errorId+1, "invalid argument format", returnValue); return; } + XmlRpc::XmlRpcValue parameters = rootParameter[0]; Ptr::Ref id; try{ diff --git a/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.cxx b/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.cxx index d546534a8..e1324584d 100644 --- a/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.cxx +++ b/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -151,38 +151,42 @@ RevertEditedPlaylistMethodTest :: firstTest(void) saveMethod(new SavePlaylistMethod); Ptr::Ref revertMethod(new RevertEditedPlaylistMethod); - XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; - parameter["playlistId"] = 1; - parameter["relativeOffset"] = 0; + parameters["playlistId"] = 1; + parameters["relativeOffset"] = 0; + rootParameter[0] = parameters; - revertMethod->execute(parameter, result); + result.clear(); + revertMethod->execute(rootParameter, result); CPPUNIT_ASSERT(result.hasMember("errorCode")); CPPUNIT_ASSERT(int(result["errorCode"]) == 804); // no saved copy yet result.clear(); - openMethod->execute(parameter, result); + openMethod->execute(rootParameter, result); CPPUNIT_ASSERT(!result.hasMember("errorCode")); result.clear(); - removeMethod->execute(parameter, result); + removeMethod->execute(rootParameter, result); CPPUNIT_ASSERT(!result.hasMember("errorCode")); result.clear(); - removeMethod->execute(parameter, result); + removeMethod->execute(rootParameter, result); CPPUNIT_ASSERT(result.hasMember("errorCode")); // can't remove it twice result.clear(); - revertMethod->execute(parameter, result); + revertMethod->execute(rootParameter, result); CPPUNIT_ASSERT(!result.hasMember("errorCode")); result.clear(); - removeMethod->execute(parameter, result); + removeMethod->execute(rootParameter, result); CPPUNIT_ASSERT(!result.hasMember("errorCode")); // but now we can again result.clear(); - saveMethod->execute(parameter, result); + saveMethod->execute(rootParameter, result); CPPUNIT_ASSERT(!result.hasMember("errorCode")); result.clear(); - revertMethod->execute(parameter, result); + revertMethod->execute(rootParameter, result); CPPUNIT_ASSERT(result.hasMember("errorCode")); // saved copy has been CPPUNIT_ASSERT(int(result["errorCode"]) == 804); // discarded } diff --git a/livesupport/products/scheduler/src/SavePlaylistMethod.cxx b/livesupport/products/scheduler/src/SavePlaylistMethod.cxx index 397524e4a..c3aa30235 100644 --- a/livesupport/products/scheduler/src/SavePlaylistMethod.cxx +++ b/livesupport/products/scheduler/src/SavePlaylistMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SavePlaylistMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -91,15 +91,16 @@ SavePlaylistMethod :: SavePlaylistMethod ( * Execute the stop XML-RPC function call. *----------------------------------------------------------------------------*/ void -SavePlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, +SavePlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, XmlRpc::XmlRpcValue & returnValue) throw () { - if (!parameters.valid()) { + if (!rootParameter.valid() || rootParameter.size() != 1) { XmlRpcTools::markError(errorId+1, "invalid argument format", returnValue); return; } + XmlRpc::XmlRpcValue parameters = rootParameter[0]; Ptr::Ref id; try{ diff --git a/livesupport/products/scheduler/src/SavePlaylistMethodTest.cxx b/livesupport/products/scheduler/src/SavePlaylistMethodTest.cxx index 9e1b9f858..f5682e859 100644 --- a/livesupport/products/scheduler/src/SavePlaylistMethodTest.cxx +++ b/livesupport/products/scheduler/src/SavePlaylistMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SavePlaylistMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -145,23 +145,28 @@ SavePlaylistMethodTest :: firstTest(void) openMethod(new OpenPlaylistForEditingMethod()); Ptr::Ref saveMethod(new SavePlaylistMethod()); XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; parameter["playlistId"] = 9999; + rootParameter[0] = parameter; - saveMethod->execute(parameter, result); + result.clear(); + saveMethod->execute(rootParameter, result); CPPUNIT_ASSERT(result.hasMember("errorCode")); CPPUNIT_ASSERT(int(result["errorCode"]) == 703); // playlist not found parameter["playlistId"] = 1; + rootParameter[0] = parameter; result.clear(); - openMethod->execute(parameter, result); + openMethod->execute(rootParameter, result); CPPUNIT_ASSERT(!result.hasMember("errorCode")); result.clear(); - saveMethod->execute(parameter, result); + saveMethod->execute(rootParameter, result); CPPUNIT_ASSERT(!result.hasMember("errorCode")); // open then save OK result.clear(); - openMethod->execute(parameter, result); + openMethod->execute(rootParameter, result); CPPUNIT_ASSERT(!result.hasMember("errorCode")); // save then open OK } diff --git a/livesupport/products/scheduler/src/SchedulerDaemonDisplayPlaylistTest.cxx b/livesupport/products/scheduler/src/SchedulerDaemonDisplayPlaylistTest.cxx index 95f29eff7..6622f8fc2 100644 --- a/livesupport/products/scheduler/src/SchedulerDaemonDisplayPlaylistTest.cxx +++ b/livesupport/products/scheduler/src/SchedulerDaemonDisplayPlaylistTest.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/SchedulerDaemonDisplayPlaylistTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -48,6 +48,7 @@ #include "SchedulerDaemonDisplayPlaylistTest.h" +using namespace std; using namespace XmlRpc; using namespace LiveSupport::Scheduler; @@ -125,8 +126,9 @@ SchedulerDaemonDisplayPlaylistTest :: simpleTest(void) parameters["playlistId"] = 1; + result.clear(); xmlRpcClient.execute("displayPlaylist", parameters, result); - CPPUNIT_ASSERT(result.valid()); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); CPPUNIT_ASSERT(((int) result["id"]) == 1); CPPUNIT_ASSERT(((int) result["playlength"]) == (60 * 60)); } @@ -146,8 +148,8 @@ SchedulerDaemonDisplayPlaylistTest :: negativeTest(void) parameters["playlistId"] = 9999; + result.clear(); xmlRpcClient.execute("displayPlaylist", parameters, result); CPPUNIT_ASSERT(result.valid()); - CPPUNIT_ASSERT(((bool)result) == false); + CPPUNIT_ASSERT(result.hasMember("errorCode")); } - diff --git a/livesupport/products/scheduler/src/SchedulerDaemonDisplayScheduleTest.cxx b/livesupport/products/scheduler/src/SchedulerDaemonDisplayScheduleTest.cxx index b74f8a28a..8a9243bf8 100644 --- a/livesupport/products/scheduler/src/SchedulerDaemonDisplayScheduleTest.cxx +++ b/livesupport/products/scheduler/src/SchedulerDaemonDisplayScheduleTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/SchedulerDaemonDisplayScheduleTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -47,7 +47,7 @@ #include "SchedulerDaemon.h" #include "SchedulerDaemonDisplayScheduleTest.h" - +using namespace std; using namespace XmlRpc; using namespace LiveSupport::Scheduler; @@ -126,22 +126,24 @@ SchedulerDaemonDisplayScheduleTest :: simpleTest(void) // list the schedules for an interval (as the database is empty, // it's going to return an empty result set) - time.tm_year = 2004; + time.tm_year = 2044; time.tm_mon = 11; time.tm_mday = 12; time.tm_hour = 10; time.tm_min = 0; time.tm_sec = 0; parameters["from"] = &time; - time.tm_year = 2004; + time.tm_year = 2044; time.tm_mon = 11; time.tm_mday = 12; time.tm_hour = 11; time.tm_min = 0; time.tm_sec = 0; parameters["to"] = &time; + + result.clear(); xmlRpcClient.execute("displaySchedule", parameters, result); - CPPUNIT_ASSERT(result.valid()); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); CPPUNIT_ASSERT(result.size() == 0); } diff --git a/livesupport/products/scheduler/src/SchedulerDaemonRemoveFromScheduleTest.cxx b/livesupport/products/scheduler/src/SchedulerDaemonRemoveFromScheduleTest.cxx index 390889cff..5ff6f9302 100644 --- a/livesupport/products/scheduler/src/SchedulerDaemonRemoveFromScheduleTest.cxx +++ b/livesupport/products/scheduler/src/SchedulerDaemonRemoveFromScheduleTest.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/SchedulerDaemonRemoveFromScheduleTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -48,6 +48,7 @@ #include "SchedulerDaemonRemoveFromScheduleTest.h" +using namespace std; using namespace XmlRpc; using namespace LiveSupport::Scheduler; @@ -134,16 +135,17 @@ SchedulerDaemonRemoveFromScheduleTest :: simpleTest(void) time.tm_sec = 0; parameters["playtime"] = &time; + result.clear(); xmlRpcClient.execute("uploadPlaylist", parameters, result); - CPPUNIT_ASSERT(result.valid()); - - Ptr::Ref entryId(new UniqueId((int) result)); - + CPPUNIT_ASSERT(!result.hasMember("errorCode")); + CPPUNIT_ASSERT(result.hasMember("scheduleEntryId")); + + Ptr::Ref entryId(new UniqueId(int(result["scheduleEntryId"]))); parameters["scheduleEntryId"] = (int) entryId->getId(); + result.clear(); xmlRpcClient.execute("removeFromSchedule", parameters, result); - CPPUNIT_ASSERT(result.valid()); - CPPUNIT_ASSERT(((bool)result) == true); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); } @@ -161,8 +163,8 @@ SchedulerDaemonRemoveFromScheduleTest :: negativeTest(void) parameters["scheduleEntryId"] = 9999; + result.clear(); xmlRpcClient.execute("removeFromSchedule", parameters, result); - CPPUNIT_ASSERT(result.valid()); - CPPUNIT_ASSERT(((bool)result) == false); + CPPUNIT_ASSERT(result.hasMember("errorCode")); } diff --git a/livesupport/products/scheduler/src/SchedulerDaemonRescheduleTest.cxx b/livesupport/products/scheduler/src/SchedulerDaemonRescheduleTest.cxx index 23a643abc..61c82bec4 100644 --- a/livesupport/products/scheduler/src/SchedulerDaemonRescheduleTest.cxx +++ b/livesupport/products/scheduler/src/SchedulerDaemonRescheduleTest.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/SchedulerDaemonRescheduleTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -134,10 +134,10 @@ SchedulerDaemonRescheduleTest :: simpleTest(void) time.tm_sec = 0; parameters["playtime"] = &time; + result.clear(); xmlRpcClient.execute("uploadPlaylist", parameters, result); - CPPUNIT_ASSERT(result.valid()); - - Ptr::Ref entryId(new UniqueId((int) result)); + CPPUNIT_ASSERT(result.hasMember("scheduleEntryId")); + Ptr::Ref entryId(new UniqueId(int(result["scheduleEntryId"]))); // now reschedule it parameters["scheduleEntryId"] = (int) entryId->getId(); @@ -149,9 +149,9 @@ SchedulerDaemonRescheduleTest :: simpleTest(void) time.tm_sec = 0; parameters["playtime"] = &time; + result.clear(); xmlRpcClient.execute("reschedule", parameters, result); - CPPUNIT_ASSERT(result.valid()); - CPPUNIT_ASSERT(((bool)result) == true); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); // now reschedule it unto itself, should fail parameters["scheduleEntryId"] = (int) entryId->getId(); @@ -163,9 +163,9 @@ SchedulerDaemonRescheduleTest :: simpleTest(void) time.tm_sec = 0; parameters["playtime"] = &time; + result.clear(); xmlRpcClient.execute("reschedule", parameters, result); - CPPUNIT_ASSERT(result.valid()); - CPPUNIT_ASSERT(((bool)result) == false); + CPPUNIT_ASSERT(result.hasMember("errorCode")); } @@ -183,8 +183,8 @@ SchedulerDaemonRescheduleTest :: negativeTest(void) parameters["scheduleEntryId"] = 9999; + result.clear(); xmlRpcClient.execute("removeFromSchedule", parameters, result); - CPPUNIT_ASSERT(result.valid()); - CPPUNIT_ASSERT(((bool)result) == false); + CPPUNIT_ASSERT(result.hasMember("errorCode")); } diff --git a/livesupport/products/scheduler/src/SchedulerDaemonTest.cxx b/livesupport/products/scheduler/src/SchedulerDaemonTest.cxx index e31cd4a80..220b3055c 100644 --- a/livesupport/products/scheduler/src/SchedulerDaemonTest.cxx +++ b/livesupport/products/scheduler/src/SchedulerDaemonTest.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.2 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemonTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -53,7 +53,7 @@ using namespace LiveSupport::Scheduler; /* ================================================ local constants & macros */ -//CPPUNIT_TEST_SUITE_REGISTRATION(SchedulerDaemonTest); +// CPPUNIT_TEST_SUITE_REGISTRATION(SchedulerDaemonTest); /** * The name of the configuration file for the scheduler daemon. diff --git a/livesupport/products/scheduler/src/SchedulerDaemonUploadTest.cxx b/livesupport/products/scheduler/src/SchedulerDaemonUploadTest.cxx index 1087086b9..d91af77b1 100644 --- a/livesupport/products/scheduler/src/SchedulerDaemonUploadTest.cxx +++ b/livesupport/products/scheduler/src/SchedulerDaemonUploadTest.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/SchedulerDaemonUploadTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -44,10 +44,13 @@ #include #include +#include "XmlRpcTools.h" +#include "LiveSupport/Core/UniqueId.h" #include "SchedulerDaemon.h" #include "SchedulerDaemonUploadTest.h" +using namespace std; using namespace XmlRpc; using namespace LiveSupport::Scheduler; @@ -134,7 +137,8 @@ SchedulerDaemonUploadTest :: simpleTest(void) time.tm_sec = 0; parameters["playtime"] = &time; + result.clear(); xmlRpcClient.execute("uploadPlaylist", parameters, result); - CPPUNIT_ASSERT(result.valid()); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); } diff --git a/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx b/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx index d8899c60c..beb0afa08 100644 --- a/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx +++ b/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.5 $ + Version : $Revision: 1.6 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -70,6 +70,11 @@ using namespace LiveSupport::Scheduler; *----------------------------------------------------------------------------*/ const std::string UploadPlaylistMethod::methodName = "uploadPlaylist"; +/*------------------------------------------------------------------------------ + * The ID of this method for error reporting purposes. + *----------------------------------------------------------------------------*/ +const int UploadPlaylistMethod::errorId = 1400; + /* =============================================== local function prototypes */ @@ -90,56 +95,73 @@ UploadPlaylistMethod :: UploadPlaylistMethod ( * Execute the upload playlist method XML-RPC function call. *----------------------------------------------------------------------------*/ void -UploadPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, +UploadPlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, XmlRpc::XmlRpcValue & returnValue) throw () { - try { - if (!parameters.valid()) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); - return; - } - - Ptr::Ref id - = XmlRpcTools::extractPlaylistId(parameters[0]); - Ptr::Ref playschedule - = XmlRpcTools::extractPlayschedule(parameters[0]); - Ptr::Ref scheduleEntryId; - - Ptr::Ref scf; - Ptr::Ref storage; - - scf = StorageClientFactory::getInstance(); - storage = scf->getStorageClient(); - - if (!storage->existsPlaylist(id)) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); - return; - } - - Ptr::Ref playlist = storage->getPlaylist(id); - Ptr::Ref until(new ptime(*playschedule - + *(playlist->getPlaylength()))); - - Ptr::Ref sf = ScheduleFactory::getInstance(); - Ptr::Ref schedule = sf->getSchedule(); - - if (!schedule->isTimeframeAvailable(playschedule, until)) { - // TODO: mark error; - returnValue = XmlRpc::XmlRpcValue(false); - return; - } - - scheduleEntryId = schedule->schedulePlaylist(playlist, playschedule); - - returnValue = XmlRpc::XmlRpcValue((int) scheduleEntryId->getId()); - - } catch (std::invalid_argument &e) { - // TODO: mark error - returnValue = XmlRpc::XmlRpcValue(false); + if (!rootParameter.valid() || rootParameter.size() != 1) { + XmlRpcTools::markError(errorId+1, "invalid argument format", + returnValue); return; } -} + XmlRpc::XmlRpcValue parameters = rootParameter[0]; + Ptr::Ref playlistId; + try { + playlistId = XmlRpcTools::extractPlaylistId(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+2, "missing playlist ID argument", + returnValue); + return; + } + + Ptr::Ref playschedule; + try { + playschedule = XmlRpcTools::extractPlayschedule(parameters); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+3, "missing playtime argument", + returnValue); + return; + } + + Ptr::Ref scf + = StorageClientFactory::getInstance(); + Ptr::Ref storage + = scf->getStorageClient(); + + Ptr::Ref playlist; + try { + playlist = storage->getPlaylist(playlistId); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+4, "playlist not found", + returnValue); + return; + } + + Ptr::Ref until(new ptime(*playschedule + + *(playlist->getPlaylength()))); + + Ptr::Ref sf = ScheduleFactory::getInstance(); + Ptr::Ref schedule = sf->getSchedule(); + + if (!schedule->isTimeframeAvailable(playschedule, until)) { + XmlRpcTools::markError(errorId+5, "timeframe not available", + returnValue); + return; + } + + Ptr::Ref scheduleEntryId; + try { + scheduleEntryId = schedule->schedulePlaylist(playlist, playschedule); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+6, e.what(), + returnValue); + return; + } + + XmlRpcTools::scheduleEntryIdToXmlRpcValue(scheduleEntryId, returnValue); +} diff --git a/livesupport/products/scheduler/src/UploadPlaylistMethod.h b/livesupport/products/scheduler/src/UploadPlaylistMethod.h index ef79d2921..77aa51234 100644 --- a/livesupport/products/scheduler/src/UploadPlaylistMethod.h +++ b/livesupport/products/scheduler/src/UploadPlaylistMethod.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.5 $ + Version : $Revision: 1.6 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/UploadPlaylistMethod.h,v $ ------------------------------------------------------------------------------*/ @@ -76,11 +76,32 @@ using namespace LiveSupport::Core; *
  • playtime - the time when the playlist should be scheduled, * an ISO 8601 DateTime field
  • * - * The return value is an int, the id of the schedule entry created - * by uploading, or a boolean false, if there were errors. + * + * If the upload is successful, the method returns an XML-RPC structure with + * the following members: + *
      + *
    • scheduleEntryId - int - the id of the schedule entry created + * by the upload
    • + *
    + * + * In case of an error, an XML-RPC structure is returned with the following + * members: + *
      + *
    • errorCode - int - the id of the error condition
    • + *
    • errorMessage - string - a description of the error
    • + *
    + * The possible error codes are: + *
      + *
    • 1401 - invalid argument format
    • + *
    • 1402 - missing playlist ID argument
    • + *
    • 1403 - missing playtime argument
    • + *
    • 1404 - playlist not found
    • + *
    • 1405 - timeframe not available
    • + *
    • 1406 - could not schedule playlist
    • + *
    * * @author $Author: fgerlits $ - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ class UploadPlaylistMethod : public XmlRpc::XmlRpcServerMethod { @@ -91,6 +112,11 @@ class UploadPlaylistMethod : public XmlRpc::XmlRpcServerMethod */ static const std::string methodName; + /** + * The ID of this method for error reporting purposes. + */ + static const int errorId; + public: /** diff --git a/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx b/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx index 45abf175f..df5420f8a 100644 --- a/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx +++ b/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: maroy $ - Version : $Revision: 1.4 $ + Author : $Author: fgerlits $ + Version : $Revision: 1.5 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -152,8 +152,9 @@ UploadPlaylistMethodTest :: firstTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref method(new UploadPlaylistMethod()); - XmlRpc::XmlRpcValue rootParameter; XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; struct tm time; @@ -166,10 +167,11 @@ UploadPlaylistMethodTest :: firstTest(void) time.tm_min = 31; time.tm_sec = 1; parameters["playtime"] = &time; - rootParameter[0] = parameters; + rootParameter[0] = parameters; + result.clear(); method->execute(rootParameter, result); - CPPUNIT_ASSERT(result.valid()); + CPPUNIT_ASSERT(result.hasMember("scheduleEntryId")); } @@ -181,8 +183,9 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref method(new UploadPlaylistMethod()); - XmlRpc::XmlRpcValue rootParameter; XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; struct tm time; @@ -195,13 +198,14 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void) time.tm_min = 0; time.tm_sec = 0; parameters["playtime"] = &time; - rootParameter[0] = parameters; + rootParameter[0] = parameters; + result.clear(); method->execute(rootParameter, result); - CPPUNIT_ASSERT(result.valid()); + CPPUNIT_ASSERT(result.hasMember("scheduleEntryId")); // try to load the same one, but in an overlapping time region - // (we know that playlist with id 1 in 1 hour long) + // (we know that playlist with id 1 is 1 hour long) parameters["playlistId"] = 1; time.tm_year = 2001; time.tm_mon = 11; @@ -210,10 +214,12 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void) time.tm_min = 30; time.tm_sec = 0; parameters["playtime"] = &time; - rootParameter[0] = parameters; + rootParameter[0] = parameters; + result.clear(); method->execute(rootParameter, result); - CPPUNIT_ASSERT(!result); + CPPUNIT_ASSERT(result.hasMember("errorCode")); + CPPUNIT_ASSERT(int(result["errorCode"]) == 1405); // timeframe not available // try to load the same one, but now in good timing parameters["playlistId"] = 1; @@ -224,12 +230,13 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void) time.tm_min = 30; time.tm_sec = 0; parameters["playtime"] = &time; - rootParameter[0] = parameters; + rootParameter[0] = parameters; + result.clear(); method->execute(rootParameter, result); - CPPUNIT_ASSERT(result.valid()); + CPPUNIT_ASSERT(result.hasMember("scheduleEntryId")); - // try to load the same one, this time overlapping both previos instnaces + // try to load the same one, this time overlapping both previos instances parameters["playlistId"] = 1; time.tm_year = 2001; time.tm_mon = 11; @@ -238,9 +245,10 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void) time.tm_min = 45; time.tm_sec = 0; parameters["playtime"] = &time; - rootParameter[0] = parameters; + rootParameter[0] = parameters; + result.clear(); method->execute(rootParameter, result); - CPPUNIT_ASSERT(!result); + CPPUNIT_ASSERT(result.hasMember("errorCode")); + CPPUNIT_ASSERT(int(result["errorCode"]) == 1405); // timeframe not available } - diff --git a/livesupport/products/scheduler/src/ValidatePlaylistMethod.cxx b/livesupport/products/scheduler/src/ValidatePlaylistMethod.cxx index b1c410da5..7905885d5 100644 --- a/livesupport/products/scheduler/src/ValidatePlaylistMethod.cxx +++ b/livesupport/products/scheduler/src/ValidatePlaylistMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/ValidatePlaylistMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -96,15 +96,16 @@ ValidatePlaylistMethod :: ValidatePlaylistMethod ( * Execute the stop XML-RPC function call. *----------------------------------------------------------------------------*/ void -ValidatePlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, - XmlRpc::XmlRpcValue & returnValue) +ValidatePlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, + XmlRpc::XmlRpcValue & returnValue) throw () { - if (!parameters.valid()) { + if (!rootParameter.valid() || rootParameter.size() != 1) { XmlRpcTools::markError(errorId+1, "invalid argument format", returnValue); return; } + XmlRpc::XmlRpcValue parameters = rootParameter[0]; Ptr::Ref playlistId; try{ diff --git a/livesupport/products/scheduler/src/ValidatePlaylistMethodTest.cxx b/livesupport/products/scheduler/src/ValidatePlaylistMethodTest.cxx index 9a61fced4..13ea512a8 100644 --- a/livesupport/products/scheduler/src/ValidatePlaylistMethodTest.cxx +++ b/livesupport/products/scheduler/src/ValidatePlaylistMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/ValidatePlaylistMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -152,29 +152,35 @@ ValidatePlaylistMethodTest :: firstTest(void) Ptr::Ref validatePlaylistMethod(new ValidatePlaylistMethod()); XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); XmlRpc::XmlRpcValue result; + result.clear(); parameter["playlistId"] = 275; - validatePlaylistMethod->execute(parameter, result); + rootParameter[0] = parameter; + validatePlaylistMethod->execute(rootParameter, result); CPPUNIT_ASSERT(result.hasMember("errorCode")); CPPUNIT_ASSERT(int(result["errorCode"]) == 503); // no such playlist result.clear(); parameter.clear(); parameter["playlistId"] = 1; - openPlaylistMethod->execute(parameter, result); + rootParameter[0] = parameter; + openPlaylistMethod->execute(rootParameter, result); CPPUNIT_ASSERT(!result.hasMember("errorCode")); result.clear(); - validatePlaylistMethod->execute(parameter, result); + validatePlaylistMethod->execute(rootParameter, result); CPPUNIT_ASSERT(result.hasMember("valid")); CPPUNIT_ASSERT(bool(result["valid"])); result.clear(); parameter["relativeOffset"] = 0; - removeAudioClipMethod->execute(parameter, result); + rootParameter[0] = parameter; + removeAudioClipMethod->execute(rootParameter, result); CPPUNIT_ASSERT(!result.hasMember("errorCode")); result.clear(); - validatePlaylistMethod->execute(parameter, result); + validatePlaylistMethod->execute(rootParameter, result); CPPUNIT_ASSERT(result.hasMember("valid")); CPPUNIT_ASSERT(!bool(result["valid"])); // has a gap at the beginning } diff --git a/livesupport/products/scheduler/src/XmlRpcTools.cxx b/livesupport/products/scheduler/src/XmlRpcTools.cxx index a32574845..9bd1e9652 100644 --- a/livesupport/products/scheduler/src/XmlRpcTools.cxx +++ b/livesupport/products/scheduler/src/XmlRpcTools.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.6 $ + Version : $Revision: 1.7 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcTools.cxx,v $ ------------------------------------------------------------------------------*/ @@ -401,3 +401,16 @@ XmlRpcTools :: extractPlayschedule( return ptime; } + +/*------------------------------------------------------------------------------ + * Convert a schedule entry ID (a UniqueId) to an XmlRpcValue + *----------------------------------------------------------------------------*/ +void +XmlRpcTools :: scheduleEntryIdToXmlRpcValue( + Ptr::Ref scheduleEntryId, + XmlRpc::XmlRpcValue & returnValue) + throw () +{ + returnValue[scheduleEntryIdName] = int(scheduleEntryId->getId()); +} + diff --git a/livesupport/products/scheduler/src/XmlRpcTools.h b/livesupport/products/scheduler/src/XmlRpcTools.h index 341116fed..847efff92 100644 --- a/livesupport/products/scheduler/src/XmlRpcTools.h +++ b/livesupport/products/scheduler/src/XmlRpcTools.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.5 $ + Version : $Revision: 1.6 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcTools.h,v $ ------------------------------------------------------------------------------*/ @@ -71,7 +71,7 @@ using namespace LiveSupport::Core; * in the Scheduler. * * @author $Author: fgerlits $ - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ class XmlRpcTools { @@ -303,6 +303,18 @@ class XmlRpcTools XmlRpc::XmlRpcValue & returnValue) throw (); + /** + * Convert a schedule entry ID (a UniqueId) to an XmlRpcValue + * + * @param scheduleEntryId the UniqueId to convert. + * @param xmlRpcValue the output parameter holding the result of + * the conversion. + */ + static void + scheduleEntryIdToXmlRpcValue( + Ptr::Ref scheduleEntryId, + XmlRpc::XmlRpcValue & returnValue) throw (); + }; /* ================================================= external data structures */