From 27ac235d066bc227c0761c7e2ac28094409ea8f4 Mon Sep 17 00:00:00 2001 From: fgerlits Date: Wed, 20 Oct 2004 06:16:31 +0000 Subject: [PATCH] added savePlaylist and revertEditedPlaylist --- .../src/RevertEditedPlaylistMethod.cxx | 138 +++++++++++++ .../src/RevertEditedPlaylistMethod.h | 149 ++++++++++++++ .../src/RevertEditedPlaylistMethodTest.cxx | 188 ++++++++++++++++++ .../src/RevertEditedPlaylistMethodTest.h | 135 +++++++++++++ .../scheduler/src/SavePlaylistMethod.cxx | 138 +++++++++++++ .../scheduler/src/SavePlaylistMethod.h | 150 ++++++++++++++ .../scheduler/src/SavePlaylistMethodTest.cxx | 167 ++++++++++++++++ .../scheduler/src/SavePlaylistMethodTest.h | 135 +++++++++++++ 8 files changed, 1200 insertions(+) create mode 100644 livesupport/products/scheduler/src/RevertEditedPlaylistMethod.cxx create mode 100644 livesupport/products/scheduler/src/RevertEditedPlaylistMethod.h create mode 100644 livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.cxx create mode 100644 livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.h create mode 100644 livesupport/products/scheduler/src/SavePlaylistMethod.cxx create mode 100644 livesupport/products/scheduler/src/SavePlaylistMethod.h create mode 100644 livesupport/products/scheduler/src/SavePlaylistMethodTest.cxx create mode 100644 livesupport/products/scheduler/src/SavePlaylistMethodTest.h diff --git a/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.cxx b/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.cxx new file mode 100644 index 000000000..b663f86be --- /dev/null +++ b/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.cxx @@ -0,0 +1,138 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#ifdef HAVE_TIME_H +#include +#else +#error need time.h +#endif + + +#include + +#include "LiveSupport/Core/StorageClientInterface.h" +#include "LiveSupport/Storage/StorageClientFactory.h" +#include "XmlRpcTools.h" + +#include "RevertEditedPlaylistMethod.h" + + +using namespace LiveSupport; +using namespace LiveSupport::Core; +using namespace LiveSupport::Storage; + +using namespace LiveSupport::Scheduler; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * The name of this XML-RPC method. + *----------------------------------------------------------------------------*/ +const std::string RevertEditedPlaylistMethod::methodName + = "revertEditedPlaylist"; + +/*------------------------------------------------------------------------------ + * The ID of this method for error reporting purposes. + *----------------------------------------------------------------------------*/ +const int RevertEditedPlaylistMethod::errorId = 800; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Construct the method and register it right away. + *----------------------------------------------------------------------------*/ +RevertEditedPlaylistMethod :: RevertEditedPlaylistMethod ( + Ptr::Ref xmlRpcServer) throw() + : XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get()) +{ +} + + +/*------------------------------------------------------------------------------ + * Execute the stop XML-RPC function call. + *----------------------------------------------------------------------------*/ +void +RevertEditedPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, + XmlRpc::XmlRpcValue & returnValue) + throw () +{ + if (!parameters.valid()) { + XmlRpcTools::markError(errorId+1, "invalid argument format", + returnValue); + return; + } + + 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; + } + + try { + playlist->revertToSavedCopy(); + } + catch (std::logic_error) { + XmlRpcTools::markError(errorId+4, "could not revert playlist", + returnValue); + return; + } +} diff --git a/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.h b/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.h new file mode 100644 index 000000000..6b4cffea6 --- /dev/null +++ b/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.h @@ -0,0 +1,149 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef RevertEditedPlaylistMethod_h +#define RevertEditedPlaylistMethod_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include +#include +#include +#include + +#include "LiveSupport/Core/Ptr.h" +#include "LiveSupport/Core/Playlist.h" + + +namespace LiveSupport { +namespace Scheduler { + +using namespace LiveSupport; +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * An XML-RPC method object to revert a playlist (specified by its playlist id) + * to its previous state, before we started editing it. + * + * The name of the method when called through XML-RPC is + * "revertEditedPlaylist". + * The expected parameter is an XML-RPC structure, with the following + * member: + *
    + *
  • playlistId - int - the unique id of the playlist requested.
  • + *
