diff options
author | randomdan <randomdan@localhost> | 2011-10-10 21:00:44 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-10-10 21:00:44 +0000 |
commit | 3721aaa5061ed43a3e718467d7ad56315fb4546b (patch) | |
tree | 9c72130ee8265acccaa6ea6dc3470bfe2b07d89a | |
parent | The session ID is an attribute of it, not a member of it (diff) | |
download | project2-3721aaa5061ed43a3e718467d7ad56315fb4546b.tar.bz2 project2-3721aaa5061ed43a3e718467d7ad56315fb4546b.tar.xz project2-3721aaa5061ed43a3e718467d7ad56315fb4546b.zip |
Allow XSL row prefetches to return their failures upon actual use
-rw-r--r-- | project2/xml/xslRowsCache.cpp | 23 | ||||
-rw-r--r-- | 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 <class Exception> +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<XmlParseError>, 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<DownloadFailed>, 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<DownloadFailed>(documents, url)->second.get(); + return safeMapFind<DownloadFailed>(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 <glibmm/ustring.h> class XslRowsCache { - protected: + public: typedef std::set<Glib::ustring> Queued; - typedef std::map<const Glib::ustring, boost::shared_ptr<xmlDoc> > Documents; + typedef boost::shared_ptr<xmlDoc> DocumentPtr; + typedef boost::function0<DocumentPtr> ReturnDocument; + typedef std::map<const Glib::ustring, ReturnDocument> Documents; + protected: static Queued queued; static Documents documents; |