Finally got reading from the storage server to work. Yippee!

This commit is contained in:
fgerlits 2004-12-21 21:00:37 +00:00
parent 48be2884b4
commit 288ad456be
9 changed files with 241 additions and 64 deletions

View File

@ -1,9 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE audioClip [
<!ELEMENT audioClip EMPTY >
<!ATTLIST audioClip id NMTOKEN #REQUIRED >
<!ATTLIST audioClip playlength NMTOKEN #REQUIRED >
<!ATTLIST audioClip uri CDATA #IMPLIED >
]>
<audioClip id="1" playlength="00:18:30.000" uri="file:var/test1.mp3" />
<audioClip id="1" playlength="00:18:30.000" uri="file:var/test1.mp3">
<metadata
xmlns="http://www.streamonthefly.org/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:xbmf="http://www.streamonthefly.org/xbmf"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
<dc:title >File Title txt</dc:title>
<dcterms:alternative >Alternative File Title ín sőmé %$#@* LÁNGŰAGÉ</dcterms:alternative>
<dc:subject >Keywords: qwe, asd, zcx</dc:subject>
<dc:description >Abstract txt</dc:description>
<dc:date >2004-05-21</dc:date>
<dcterms:available >2004-05-22</dcterms:available>
<dcterms:issued >2004-05-23</dcterms:issued>
<dcterms:modified >2004-05-24</dcterms:modified>
<dcterms:valid >2004-05-25</dcterms:valid>
<dc:type xsi:type="dcterms:DCMIType" >Sound</dc:type>
<dc:format xsi:type="dcterms:IMT" >audio/mpeg</dc:format>
<dcterms:extent >123</dcterms:extent>
<dcterms:medium >online</dcterms:medium>
<dc:identifier >streamonthefly:</dc:identifier>
<dc:identifier >http://some.url.mdlf.org/</dc:identifier>
<dcterms:spatial >Spatial Coverage</dcterms:spatial>
<dcterms:temporal >Temporal Covarage</dcterms:temporal>
<xbmf:episodetitle >Episode Title txt</xbmf:episodetitle>
<xbmf:episodesequence >Episode sequence</xbmf:episodesequence>
<xbmf:contributor>
<xbmf:role>Editor</xbmf:role>
<xbmf:name>John X</xbmf:name>
<xbmf:phone>123456789</xbmf:phone>
</xbmf:contributor>
</metadata>
</audioClip>

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.10 $
Version : $Revision: 1.11 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h,v $
------------------------------------------------------------------------------*/
@ -78,24 +78,43 @@ using namespace boost::posix_time;
* <pre><code>
* &lt;audioClip id="1"
* playlength="00:18:30.000000"
* uri="file:var/test1.mp3"
* uri="file:var/test1.mp3" &gt;
* &lt;metadata
* xmlns="http://www.streamonthefly.org/"
* xmlns:dc="http://purl.org/dc/elements/1.1/"
* xmlns:dcterms="http://purl.org/dc/terms/"
* xmlns:xbmf="http://www.streamonthefly.org/xbmf"
* xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" &gt;
* &lt;dc:title &gt;File Title txt&lt;/dc:title&gt;
* &lt;dcterms:extent &gt;123&lt;/dcterms:extent&gt;
* ...
* &lt;/metadata&gt;
* &lt;/audioClip&gt;
* </code></pre>
*
* The metadata element is optional. The <code>configure()</code> method
* sets only those fields which had not been set previously: e.g., if we set
* some or all fields of the AudioClip in the constructor, then these fields
* in the XML element will be ignored by <code>configure()</code>. If both the
* <code>playlength</code> attribute and the
* <code>&lt;dcterms:extent&gt;</code>
* element are present, then the playlength is set from the attribute and
* <code>&lt;dcterms:extent&gt;</code> is ignored.
*
* The URI is not normally part of the XML element; it's only included
* as an optional attribute for testing purposes.
*
* The DTD for the above element is:
*
* <pre><code>
* &lt;!ELEMENT audioClip EMPTY &gt;
* &lt;!ELEMENT audioClip (metadata?) &gt;
* &lt;!ATTLIST audioClip id NMTOKEN #REQUIRED &gt;
* &lt;!ATTLIST audioClip playlength NMTOKEN #REQUIRED &gt;
* &lt;!ATTLIST audioClip uri CDATA #IMPLIED &gt;
* </code></pre>
*
* @author $Author: fgerlits $
* @version $Revision: 1.10 $
* @version $Revision: 1.11 $
*/
class AudioClip : public Configurable,
public Playable
@ -135,6 +154,18 @@ class AudioClip : public Configurable,
{
}
/**
* Create an audio clip by specifying its unique ID.
* The other fields will be filled in by configure().
*
* @param id the id of the audio clip.
*/
AudioClip(Ptr<UniqueId>::Ref id)
throw ()
{
this->id = id;
}
/**
* Create an audio clip by specifying all details.
* This is used for testing purposes.

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/modules/core/include/LiveSupport/Core/TimeConversion.h,v $
------------------------------------------------------------------------------*/
@ -71,7 +71,7 @@ using namespace LiveSupport;
* A helper object holding static time conversion functions.
*
* @author $Author: fgerlits $
* @version $Revision: 1.5 $
* @version $Revision: 1.6 $
*/
class TimeConversion
{
@ -115,7 +115,8 @@ class TimeConversion
* Convert a boost::posix_time::ptime to a struct tm,
* with second precision.
*
* @param time the boost::posix_time::ptime to convert.
* @param convertFrom the boost::posix_time::ptime to convert.
* @param convertTo holds the result of the conversion
* @return a struct tm, holding the same time.
*/
static void

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/modules/core/src/AudioClip.cxx,v $
------------------------------------------------------------------------------*/
@ -51,6 +51,21 @@ using namespace LiveSupport::Core;
*----------------------------------------------------------------------------*/
const std::string AudioClip::configElementNameStr = "audioClip";
/**
* The name of the metadata child element.
*/
static const std::string metadataElementName = "metadata";
/**
* The prefix of the extent (length) metadata element.
*/
static const std::string extentElementPrefix = "dcterms";
/**
* The name of the extent (length) metadata element.
*/
static const std::string extentElementName = "extent";
/**
* The name of the attribute to get the id of the audio clip.
*/
@ -66,6 +81,7 @@ static const std::string uriAttrName = "uri";
*/
static const std::string playlengthAttrName = "playlength";
/* =============================================== local function prototypes */
@ -83,31 +99,76 @@ AudioClip :: configure(const xmlpp::Element & element)
eMsg += element.get_name();
throw std::invalid_argument(eMsg);
}
const xmlpp::Attribute * attribute;
std::stringstream strStr;
unsigned long int idValue;
if (!(attribute = element.get_attribute(idAttrName))) {
std::string eMsg = "missing attribute ";
eMsg += idAttrName;
throw std::invalid_argument(eMsg);
if (!id) {
if (!(attribute = element.get_attribute(idAttrName))) {
std::string eMsg = "missing attribute ";
eMsg += idAttrName;
throw std::invalid_argument(eMsg);
}
std::stringstream strStr(attribute->get_value());
UniqueId::IdType idValue;
strStr >> idValue;
id.reset(new UniqueId(idValue));
}
strStr.str(attribute->get_value());
strStr >> idValue;
id.reset(new UniqueId(idValue));
if (!(attribute = element.get_attribute(playlengthAttrName))) {
std::string eMsg = "missing attribute ";
eMsg += idAttrName;
throw std::invalid_argument(eMsg);
if (!playlength
&& (attribute = element.get_attribute(playlengthAttrName))) {
playlength.reset(new time_duration(
duration_from_string(attribute->get_value())));
}
playlength.reset(new time_duration(
duration_from_string(attribute->get_value())));
if ((attribute = element.get_attribute(uriAttrName))) {
std::string uriValue = attribute->get_value();
uri.reset(new std::string(uriValue));
if (!uri
&& (attribute = element.get_attribute(uriAttrName))) {
uri.reset(new std::string(attribute->get_value()));
}
xmlpp::Node::NodeList childNodes
= element.get_children(metadataElementName);
xmlpp::Node::NodeList::iterator it = childNodes.begin();
if (it != childNodes.end()) {
const xmlpp::Element * metadataElement
= dynamic_cast<const xmlpp::Element*> (*it);
xmlpp::Node::NodeList dataFieldList
= metadataElement->get_children();
xmlpp::Node::NodeList::iterator listIt = dataFieldList.begin();
while (listIt != dataFieldList.end()) {
const xmlpp::Node * dataNode = *listIt;
if (!playlength
&& dataNode->get_namespace_prefix() == extentElementPrefix
&& dataNode->get_name() == extentElementName) {
const xmlpp::Element
* dataElement
= dynamic_cast<const xmlpp::Element*> (dataNode);
if (dataElement->has_child_text()) {
std::stringstream strStr(dataElement->get_child_text()
->get_content());
unsigned long int seconds;
strStr >> seconds;
playlength.reset(new time_duration(0,0,seconds,0));
}
}
++listIt;
}
++it;
if (it != childNodes.end()) {
std::string eMsg = "more than one ";
eMsg += metadataElementName;
eMsg += " XML element";
throw std::invalid_argument(eMsg);
}
}
if (!playlength) {
std::string eMsg = "missing attribute ";
eMsg += playlengthAttrName;
throw std::invalid_argument(eMsg);
}
}

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/modules/core/src/AudioClipTest.cxx,v $
------------------------------------------------------------------------------*/
@ -95,7 +95,7 @@ AudioClipTest :: firstTest(void)
{
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, true));
new xmlpp::DomParser(configFileName, false));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
Ptr<AudioClip>::Ref audioClip(new AudioClip());

