diff --git a/livesupport/modules/core/etc/Makefile.in b/livesupport/modules/core/etc/Makefile.in index 3b8c187b6..db8b16901 100644 --- a/livesupport/modules/core/etc/Makefile.in +++ b/livesupport/modules/core/etc/Makefile.in @@ -21,7 +21,7 @@ # # # Author : $Author: fgerlits $ -# Version : $Revision: 1.5 $ +# Version : $Revision: 1.6 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/etc/Makefile.in,v $ # # @configure_input@ @@ -85,11 +85,9 @@ LDFLAGS = @LDFLAGS@ -L${USR_LIB_DIR} -L${LIB_DIR} # Dependencies #------------------------------------------------------------------------------- CORE_LIB_OBJS = ${TMP_DIR}/UniqueId.o \ - ${TMP_DIR}/Playlist.o \ - ${TMP_DIR}/AudioClip.o + ${TMP_DIR}/Playlist.o TEST_RUNNER_OBJS = ${TMP_DIR}/PlaylistTest.o \ - ${TMP_DIR}/AudioClipTest.o \ ${TMP_DIR}/TestRunner.o TEST_RUNNER_LIBS = -l${CORE_LIB} -lxml++-1.0 -lcppunit -ldl diff --git a/livesupport/products/scheduler/doc/model/SchedulerModel.zuml b/livesupport/products/scheduler/doc/model/SchedulerModel.zuml index 726140fad..ab5f95812 100644 Binary files a/livesupport/products/scheduler/doc/model/SchedulerModel.zuml and b/livesupport/products/scheduler/doc/model/SchedulerModel.zuml differ diff --git a/livesupport/products/scheduler/etc/Makefile.in b/livesupport/products/scheduler/etc/Makefile.in index 223ce171c..165d43bb3 100644 --- a/livesupport/products/scheduler/etc/Makefile.in +++ b/livesupport/products/scheduler/etc/Makefile.in @@ -21,7 +21,7 @@ # # # Author : $Author: fgerlits $ -# Version : $Revision: 1.11 $ +# Version : $Revision: 1.12 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/etc/Makefile.in,v $ # # @configure_input@ @@ -121,8 +121,8 @@ SCHEDULER_OBJS = ${TMP_DIR}/SignalDispatcher.o \ ${TMP_DIR}/PostgresqlSchedule.o \ ${TMP_DIR}/DeletePlaylistMethod.o \ ${TMP_DIR}/DisplayPlaylistsMethod.o \ - ${TMP_DIR}/CreatePlaylistMethod.o \ - ${TMP_DIR}/OpenPlaylistForEditingMethod.o + ${TMP_DIR}/OpenPlaylistForEditingMethod.o \ + ${TMP_DIR}/CreatePlaylistMethod.o SCHEDULER_EXE_OBJS = ${SCHEDULER_OBJS} \ ${TMP_DIR}/main.o @@ -146,8 +146,8 @@ TEST_RUNNER_OBJS = ${SCHEDULER_OBJS} \ ${TMP_DIR}/PostgresqlScheduleTest.o \ ${TMP_DIR}/DeletePlaylistMethodTest.o \ ${TMP_DIR}/DisplayPlaylistsMethodTest.o \ - ${TMP_DIR}/CreatePlaylistMethodTest.o \ ${TMP_DIR}/OpenPlaylistForEditingMethodTest.o \ + ${TMP_DIR}/CreatePlaylistMethodTest.o \ ${TMP_DIR}/TestRunner.o TEST_RUNNER_LIBS = ${SCHEDULER_EXE_LIBS} -lcppunit -ldl diff --git a/livesupport/products/scheduler/src/CreatePlaylistMethod.cxx b/livesupport/products/scheduler/src/CreatePlaylistMethod.cxx new file mode 100644 index 000000000..4819bcddb --- /dev/null +++ b/livesupport/products/scheduler/src/CreatePlaylistMethod.cxx @@ -0,0 +1,117 @@ +/*------------------------------------------------------------------------------ + + 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.4 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/CreatePlaylistMethod.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 "ScheduleInterface.h" +#include "ScheduleFactory.h" +#include "XmlRpcTools.h" + +#include "CreatePlaylistMethod.h" + + +using namespace boost; +using namespace boost::posix_time; + +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 CreatePlaylistMethod::methodName = "createPlaylist"; + +/*------------------------------------------------------------------------------ + * The ID of this method for error reporting purposes. + *----------------------------------------------------------------------------*/ +const int CreatePlaylistMethod::errorId = 200; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Construct the method and register it right away. + *----------------------------------------------------------------------------*/ +CreatePlaylistMethod :: CreatePlaylistMethod ( + Ptr::Ref xmlRpcServer) throw() + : XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get()) +{ +} + + +/*------------------------------------------------------------------------------ + * Execute the stop XML-RPC function call. + *----------------------------------------------------------------------------*/ +void +CreatePlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, + XmlRpc::XmlRpcValue & returnValue) + throw () +{ + Ptr::Ref scf; + Ptr::Ref storage; + + scf = StorageClientFactory::getInstance(); + storage = scf->getStorageClient(); + + Ptr::Ref playlist = storage->createPlaylist(); + + if (!playlist->setLockedForEditing(true)) { // this should never happen + XmlRpcTools :: markError(errorId+1, + "could not open new playlist for editing", + returnValue); + return; + } + XmlRpcTools :: playlistToXmlRpcValue(playlist, returnValue); +} diff --git a/livesupport/products/scheduler/src/CreatePlaylistMethod.h b/livesupport/products/scheduler/src/CreatePlaylistMethod.h new file mode 100644 index 000000000..1541f0725 --- /dev/null +++ b/livesupport/products/scheduler/src/CreatePlaylistMethod.h @@ -0,0 +1,147 @@ +/*------------------------------------------------------------------------------ + + 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.4 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/CreatePlaylistMethod.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef CreatePlaylistMethod_h +#define CreatePlaylistMethod_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 create a new playlist in the playlist store. + * + * The name of the method when called through XML-RPC is "createPlaylist". + * + * The XML-RPC function returns an XML-RPC structure, containing the following + * fields: + *
    + *
  • id - int - the unique id of the new playlist
  • + *
  • playlength - int - the playlist length of the playlist, in seconds + *
  • + *
