ugh - cleaned up the mess I made earlier when I added the error reporting

to the XML-RPC server methods...  it works now, I think
This commit is contained in:
fgerlits 2004-10-22 12:48:58 +00:00
parent 27ac235d06
commit 680d7eccf9
44 changed files with 769 additions and 446 deletions

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -96,22 +96,24 @@ AddAudioClipToPlaylistMethod :: AddAudioClipToPlaylistMethod (
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
AddAudioClipToPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
AddAudioClipToPlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
XmlRpc::XmlRpcValue & returnValue)
throw ()
throw ()
{
if (!parameters.valid()) {
if (!rootParameter.valid() || rootParameter.size() != 1) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
XmlRpc::XmlRpcValue parameters = rootParameter[0];
Ptr<UniqueId>::Ref playlistId;
try{
playlistId = XmlRpcTools::extractPlaylistId(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+2, e.what(), returnValue);
XmlRpcTools::markError(errorId+2, "missing playlist ID argument",
returnValue);
return;
}
@ -120,7 +122,8 @@ AddAudioClipToPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
audioClipId = XmlRpcTools::extractAudioClipId(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+3, e.what(), returnValue);
XmlRpcTools::markError(errorId+3, "missing audio clip ID argument",
returnValue);
return;
}
@ -129,7 +132,8 @@ AddAudioClipToPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
relativeOffset = XmlRpcTools::extractRelativeOffset(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+4, e.what(), returnValue);
XmlRpcTools::markError(errorId+4, "missing relative offset argument",
returnValue);
return;
}
@ -143,7 +147,7 @@ AddAudioClipToPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
playlist = storage->getPlaylist(playlistId);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+5, "playlist does not exist",
XmlRpcTools::markError(errorId+5, "playlist not found",
returnValue);
return;
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.3 $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethod.h,v $
------------------------------------------------------------------------------*/
@ -91,13 +91,14 @@ using namespace LiveSupport::Core;
* <li>302 - missing playlist ID argument </li>
* <li>303 - missing audio clip ID argument </li>
* <li>304 - missing relative offset argument </li>
* <li>305 - playlist does not exist </li>
* <li>305 - playlist not found </li>
* <li>306 - playlist has not been opened for editing </li>
* <li>307 - audio clip does not exist </li>
* <li>308 - two audio clips at the same relative offset</li>
* </ul>
*
* @author $Author: fgerlits $
* @version $Revision: 1.3 $
* @version $Revision: 1.4 $
*/
class AddAudioClipToPlaylistMethod : public XmlRpc::XmlRpcServerMethod
{

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/AddAudioClipToPlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -147,23 +147,31 @@ AddAudioClipToPlaylistMethodTest :: firstTest(void)
openPlaylistMethod(new OpenPlaylistForEditingMethod());
Ptr<AddAudioClipToPlaylistMethod>::Ref
addAudioClipMethod(new AddAudioClipToPlaylistMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
parameter["playlistId"] = 1;
parameter["audioClipId"] = 10001;
parameter["relativeOffset"] = 60*60;
parameters["playlistId"] = 1;
parameters["audioClipId"] = 10001;
parameters["relativeOffset"] = 60*60;
rootParameter[0] = parameters;
openPlaylistMethod->execute(parameter, result);
addAudioClipMethod->execute(parameter, result);
result.clear();
openPlaylistMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
addAudioClipMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT((int)(result["errorCode"]) == 308);
parameter.clear();
parameters.clear();
parameters["playlistId"] = 1;
parameters["audioClipId"] = 10001;
parameters["relativeOffset"] = 90*60;
rootParameter[0] = parameters;
result.clear();
parameter["playlistId"] = 1;
parameter["audioClipId"] = 10001;
parameter["relativeOffset"] = 90*60;
addAudioClipMethod->execute(parameter, result);
addAudioClipMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.6 $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/CreatePlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -142,19 +142,24 @@ CreatePlaylistMethodTest :: firstTest(void)
{
Ptr<XmlRpcServerMethod>::Ref method(new CreatePlaylistMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
method->execute(parameter, result);
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("id"));
CPPUNIT_ASSERT(((int) result["playlength"]) == 0);
int playlistId = (int) result["id"];
method.reset(new OpenPlaylistForEditingMethod());
parameter.clear();
result.clear();
parameter["playlistId"] = playlistId;
rootParameter[0] = parameter;
// should not allow to open the same playlist for editing again
method->execute(parameter, result);
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT((int) result["errorCode"] == 105);
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.3 $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/DeletePlaylistMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -61,10 +61,9 @@ using namespace LiveSupport::Scheduler;
const std::string DeletePlaylistMethod::methodName = "deletePlaylist";
/*------------------------------------------------------------------------------
* The name of the playlistId member in the XML-RPC parameter
* structure.
* The ID of this method for error reporting purposes.
*----------------------------------------------------------------------------*/
const std::string DeletePlaylistMethod::playlistIdName = "playlistId";
const int DeletePlaylistMethod::errorId = 900;
/* =============================================== local function prototypes */
@ -87,48 +86,53 @@ DeletePlaylistMethod :: DeletePlaylistMethod (
* (Overrides 'execute' in XmlRpcServerMethod.)
*----------------------------------------------------------------------------*/
void
DeletePlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
DeletePlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
if (!rootParameter.valid() || rootParameter.size() != 1) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
XmlRpc::XmlRpcValue parameters = rootParameter[0];
Ptr<UniqueId>::Ref playlistId;
try{
playlistId = XmlRpcTools::extractPlaylistId(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+2, "missing playlist ID argument",
returnValue);
return;
}
Ptr<StorageClientFactory>::Ref scf
= StorageClientFactory::getInstance();
Ptr<StorageClientInterface>::Ref storage
= scf->getStorageClient();
Ptr<Playlist>::Ref playlist;
try {
if (!parameters.valid()) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
playlist = storage->getPlaylist(playlistId);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+3, "playlist not found",
returnValue);
return;
}
Ptr<UniqueId>::Ref id = XmlRpcTools::extractPlaylistId(parameters[0]);
if (playlist->isLocked()) {
XmlRpcTools::markError(errorId+4, "playlist is locked",
returnValue);
return;
}
Ptr<StorageClientFactory>::Ref scf;
Ptr<StorageClientInterface>::Ref storage;
scf = StorageClientFactory::getInstance();
storage = scf->getStorageClient();
Ptr<Playlist>::Ref playlist;
try {
playlist = storage->getPlaylist(id);
}
catch (std::invalid_argument &e) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
if (playlist->isLocked()) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
storage->deletePlaylist(id);
returnValue = XmlRpc::XmlRpcValue(true);
} catch (std::invalid_argument &e) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
try {
storage->deletePlaylist(playlistId);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+5, "playlist could not be deleted",
returnValue);
return;
}
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/DeletePlaylistMethod.h,v $
------------------------------------------------------------------------------*/
@ -74,14 +74,23 @@ using namespace LiveSupport::Core;
* to be deleted.</li>
* </ul>
*
* The XML-RPC function returns the XML-RPC value:
* If there is an error, an XML-RPC structure is returned, with the following
* fields:
* <ul>
* <li>true if the operation completed successfully,</li>
* <li>false if playlist is not found or there was some other error.</li>
* <li>errorCode - int - a numerical code for the error</li>
* <li>errorMessage - string - a description of the error</li>
* </ul>
* The possible error codes are:
* <ul>
* <li>901 - invalid argument format </li>
* <li>902 - missing playlist ID argument </li>
* <li>903 - playlist not found </li>
* <li>904 - playlist is locked </li>
* <li>905 - playlist could not be deleted </li>
* </ul>
*
* @author $Author: fgerlits $
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
class DeletePlaylistMethod : public XmlRpc::XmlRpcServerMethod
{
@ -93,10 +102,9 @@ class DeletePlaylistMethod : public XmlRpc::XmlRpcServerMethod
static const std::string methodName;
/**
* The name of the playlistId member in the XML-RPC parameter
* structure.
* The ID of this method for error reporting purposes.
*/
static const std::string playlistIdName;
static const int errorId;
public:

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/DeletePlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -46,6 +46,9 @@
#include "LiveSupport/Db/ConnectionManagerFactory.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "OpenPlaylistForEditingMethod.h"
#include "SavePlaylistMethod.h"
#include "DeletePlaylistMethod.h"
#include "DeletePlaylistMethodTest.h"
@ -138,17 +141,37 @@ void
DeletePlaylistMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DeletePlaylistMethod>::Ref method(new DeletePlaylistMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result;
Ptr<OpenPlaylistForEditingMethod>::Ref
openMethod (new OpenPlaylistForEditingMethod);
Ptr<SavePlaylistMethod>::Ref
saveMethod (new SavePlaylistMethod);
Ptr<DeletePlaylistMethod>::Ref
deleteMethod(new DeletePlaylistMethod);
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
// set up a structure for the parameters
parameters["playlistId"] = 1;
rootParameter[0] = parameters;
parameter["playlistId"] = 1;
rootParameter[0] = parameter;
method->execute(rootParameter, result);
CPPUNIT_ASSERT(((bool) result) == true);
result.clear();
openMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
deleteMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT(int(result["errorCode"]) == 904); // playlist is locked
result.clear();
saveMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
deleteMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode")); // OK
}
@ -160,15 +183,18 @@ DeletePlaylistMethodTest :: negativeTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DeletePlaylistMethod>::Ref method(new DeletePlaylistMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
// set up a structure for the parameters
parameters["playlistId"] = 9999;
rootParameter[0] = parameters;
parameter["playlistId"] = 9999;
rootParameter[0] = parameter;
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT(((bool)result) == false);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT(int(result["errorCode"]) == 903); // playlist not found
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayAudioClipMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -95,15 +95,16 @@ DisplayAudioClipMethod :: DisplayAudioClipMethod (
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
DisplayAudioClipMethod :: execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue)
DisplayAudioClipMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
if (!parameters.valid()) {
if (!rootParameter.valid() || rootParameter.size() != 1) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
XmlRpc::XmlRpcValue parameters = rootParameter[0];
Ptr<UniqueId>::Ref id;
try{

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayAudioClipMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -140,12 +140,16 @@ DisplayAudioClipMethodTest :: firstTest(void)
{
Ptr<DisplayAudioClipMethod>::Ref method(new DisplayAudioClipMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
// set up a structure for the parameter
parameter["audioClipId"] = 10001;
rootParameter[0] = parameter;
method->execute(parameter, result);
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT(int(result["id"]) == 10001);
CPPUNIT_ASSERT(int(result["playlength"]) == (60 * 60));
}
@ -160,12 +164,16 @@ DisplayAudioClipMethodTest :: negativeTest(void)
{
Ptr<DisplayAudioClipMethod>::Ref method(new DisplayAudioClipMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
// set up a structure for the parameter
parameter["audioClipId"] = 9999;
rootParameter[0] = parameter;
method->execute(parameter, result);
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT(int(result["errorCode"]) == 603); // audio clip not found
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayAudioClipsMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -144,6 +144,7 @@ DisplayAudioClipsMethodTest :: firstTest(void)
XmlRpc::XmlRpcValue result;
XmlRpc::XmlRpcValue audioClip;
result.clear();
method->execute(parameter, result);
CPPUNIT_ASSERT(result.size() == 2);

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayPlaylistMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -71,10 +71,9 @@ using namespace LiveSupport::Scheduler;
const std::string DisplayPlaylistMethod::methodName = "displayPlaylist";
/*------------------------------------------------------------------------------
* The name of the playlistId member in the XML-RPC parameter
* structure.
* The ID of this method for error reporting purposes.
*----------------------------------------------------------------------------*/
const std::string DisplayPlaylistMethod::playlistIdName = "playlistId";
const int DisplayPlaylistMethod::errorId = 1000;
/* =============================================== local function prototypes */
@ -96,39 +95,42 @@ DisplayPlaylistMethod :: DisplayPlaylistMethod (
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
DisplayPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
DisplayPlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
try {
if (!parameters.valid()) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
Ptr<UniqueId>::Ref id = XmlRpcTools::extractPlaylistId(parameters[0]);
Ptr<StorageClientFactory>::Ref scf;
Ptr<StorageClientInterface>::Ref storage;
scf = StorageClientFactory::getInstance();
storage = scf->getStorageClient();
if (!storage->existsPlaylist(id)) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
Ptr<Playlist>::Ref playlist = storage->getPlaylist(id);
XmlRpcTools::playlistToXmlRpcValue(playlist, returnValue);
} catch (std::invalid_argument &e) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
if (!rootParameter.valid() || rootParameter.size() != 1) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
}
XmlRpc::XmlRpcValue parameters = rootParameter[0];
Ptr<UniqueId>::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<StorageClientFactory>::Ref scf;
Ptr<StorageClientInterface>::Ref storage;
scf = StorageClientFactory::getInstance();
storage = scf->getStorageClient();
Ptr<Playlist>::Ref playlist;
try {
playlist = storage->getPlaylist(id);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+3, "playlist not found",
returnValue);
return;
}
XmlRpcTools::playlistToXmlRpcValue(playlist, returnValue);
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayPlaylistMethod.h,v $
------------------------------------------------------------------------------*/
@ -81,10 +81,22 @@ using namespace LiveSupport::Core;
* <li>playlength - int - the playlist length of the playlist, in seconds
* </li>
* </ul>
* In case of an error, a simple false value is returned.
*
* If there is an error, an XML-RPC structure is returned, with the following
* fields:
* <ul>
* <li>errorCode - int - a numerical code for the error</li>
* <li>errorMessage - string - a description of the error</li>
* </ul>
* The possible error codes are:
* <ul>
* <li>1001 - invalid argument format </li>
* <li>1002 - argument is not a playlist ID </li>
* <li>1003 - playlist not found </li>
* </ul>
*
* @author $Author: fgerlits $
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
class DisplayPlaylistMethod : public XmlRpc::XmlRpcServerMethod
{
@ -96,10 +108,9 @@ class DisplayPlaylistMethod : public XmlRpc::XmlRpcServerMethod
static const std::string methodName;
/**
* The name of the playlistId member in the XML-RPC parameter
* structure.
* The ID of this method for error reporting purposes.
*/
static const std::string playlistIdName;
static const int errorId;
public:

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayPlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -139,17 +139,19 @@ DisplayPlaylistMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DisplayPlaylistMethod>::Ref method(new DisplayPlaylistMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
// set up a structure for the parameters
parameters["playlistId"] = 1;
rootParameter[0] = parameters;
// set up a structure for the parameter
parameter["playlistId"] = 1;
rootParameter[0] = parameter;
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT(((int) result["id"]) == 1);
CPPUNIT_ASSERT(((int) result["playlength"]) == (90 * 60));
CPPUNIT_ASSERT(int(result["id"]) == 1);
CPPUNIT_ASSERT(int(result["playlength"]) == 90 * 60);
}
@ -161,15 +163,18 @@ DisplayPlaylistMethodTest :: negativeTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DisplayPlaylistMethod>::Ref method(new DisplayPlaylistMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
// set up a structure for the parameters
parameters["playlistId"] = 9999;
rootParameter[0] = parameters;
// set up a structure for the parameter
parameter["playlistId"] = 9999;
rootParameter[0] = parameter;
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT(((bool)result) == false);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT(int(result["errorCode"]) == 1003); // playlist not found
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayPlaylistsMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -144,6 +144,7 @@ DisplayPlaylistsMethodTest :: firstTest(void)
XmlRpc::XmlRpcValue result;
XmlRpc::XmlRpcValue playlist;
result.clear();
method->execute(parameters, result);
CPPUNIT_ASSERT(result.size() == 1);

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayScheduleMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -67,6 +67,11 @@ using namespace LiveSupport::Scheduler;
*----------------------------------------------------------------------------*/
const std::string DisplayScheduleMethod::methodName = "displaySchedule";
/*------------------------------------------------------------------------------
* The ID of this method for error reporting purposes.
*----------------------------------------------------------------------------*/
const int DisplayScheduleMethod::errorId = 1100;
/* =============================================== local function prototypes */
@ -87,35 +92,42 @@ DisplayScheduleMethod :: DisplayScheduleMethod (
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
DisplayScheduleMethod :: execute(XmlRpc::XmlRpcValue & parameters,
DisplayScheduleMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
try {
if (!parameters.valid()) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
Ptr<ptime>::Ref fromTime
= XmlRpcTools::extractFromTime(parameters[0]);
Ptr<ptime>::Ref toTime
= XmlRpcTools::extractToTime(parameters[0]);
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule();
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref scheduleEntries
= schedule->getScheduleEntries(fromTime, toTime);
XmlRpcTools::scheduleEntriesToXmlRpcValue(scheduleEntries,
returnValue);
} catch (std::invalid_argument &e) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
if (!rootParameter.valid() || rootParameter.size() != 1) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
}
XmlRpc::XmlRpcValue parameters = rootParameter[0];
Ptr<ptime>::Ref fromTime;
try {
fromTime = XmlRpcTools::extractFromTime(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+2, "missing or invalid 'from' argument",
returnValue);
return;
}
Ptr<ptime>::Ref toTime;
try {
toTime = XmlRpcTools::extractToTime(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+3, "missing or invalid 'to' argument",
returnValue);
return;
}
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule();
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref scheduleEntries
= schedule->getScheduleEntries(fromTime, toTime);
XmlRpcTools::scheduleEntriesToXmlRpcValue(scheduleEntries, returnValue);
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayScheduleMethod.h,v $
------------------------------------------------------------------------------*/
@ -92,8 +92,21 @@ using namespace LiveSupport::Core;
* <li>end - datetime - the end of the scheduled item</li>
* </ul>
*
* If there is an error, an XML-RPC structure is returned, with the following
* fields:
* <ul>
* <li>errorCode - int - a numerical code for the error</li>
* <li>errorMessage - string - a description of the error</li>
* </ul>
* The possible error codes are:
* <ul>
* <li>1101 - invalid argument format </li>
* <li>1102 - missing or invalid 'from' argument </li>
* <li>1103 - missing or invalid 'to' argument </li>
* </ul>
*
* @author $Author: fgerlits $
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
class DisplayScheduleMethod : public XmlRpc::XmlRpcServerMethod
{
@ -104,6 +117,11 @@ class DisplayScheduleMethod : public XmlRpc::XmlRpcServerMethod
*/
static const std::string methodName;
/**
* The ID of this method for error reporting purposes.
*/
static const int errorId;
public:
/**

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/DisplayScheduleMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -51,6 +51,7 @@
#include "DisplayScheduleMethod.h"
#include "DisplayScheduleMethodTest.h"
using namespace std;
using namespace LiveSupport::Db;
using namespace LiveSupport::Storage;
@ -155,8 +156,9 @@ DisplayScheduleMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DisplayScheduleMethod>::Ref method(new DisplayScheduleMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
struct tm time;
@ -177,6 +179,7 @@ DisplayScheduleMethodTest :: firstTest(void)
parameters["to"] = &time;
rootParameter[0] = parameters;
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT(result.size() == 0);
}
@ -190,8 +193,9 @@ DisplayScheduleMethodTest :: insertEntries(void)
throw ()
{
Ptr<UploadPlaylistMethod>::Ref method(new UploadPlaylistMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
struct tm time;
@ -205,6 +209,8 @@ DisplayScheduleMethodTest :: insertEntries(void)
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
result.clear();
method->execute(rootParameter, result);
// insert a playlist for 2004-07-31, at 12 o'clock
@ -217,6 +223,8 @@ DisplayScheduleMethodTest :: insertEntries(void)
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
result.clear();
method->execute(rootParameter, result);
// insert a playlist for 2004-07-31, at 14 o'clock
@ -229,6 +237,8 @@ DisplayScheduleMethodTest :: insertEntries(void)
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
result.clear();
method->execute(rootParameter, result);
}
@ -241,8 +251,9 @@ DisplayScheduleMethodTest :: intervalTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<DisplayScheduleMethod>::Ref method(new DisplayScheduleMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
struct tm time;
@ -262,7 +273,8 @@ DisplayScheduleMethodTest :: intervalTest(void)
time.tm_sec = 0;
parameters["to"] = &time;
rootParameter[0] = parameters;
result = XmlRpc::XmlRpcValue();
result.clear();
method->execute(rootParameter, result);
// check the returned values
@ -299,7 +311,8 @@ DisplayScheduleMethodTest :: intervalTest(void)
time.tm_sec = 0;
parameters["to"] = &time;
rootParameter[0] = parameters;
result = XmlRpc::XmlRpcValue();
result.clear();
method->execute(rootParameter, result);
// check the returned values
@ -352,7 +365,8 @@ DisplayScheduleMethodTest :: intervalTest(void)
time.tm_sec = 0;
parameters["to"] = &time;
rootParameter[0] = parameters;
result = XmlRpc::XmlRpcValue();
result.clear();
method->execute(rootParameter, result);
// check the returned values

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.7 $
Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/OpenPlaylistForEditingMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -96,15 +96,16 @@ OpenPlaylistForEditingMethod :: OpenPlaylistForEditingMethod (
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
OpenPlaylistForEditingMethod :: execute(XmlRpc::XmlRpcValue & parameters,
OpenPlaylistForEditingMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
XmlRpc::XmlRpcValue & returnValue)
throw ()
throw ()
{
if (!parameters.valid()) {
if (!rootParameter.valid() || rootParameter.size() != 1) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
XmlRpc::XmlRpcValue parameters = rootParameter[0];
Ptr<UniqueId>::Ref id;
try{

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.6 $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/OpenPlaylistForEditingMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -143,29 +143,35 @@ OpenPlaylistForEditingMethodTest :: firstTest(void)
Ptr<OpenPlaylistForEditingMethod>::Ref
method(new OpenPlaylistForEditingMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
parameter["playlistId"] = 1;
rootParameter[0] = parameter;
method->execute(parameter, result);
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT((int) result["id"] == 1);
CPPUNIT_ASSERT((int) result["playlength"] == (90 * 60));
parameter.clear();
result.clear();
parameter["playlistId"] = 6376;
rootParameter[0] = parameter;
// no such playlist
method->execute(parameter, result);
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT((int) result["errorCode"] == 104);
CPPUNIT_ASSERT((const std::string) result["errorMessage"] ==
"playlist not found");
parameter.clear();
result.clear();
parameter["playlistId"] = 1;
rootParameter[0] = parameter;
// should not allow to open the same playlist for editing again
method->execute(parameter, result);
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT((int) result["errorCode"] == 105);
CPPUNIT_ASSERT((const std::string) result["errorMessage"] ==
"could not open playlist");

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -96,15 +96,17 @@ RemoveAudioClipFromPlaylistMethod :: RemoveAudioClipFromPlaylistMethod (
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
RemoveAudioClipFromPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue)
RemoveAudioClipFromPlaylistMethod :: execute(
XmlRpc::XmlRpcValue & rootParameter,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
if (!parameters.valid()) {
if (!rootParameter.valid() || rootParameter.size() != 1) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
XmlRpc::XmlRpcValue parameters = rootParameter[0];
Ptr<UniqueId>::Ref playlistId;
try{

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveAudioClipFromPlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -151,25 +151,33 @@ RemoveAudioClipFromPlaylistMethodTest :: firstTest(void)
addAudioClipMethod(new AddAudioClipToPlaylistMethod());
Ptr<RemoveAudioClipFromPlaylistMethod>::Ref
removeAudioClipMethod(new RemoveAudioClipFromPlaylistMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
parameter["playlistId"] = 1;
parameter["audioClipId"] = 10001;
parameter["relativeOffset"] = 90*60;
parameters["playlistId"] = 1;
parameters["audioClipId"] = 10001;
parameters["relativeOffset"] = 90*60;
rootParameter[0] = parameters;
removeAudioClipMethod->execute(parameter, result);
result.clear();
removeAudioClipMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT((int)(result["errorCode"]) == 405); // not open for editing
result.clear();
openPlaylistMethod->execute(parameter, result);
removeAudioClipMethod->execute(parameter, result);
openPlaylistMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
removeAudioClipMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT((int)(result["errorCode"]) == 406); // no audio clip at
// this rel offset
result.clear();
addAudioClipMethod->execute(parameter, result);
removeAudioClipMethod->execute(parameter, result);
addAudioClipMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
removeAudioClipMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -64,6 +64,11 @@ using namespace LiveSupport::Scheduler;
*----------------------------------------------------------------------------*/
const std::string RemoveFromScheduleMethod::methodName = "removeFromSchedule";
/*------------------------------------------------------------------------------
* The ID of this method for error reporting purposes.
*----------------------------------------------------------------------------*/
const int RemoveFromScheduleMethod::errorId = 1200;
/* =============================================== local function prototypes */
@ -84,37 +89,37 @@ RemoveFromScheduleMethod :: RemoveFromScheduleMethod (
* Execute the remove from schedule XML-RPC function call.
*----------------------------------------------------------------------------*/
void
RemoveFromScheduleMethod :: execute(XmlRpc::XmlRpcValue & parameters,
RemoveFromScheduleMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
XmlRpc::XmlRpcValue & returnValue)
throw ()
throw ()
{
try {
if (!parameters.valid()) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
if (!rootParameter.valid() || rootParameter.size() != 1) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
XmlRpc::XmlRpcValue parameters = rootParameter[0];
Ptr<UniqueId>::Ref entryId
= XmlRpcTools::extractScheduleEntryId(parameters[0]);
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule();
if (!schedule->scheduleEntryExists(entryId)) {
// TODO: mark error;
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
schedule->removeFromSchedule(entryId);
} catch (std::invalid_argument &e) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
Ptr<UniqueId>::Ref entryId;
try {
entryId = XmlRpcTools::extractScheduleEntryId(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+2, "missing schedule entry ID argument",
returnValue);
return;
}
returnValue = XmlRpc::XmlRpcValue(true);
}
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule();
try {
schedule->removeFromSchedule(entryId);
} catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+3, "schedule entry not found",
returnValue);
return;
}
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h,v $
------------------------------------------------------------------------------*/
@ -74,8 +74,21 @@ using namespace LiveSupport::Core;
* <li>scheduleEntryId - int - the id of the scheduled entry to remove</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>1201 - invalid argument format </li>
* <li>1202 - missing argument </li>
* <li>1203 - not found </li>
* </ul>
*
* @author $Author: fgerlits $
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
class RemoveFromScheduleMethod : public XmlRpc::XmlRpcServerMethod
{
@ -86,6 +99,11 @@ class RemoveFromScheduleMethod : public XmlRpc::XmlRpcServerMethod
*/
static const std::string methodName;
/**
* The ID of this method for error reporting purposes.
*/
static const int errorId;
public:
/**

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.1 $
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -129,16 +129,17 @@ RemoveFromScheduleMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<UploadPlaylistMethod>::Ref uploadMethod(
new UploadPlaylistMethod());
new UploadPlaylistMethod());
Ptr<RemoveFromScheduleMethod>::Ref removeMethod(
new RemoveFromScheduleMethod());
XmlRpc::XmlRpcValue rootParameter;
new RemoveFromScheduleMethod());
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
struct tm time;
Ptr<UniqueId>::Ref entryId;
// first schedule (upload) a playlist)
// first schedule (upload) a playlist
parameters["playlistId"] = 1;
time.tm_year = 2001;
time.tm_mon = 11;
@ -147,18 +148,20 @@ RemoveFromScheduleMethodTest :: firstTest(void)
time.tm_min = 0;
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
rootParameter[0] = parameters;
result.clear();
uploadMethod->execute(rootParameter, result);
entryId.reset(new UniqueId((int) result));
CPPUNIT_ASSERT(result.hasMember("scheduleEntryId"));
entryId.reset(new UniqueId(int(result["scheduleEntryId"])));
parameters.clear();
result.clear();
parameters["scheduleEntryId"] = (int) entryId->getId();
rootParameter[0] = parameters;
parameters["scheduleEntryId"] = int(entryId->getId());
rootParameter[0] = parameters;
result.clear();
removeMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
}
@ -170,16 +173,18 @@ RemoveFromScheduleMethodTest :: negativeTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<RemoveFromScheduleMethod>::Ref removeMethod(
new RemoveFromScheduleMethod());
XmlRpc::XmlRpcValue rootParameter;
new RemoveFromScheduleMethod());
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
Ptr<UniqueId>::Ref entryId(new UniqueId(9999));
parameters["scheduleEntryId"] = (int) entryId->getId();
rootParameter[0] = parameters;
parameters["scheduleEntryId"] = int(entryId->getId());
rootParameter[0] = parameters;
result.clear();
removeMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -67,6 +67,11 @@ using namespace LiveSupport::Scheduler;
*----------------------------------------------------------------------------*/
const std::string RescheduleMethod::methodName = "reschedule";
/*------------------------------------------------------------------------------
* The ID of this method for error reporting purposes.
*----------------------------------------------------------------------------*/
const int RescheduleMethod::errorId = 1300;
/* =============================================== local function prototypes */
@ -87,40 +92,54 @@ RescheduleMethod :: RescheduleMethod (
* Execute the upload playlist method XML-RPC function call.
*----------------------------------------------------------------------------*/
void
RescheduleMethod :: execute(XmlRpc::XmlRpcValue & parameters,
RescheduleMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
XmlRpc::XmlRpcValue & returnValue)
throw ()
throw ()
{
if (!rootParameter.valid() || rootParameter.size() != 1) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
XmlRpc::XmlRpcValue parameters = rootParameter[0];
Ptr<UniqueId>::Ref entryId;
try {
if (!parameters.valid()) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
Ptr<UniqueId>::Ref entryId
= XmlRpcTools::extractScheduleEntryId(parameters[0]);
Ptr<ptime>::Ref playschedule
= XmlRpcTools::extractPlayschedule(parameters[0]);
Ptr<UniqueId>::Ref scheduleEntryId;
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule();
if (!schedule->scheduleEntryExists(entryId)) {
// TODO: mark error;
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
schedule->reschedule(entryId, playschedule);
} catch (std::invalid_argument &e) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
entryId = XmlRpcTools::extractScheduleEntryId(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+2, "missing schedule entry ID argument",
returnValue);
return;
}
returnValue = XmlRpc::XmlRpcValue(true);
Ptr<ptime>::Ref playschedule;
try {
playschedule = XmlRpcTools::extractPlayschedule(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+3, "missing playtime argument",
returnValue);
return;
}
Ptr<UniqueId>::Ref scheduleEntryId;
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule();
if (!schedule->scheduleEntryExists(entryId)) {
XmlRpcTools::markError(errorId+4, "schedule entry not found",
returnValue);
return;
}
try {
schedule->reschedule(entryId, playschedule);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+5, e.what(),
returnValue);
return;
}
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethod.h,v $
------------------------------------------------------------------------------*/
@ -75,11 +75,24 @@ using namespace LiveSupport::Core;
* </li>
* <li>playtime - datetime - the new playing time for the entry</li>
* </ul>
* The return value is true if all went well,
* or a boolean false, if there were errors.
*
* In case of an error, an XML-RPC structure is returned, with the following
* fields:
* <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>1301 - invalid argument format </li>
* <li>1302 - missing schedule entry ID argument </li>
* <li>1303 - missing playtime argument </li>
* <li>1304 - schedule entry not found </li>
* <li>1305 - could not reschedule entry </li>
* </ul>
*
* @author $Author: fgerlits $
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
class RescheduleMethod : public XmlRpc::XmlRpcServerMethod
{
@ -90,6 +103,11 @@ class RescheduleMethod : public XmlRpc::XmlRpcServerMethod
*/
static const std::string methodName;
/**
* The ID of this method for error reporting purposes.
*/
static const int errorId;
public:
/**

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.1 $
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -133,8 +133,9 @@ RescheduleMethodTest :: firstTest(void)
{
Ptr<UploadPlaylistMethod>::Ref uploadMethod(new UploadPlaylistMethod());
Ptr<RescheduleMethod>::Ref rescheduleMethod(new RescheduleMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
struct tm time;
Ptr<UniqueId>::Ref entryId;
@ -148,15 +149,16 @@ RescheduleMethodTest :: firstTest(void)
time.tm_min = 31;
time.tm_sec = 1;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
rootParameter[0] = parameters;
result.clear();
uploadMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.valid());
entryId.reset(new UniqueId((int) result));
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
CPPUNIT_ASSERT(result.hasMember("scheduleEntryId"));
entryId.reset(new UniqueId(int(result["scheduleEntryId"])));
// now let's reschedule it
parameters.clear();
result.clear();
parameters["scheduleEntryId"] = (int) entryId->getId();
time.tm_year = 2001;
time.tm_mon = 11;
@ -165,15 +167,14 @@ RescheduleMethodTest :: firstTest(void)
time.tm_min = 31;
time.tm_sec = 1;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
rootParameter[0] = parameters;
result.clear();
rescheduleMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT((bool) result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
// now let's reschedule unto itself, should fail
parameters.clear();
result.clear();
parameters["scheduleEntryId"] = (int) entryId->getId();
time.tm_year = 2001;
time.tm_mon = 11;
@ -182,10 +183,12 @@ RescheduleMethodTest :: firstTest(void)
time.tm_min = 51;
time.tm_sec = 1;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
rootParameter[0] = parameters;
result.clear();
rescheduleMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(!((bool) result));
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT(int(result["errorCode"]) == 1305);
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RevertEditedPlaylistMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -91,15 +91,16 @@ RevertEditedPlaylistMethod :: RevertEditedPlaylistMethod (
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
RevertEditedPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
RevertEditedPlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
if (!parameters.valid()) {
if (!rootParameter.valid() || rootParameter.size() != 1) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
XmlRpc::XmlRpcValue parameters = rootParameter[0];
Ptr<UniqueId>::Ref id;
try{

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RevertEditedPlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -151,38 +151,42 @@ RevertEditedPlaylistMethodTest :: firstTest(void)
saveMethod(new SavePlaylistMethod);
Ptr<RevertEditedPlaylistMethod>::Ref
revertMethod(new RevertEditedPlaylistMethod);
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
parameter["playlistId"] = 1;
parameter["relativeOffset"] = 0;
parameters["playlistId"] = 1;
parameters["relativeOffset"] = 0;
rootParameter[0] = parameters;
revertMethod->execute(parameter, result);
result.clear();
revertMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT(int(result["errorCode"]) == 804); // no saved copy yet
result.clear();
openMethod->execute(parameter, result);
openMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
removeMethod->execute(parameter, result);
removeMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
removeMethod->execute(parameter, result);
removeMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode")); // can't remove it twice
result.clear();
revertMethod->execute(parameter, result);
revertMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
removeMethod->execute(parameter, result);
removeMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode")); // but now we can again
result.clear();
saveMethod->execute(parameter, result);
saveMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
revertMethod->execute(parameter, result);
revertMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode")); // saved copy has been
CPPUNIT_ASSERT(int(result["errorCode"]) == 804); // discarded
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SavePlaylistMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -91,15 +91,16 @@ SavePlaylistMethod :: SavePlaylistMethod (
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
SavePlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
SavePlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
if (!parameters.valid()) {
if (!rootParameter.valid() || rootParameter.size() != 1) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
XmlRpc::XmlRpcValue parameters = rootParameter[0];
Ptr<UniqueId>::Ref id;
try{

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SavePlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -145,23 +145,28 @@ SavePlaylistMethodTest :: firstTest(void)
openMethod(new OpenPlaylistForEditingMethod());
Ptr<SavePlaylistMethod>::Ref saveMethod(new SavePlaylistMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
parameter["playlistId"] = 9999;
rootParameter[0] = parameter;
saveMethod->execute(parameter, result);
result.clear();
saveMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT(int(result["errorCode"]) == 703); // playlist not found
parameter["playlistId"] = 1;
rootParameter[0] = parameter;
result.clear();
openMethod->execute(parameter, result);
openMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
saveMethod->execute(parameter, result);
saveMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode")); // open then save OK
result.clear();
openMethod->execute(parameter, result);
openMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode")); // save then open OK
}

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.1 $
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/SchedulerDaemonDisplayPlaylistTest.cxx,v $
------------------------------------------------------------------------------*/
@ -48,6 +48,7 @@
#include "SchedulerDaemonDisplayPlaylistTest.h"
using namespace std;
using namespace XmlRpc;
using namespace LiveSupport::Scheduler;
@ -125,8 +126,9 @@ SchedulerDaemonDisplayPlaylistTest :: simpleTest(void)
parameters["playlistId"] = 1;
result.clear();
xmlRpcClient.execute("displayPlaylist", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
CPPUNIT_ASSERT(((int) result["id"]) == 1);
CPPUNIT_ASSERT(((int) result["playlength"]) == (60 * 60));
}
@ -146,8 +148,8 @@ SchedulerDaemonDisplayPlaylistTest :: negativeTest(void)
parameters["playlistId"] = 9999;
result.clear();
xmlRpcClient.execute("displayPlaylist", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(((bool)result) == false);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/SchedulerDaemonDisplayScheduleTest.cxx,v $
------------------------------------------------------------------------------*/
@ -47,7 +47,7 @@
#include "SchedulerDaemon.h"
#include "SchedulerDaemonDisplayScheduleTest.h"
using namespace std;
using namespace XmlRpc;
using namespace LiveSupport::Scheduler;
@ -126,22 +126,24 @@ SchedulerDaemonDisplayScheduleTest :: simpleTest(void)
// list the schedules for an interval (as the database is empty,
// it's going to return an empty result set)
time.tm_year = 2004;
time.tm_year = 2044;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 10;
time.tm_min = 0;
time.tm_sec = 0;
parameters["from"] = &time;
time.tm_year = 2004;
time.tm_year = 2044;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 11;
time.tm_min = 0;
time.tm_sec = 0;
parameters["to"] = &time;
result.clear();
xmlRpcClient.execute("displaySchedule", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
CPPUNIT_ASSERT(result.size() == 0);
}

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.1 $
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/SchedulerDaemonRemoveFromScheduleTest.cxx,v $
------------------------------------------------------------------------------*/
@ -48,6 +48,7 @@
#include "SchedulerDaemonRemoveFromScheduleTest.h"
using namespace std;
using namespace XmlRpc;
using namespace LiveSupport::Scheduler;
@ -134,16 +135,17 @@ SchedulerDaemonRemoveFromScheduleTest :: simpleTest(void)
time.tm_sec = 0;
parameters["playtime"] = &time;
result.clear();
xmlRpcClient.execute("uploadPlaylist", parameters, result);
CPPUNIT_ASSERT(result.valid());
Ptr<UniqueId>::Ref entryId(new UniqueId((int) result));
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
CPPUNIT_ASSERT(result.hasMember("scheduleEntryId"));
Ptr<UniqueId>::Ref entryId(new UniqueId(int(result["scheduleEntryId"])));
parameters["scheduleEntryId"] = (int) entryId->getId();
result.clear();
xmlRpcClient.execute("removeFromSchedule", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(((bool)result) == true);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
}
@ -161,8 +163,8 @@ SchedulerDaemonRemoveFromScheduleTest :: negativeTest(void)
parameters["scheduleEntryId"] = 9999;
result.clear();
xmlRpcClient.execute("removeFromSchedule", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(((bool)result) == false);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
}

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.1 $
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/SchedulerDaemonRescheduleTest.cxx,v $
------------------------------------------------------------------------------*/
@ -134,10 +134,10 @@ SchedulerDaemonRescheduleTest :: simpleTest(void)
time.tm_sec = 0;
parameters["playtime"] = &time;
result.clear();
xmlRpcClient.execute("uploadPlaylist", parameters, result);
CPPUNIT_ASSERT(result.valid());
Ptr<UniqueId>::Ref entryId(new UniqueId((int) result));
CPPUNIT_ASSERT(result.hasMember("scheduleEntryId"));
Ptr<UniqueId>::Ref entryId(new UniqueId(int(result["scheduleEntryId"])));
// now reschedule it
parameters["scheduleEntryId"] = (int) entryId->getId();
@ -149,9 +149,9 @@ SchedulerDaemonRescheduleTest :: simpleTest(void)
time.tm_sec = 0;
parameters["playtime"] = &time;
result.clear();
xmlRpcClient.execute("reschedule", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(((bool)result) == true);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
// now reschedule it unto itself, should fail
parameters["scheduleEntryId"] = (int) entryId->getId();
@ -163,9 +163,9 @@ SchedulerDaemonRescheduleTest :: simpleTest(void)
time.tm_sec = 0;
parameters["playtime"] = &time;
result.clear();
xmlRpcClient.execute("reschedule", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(((bool)result) == false);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
}
@ -183,8 +183,8 @@ SchedulerDaemonRescheduleTest :: negativeTest(void)
parameters["scheduleEntryId"] = 9999;
result.clear();
xmlRpcClient.execute("removeFromSchedule", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(((bool)result) == false);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
}

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.2 $
Author : $Author: fgerlits $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemonTest.cxx,v $
------------------------------------------------------------------------------*/
@ -53,7 +53,7 @@ using namespace LiveSupport::Scheduler;
/* ================================================ local constants & macros */
//CPPUNIT_TEST_SUITE_REGISTRATION(SchedulerDaemonTest);
// CPPUNIT_TEST_SUITE_REGISTRATION(SchedulerDaemonTest);
/**
* The name of the configuration file for the scheduler daemon.

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.3 $
Author : $Author: fgerlits $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/SchedulerDaemonUploadTest.cxx,v $
------------------------------------------------------------------------------*/
@ -44,10 +44,13 @@
#include <XmlRpcClient.h>
#include <XmlRpcValue.h>
#include "XmlRpcTools.h"
#include "LiveSupport/Core/UniqueId.h"
#include "SchedulerDaemon.h"
#include "SchedulerDaemonUploadTest.h"
using namespace std;
using namespace XmlRpc;
using namespace LiveSupport::Scheduler;
@ -134,7 +137,8 @@ SchedulerDaemonUploadTest :: simpleTest(void)
time.tm_sec = 0;
parameters["playtime"] = &time;
result.clear();
xmlRpcClient.execute("uploadPlaylist", parameters, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.5 $
Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -70,6 +70,11 @@ using namespace LiveSupport::Scheduler;
*----------------------------------------------------------------------------*/
const std::string UploadPlaylistMethod::methodName = "uploadPlaylist";
/*------------------------------------------------------------------------------
* The ID of this method for error reporting purposes.
*----------------------------------------------------------------------------*/
const int UploadPlaylistMethod::errorId = 1400;
/* =============================================== local function prototypes */
@ -90,56 +95,73 @@ UploadPlaylistMethod :: UploadPlaylistMethod (
* Execute the upload playlist method XML-RPC function call.
*----------------------------------------------------------------------------*/
void
UploadPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
UploadPlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
try {
if (!parameters.valid()) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
Ptr<UniqueId>::Ref id
= XmlRpcTools::extractPlaylistId(parameters[0]);
Ptr<ptime>::Ref playschedule
= XmlRpcTools::extractPlayschedule(parameters[0]);
Ptr<UniqueId>::Ref scheduleEntryId;
Ptr<StorageClientFactory>::Ref scf;
Ptr<StorageClientInterface>::Ref storage;
scf = StorageClientFactory::getInstance();
storage = scf->getStorageClient();
if (!storage->existsPlaylist(id)) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
Ptr<Playlist>::Ref playlist = storage->getPlaylist(id);
Ptr<ptime>::Ref until(new ptime(*playschedule
+ *(playlist->getPlaylength())));
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule();
if (!schedule->isTimeframeAvailable(playschedule, until)) {
// TODO: mark error;
returnValue = XmlRpc::XmlRpcValue(false);
return;
}
scheduleEntryId = schedule->schedulePlaylist(playlist, playschedule);
returnValue = XmlRpc::XmlRpcValue((int) scheduleEntryId->getId());
} catch (std::invalid_argument &e) {
// TODO: mark error
returnValue = XmlRpc::XmlRpcValue(false);
if (!rootParameter.valid() || rootParameter.size() != 1) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
}
XmlRpc::XmlRpcValue parameters = rootParameter[0];
Ptr<UniqueId>::Ref playlistId;
try {
playlistId = XmlRpcTools::extractPlaylistId(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+2, "missing playlist ID argument",
returnValue);
return;
}
Ptr<ptime>::Ref playschedule;
try {
playschedule = XmlRpcTools::extractPlayschedule(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+3, "missing playtime argument",
returnValue);
return;
}
Ptr<StorageClientFactory>::Ref scf
= StorageClientFactory::getInstance();
Ptr<StorageClientInterface>::Ref storage
= scf->getStorageClient();
Ptr<Playlist>::Ref playlist;
try {
playlist = storage->getPlaylist(playlistId);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+4, "playlist not found",
returnValue);
return;
}
Ptr<ptime>::Ref until(new ptime(*playschedule
+ *(playlist->getPlaylength())));
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule();
if (!schedule->isTimeframeAvailable(playschedule, until)) {
XmlRpcTools::markError(errorId+5, "timeframe not available",
returnValue);
return;
}
Ptr<const UniqueId>::Ref scheduleEntryId;
try {
scheduleEntryId = schedule->schedulePlaylist(playlist, playschedule);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+6, e.what(),
returnValue);
return;
}
XmlRpcTools::scheduleEntryIdToXmlRpcValue(scheduleEntryId, returnValue);
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.5 $
Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/UploadPlaylistMethod.h,v $
------------------------------------------------------------------------------*/
@ -76,11 +76,32 @@ using namespace LiveSupport::Core;
* <li>playtime - the time when the playlist should be scheduled,
* an ISO 8601 DateTime field</li>
* </ul>
* The return value is an int, the id of the schedule entry created
* by uploading, or a boolean false, if there were errors.
*
* If the upload is successful, the method returns an XML-RPC structure with
* the following members:
* <ul>
* <li>scheduleEntryId - int - the id of the schedule entry created
* by the upload </li>
* </ul>
*
* In case of an error, an XML-RPC structure is returned with the following
* members:
* <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>1401 - invalid argument format </li>
* <li>1402 - missing playlist ID argument </li>
* <li>1403 - missing playtime argument </li>
* <li>1404 - playlist not found </li>
* <li>1405 - timeframe not available </li>
* <li>1406 - could not schedule playlist </li>
* </ul>
*
* @author $Author: fgerlits $
* @version $Revision: 1.5 $
* @version $Revision: 1.6 $
*/
class UploadPlaylistMethod : public XmlRpc::XmlRpcServerMethod
{
@ -91,6 +112,11 @@ class UploadPlaylistMethod : public XmlRpc::XmlRpcServerMethod
*/
static const std::string methodName;
/**
* The ID of this method for error reporting purposes.
*/
static const int errorId;
public:
/**

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.4 $
Author : $Author: fgerlits $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -152,8 +152,9 @@ UploadPlaylistMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<UploadPlaylistMethod>::Ref method(new UploadPlaylistMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
struct tm time;
@ -166,10 +167,11 @@ UploadPlaylistMethodTest :: firstTest(void)
time.tm_min = 31;
time.tm_sec = 1;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
rootParameter[0] = parameters;
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(result.hasMember("scheduleEntryId"));
}
@ -181,8 +183,9 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<UploadPlaylistMethod>::Ref method(new UploadPlaylistMethod());
XmlRpc::XmlRpcValue rootParameter;
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
struct tm time;
@ -195,13 +198,14 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void)
time.tm_min = 0;
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
rootParameter[0] = parameters;
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(result.hasMember("scheduleEntryId"));
// try to load the same one, but in an overlapping time region
// (we know that playlist with id 1 in 1 hour long)
// (we know that playlist with id 1 is 1 hour long)
parameters["playlistId"] = 1;
time.tm_year = 2001;
time.tm_mon = 11;
@ -210,10 +214,12 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void)
time.tm_min = 30;
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
rootParameter[0] = parameters;
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT(!result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT(int(result["errorCode"]) == 1405); // timeframe not available
// try to load the same one, but now in good timing
parameters["playlistId"] = 1;
@ -224,12 +230,13 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void)
time.tm_min = 30;
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
rootParameter[0] = parameters;
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT(result.valid());
CPPUNIT_ASSERT(result.hasMember("scheduleEntryId"));
// try to load the same one, this time overlapping both previos instnaces
// try to load the same one, this time overlapping both previos instances
parameters["playlistId"] = 1;
time.tm_year = 2001;
time.tm_mon = 11;
@ -238,9 +245,10 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void)
time.tm_min = 45;
time.tm_sec = 0;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
rootParameter[0] = parameters;
result.clear();
method->execute(rootParameter, result);
CPPUNIT_ASSERT(!result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT(int(result["errorCode"]) == 1405); // timeframe not available
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/ValidatePlaylistMethod.cxx,v $
------------------------------------------------------------------------------*/
@ -96,15 +96,16 @@ ValidatePlaylistMethod :: ValidatePlaylistMethod (
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
ValidatePlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue)
ValidatePlaylistMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
if (!parameters.valid()) {
if (!rootParameter.valid() || rootParameter.size() != 1) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
XmlRpc::XmlRpcValue parameters = rootParameter[0];
Ptr<UniqueId>::Ref playlistId;
try{

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/ValidatePlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
@ -152,29 +152,35 @@ ValidatePlaylistMethodTest :: firstTest(void)
Ptr<ValidatePlaylistMethod>::Ref
validatePlaylistMethod(new ValidatePlaylistMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
result.clear();
parameter["playlistId"] = 275;
validatePlaylistMethod->execute(parameter, result);
rootParameter[0] = parameter;
validatePlaylistMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT(int(result["errorCode"]) == 503); // no such playlist
result.clear();
parameter.clear();
parameter["playlistId"] = 1;
openPlaylistMethod->execute(parameter, result);
rootParameter[0] = parameter;
openPlaylistMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
validatePlaylistMethod->execute(parameter, result);
validatePlaylistMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("valid"));
CPPUNIT_ASSERT(bool(result["valid"]));
result.clear();
parameter["relativeOffset"] = 0;
removeAudioClipMethod->execute(parameter, result);
rootParameter[0] = parameter;
removeAudioClipMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
validatePlaylistMethod->execute(parameter, result);
validatePlaylistMethod->execute(rootParameter, result);
CPPUNIT_ASSERT(result.hasMember("valid"));
CPPUNIT_ASSERT(!bool(result["valid"])); // has a gap at the beginning
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.6 $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcTools.cxx,v $
------------------------------------------------------------------------------*/
@ -401,3 +401,16 @@ XmlRpcTools :: extractPlayschedule(
return ptime;
}
/*------------------------------------------------------------------------------
* Convert a schedule entry ID (a UniqueId) to an XmlRpcValue
*----------------------------------------------------------------------------*/
void
XmlRpcTools :: scheduleEntryIdToXmlRpcValue(
Ptr<const UniqueId>::Ref scheduleEntryId,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
returnValue[scheduleEntryIdName] = int(scheduleEntryId->getId());
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.5 $
Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/XmlRpcTools.h,v $
------------------------------------------------------------------------------*/
@ -71,7 +71,7 @@ using namespace LiveSupport::Core;
* in the Scheduler.
*
* @author $Author: fgerlits $
* @version $Revision: 1.5 $
* @version $Revision: 1.6 $
*/
class XmlRpcTools
{
@ -303,6 +303,18 @@ class XmlRpcTools
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Convert a schedule entry ID (a UniqueId) to an XmlRpcValue
*
* @param scheduleEntryId the UniqueId to convert.
* @param xmlRpcValue the output parameter holding the result of
* the conversion.
*/
static void
scheduleEntryIdToXmlRpcValue(
Ptr<const UniqueId>::Ref scheduleEntryId,
XmlRpc::XmlRpcValue & returnValue) throw ();
};
/* ================================================= external data structures */