added addAudioClip XML-RPC server method

This commit is contained in:
fgerlits 2004-10-14 17:36:05 +00:00
parent 690c3e7bc0
commit 55a0dcc50f
4 changed files with 639 additions and 0 deletions

View File

@ -0,0 +1,177 @@
/*------------------------------------------------------------------------------
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/AddAudioClipToPlaylistMethod.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_TIME_H
#include <time.h>
#else
#error need time.h
#endif
#include <string>
#include "LiveSupport/Core/StorageClientInterface.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "ScheduleInterface.h"
#include "ScheduleFactory.h"
#include "XmlRpcTools.h"
#include "AddAudioClipToPlaylistMethod.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 AddAudioClipToPlaylistMethod::methodName
= "addAudioClipToPlaylist";
/*------------------------------------------------------------------------------
* The ID of this method for error reporting purposes.
*----------------------------------------------------------------------------*/
const int AddAudioClipToPlaylistMethod::errorId = 300;
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Construct the method and register it right away.
*----------------------------------------------------------------------------*/
AddAudioClipToPlaylistMethod :: AddAudioClipToPlaylistMethod (
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer) throw()
: XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get())
{
}
/*------------------------------------------------------------------------------
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
AddAudioClipToPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
if (!parameters.valid()) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
Ptr<UniqueId>::Ref playlistId;
try{
playlistId = XmlRpcTools::extractPlaylistId(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+2,
"missing playlist ID argument",
returnValue);
return;
}
Ptr<UniqueId>::Ref audioClipId;
try{
audioClipId = XmlRpcTools::extractAudioClipId(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+3,
"missing audio clip ID argument",
returnValue);
return;
}
Ptr<time_duration>::Ref relativeOffset;
try{
relativeOffset = XmlRpcTools::extractRelativeOffset(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+4,
"missing relative offset argument",
returnValue);
return;
}
Ptr<StorageClientFactory>::Ref scf;
Ptr<StorageClientInterface>::Ref storage;
scf = StorageClientFactory::getInstance();
storage = scf->getStorageClient();
if (!storage->existsPlaylist(playlistId)) {
XmlRpcTools::markError(errorId+5, "playlist does not exist",
returnValue);
return;
}
Ptr<Playlist>::Ref playlist;
try {
playlist = storage->getPlaylist(playlistId);
}
catch (std::invalid_argument &e) { // this should never happen
XmlRpcTools::markError(errorId+6, "could not load playlist",
returnValue);
return;
}
if (!playlist->getIsLockedForEditing()) {
XmlRpcTools::markError(errorId+7,
"playlist has not been opened for editing",
returnValue);
return;
}
try { // and finally, the beef
playlist->addAudioClip(audioClipId, relativeOffset);
}
catch(std::invalid_argument &e) {
XmlRpcTools::markError(errorId+8, e.what(), returnValue);
return;
}
}

View File

@ -0,0 +1,158 @@
/*------------------------------------------------------------------------------
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/AddAudioClipToPlaylistMethod.h,v $
------------------------------------------------------------------------------*/
#ifndef AddAudioClipToPlaylistMethod_h
#define AddAudioClipToPlaylistMethod_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <string>
#include <XmlRpcServerMethod.h>
#include <XmlRpcValue.h>
#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 add an audio clip (specified by its ID)
* to a playlist (also specified by its ID).
*
* The name of the method when called through XML-RPC is
* "addAudioClipToPlaylist".
* The expected parameter is an XML-RPC structure, with the following
* members:
* <ul>
* <li>playlistId - int - the unique id of the playlist.</li>
* <li>audioClipId - int - the unique id of the audio clip to
* be added.</li>
* <li>relativeOffset - int - the number of seconds between the
* start of the playlist and the start of the audio clip.</li>
* </ul>
*
* In case of an error, an XML-RPC structure is returned, with the following
* fields:
* <ul>
* <li>errorCode - int - the id of the error condition</li>
* <li>errorMessage - string - a description of the error</li>
* </ul>
* The possible error codes are:
* <ul>
* <li>301 - invalid argument format </li>
* <li>301 - missing playlist ID argument </li>
* <li>301 - missing audio clip ID argument </li>
* <li>301 - missing relative offset argument </li>
* <li>301 - playlist does not exist </li>
* <li>301 - could not load playlist </li>
* <li>301 - playlist has not been opened for editing </li>
* <li>301 - two audio clips at the same relative offset
* (from Playlist::addAudioClipToPlaylist()) </li>
* </ul>
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
*/
class AddAudioClipToPlaylistMethod : 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.
*/
AddAudioClipToPlaylistMethod(void) throw ()
: XmlRpc::XmlRpcServerMethod(methodName)
{
}
/**
* Constuctor that registers the method with the server right away.
*
* @param xmlRpcServer the XML-RPC server to register with.
*/
AddAudioClipToPlaylistMethod(
Ptr<XmlRpc::XmlRpcServer>::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 // AddAudioClipToPlaylistMethod_h

View File

@ -0,0 +1,169 @@
/*------------------------------------------------------------------------------
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/AddAudioClipToPlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#include <string>
#include <iostream>
#include <XmlRpcValue.h>
#include "LiveSupport/Db/ConnectionManagerFactory.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "XmlRpcTools.h"
#include "OpenPlaylistForEditingMethod.h"
#include "AddAudioClipToPlaylistMethod.h"
#include "AddAudioClipToPlaylistMethodTest.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(AddAudioClipToPlaylistMethodTest);
/**
* The name of the configuration file for the storage client factory.
*/
const std::string AddAudioClipToPlaylistMethodTest::storageClientConfig =
"etc/storageClient.xml";
/**
* The name of the configuration file for the connection manager factory.
*/
const std::string AddAudioClipToPlaylistMethodTest::connectionManagerConfig =
"etc/connectionManagerFactory.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Configure a Configurable with an XML file.
*----------------------------------------------------------------------------*/
void
AddAudioClipToPlaylistMethodTest :: configure(
Ptr<Configurable>::Ref configurable,
const std::string fileName)
throw (std::invalid_argument,
xmlpp::exception)
{
Ptr<xmlpp::DomParser>::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
AddAudioClipToPlaylistMethodTest :: setUp(void) throw ()
{
try {
Ptr<StorageClientFactory>::Ref scf
= StorageClientFactory::getInstance();
configure(scf, storageClientConfig);
Ptr<ConnectionManagerFactory>::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
AddAudioClipToPlaylistMethodTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Just a very simple smoke test
*----------------------------------------------------------------------------*/
void
AddAudioClipToPlaylistMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<OpenPlaylistForEditingMethod>::Ref
openPlaylistMethod(new OpenPlaylistForEditingMethod());
Ptr<AddAudioClipToPlaylistMethod>::Ref
addAudioClipMethod(new AddAudioClipToPlaylistMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue result;
parameter["playlistId"] = 1;
parameter["audioClipId"] = 20002;
parameter["relativeOffset"] = 60*60;
openPlaylistMethod->execute(parameter, result);
addAudioClipMethod->execute(parameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT((int)(result["errorCode"]) == 308);
parameter.clear();
result.clear();
parameter["playlistId"] = 1;
parameter["audioClipId"] = 20003;
parameter["relativeOffset"] = 90*60;
addAudioClipMethod->execute(parameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
}

View File

@ -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/AddAudioClipToPlaylistMethodTest.h,v $
------------------------------------------------------------------------------*/
#ifndef AddAudioClipToPlaylistMethodTest_h
#define AddAudioClipToPlaylistMethodTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Scheduler {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the AddAudioClipToPlaylistMethod class.
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
* @see AddAudioClipToPlaylistMethod
*/
class AddAudioClipToPlaylistMethodTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(AddAudioClipToPlaylistMethodTest);
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<Configurable>::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 // AddAudioClipToPlaylistMethodTest_h