+ * 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: + *
    + *
  • 201 - could not open new playlist for editing
  • + *
+ * + * @author $Author: fgerlits $ + * @version $Revision: 1.4 $ + */ +class CreatePlaylistMethod : 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. + */ + CreatePlaylistMethod(void) throw () + : XmlRpc::XmlRpcServerMethod(methodName) + { + } + + /** + * Constuctor that registers the method with the server right away. + * + * @param xmlRpcServer the XML-RPC server to register with. + */ + CreatePlaylistMethod( + Ptr::Ref xmlRpcServer) + throw (); + + /** + * Execute the create playlist 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 // CreatePlaylistMethod_h + diff --git a/livesupport/products/scheduler/src/CreatePlaylistMethodTest.cxx b/livesupport/products/scheduler/src/CreatePlaylistMethodTest.cxx new file mode 100644 index 000000000..edc1dfb4c --- /dev/null +++ b/livesupport/products/scheduler/src/CreatePlaylistMethodTest.cxx @@ -0,0 +1,162 @@ +/*------------------------------------------------------------------------------ + + 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.4 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/CreatePlaylistMethodTest.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 "CreatePlaylistMethod.h" +#include "OpenPlaylistForEditingMethod.h" +#include "CreatePlaylistMethodTest.h" + +using namespace XmlRpc; + +using namespace LiveSupport::Db; +using namespace LiveSupport::Storage; +using namespace LiveSupport::Scheduler; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +CPPUNIT_TEST_SUITE_REGISTRATION(CreatePlaylistMethodTest); + +/** + * The name of the configuration file for the storage client factory. + */ +const std::string CreatePlaylistMethodTest::storageClientConfig = + "etc/storageClient.xml"; + +/** + * The name of the configuration file for the connection manager factory. + */ +const std::string CreatePlaylistMethodTest::connectionManagerConfig = + "etc/connectionManagerFactory.xml"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Configure a Configurable with an XML file. + *----------------------------------------------------------------------------*/ +void +CreatePlaylistMethodTest :: 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 +CreatePlaylistMethodTest :: 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 +CreatePlaylistMethodTest :: tearDown(void) throw () +{ +} + + +/*------------------------------------------------------------------------------ + * Just a very simple smoke test + *----------------------------------------------------------------------------*/ +void +CreatePlaylistMethodTest :: firstTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::Ref method(new CreatePlaylistMethod()); + XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue result; + + method->execute(parameter, 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; + + // should not allow to open the same playlist for editing again + method->execute(parameter, result); + CPPUNIT_ASSERT((int) result["errorCode"] == 105); + CPPUNIT_ASSERT((const std::string) result["errorMessage"] == + "playlist could not be opened (already open?)"); +} diff --git a/livesupport/products/scheduler/src/CreatePlaylistMethodTest.h b/livesupport/products/scheduler/src/CreatePlaylistMethodTest.h new file mode 100644 index 000000000..2f1eddbb5 --- /dev/null +++ b/livesupport/products/scheduler/src/CreatePlaylistMethodTest.h @@ -0,0 +1,136 @@ +/*------------------------------------------------------------------------------ + + 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.3 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/CreatePlaylistMethodTest.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef CreatePlaylistMethodTest_h +#define CreatePlaylistMethodTest_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 CreatePlaylistMethod class. + * + * @author $Author: fgerlits $ + * @version $Revision: 1.3 $ + * @see CreatePlaylistMethod + */ +class CreatePlaylistMethodTest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(CreatePlaylistMethodTest); + 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 // CreatePlaylistMethodTest_h + diff --git a/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.cxx b/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.cxx new file mode 100644 index 000000000..6f65f36a9 --- /dev/null +++ b/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.cxx @@ -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.3 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.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 "ScheduleInterface.h" +#include "ScheduleFactory.h" +#include "XmlRpcTools.h" + +#include "OpenPlaylistForEditingMethod.h" + + +using namespace boost; +using namespace boost::posix_time; + +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 OpenPlaylistForEditingMethod::methodName = "openPlaylistForEditing"; + +/*------------------------------------------------------------------------------ + * The ID of this method for error reporting purposes. + *----------------------------------------------------------------------------*/ +const int OpenPlaylistForEditingMethod::errorId = 100; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Construct the method and register it right away. + *----------------------------------------------------------------------------*/ +OpenPlaylistForEditingMethod :: OpenPlaylistForEditingMethod ( + Ptr::Ref xmlRpcServer) throw() + : XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get()) +{ +} + + +/*------------------------------------------------------------------------------ + * Execute the stop XML-RPC function call. + *----------------------------------------------------------------------------*/ +void +OpenPlaylistForEditingMethod :: 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(); + + if (!storage->existsPlaylist(id)) { + XmlRpcTools::markError(errorId+3, "playlist does not exist", + returnValue); + return; + } + + Ptr::Ref playlist; + try { + playlist = storage->getPlaylist(id); + } + catch (std::invalid_argument &e) { + XmlRpcTools::markError(errorId+4, "could not open playlist", + returnValue); + return; + } + + if (!playlist->setLockedForEditing(true)) { + XmlRpcTools::markError(errorId+5, "playlist could not be opened (already open?)", + returnValue); + return; + } + + XmlRpcTools::playlistToXmlRpcValue(playlist, returnValue); + + return; +} diff --git a/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.h b/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.h new file mode 100644 index 000000000..fd03087cf --- /dev/null +++ b/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.h @@ -0,0 +1,157 @@ +/*------------------------------------------------------------------------------ + + 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.3 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef OpenPlaylistForEditingMethod_h +#define OpenPlaylistForEditingMethod_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 open a playlist (specified by its playlist id) + * for editing. + * + * The name of the method when called through XML-RPC is + * "openPlaylistForEditing". + * The expected parameter is an XML-RPC structure, with the following + * member: + *
    + *
  • playlistId - int - the unique id of the playlist requested.
  • + *
+ * + * The XML-RPC function returns an XML-RPC structure, containing the following + * fields: + *
    + *
  • id - int - the unique id of the playlist
  • + *
  • playlength - int - the playlist length of the playlist, in seconds + *
  • + *
+ * 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: + *
    + *
  • 101 - invalid argument format
  • + *
  • 102 - argument is not a playlist ID
  • + *
  • 103 - playlist does not exist
  • + *
  • 104 - could not open playlist
  • + *
  • 105 - playlist could not be opened (already open?)
  • + *
+ * @author $Author: fgerlits $ + * @version $Revision: 1.3 $ + */ +class OpenPlaylistForEditingMethod : 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. + */ + OpenPlaylistForEditingMethod(void) throw () + : XmlRpc::XmlRpcServerMethod(methodName) + { + } + + /** + * Constuctor that registers the method with the server right away. + * + * @param xmlRpcServer the XML-RPC server to register with. + */ + OpenPlaylistForEditingMethod( + 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 // OpenPlaylistForEditingMethod_h + diff --git a/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.cxx b/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.cxx new file mode 100644 index 000000000..123da1485 --- /dev/null +++ b/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.cxx @@ -0,0 +1,173 @@ +/*------------------------------------------------------------------------------ + + 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.3 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.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 "XmlRpcTools.h" + +#include "OpenPlaylistForEditingMethod.h" +#include "OpenPlaylistForEditingMethodTest.h" + + +using namespace LiveSupport::Db; +using namespace LiveSupport::Storage; +using namespace LiveSupport::Scheduler; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +CPPUNIT_TEST_SUITE_REGISTRATION(OpenPlaylistForEditingMethodTest); + +/** + * The name of the configuration file for the storage client factory. + */ +const std::string OpenPlaylistForEditingMethodTest::storageClientConfig = + "etc/storageClient.xml"; + +/** + * The name of the configuration file for the connection manager factory. + */ +const std::string OpenPlaylistForEditingMethodTest::connectionManagerConfig = + "etc/connectionManagerFactory.xml"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Configure a Configurable with an XML file. + *----------------------------------------------------------------------------*/ +void +OpenPlaylistForEditingMethodTest :: 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 +OpenPlaylistForEditingMethodTest :: 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 +OpenPlaylistForEditingMethodTest :: tearDown(void) throw () +{ +} + + +/*------------------------------------------------------------------------------ + * Just a very simple smoke test + *----------------------------------------------------------------------------*/ +void +OpenPlaylistForEditingMethodTest :: firstTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::Ref + method(new OpenPlaylistForEditingMethod()); + XmlRpc::XmlRpcValue parameter; + XmlRpc::XmlRpcValue result; + + parameter["playlistId"] = 1; + + method->execute(parameter, result); + CPPUNIT_ASSERT((int) result["id"] == 1); + CPPUNIT_ASSERT((int) result["playlength"] == (60 * 60)); + + parameter.clear(); + result.clear(); + parameter["playlistId"] = 6376; + + // no such playlist + method->execute(parameter, result); + CPPUNIT_ASSERT((int) result["errorCode"] == 103); + CPPUNIT_ASSERT((const std::string) result["errorMessage"] == + "playlist does not exist"); + parameter.clear(); + result.clear(); + parameter["playlistId"] = 1; + + // should not allow to open the same playlist for editing again + method->execute(parameter, result); + CPPUNIT_ASSERT((int) result["errorCode"] == 105); + CPPUNIT_ASSERT((const std::string) result["errorMessage"] == + "playlist could not be opened (already open?)"); + +} diff --git a/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.h b/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.h new file mode 100644 index 000000000..ec9a01f88 --- /dev/null +++ b/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.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.3 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef OpenPlaylistForEditingMethodTest_h +#define OpenPlaylistForEditingMethodTest_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 OpenPlaylistForEditingMethod class. + * + * @author $Author: fgerlits $ + * @version $Revision: 1.3 $ + * @see OpenPlaylistForEditingMethod + */ +class OpenPlaylistForEditingMethodTest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(OpenPlaylistForEditingMethodTest); + 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 // OpenPlaylistForEditingMethodTest_h +