From 3721aaa5061ed43a3e718467d7ad56315fb4546b Mon Sep 17 00:00:00 2001 From: randomdan Date: Mon, 10 Oct 2011 21:00:44 +0000 Subject: Allow XSL row prefetches to return their failures upon actual use --- project2/xml/xslRowsCache.cpp | 23 ++++++++++++++++++++--- project2/xml/xslRowsCache.h | 7 +++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/project2/xml/xslRowsCache.cpp b/project2/xml/xslRowsCache.cpp index 0bfb4a5..bd017d7 100644 --- a/project2/xml/xslRowsCache.cpp +++ b/project2/xml/xslRowsCache.cpp @@ -14,6 +14,14 @@ CurlBulkFetcher XslRowsCache::cbf; SimpleMessageException(XmlParseError); SimpleMessageException(DownloadFailed); +template +static XslRowsCache::DocumentPtr helperThrow(const std::string & msg) { + throw Exception(msg); +} +static XslRowsCache::DocumentPtr helperReturnDocument(XslRowsCache::DocumentPtr dp) { + return dp; +} + class XslCachePopulator : public CurlCompleteCallback { public: XslCachePopulator(CurlPtr ch, const Glib::ustring & u, bool h, bool w, const char * e) : @@ -38,10 +46,19 @@ class XslCachePopulator : public CurlCompleteCallback { htmlReadMemory(buf.c_str(), buf.length(), url.c_str(), encoding, flags) : xmlReadMemory(buf.c_str(), buf.length(), url.c_str(), encoding, flags); if (!doc) { - throw XmlParseError(xmlGetLastError()->message); + Logger()->messagef(LOG_DEBUG, "Download of '%s' succeeded, but parsing failed with error '%s'", url.c_str(), xmlGetLastError()->message); + XslRowsCache::documents.insert(XslRowsCache::Documents::value_type(url, + boost::bind(helperThrow, std::string(xmlGetLastError()->message)))); } XslRowsCache::documents.insert(XslRowsCache::Documents::value_type(url, - XslRowsCache::Documents::value_type::second_type(doc, xmlFreeDoc))); + boost::bind(helperReturnDocument, XslRowsCache::DocumentPtr(doc, xmlFreeDoc)))); + Logger()->messagef(LOG_DEBUG, "Download of '%s' completed, stored", url.c_str()); + } + void error(CurlBulkFetcher *, const char * error) + { + Logger()->messagef(LOG_DEBUG, "Download of '%s' failed with error '%s'", url.c_str(), error); + XslRowsCache::documents.insert(XslRowsCache::Documents::value_type(url, + boost::bind(helperThrow, std::string(error)))); } size_t append(const char * c, size_t b) { @@ -66,7 +83,7 @@ XslRowsCache::getDocument(const Glib::ustring & url, const char * encoding) cons cbf.perform(); queued.clear(); } - return safeMapFind(documents, url)->second.get(); + return safeMapFind(documents, url)->second().get(); } void diff --git a/project2/xml/xslRowsCache.h b/project2/xml/xslRowsCache.h index ec3b6e8..14362b5 100644 --- a/project2/xml/xslRowsCache.h +++ b/project2/xml/xslRowsCache.h @@ -9,10 +9,13 @@ #include class XslRowsCache { - protected: + public: typedef std::set Queued; - typedef std::map > Documents; + typedef boost::shared_ptr DocumentPtr; + typedef boost::function0 ReturnDocument; + typedef std::map Documents; + protected: static Queued queued; static Documents documents; -- cgit v1.2.3