+ * + * 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: + *
    + *
  • 801 - invalid argument format
  • + *
  • 802 - argument is not a playlist ID
  • + *
  • 803 - playlist not found
  • + *
  • 804 - could not revert playlist
  • + *
+ * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + */ +class RevertEditedPlaylistMethod : public XmlRpc::XmlRpcServerMethod +{ + private: + /** + * The name of this method, as it will be registered into the + * XML-RPC server. + */ + static const std::string methodName; + + /** + * The ID of this method for error reporting purposes. + */ + static const int errorId; + + + public: + /** + * A default constructor, for testing purposes. + */ + RevertEditedPlaylistMethod(void) throw () + : XmlRpc::XmlRpcServerMethod(methodName) + { + } + + /** + * Constuctor that registers the method with the server right away. + * + * @param xmlRpcServer the XML-RPC server to register with. + */ + RevertEditedPlaylistMethod( + Ptr::Ref xmlRpcServer) + throw (); + + /** + * Execute the display schedule command on the Scheduler daemon. + * + * @param parameters XML-RPC function call parameters + * @param returnValue the return value of the call (out parameter) + */ + void + execute(XmlRpc::XmlRpcValue & parameters, + XmlRpc::XmlRpcValue & returnValue) throw (); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Scheduler +} // namespace LiveSupport + +#endif // RevertEditedPlaylistMethod_h + diff --git a/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.cxx b/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.cxx new file mode 100644 index 000000000..d546534a8 --- /dev/null +++ b/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.cxx @@ -0,0 +1,188 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#if HAVE_UNISTD_H +#include +#else +#error "Need unistd.h" +#endif + + +#include +#include +#include + +#include "LiveSupport/Db/ConnectionManagerFactory.h" +#include "LiveSupport/Storage/StorageClientFactory.h" +#include "OpenPlaylistForEditingMethod.h" +#include "RemoveAudioClipFromPlaylistMethod.h" +#include "SavePlaylistMethod.h" + + +#include "RevertEditedPlaylistMethod.h" +#include "RevertEditedPlaylistMethodTest.h" + +using namespace std; +using namespace LiveSupport::Db; +using namespace LiveSupport::Storage; +using namespace LiveSupport::Scheduler; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +CPPUNIT_TEST_SUITE_REGISTRATION(RevertEditedPlaylistMethodTest); + +/** + * The name of the configuration file for the storage client factory. + */ +const std::string RevertEditedPlaylistMethodTest::storageClientConfig = + "etc/storageClient.xml"; + +/** + * The name of the configuration file for the connection manager factory. + */ +const std::string RevertEditedPlaylistMethodTest::connectionManagerConfig = + "etc/connectionManagerFactory.xml"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Configure a Configurable with an XML file. + *----------------------------------------------------------------------------*/ +void +RevertEditedPlaylistMethodTest :: configure( + Ptr::Ref configurable, + const std::string fileName) + throw (std::invalid_argument, + xmlpp::exception) +{ + Ptr::Ref parser(new xmlpp::DomParser(fileName, true)); + const xmlpp::Document * document = parser->get_document(); + const xmlpp::Element * root = document->get_root_node(); + + configurable->configure(*root); +} + + +/*------------------------------------------------------------------------------ + * Set up the test environment + *----------------------------------------------------------------------------*/ +void +RevertEditedPlaylistMethodTest :: setUp(void) throw () +{ + try { + Ptr::Ref scf + = StorageClientFactory::getInstance(); + configure(scf, storageClientConfig); + + Ptr::Ref cmf + = ConnectionManagerFactory::getInstance(); + configure(cmf, connectionManagerConfig); + + } catch (std::invalid_argument &e) { + CPPUNIT_FAIL("semantic error in configuration file"); + } catch (xmlpp::exception &e) { + CPPUNIT_FAIL("error parsing configuration file"); + } catch (std::exception &e) { + CPPUNIT_FAIL(e.what()); + } +} + + +/*------------------------------------------------------------------------------ + * Clean up the test environment + *----------------------------------------------------------------------------*/ +void +RevertEditedPlaylistMethodTest :: tearDown(void) throw () +{ +} + + +/*------------------------------------------------------------------------------ + * Just a very simple smoke test + *----------------------------------------------------------------------------*/ +void +RevertEditedPlaylistMethodTest :: firstTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::Ref + openMethod(new OpenPlaylistForEditingMethod); + Ptr::Ref + removeMethod(new RemoveAudioClipFromPlaylistMethod); + Ptr::Ref + saveMethod(new SavePlaylistMethod); + Ptr::Ref + revertMethod(new RevertEditedPlaylistMethod); + XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue result; + + parameter["playlistId"] = 1; + parameter["relativeOffset"] = 0; + + revertMethod->execute(parameter, result); + CPPUNIT_ASSERT(result.hasMember("errorCode")); + CPPUNIT_ASSERT(int(result["errorCode"]) == 804); // no saved copy yet + + result.clear(); + openMethod->execute(parameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); + result.clear(); + removeMethod->execute(parameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); + result.clear(); + removeMethod->execute(parameter, result); + CPPUNIT_ASSERT(result.hasMember("errorCode")); // can't remove it twice + + result.clear(); + revertMethod->execute(parameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); + result.clear(); + removeMethod->execute(parameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); // but now we can again + + result.clear(); + saveMethod->execute(parameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); + result.clear(); + revertMethod->execute(parameter, result); + CPPUNIT_ASSERT(result.hasMember("errorCode")); // saved copy has been + CPPUNIT_ASSERT(int(result["errorCode"]) == 804); // discarded +} diff --git a/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.h b/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.h new file mode 100644 index 000000000..fe681de74 --- /dev/null +++ b/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.h @@ -0,0 +1,135 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef RevertEditedPlaylistMethodTest_h +#define RevertEditedPlaylistMethodTest_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include + + +namespace LiveSupport { +namespace Scheduler { + +using namespace LiveSupport; +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * Unit test for the RevertEditedPlaylistMethod class. + * + * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + * @see RevertEditedPlaylistMethod + */ +class RevertEditedPlaylistMethodTest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(RevertEditedPlaylistMethodTest); + CPPUNIT_TEST(firstTest); + CPPUNIT_TEST_SUITE_END(); + + /** + * The name of the configuration file for the storage client factory. + */ + static const std::string storageClientConfig; + + /** + * The name of the configuration file for the connection manager + * factory. + */ + static const std::string connectionManagerConfig; + + /** + * Configure a configurable with an XML file. + * + * @param configurable configure this + * @param fileName the name of the XML file to configure with. + * @exception std::invalid_argument on configuration errors. + * @exception xmlpp::exception on XML parsing errors. + */ + void + configure(Ptr::Ref configurable, + std::string fileName) + throw (std::invalid_argument, + xmlpp::exception); + + protected: + + /** + * A simple test. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + firstTest(void) throw (CPPUNIT_NS::Exception); + + + public: + + /** + * Set up the environment for the test case. + */ + void + setUp(void) throw (); + + /** + * Clean up the environment after the test case. + */ + void + tearDown(void) throw (); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Scheduler +} // namespace LiveSupport + +#endif // RevertEditedPlaylistMethodTest_h + diff --git a/livesupport/products/scheduler/src/SavePlaylistMethod.cxx b/livesupport/products/scheduler/src/SavePlaylistMethod.cxx new file mode 100644 index 000000000..397524e4a --- /dev/null +++ b/livesupport/products/scheduler/src/SavePlaylistMethod.cxx @@ -0,0 +1,138 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SavePlaylistMethod.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#ifdef HAVE_TIME_H +#include +#else +#error need time.h +#endif + + +#include + +#include "LiveSupport/Core/StorageClientInterface.h" +#include "LiveSupport/Storage/StorageClientFactory.h" +#include "XmlRpcTools.h" + +#include "SavePlaylistMethod.h" + + +using namespace LiveSupport; +using namespace LiveSupport::Core; +using namespace LiveSupport::Storage; + +using namespace LiveSupport::Scheduler; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * The name of this XML-RPC method. + *----------------------------------------------------------------------------*/ +const std::string SavePlaylistMethod::methodName + = "savePlaylist"; + +/*------------------------------------------------------------------------------ + * The ID of this method for error reporting purposes. + *----------------------------------------------------------------------------*/ +const int SavePlaylistMethod::errorId = 700; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Construct the method and register it right away. + *----------------------------------------------------------------------------*/ +SavePlaylistMethod :: SavePlaylistMethod ( + Ptr::Ref xmlRpcServer) throw() + : XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get()) +{ +} + + +/*------------------------------------------------------------------------------ + * Execute the stop XML-RPC function call. + *----------------------------------------------------------------------------*/ +void +SavePlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, + XmlRpc::XmlRpcValue & returnValue) + throw () +{ + if (!parameters.valid()) { + XmlRpcTools::markError(errorId+1, "invalid argument format", + returnValue); + return; + } + + 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; + } + + if (!playlist->setLockedForEditing(false)) { + XmlRpcTools::markError(errorId+4, + "could not save playlist", + returnValue); + return; + } + + playlist->deleteSavedCopy(); +} diff --git a/livesupport/products/scheduler/src/SavePlaylistMethod.h b/livesupport/products/scheduler/src/SavePlaylistMethod.h new file mode 100644 index 000000000..b3ec83f59 --- /dev/null +++ b/livesupport/products/scheduler/src/SavePlaylistMethod.h @@ -0,0 +1,150 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SavePlaylistMethod.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef SavePlaylistMethod_h +#define SavePlaylistMethod_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include +#include +#include +#include + +#include "LiveSupport/Core/Ptr.h" +#include "LiveSupport/Core/Playlist.h" + + +namespace LiveSupport { +namespace Scheduler { + +using namespace LiveSupport; +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * An XML-RPC method object to save a playlist (specified by its playlist id) + * after editing. It releases the "locked for editing" lock and discards the + * copy of the playlist which was saved for reverting to. + * + * The name of the method when called through XML-RPC is + * "savePlaylist". + * The expected parameter is an XML-RPC structure, with the following + * member: + *
    + *
  • playlistId - int - the unique id of the playlist to save.
  • + *