View File

@ -20,8 +20,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# Author : $Author: maroy $
# Version : $Revision: 1.10 $
# Author : $Author: fgerlits $
# Version : $Revision: 1.11 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/etc/Makefile.in,v $
#
# @configure_input@
@ -147,7 +147,7 @@ depclean: clean
distclean: clean docclean
${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te*
check: all ${TEST_RUNNER}
check: all storage_server_init ${TEST_RUNNER}
LD_LIBRARY_PATH=${USR_LIB_DIR} ${TEST_RUNNER} \
-o ${TEST_RESULTS} -s ${TEST_XSLT}
@ -170,6 +170,9 @@ ${TEST_RUNNER}: ${CORE_LIB_FILE} ${TEST_RUNNER_OBJS} ${STORAGE_LIB_FILE}
${CORE_LIB_FILE}:
${MAKE} -C ${CORE_DIR}
storage_server_init:
${MAKE} -C ${BASE_DIR}/../storageServer
#-------------------------------------------------------------------------------
# Pattern rules

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.8 $
Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $
------------------------------------------------------------------------------*/
@ -202,8 +202,14 @@ static const std::string existsAudioClipMethodResultParamName = "exists";
/*------------------------------------------------------------------------------
* The name of the get audio clip method on the storage server
*----------------------------------------------------------------------------*/
static const std::string getAudioClipMethodName
= "locstor.getAudioClip";
static const std::string getAudioClipOpenMethodName
= "locstor.downloadMetadataOpen";
/*------------------------------------------------------------------------------
* The name of the get audio clip method on the storage server
*----------------------------------------------------------------------------*/
static const std::string getAudioClipCloseMethodName
= "locstor.downloadMetadataClose";
/*------------------------------------------------------------------------------
* The name of the session ID parameter in the input structure
@ -216,9 +222,19 @@ static const std::string getAudioClipMethodSessionIdParamName = "sessid";
static const std::string getAudioClipMethodAudioClipIdParamName = "gunid";
/*------------------------------------------------------------------------------
* The name of the result parameter returned by the method
* The name of the result URL parameter returned by the method
*----------------------------------------------------------------------------*/
static const std::string getAudioClipMethodResultParamName = "metadata";
static const std::string getAudioClipMethodUrlParamName = "url";
/*------------------------------------------------------------------------------
* The name of the token parameter returned (for open) or input (for close)
*----------------------------------------------------------------------------*/
static const std::string getAudioClipMethodTokenParamName = "token";
/*------------------------------------------------------------------------------
* The name of the status parameter returned by the close method
*----------------------------------------------------------------------------*/
static const std::string getAudioClipMethodStatusParamName = "status";
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storage server constants: storeAudioClip */
@ -457,11 +473,13 @@ WebStorageClient :: existsAudioClip(Ptr<SessionId>::Ref sessionId,
XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort,
storageServerPath.c_str(), false);
parameters.clear();
parameters[existsAudioClipMethodSessionIdParamName]
= sessionId->getId();
parameters[existsAudioClipMethodAudioClipIdParamName]
= std::string(*id);
result.clear();
if (!xmlRpcClient.execute(existsAudioClipMethodName.c_str(),
parameters, result)) {
std::string eMsg = "cannot execute XML-RPC method '";
@ -487,7 +505,7 @@ WebStorageClient :: existsAudioClip(Ptr<SessionId>::Ref sessionId,
/*------------------------------------------------------------------------------
* Return an audio clip.
* Retrieve an audio clip from the storage.
*----------------------------------------------------------------------------*/
Ptr<AudioClip>::Ref
WebStorageClient :: getAudioClip(Ptr<SessionId>::Ref sessionId,
@ -500,32 +518,39 @@ WebStorageClient :: getAudioClip(Ptr<SessionId>::Ref sessionId,
XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort,
storageServerPath.c_str(), false);
parameters.clear();
parameters[getAudioClipMethodSessionIdParamName]
= sessionId->getId();
parameters[getAudioClipMethodAudioClipIdParamName]
= std::string(*id);
if (!xmlRpcClient.execute(getAudioClipMethodName.c_str(),
result.clear();
if (!xmlRpcClient.execute(getAudioClipOpenMethodName.c_str(),
parameters, result)) {
std::string eMsg = "cannot execute XML-RPC method '";
eMsg += getAudioClipMethodName;
eMsg += getAudioClipOpenMethodName;
eMsg += "'";
throw std::logic_error(eMsg);
}
if (xmlRpcClient.isFault()
|| ! result.hasMember(getAudioClipMethodResultParamName)
|| result[getAudioClipMethodResultParamName].getType()
|| ! result.hasMember(getAudioClipMethodUrlParamName)
|| result[getAudioClipMethodUrlParamName].getType()
!= XmlRpcValue::TypeString
|| ! result.hasMember(getAudioClipMethodTokenParamName)
|| result[getAudioClipMethodTokenParamName].getType()
!= XmlRpcValue::TypeString) {
std::stringstream eMsg;
eMsg << "XML-RPC method '"
<< getAudioClipMethodName
<< getAudioClipOpenMethodName
<< "' returned error message:\n"
<< result;
throw std::logic_error(eMsg.str());
}
std::string xmlAudioClip(result[getAudioClipMethodResultParamName]);
std::string url = result[getAudioClipMethodUrlParamName];
std::string token = result[getAudioClipMethodTokenParamName];
/*
int offset = 353;
std::cout << "\n" << xmlAudioClip.at(offset+0) << "\n";
std::cout << xmlAudioClip.at(offset+1) << "\n";
@ -548,16 +573,15 @@ std::cout << xmlAudioClip.at(offset+17) << "\n";
std::cout << xmlAudioClip.at(offset+18) << "\n";
std::cout << xmlAudioClip.at(offset+19) << "\n";
std::cout << xmlAudioClip.at(offset+20) << "\n";
Ptr<AudioClip>::Ref audioClip;
*/
Ptr<AudioClip>::Ref audioClip(new AudioClip(id));
try {
Ptr<xmlpp::DomParser>::Ref parser(new xmlpp::DomParser());
parser->parse_memory(xmlAudioClip);
parser->parse_file(url);
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
audioClip.reset(new AudioClip);
audioClip->configure(*root);
} catch (std::invalid_argument &e) {
throw std::logic_error("semantic error in audio clip metafile");
@ -565,6 +589,34 @@ std::cout << xmlAudioClip.at(offset+20) << "\n";
throw std::logic_error("error parsing audio clip metafile");
}
parameters.clear();
parameters[getAudioClipMethodSessionIdParamName]
= sessionId->getId();
parameters[getAudioClipMethodTokenParamName]
= token;
result.clear();
if (!xmlRpcClient.execute(getAudioClipCloseMethodName.c_str(),
parameters, result)) {
std::string eMsg = "cannot execute XML-RPC method '";
eMsg += getAudioClipCloseMethodName;
eMsg += "'";
throw std::logic_error(eMsg);
}
if (xmlRpcClient.isFault()
|| ! result.hasMember(getAudioClipMethodStatusParamName)
|| result[getAudioClipMethodStatusParamName].getType()
!= XmlRpcValue::TypeBoolean
|| ! bool(result[getAudioClipMethodStatusParamName])) {
std::stringstream eMsg;
eMsg << "XML-RPC method '"
<< getAudioClipCloseMethodName
<< "' returned error message:\n"
<< result;
throw std::logic_error(eMsg.str());
}
return audioClip;
}
@ -634,7 +686,7 @@ WebStorageClient :: storeAudioClip(Ptr<SessionId>::Ref sessionId,
|| result.getType() != XmlRpcValue::TypeString) {
std::stringstream eMsg;
eMsg << "XML-RPC method '"
<< getAudioClipMethodName
<< storeAudioClipMethodName
<< "' returned error message:\n"
<< result;
throw std::logic_error(eMsg.str());
@ -709,8 +761,10 @@ WebStorageClient :: reset(void)
XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort,
storageServerPath.c_str(), false);
parameters.clear();
parameters["dummy_param"] = "dummy_value";
result.clear();
if (!xmlRpcClient.execute(resetStorageMethodName.c_str(),
parameters, result)) {
std::string eMsg = "cannot execute XML-RPC method '";
@ -743,7 +797,7 @@ WebStorageClient :: reset(void)
<< "':\n"
<< result;
throw std::logic_error(eMsg.str());
}
}
Ptr<UniqueId>::Ref uniqueId(new UniqueId(std::string(uniqueIdArray[i])));
returnValue->push_back(uniqueId);
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.8 $
Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $
------------------------------------------------------------------------------*/
@ -165,7 +165,7 @@ WebStorageClientTest :: audioClipTest(void)
/* std::cout << "\nReset storage result:\n";
for (unsigned i=0; i<uniqueIdVector->size(); i++) {
std::cout << std::hex << uniqueIdVector->at(i)->getId() << std::endl;
std::cout << std::hex << std::string(*uniqueIdVector->at(i)) << std::endl;
} */
Ptr<SessionId>::Ref sessionId = authentication->login("root", "q");
@ -179,7 +179,7 @@ WebStorageClientTest :: audioClipTest(void)
CPPUNIT_FAIL(e.what());
}
CPPUNIT_ASSERT(exists);
/*
Ptr<AudioClip>::Ref audioClip;
try {
audioClip = wsc->getAudioClip(sessionId, id01);
@ -187,9 +187,7 @@ WebStorageClientTest :: audioClipTest(void)
catch (std::logic_error &e) {
CPPUNIT_FAIL(e.what());
}
std::cout << "\nid: " << audioClip->getId()->getId()
<< "\nplaylength: " << audioClip->getPlaylength() << "\n";
*/
Ptr<UniqueId>::Ref id77(new UniqueId(10077));
try {
exists = wsc->existsAudioClip(sessionId, id77);
@ -198,6 +196,7 @@ std::cout << "\nid: " << audioClip->getId()->getId()
CPPUNIT_FAIL(e.what());
}
CPPUNIT_ASSERT(!exists);
/*
Ptr<time_duration>::Ref playlength(new time_duration(0,0,11,0));
Ptr<std::string>::Ref uri(new std::string("file:var/test10001.mp3"));

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<audioClip>
<metadata
xmlns="http://www.streamonthefly.org/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
@ -31,3 +32,4 @@
<xbmf:phone>123456789</xbmf:phone>
</xbmf:contributor>
</metadata>
</audioClip>