From 02860860e0b9d31ba29b2d70ab7314b2244e1968 Mon Sep 17 00:00:00 2001 From: randomdan Date: Fri, 15 Mar 2013 00:39:41 +0000 Subject: Add a rowset that lists the routes configured in a programable router --- project2/cgi/cgiProgRouter.cpp | 43 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/project2/cgi/cgiProgRouter.cpp b/project2/cgi/cgiProgRouter.cpp index 9218c89..ff7c864 100644 --- a/project2/cgi/cgiProgRouter.cpp +++ b/project2/cgi/cgiProgRouter.cpp @@ -36,7 +36,7 @@ class RoutingTable { std::string routeScriptPath; const std::string & present(const std::string & path, VarMap & vars) const { - BOOST_FOREACH(const auto route, routes) { + BOOST_FOREACH(const auto & route, routes) { vars.clear(); if (route->matches(path, vars)) { return route->present; @@ -74,12 +74,13 @@ class RoutingTable { public: Route(ScriptNodePtr s) : SourceObject(s), - present(s->value("present").as()) + present(s->value("present").as()), + path(s->value("path").as()) { - boost::filesystem::path path = s->value("path").as(); - boost::filesystem::path::iterator p = path.begin(); + boost::filesystem::path fspath = path; + boost::filesystem::path::iterator p = fspath.begin(); p++; - while(p != path.end() && p->string() != ".") { + while(p != fspath.end() && p->string() != ".") { switch (p->string().front()) { case '{': routeElems.push_back(new RouteVar(p->string())); @@ -105,6 +106,7 @@ class RoutingTable { typedef std::list RouteElems; RouteElems routeElems; const std::string present; + const std::string path; }; typedef boost::intrusive_ptr RoutePtr; @@ -184,3 +186,34 @@ class ProgRouter : public Router { }; DECLARE_CUSTOM_COMPONENT_LOADER("progRouter", ProgRouter, ProgRouterLoader, RouterLoader); + +class Routes : public RowSet { + public: + Routes(ScriptNodePtr s) : + RowSet(s) { } + class RouteRowState : public RowState { + public: + RouteRowState() { + columns.insert(new Column(0, "present")); + columns.insert(new Column(1, "path")); + fields.resize(2); + } + const Columns & getColumns() const { return columns; } + mutable Columns columns; + friend class Routes; + }; + void execute(const Glib::ustring & filter, const RowProcessor * rp) const + { + RouteRowState rs; + BOOST_FOREACH(const auto & r, ProgRouterLoader::routingTable.routes) { + if (boost::algorithm::starts_with(r->path, filter)) { + rs.fields[0] = VariableType(r->present); + rs.fields[1] = VariableType(r->path); + rs.process(rp); + } + } + } +}; + +DECLARE_LOADER("routes", Routes); + -- cgit v1.2.3