+ * + * 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: + *
    + *
  • 701 - invalid argument format
  • + *
  • 702 - argument is not a playlist ID
  • + *
  • 703 - playlist not found
  • + *
  • 704 - could not save playlist
  • + *
+ * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + */ +class SavePlaylistMethod : public XmlRpc::XmlRpcServerMethod +{ + private: + /** + * The name of this method, as it will be registered into the + * XML-RPC server. + */ + static const std::string methodName; + + /** + * The ID of this method for error reporting purposes. + */ + static const int errorId; + + + public: + /** + * A default constructor, for testing purposes. + */ + SavePlaylistMethod(void) throw () + : XmlRpc::XmlRpcServerMethod(methodName) + { + } + + /** + * Constuctor that registers the method with the server right away. + * + * @param xmlRpcServer the XML-RPC server to register with. + */ + SavePlaylistMethod( + Ptr::Ref xmlRpcServer) + throw (); + + /** + * Execute the display schedule command on the Scheduler daemon. + * + * @param parameters XML-RPC function call parameters + * @param returnValue the return value of the call (out parameter) + */ + void + execute(XmlRpc::XmlRpcValue & parameters, + XmlRpc::XmlRpcValue & returnValue) throw (); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Scheduler +} // namespace LiveSupport + +#endif // SavePlaylistMethod_h + diff --git a/livesupport/products/scheduler/src/SavePlaylistMethodTest.cxx b/livesupport/products/scheduler/src/SavePlaylistMethodTest.cxx new file mode 100644 index 000000000..9e1b9f858 --- /dev/null +++ b/livesupport/products/scheduler/src/SavePlaylistMethodTest.cxx @@ -0,0 +1,167 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SavePlaylistMethodTest.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#if HAVE_UNISTD_H +#include +#else +#error "Need unistd.h" +#endif + + +#include +#include +#include + +#include "LiveSupport/Db/ConnectionManagerFactory.h" +#include "LiveSupport/Storage/StorageClientFactory.h" +#include "OpenPlaylistForEditingMethod.h" + +#include "SavePlaylistMethod.h" +#include "SavePlaylistMethodTest.h" + + +using namespace std; +using namespace LiveSupport::Db; +using namespace LiveSupport::Storage; +using namespace LiveSupport::Scheduler; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +CPPUNIT_TEST_SUITE_REGISTRATION(SavePlaylistMethodTest); + +/** + * The name of the configuration file for the storage client factory. + */ +const std::string SavePlaylistMethodTest::storageClientConfig = + "etc/storageClient.xml"; + +/** + * The name of the configuration file for the connection manager factory. + */ +const std::string SavePlaylistMethodTest::connectionManagerConfig = + "etc/connectionManagerFactory.xml"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Configure a Configurable with an XML file. + *----------------------------------------------------------------------------*/ +void +SavePlaylistMethodTest :: configure( + Ptr::Ref configurable, + const std::string fileName) + throw (std::invalid_argument, + xmlpp::exception) +{ + Ptr::Ref parser(new xmlpp::DomParser(fileName, true)); + const xmlpp::Document * document = parser->get_document(); + const xmlpp::Element * root = document->get_root_node(); + + configurable->configure(*root); +} + + +/*------------------------------------------------------------------------------ + * Set up the test environment + *----------------------------------------------------------------------------*/ +void +SavePlaylistMethodTest :: setUp(void) throw () +{ + try { + Ptr::Ref scf + = StorageClientFactory::getInstance(); + configure(scf, storageClientConfig); + + Ptr::Ref cmf + = ConnectionManagerFactory::getInstance(); + configure(cmf, connectionManagerConfig); + + } catch (std::invalid_argument &e) { + CPPUNIT_FAIL("semantic error in configuration file"); + } catch (xmlpp::exception &e) { + CPPUNIT_FAIL("error parsing configuration file"); + } catch (std::exception &e) { + CPPUNIT_FAIL(e.what()); + } +} + + +/*------------------------------------------------------------------------------ + * Clean up the test environment + *----------------------------------------------------------------------------*/ +void +SavePlaylistMethodTest :: tearDown(void) throw () +{ +} + + +/*------------------------------------------------------------------------------ + * Just a very simple smoke test + *----------------------------------------------------------------------------*/ +void +SavePlaylistMethodTest :: firstTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::Ref + openMethod(new OpenPlaylistForEditingMethod()); + Ptr::Ref saveMethod(new SavePlaylistMethod()); + XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue result; + + parameter["playlistId"] = 9999; + + saveMethod->execute(parameter, result); + CPPUNIT_ASSERT(result.hasMember("errorCode")); + CPPUNIT_ASSERT(int(result["errorCode"]) == 703); // playlist not found + + parameter["playlistId"] = 1; + result.clear(); + openMethod->execute(parameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); + result.clear(); + saveMethod->execute(parameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); // open then save OK + + result.clear(); + openMethod->execute(parameter, result); + CPPUNIT_ASSERT(!result.hasMember("errorCode")); // save then open OK +} diff --git a/livesupport/products/scheduler/src/SavePlaylistMethodTest.h b/livesupport/products/scheduler/src/SavePlaylistMethodTest.h new file mode 100644 index 000000000..d2daf4845 --- /dev/null +++ b/livesupport/products/scheduler/src/SavePlaylistMethodTest.h @@ -0,0 +1,135 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SavePlaylistMethodTest.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef SavePlaylistMethodTest_h +#define SavePlaylistMethodTest_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include + + +namespace LiveSupport { +namespace Scheduler { + +using namespace LiveSupport; +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * Unit test for the SavePlaylistMethod class. + * + * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + * @see SavePlaylistMethod + */ +class SavePlaylistMethodTest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(SavePlaylistMethodTest); + CPPUNIT_TEST(firstTest); + CPPUNIT_TEST_SUITE_END(); + + /** + * The name of the configuration file for the storage client factory. + */ + static const std::string storageClientConfig; + + /** + * The name of the configuration file for the connection manager + * factory. + */ + static const std::string connectionManagerConfig; + + /** + * Configure a configurable with an XML file. + * + * @param configurable configure this + * @param fileName the name of the XML file to configure with. + * @exception std::invalid_argument on configuration errors. + * @exception xmlpp::exception on XML parsing errors. + */ + void + configure(Ptr::Ref configurable, + std::string fileName) + throw (std::invalid_argument, + xmlpp::exception); + + protected: + + /** + * A simple test. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + firstTest(void) throw (CPPUNIT_NS::Exception); + + + public: + + /** + * Set up the environment for the test case. + */ + void + setUp(void) throw (); + + /** + * Clean up the environment after the test case. + */ + void + tearDown(void) throw (); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Scheduler +} // namespace LiveSupport + +#endif // SavePlaylistMethodTest_h +