added some more functions
This commit is contained in:
parent
0cf03f59bb
commit
a08d2b4dcd
2 changed files with 306 additions and 17 deletions
|
@ -21,8 +21,8 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.1 $
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.2 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/XmlRpcTools.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -73,8 +73,8 @@ using namespace LiveSupport::Core;
|
|||
* and XmlRpcValues. Used by almost all XmlRpcServerMethod subclasses
|
||||
* in the Scheduler.
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.1 $
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
class XmlRpcTools
|
||||
{
|
||||
|
@ -117,6 +117,18 @@ class XmlRpcTools
|
|||
extractScheduleEntryId(XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||
throw (std::invalid_argument);
|
||||
|
||||
/**
|
||||
* Extract the generic 'id' from the XML-RPC parameters.
|
||||
*
|
||||
* @param xmlRpcValue the XML-RPC parameter to extract from.
|
||||
* @return a UniqueId that was found in the XML-RPC parameter.
|
||||
* @exception std::invalid_argument if there was no playlistId
|
||||
* member in xmlRpcValue
|
||||
*/
|
||||
static Ptr<UniqueId>::Ref
|
||||
extractId(XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||
throw (std::invalid_argument);
|
||||
|
||||
/**
|
||||
* Extract the playlist id from the XML-RPC parameters.
|
||||
*
|
||||
|
@ -233,10 +245,10 @@ class XmlRpcTools
|
|||
throw ();
|
||||
|
||||
/**
|
||||
* Extract the from time parameter from the XML-RPC parameters.
|
||||
* Extract the 'from' time parameter from the XML-RPC parameters.
|
||||
*
|
||||
* @param xmlRpcValue the XML-RPC parameter to extract from.
|
||||
* @return the time value for the from parameter
|
||||
* @return the time value for the 'from' parameter
|
||||
* @exception std::invalid_argument if there was no from parameter
|
||||
* in xmlRpcValue
|
||||
*/
|
||||
|
@ -245,10 +257,10 @@ class XmlRpcTools
|
|||
throw (std::invalid_argument);
|
||||
|
||||
/**
|
||||
* Extract the to parameter from the XML-RPC parameters.
|
||||
* Extract the 'to' parameter from the XML-RPC parameters.
|
||||
*
|
||||
* @param xmlRpcValue the XML-RPC parameter to extract from.
|
||||
* @return the time value for the to parameter
|
||||
* @return the time value for the 'to' parameter
|
||||
* @exception std::invalid_argument if there was no to parameter
|
||||
* in xmlRpcValue
|
||||
*/
|
||||
|
@ -256,6 +268,56 @@ class XmlRpcTools
|
|||
extractToTime(XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||
throw (std::invalid_argument);
|
||||
|
||||
/**
|
||||
* Extract the 'start' parameter from the XML-RPC parameters.
|
||||
*
|
||||
* @param xmlRpcValue the XML-RPC parameter to extract from.
|
||||
* @return the time value for the 'start' parameter
|
||||
* @exception std::invalid_argument if there was no to parameter
|
||||
* in xmlRpcValue
|
||||
*/
|
||||
static Ptr<boost::posix_time::ptime>::Ref
|
||||
extractStartTime(XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||
throw (std::invalid_argument);
|
||||
|
||||
/**
|
||||
* Extract the 'end' parameter from the XML-RPC parameters.
|
||||
*
|
||||
* @param xmlRpcValue the XML-RPC parameter to extract from.
|
||||
* @return the time value for the 'end' parameter
|
||||
* @exception std::invalid_argument if there was no to parameter
|
||||
* in xmlRpcValue
|
||||
*/
|
||||
static Ptr<boost::posix_time::ptime>::Ref
|
||||
extractEndTime(XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||
throw (std::invalid_argument);
|
||||
|
||||
/**
|
||||
* Add a 'from' time value to an XmlRpcValue.
|
||||
*
|
||||
* @param from the 'from' time value to add.
|
||||
* @param returnValue an output parameter, which has the
|
||||
* 'from' time added after the function returns.
|
||||
*/
|
||||
static void
|
||||
fromTimeToXmlRpcValue(
|
||||
Ptr<const boost::posix_time::ptime>::Ref from,
|
||||
XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* Add a 'to' time value to an XmlRpcValue.
|
||||
*
|
||||
* @param to the 'to' time value to add.
|
||||
* @param returnValue an output parameter, which has the
|
||||
* 'to' time added after the function returns.
|
||||
*/
|
||||
static void
|
||||
toTimeToXmlRpcValue(
|
||||
Ptr<const boost::posix_time::ptime>::Ref to,
|
||||
XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* Extract the playtime from the XML-RPC parameters.
|
||||
*
|
||||
|
@ -305,6 +367,19 @@ class XmlRpcTools
|
|||
XmlRpc::XmlRpcValue & returnValue)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* Convert an XmlRpcValue array, holding schedule entries,
|
||||
* to a vector of ScheduleEntry object references.
|
||||
*
|
||||
* @param xmlRpcValue the XML-RPC array holding the schedule entry
|
||||
* data
|
||||
* @return a vector of ScheduleEntry object references, holding
|
||||
* the same data.
|
||||
*/
|
||||
static Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref
|
||||
extractScheduleEntries(XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* Convert a schedule entry ID (a UniqueId) to an XmlRpcValue
|
||||
*
|
||||
|
@ -317,6 +392,43 @@ class XmlRpcTools
|
|||
Ptr<const UniqueId>::Ref scheduleEntryId,
|
||||
XmlRpc::XmlRpcValue & returnValue) throw ();
|
||||
|
||||
/**
|
||||
* Add a session id to an XmlRpcValue
|
||||
*
|
||||
* @param sessionId the session id to add to the XmlRpcValue
|
||||
* @param returnValue an output parameter, which has the
|
||||
* session id added after the function returns.
|
||||
*/
|
||||
static void
|
||||
sessionIdToXmlRpcValue(
|
||||
Ptr<const SessionId>::Ref sessionId,
|
||||
XmlRpc::XmlRpcValue & returnValue) throw ();
|
||||
|
||||
/**
|
||||
* Add a playlist id to an XmlRpcValue
|
||||
*
|
||||
* @param playlist the playlist idt o add to the XmlRpcValue
|
||||
* @param returnValue an output parameter, which has the
|
||||
* playlist id added after the function returns.
|
||||
*/
|
||||
static void
|
||||
playlistIdToXmlRpcValue(
|
||||
Ptr<const UniqueId>::Ref playlistId,
|
||||
XmlRpc::XmlRpcValue & returnValue) throw ();
|
||||
|
||||
/**
|
||||
* Add a playtime value to an XmlRpcValue.
|
||||
*
|
||||
* @param playtime the playtime to add to the XmlRpcValue
|
||||
* @param returnValue an output parameter, which has the
|
||||
* playtime added after the function returns.
|
||||
*/
|
||||
static void
|
||||
playtimeToXmlRpcValue(
|
||||
Ptr<const boost::posix_time::ptime>::Ref playtime,
|
||||
XmlRpc::XmlRpcValue & returnValue)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* Convert a vector of PlayLogEntries to an XML-RPC return value.
|
||||
*
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.1 $
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.2 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/XmlRpcTools.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -54,6 +54,11 @@ using namespace LiveSupport::Core;
|
|||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the generic ID member in the XML-RPC parameter structure
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string idName = "id";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the playlist ID member in the XML-RPC parameter structure
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
@ -80,7 +85,17 @@ static const std::string fromTimeName = "from";
|
|||
static const std::string toTimeName = "to";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the playlist id member in the XML-RPC parameter structure.
|
||||
* The name of the start member in the XML-RPC parameter structure.
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string startTimeName = "start";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the end member in the XML-RPC parameter structure.
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string endTimeName = "end";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the schedule entry id member in the XML-RPC parameter structure.
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string scheduleEntryIdName = "scheduleEntryId";
|
||||
|
||||
|
@ -134,6 +149,24 @@ XmlRpcTools :: extractScheduleEntryId(
|
|||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Extract the generic ID from an XML-RPC function call parameter
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<UniqueId>::Ref
|
||||
XmlRpcTools :: extractId(XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||
throw (std::invalid_argument)
|
||||
{
|
||||
if (!xmlRpcValue.hasMember(idName)
|
||||
|| xmlRpcValue[idName].getType()
|
||||
!= XmlRpc::XmlRpcValue::TypeString) {
|
||||
throw std::invalid_argument("missing or bad ID argument");
|
||||
}
|
||||
|
||||
Ptr<UniqueId>::Ref id(new UniqueId(std::string(xmlRpcValue[idName])));
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Extract the playlist ID from an XML-RPC function call parameter
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
@ -300,7 +333,7 @@ XmlRpcTools :: validStatusToXmlRpcValue(
|
|||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Extract the from time from an XML-RPC function call parameter
|
||||
* Extract the 'from' time from an XML-RPC function call parameter
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<ptime>::Ref
|
||||
XmlRpcTools :: extractFromTime(
|
||||
|
@ -320,7 +353,7 @@ XmlRpcTools :: extractFromTime(
|
|||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Extract the to time from an XML-RPC function call parameter
|
||||
* Extract the 'to' time from an XML-RPC function call parameter
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<ptime>::Ref
|
||||
XmlRpcTools :: extractToTime(
|
||||
|
@ -339,6 +372,46 @@ XmlRpcTools :: extractToTime(
|
|||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Extract the 'start' time from an XML-RPC function call parameter
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<ptime>::Ref
|
||||
XmlRpcTools :: extractStartTime(
|
||||
XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||
throw (std::invalid_argument)
|
||||
{
|
||||
if (!xmlRpcValue.hasMember(startTimeName)
|
||||
|| xmlRpcValue[startTimeName].getType()
|
||||
!= XmlRpc::XmlRpcValue::TypeDateTime) {
|
||||
throw std::invalid_argument("missing or bad 'start' time in "
|
||||
"parameter structure");
|
||||
}
|
||||
|
||||
struct tm time = (struct tm) xmlRpcValue[startTimeName];
|
||||
return TimeConversion::tmToPtime(&time);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Extract the 'end' time from an XML-RPC function call parameter
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<ptime>::Ref
|
||||
XmlRpcTools :: extractEndTime(
|
||||
XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||
throw (std::invalid_argument)
|
||||
{
|
||||
if (!xmlRpcValue.hasMember(endTimeName)
|
||||
|| xmlRpcValue[endTimeName].getType()
|
||||
!= XmlRpc::XmlRpcValue::TypeDateTime) {
|
||||
throw std::invalid_argument("missing or bad 'end' time in "
|
||||
"parameter structure");
|
||||
}
|
||||
|
||||
struct tm time = (struct tm) xmlRpcValue[endTimeName];
|
||||
return TimeConversion::tmToPtime(&time);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Convert a boost::posix_time::ptime to an XmlRpcValue
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
@ -376,15 +449,15 @@ XmlRpcTools :: scheduleEntriesToXmlRpcValue(
|
|||
while (it != scheduleEntries->end()) {
|
||||
Ptr<ScheduleEntry>::Ref entry = *it;
|
||||
XmlRpc::XmlRpcValue returnStruct;
|
||||
returnStruct["id"] = std::string(*entry->getId());
|
||||
returnStruct["playlistId"] = std::string(*entry->getPlaylistId());
|
||||
returnStruct[idName] = std::string(*entry->getId());
|
||||
returnStruct[playlistIdName] = std::string(*entry->getPlaylistId());
|
||||
|
||||
XmlRpc::XmlRpcValue time;
|
||||
ptimeToXmlRpcValue(entry->getStartTime(), time);
|
||||
returnStruct["start"] = time;
|
||||
returnStruct[startTimeName] = time;
|
||||
|
||||
ptimeToXmlRpcValue(entry->getEndTime(), time);
|
||||
returnStruct["end"] = time;
|
||||
returnStruct[endTimeName] = time;
|
||||
|
||||
returnValue[arraySize++] = returnStruct;
|
||||
++it;
|
||||
|
@ -392,6 +465,39 @@ XmlRpcTools :: scheduleEntriesToXmlRpcValue(
|
|||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Convert an XML-RPC value, holding an array of schedule entries
|
||||
* to a vector holding the same ScheduleEntry object.
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref
|
||||
XmlRpcTools :: extractScheduleEntries(
|
||||
XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||
throw ()
|
||||
{
|
||||
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref entries;
|
||||
entries.reset(new std::vector<Ptr<ScheduleEntry>::Ref>());
|
||||
|
||||
int nEntries = xmlRpcValue.size();
|
||||
for (int i = 0; i < nEntries; ++i) {
|
||||
XmlRpc::XmlRpcValue & entryValue = xmlRpcValue[i];
|
||||
|
||||
Ptr<UniqueId>::Ref entryId = extractId(entryValue);
|
||||
Ptr<UniqueId>::Ref playlistId = extractPlaylistId(entryValue);
|
||||
Ptr<ptime>::Ref start = extractStartTime(entryValue);
|
||||
Ptr<ptime>::Ref end = extractEndTime(entryValue);
|
||||
|
||||
Ptr<ScheduleEntry>::Ref entry(new ScheduleEntry(entryId,
|
||||
playlistId,
|
||||
start,
|
||||
end));
|
||||
|
||||
entries->push_back(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Extract the playtime from an XML-RPC function call parameter
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
@ -463,6 +569,77 @@ XmlRpcTools :: scheduleEntryIdToXmlRpcValue(
|
|||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Add a session ID to an XmlRpcValue
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
XmlRpcTools :: sessionIdToXmlRpcValue(
|
||||
Ptr<const SessionId>::Ref sessionId,
|
||||
XmlRpc::XmlRpcValue & returnValue)
|
||||
throw ()
|
||||
{
|
||||
returnValue[sessionIdName] = sessionId->getId();
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Add a playlist ID to an XmlRpcValue
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
XmlRpcTools :: playlistIdToXmlRpcValue(
|
||||
Ptr<const UniqueId>::Ref playlistId,
|
||||
XmlRpc::XmlRpcValue & returnValue)
|
||||
throw ()
|
||||
{
|
||||
returnValue[playlistIdName] = std::string(*playlistId);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Add a playtime value to an XmlRpcValue
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
XmlRpcTools :: playtimeToXmlRpcValue(
|
||||
Ptr<const ptime>::Ref playtime,
|
||||
XmlRpc::XmlRpcValue & returnValue)
|
||||
throw ()
|
||||
{
|
||||
XmlRpc::XmlRpcValue timestamp;
|
||||
ptimeToXmlRpcValue(playtime, timestamp);
|
||||
returnValue[playtimeName] = timestamp;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Add a 'from' time value to an XmlRpcValue
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
XmlRpcTools :: fromTimeToXmlRpcValue(
|
||||
Ptr<const ptime>::Ref from,
|
||||
XmlRpc::XmlRpcValue & returnValue)
|
||||
throw ()
|
||||
{
|
||||
XmlRpc::XmlRpcValue timestamp;
|
||||
ptimeToXmlRpcValue(from, timestamp);
|
||||
returnValue[fromTimeName] = timestamp;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Add a 'to' time value to an XmlRpcValue
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
XmlRpcTools :: toTimeToXmlRpcValue(
|
||||
Ptr<const ptime>::Ref to,
|
||||
XmlRpc::XmlRpcValue & returnValue)
|
||||
throw ()
|
||||
{
|
||||
XmlRpc::XmlRpcValue timestamp;
|
||||
ptimeToXmlRpcValue(to, timestamp);
|
||||
returnValue[toTimeName] = timestamp;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Convert a PlayLogEntry to an XmlRpcValue
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue