summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-10-25 19:41:26 +0000
committerrandomdan <randomdan@localhost>2011-10-25 19:41:26 +0000
commit210856e9cf7afb547ee5c1f40fca932fb0cf5264 (patch)
treef6f4561b81378b2bc2039f669c2855527642d05e
parentRemove session implementations per container, not point (diff)
downloadproject2-210856e9cf7afb547ee5c1f40fca932fb0cf5264.tar.bz2
project2-210856e9cf7afb547ee5c1f40fca932fb0cf5264.tar.xz
project2-210856e9cf7afb547ee5c1f40fca932fb0cf5264.zip
Finally sort the stupid names problem in the XML lib and remove xmlMemCache for flawed from day one
-rw-r--r--project2/xml/Jamfile.jam2
-rw-r--r--project2/xml/xmlDocumentCache.cpp (renamed from project2/xml/xslRowsCache.cpp)42
-rw-r--r--project2/xml/xmlDocumentCache.h (renamed from project2/xml/xslRowsCache.h)10
-rw-r--r--project2/xml/xmlDocumentPrefetch.cpp57
-rw-r--r--project2/xml/xmlDocumentPrefetch.h (renamed from project2/xml/xslPreFetch.h)12
-rw-r--r--project2/xml/xmlMemCache.cpp121
-rw-r--r--project2/xml/xpathRows.cpp (renamed from project2/xml/xslRows.cpp)34
-rw-r--r--project2/xml/xpathRows.h (renamed from project2/xml/xslRows.h)16
-rw-r--r--project2/xml/xslPreFetch.cpp57
9 files changed, 115 insertions, 236 deletions
diff --git a/project2/xml/Jamfile.jam b/project2/xml/Jamfile.jam
index 8a4a5cc..6078290 100644
--- a/project2/xml/Jamfile.jam
+++ b/project2/xml/Jamfile.jam
@@ -15,7 +15,7 @@ cpp-pch pch : pch.hpp :
lib p2xml :
pch
rawView.cpp xmlPresenter.cpp transformXml.cpp transformHtml.cpp transformText.cpp xmlRows.cpp
- xmlRawRows.cpp xslRows.cpp xslRowsCache.cpp xslPreFetch.cpp xmlMemCache.cpp xmlCache.cpp sessionXml.cpp
+ xmlRawRows.cpp xpathRows.cpp xmlDocumentCache.cpp xmlDocumentPrefetch.cpp xmlCache.cpp sessionXml.cpp
:
<include>../libmisc
<library>libxmlpp
diff --git a/project2/xml/xslRowsCache.cpp b/project2/xml/xmlDocumentCache.cpp
index bd017d7..9941336 100644
--- a/project2/xml/xslRowsCache.cpp
+++ b/project2/xml/xmlDocumentCache.cpp
@@ -1,32 +1,32 @@
#include <pch.hpp>
#include <xmlObjectLoader.h>
-#include "xslRowsCache.h"
+#include "xmlDocumentCache.h"
#include <string.h>
#include <libxml/HTMLparser.h>
#include "exceptions.h"
#include "curlHelper.h"
#include "safeMapFind.h"
-XslRowsCache::Documents XslRowsCache::documents;
-XslRowsCache::Queued XslRowsCache::queued;
-CurlBulkFetcher XslRowsCache::cbf;
+XmlDocumentCache::Documents XmlDocumentCache::documents;
+XmlDocumentCache::Queued XmlDocumentCache::queued;
+CurlBulkFetcher XmlDocumentCache::cbf;
SimpleMessageException(XmlParseError);
SimpleMessageException(DownloadFailed);
template <class Exception>
-static XslRowsCache::DocumentPtr helperThrow(const std::string & msg) {
+static XmlDocumentCache::DocumentPtr helperThrow(const std::string & msg) {
throw Exception(msg);
}
-static XslRowsCache::DocumentPtr helperReturnDocument(XslRowsCache::DocumentPtr dp) {
+static XmlDocumentCache::DocumentPtr helperReturnDocument(XmlDocumentCache::DocumentPtr dp) {
return dp;
}
-class XslCachePopulator : public CurlCompleteCallback {
+class XmlDocumentCachePopulator : public CurlCompleteCallback {
public:
- XslCachePopulator(CurlPtr ch, const Glib::ustring & u, bool h, bool w, const char * e) :
+ XmlDocumentCachePopulator(CurlPtr ch, const Glib::ustring & u, bool h, bool w, const char * e) :
CurlCompleteCallback(ch),
- handler(boost::bind(&XslCachePopulator::append, this, _1, _2)),
+ handler(boost::bind(&XmlDocumentCachePopulator::append, this, _1, _2)),
url(u),
html(h),
warnings(w),
@@ -34,7 +34,7 @@ class XslCachePopulator : public CurlCompleteCallback {
{
ch->setReadHandler(handler);
}
- ~XslCachePopulator()
+ ~XmlDocumentCachePopulator()
{
free(encoding);
}
@@ -47,17 +47,17 @@ class XslCachePopulator : public CurlCompleteCallback {
xmlReadMemory(buf.c_str(), buf.length(), url.c_str(), encoding, flags);
if (!doc) {
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,
+ XmlDocumentCache::documents.insert(XmlDocumentCache::Documents::value_type(url,
boost::bind(helperThrow<XmlParseError>, std::string(xmlGetLastError()->message))));
}
- XslRowsCache::documents.insert(XslRowsCache::Documents::value_type(url,
- boost::bind(helperReturnDocument, XslRowsCache::DocumentPtr(doc, xmlFreeDoc))));
+ XmlDocumentCache::documents.insert(XmlDocumentCache::Documents::value_type(url,
+ boost::bind(helperReturnDocument, XmlDocumentCache::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,
+ XmlDocumentCache::documents.insert(XmlDocumentCache::Documents::value_type(url,
boost::bind(helperThrow<DownloadFailed>, std::string(error))));
}
size_t append(const char * c, size_t b)
@@ -75,7 +75,7 @@ class XslCachePopulator : public CurlCompleteCallback {
};
xmlDocPtr
-XslRowsCache::getDocument(const Glib::ustring & url, const char * encoding) const
+XmlDocumentCache::getDocument(const Glib::ustring & url, const char * encoding) const
{
Documents::const_iterator i = documents.find(url);
if (i == documents.end()) {
@@ -87,21 +87,21 @@ XslRowsCache::getDocument(const Glib::ustring & url, const char * encoding) cons
}
void
-XslRowsCache::queue(const Glib::ustring & url, const char * encoding) const
+XmlDocumentCache::queue(const Glib::ustring & url, const char * encoding) const
{
if (queued.find(url) == queued.end()) {
- cbf.curls.insert(new XslCachePopulator(newCurl(), url, asHtml(), withWarnings(), encoding));
+ cbf.curls.insert(new XmlDocumentCachePopulator(newCurl(), url, asHtml(), withWarnings(), encoding));
queued.insert(url);
}
}
-class XslCacheClearer : public ComponentLoader {
+class XmlDocumentCacheClearer : public ComponentLoader {
public:
void onIteration()
{
- Logger()->messagef(LOG_DEBUG, "%s: Clearing XSL row document cache", __PRETTY_FUNCTION__);
- XslRowsCache::documents.clear();
+ Logger()->messagef(LOG_DEBUG, "%s: Clearing XML document cache", __PRETTY_FUNCTION__);
+ XmlDocumentCache::documents.clear();
}
};
-DECLARE_CUSTOM_COMPONENT_LOADER("XslCacheClearer", XslCacheClearer, XslCacheClearer, ComponentLoader);
+DECLARE_CUSTOM_COMPONENT_LOADER("XmlDocumentCacheClearer", XmlDocumentCacheClearer, XmlDocumentCacheClearer, ComponentLoader);
diff --git a/project2/xml/xslRowsCache.h b/project2/xml/xmlDocumentCache.h
index 14362b5..190c989 100644
--- a/project2/xml/xslRowsCache.h
+++ b/project2/xml/xmlDocumentCache.h
@@ -1,5 +1,5 @@
-#ifndef XSLROWSCACHE_H
-#define XSLROWSCACHE_H
+#ifndef XMLDOCUMENTROWSCACHE_H
+#define XMLDOCUMENTROWSCACHE_H
#include <libxml/tree.h>
#include <boost/shared_ptr.hpp>
@@ -8,7 +8,7 @@
#include <curlHelper.h>
#include <glibmm/ustring.h>
-class XslRowsCache {
+class XmlDocumentCache {
public:
typedef std::set<Glib::ustring> Queued;
typedef boost::shared_ptr<xmlDoc> DocumentPtr;
@@ -31,8 +31,8 @@ class XslRowsCache {
private:
static CurlBulkFetcher cbf;
- friend class XslCachePopulator;
- friend class XslCacheClearer;
+ friend class XmlDocumentCachePopulator;
+ friend class XmlDocumentCacheClearer;
};
#endif
diff --git a/project2/xml/xmlDocumentPrefetch.cpp b/project2/xml/xmlDocumentPrefetch.cpp
new file mode 100644
index 0000000..f2ff4d0
--- /dev/null
+++ b/project2/xml/xmlDocumentPrefetch.cpp
@@ -0,0 +1,57 @@
+#include <pch.hpp>
+#include "xmlDocumentPrefetch.h"
+#include "xmlObjectLoader.h"
+
+DECLARE_LOADER("xmldocumentprefetch", XmlDocumentPrefetch);
+
+XmlDocumentPrefetch::XmlDocumentPrefetch(const xmlpp::Element * p) :
+ SourceObject(p),
+ View(p),
+ Task(p),
+ VariableCurlHelper(p),
+ html(p->get_attribute_value("html") == "true"),
+ warnings(p->get_attribute_value("warnings") != "false"),
+ encoding(p, "encoding", false)
+{
+}
+
+XmlDocumentPrefetch::~XmlDocumentPrefetch()
+{
+}
+
+void
+XmlDocumentPrefetch::execute(const Presenter*) const
+{
+ execute();
+}
+
+void
+XmlDocumentPrefetch::execute() const
+{
+ queue(url(), encoding());
+}
+
+void
+XmlDocumentPrefetch::loadComplete(const CommonObjects *)
+{
+}
+
+
+CurlPtr
+XmlDocumentPrefetch::newCurl() const
+{
+ return VariableCurlHelper::newCurl();
+}
+
+bool
+XmlDocumentPrefetch::asHtml() const
+{
+ return html;
+}
+
+bool
+XmlDocumentPrefetch::withWarnings() const
+{
+ return warnings;
+}
+
diff --git a/project2/xml/xslPreFetch.h b/project2/xml/xmlDocumentPrefetch.h
index fb453d5..e6ccbec 100644
--- a/project2/xml/xslPreFetch.h
+++ b/project2/xml/xmlDocumentPrefetch.h
@@ -1,17 +1,17 @@
-#ifndef XSLPREFETCH_H
-#define XSLPREFETCH_H
+#ifndef XMLDOCUMENTPREFETCH_H
+#define XMLDOCUMENTPREFETCH_H
-#include "xslRowsCache.h"
+#include "xmlDocumentCache.h"
#include "curlHelper.h"
#include "view.h"
#include "task.h"
#include <libxml++/nodes/element.h>
/// Project2 component to queue up CURL objects to be downloaded
-class XslPreFetch : public View, public Task, XslRowsCache, VariableCurlHelper {
+class XmlDocumentPrefetch : public View, public Task, XmlDocumentCache, VariableCurlHelper {
public:
- XslPreFetch(const xmlpp::Element * p);
- ~XslPreFetch();
+ XmlDocumentPrefetch(const xmlpp::Element * p);
+ ~XmlDocumentPrefetch();
void execute(const Presenter*) const;
void execute() const;
diff --git a/project2/xml/xmlMemCache.cpp b/project2/xml/xmlMemCache.cpp
deleted file mode 100644
index 9fe0a6f..0000000
--- a/project2/xml/xmlMemCache.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-#include <pch.hpp>
-#include "cache.h"
-#include "logger.h"
-#include "xmlObjectLoader.h"
-#include "iHaveParameters.h"
-#include "xmlRawRows.h"
-#include "xmlPresenter.h"
-#include <sys/stat.h>
-#include <boost/foreach.hpp>
-#include <boost/program_options.hpp>
-#include <libxml++/document.h>
-#include <boost/multi_index_container.hpp>
-#include <boost/multi_index/member.hpp>
-#include <boost/multi_index/ordered_index.hpp>
-
-class XmlMemCache : public Cache {
- public:
- class CacheEntry : public IntrusivePtrBase {
- public:
- std::vector<std::string> key;
- time_t createdAt;
- boost::shared_ptr<const xmlpp::Document> doc;
- };
- typedef boost::intrusive_ptr<CacheEntry> CacheEntryPtr;
- typedef boost::intrusive_ptr<const CacheEntry> CacheEntryCPtr;
-
- struct IndexByKey { };
- struct IndexByTime { };
- typedef boost::multi_index::multi_index_container<
- boost::intrusive_ptr<const CacheEntry>,
- boost::multi_index::indexed_by<
- boost::multi_index::ordered_unique<
- boost::multi_index::tag<IndexByKey>, BOOST_MULTI_INDEX_MEMBER(CacheEntry, const std::vector<std::string>, key)>,
- boost::multi_index::ordered_non_unique<
- boost::multi_index::tag<IndexByTime>, BOOST_MULTI_INDEX_MEMBER(CacheEntry, const time_t, createdAt)>
- > > CacheStore;
-
- XmlMemCache(const xmlpp::Element * p) :
- Cache(p)
- {
- }
-
- void loadComplete(const CommonObjects*)
- {
- }
-
- RowSetCPtr getCachedRowSet(const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * ps) const
- {
- std::vector<std::string> key;
- key.push_back(n);
- key.push_back(f);
- applyKeys(boost::bind(&std::vector<std::string>::push_back, &key, _2), ps);
- CacheStore::index<IndexByKey>::type::const_iterator i = Store.get<IndexByKey>().find(key);
- if (i == Store.get<IndexByKey>().end()) {
- return NULL;
- }
- if ((*i)->createdAt < (time(NULL) - CacheLife)) {
- Store.erase(i);
- return NULL;
- }
- return new XmlMemRawRows((*i)->doc);
- }
-
- PresenterPtr openFor(const Glib::ustring & n, const Glib::ustring &, const IHaveParameters *)
- {
- writeTo = new XmlPresenter(n, Glib::ustring(), Glib::ustring());
- return writeTo;
- }
-
- void close(const Glib::ustring & n, const Glib::ustring & f, const IHaveParameters * ps)
- {
- CacheEntryPtr ce = new CacheEntry();
- ce->key.push_back(n);
- ce->key.push_back(f);
- applyKeys(boost::bind(&std::vector<std::string>::push_back, &ce->key, _2), ps);
- time(&ce->createdAt);
- ce->doc = *(const boost::shared_ptr<xmlpp::Document>*)(*writeTo);
- Store.insert(ce);
- }
-
- private:
- XmlPresenterPtr writeTo;
-
- friend class CustomXmlMemCacheLoader;
- static time_t CacheLife;
- static CacheStore Store;
-};
-
-time_t XmlMemCache::CacheLife;
-XmlMemCache::CacheStore XmlMemCache::Store;
-
-namespace po = boost::program_options;
-class CustomXmlMemCacheLoader : public ElementLoaderImpl<XmlMemCache> {
- public:
- CustomXmlMemCacheLoader() :
- opts("XML Memory Cache options")
- {
- opts.add_options()
- ("cache.xmlmem.life", po::value(&XmlMemCache::CacheLife)->default_value(3600),
- "The age of cache entries after which they are removed (seconds)")
- ;
- }
-
- po::options_description * options()
- {
- return &opts;
- }
-
- void onIdle()
- {
- typedef XmlMemCache::CacheStore::index<XmlMemCache::IndexByTime>::type::iterator iter;
- iter x = XmlMemCache::Store.get<XmlMemCache::IndexByTime>().begin();
- iter y = XmlMemCache::Store.get<XmlMemCache::IndexByTime>().upper_bound(time(NULL) - XmlMemCache::CacheLife);
- XmlMemCache::Store.get<XmlMemCache::IndexByTime>().erase(x, y);
- }
-
- private:
- po::options_description opts;
-};
-DECLARE_CUSTOM_LOADER("xmlmemcache", CustomXmlMemCacheLoader);
-
diff --git a/project2/xml/xslRows.cpp b/project2/xml/xpathRows.cpp
index 31d0e0b..24283dd 100644
--- a/project2/xml/xslRows.cpp
+++ b/project2/xml/xpathRows.cpp
@@ -1,5 +1,5 @@
#include <pch.hpp>
-#include "xslRows.h"
+#include "xpathRows.h"
#include "safeMapFind.h"
#include "rowProcessor.h"
#include "logger.h"
@@ -12,12 +12,12 @@
#include "../libmisc/curlsup.h"
#include <boost/foreach.hpp>
-DECLARE_LOADER("xslrows", XslRows);
+DECLARE_LOADER("xpathrows", XPathRows);
SimpleMessageException(XpathInitError);
SimpleMessageException(XpathEvalError);
-XslRows::XslRows(const xmlpp::Element * p) :
+XPathRows::XPathRows(const xmlpp::Element * p) :
RowSet(p),
VariableCurlHelper(p),
html(p->get_attribute_value("html") == "true"),
@@ -39,35 +39,35 @@ XslRows::XslRows(const xmlpp::Element * p) :
}
}
-XslRows::~XslRows()
+XPathRows::~XPathRows()
{
}
void
-XslRows::loadComplete(const CommonObjects *)
+XPathRows::loadComplete(const CommonObjects *)
{
}
bool
-XslRows::asHtml() const
+XPathRows::asHtml() const
{
return html;
}
bool
-XslRows::withWarnings() const
+XPathRows::withWarnings() const
{
return warnings;
}
CurlPtr
-XslRows::newCurl() const
+XPathRows::newCurl() const
{
return VariableCurlHelper::newCurl();
}
void
-XslRows::execute(const Glib::ustring & filter, const RowProcessor * rp) const
+XPathRows::execute(const Glib::ustring & filter, const RowProcessor * rp) const
{
FilterViewPtr fv = safeMapFind<FilterNotFound>(fvs, filter)->second;
@@ -86,7 +86,7 @@ XslRows::execute(const Glib::ustring & filter, const RowProcessor * rp) const
throw XpathEvalError(xmlGetLastError()->message);
}
Logger()->messagef(LOG_INFO, "%d nodes matched %s", xpathObj->nodesetval->nodeNr, (const char *)(fv->root()));
- XslState xs(fv);
+ XPathState xs(fv);
for (int row = 0; row < xpathObj->nodesetval->nodeNr; row += 1) {
xmlNodePtr rowRoot = xpathObj->nodesetval->nodeTab[row];
xpathCtx->node = rowRoot;
@@ -127,33 +127,33 @@ XslRows::execute(const Glib::ustring & filter, const RowProcessor * rp) const
}
}
-XslRows::FilterView::FilterView(const xmlpp::Element * p) :
- DefinedColumns(p, "field", boost::bind(XslRows::FilterViewColumn::make, _1, _2)),
+XPathRows::FilterView::FilterView(const xmlpp::Element * p) :
+ DefinedColumns(p, "field", boost::bind(XPathRows::FilterViewColumn::make, _1, _2)),
name(p->get_attribute_value("name")),
root(p, "root")
{
}
-XslRows::FilterViewColumn::FilterViewColumn(unsigned int idx, const xmlpp::Element * p) :
+XPathRows::FilterViewColumn::FilterViewColumn(unsigned int idx, const xmlpp::Element * p) :
Column(idx, p),
path(p, "xpath")
{
}
-XslRows::FilterViewColumn *
-XslRows::FilterViewColumn::make(unsigned int idx, const xmlpp::Element * p)
+XPathRows::FilterViewColumn *
+XPathRows::FilterViewColumn::make(unsigned int idx, const xmlpp::Element * p)
{
return new FilterViewColumn(idx, p);
}
-XslRows::XslState::XslState(FilterViewCPtr f) :
+XPathRows::XPathState::XPathState(FilterViewCPtr f) :
fv(f)
{
fields.resize(f->columns.size());
}
const Columns &
-XslRows::XslState::getColumns() const
+XPathRows::XPathState::getColumns() const
{
return fv->columns;
}
diff --git a/project2/xml/xslRows.h b/project2/xml/xpathRows.h
index 9611ca4..4b9e008 100644
--- a/project2/xml/xslRows.h
+++ b/project2/xml/xpathRows.h
@@ -1,5 +1,5 @@
-#ifndef XSLROWS_H
-#define XSLROWS_H
+#ifndef XPATHROWS_H
+#define XPATHROWS_H
#include <libxml++/nodes/element.h>
#include <libxml/tree.h>
@@ -7,15 +7,15 @@
#include <map>
#include "rowSet.h"
#include "variables.h"
-#include "xslRowsCache.h"
+#include "xmlDocumentCache.h"
#include "curlHelper.h"
#include "definedColumns.h"
/// Project2 component to create a row set based on the contents of an XML resource and specific XPaths with its hierarchy
-class XslRows : public RowSet, XslRowsCache, VariableCurlHelper {
+class XPathRows : public RowSet, XmlDocumentCache, VariableCurlHelper {
public:
- XslRows(const xmlpp::Element * p);
- ~XslRows();
+ XPathRows(const xmlpp::Element * p);
+ ~XPathRows();
void execute(const Glib::ustring &, const RowProcessor *) const;
virtual void loadComplete(const CommonObjects *);
@@ -50,9 +50,9 @@ class XslRows : public RowSet, XslRowsCache, VariableCurlHelper {
typedef std::map<const Glib::ustring, Glib::ustring> Namespaces;
Namespaces namespaces;
- class XslState : public RowState {
+ class XPathState : public RowState {
public:
- XslState(FilterViewCPtr);
+ XPathState(FilterViewCPtr);
const Columns & getColumns() const;
private:
const FilterViewCPtr fv;
diff --git a/project2/xml/xslPreFetch.cpp b/project2/xml/xslPreFetch.cpp
deleted file mode 100644
index be72fb5..0000000
--- a/project2/xml/xslPreFetch.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#include <pch.hpp>
-#include "xslPreFetch.h"
-#include "xmlObjectLoader.h"
-
-DECLARE_LOADER("xslprefetch", XslPreFetch);
-
-XslPreFetch::XslPreFetch(const xmlpp::Element * p) :
- SourceObject(p),
- View(p),
- Task(p),
- VariableCurlHelper(p),
- html(p->get_attribute_value("html") == "true"),
- warnings(p->get_attribute_value("warnings") != "false"),
- encoding(p, "encoding", false)
-{
-}
-
-XslPreFetch::~XslPreFetch()
-{
-}
-
-void
-XslPreFetch::execute(const Presenter*) const
-{
- execute();
-}
-
-void
-XslPreFetch::execute() const
-{
- queue(url(), encoding());
-}
-
-void
-XslPreFetch::loadComplete(const CommonObjects *)
-{
-}
-
-
-CurlPtr
-XslPreFetch::newCurl() const
-{
- return VariableCurlHelper::newCurl();
-}
-
-bool
-XslPreFetch::asHtml() const
-{
- return html;
-}
-
-bool
-XslPreFetch::withWarnings() const
-{
- return warnings;
-}
-