diff --git a/include/xo/webutil/Alist.hpp b/include/xo/webutil/Alist.hpp index 80fcaa20..ccb317b3 100644 --- a/include/xo/webutil/Alist.hpp +++ b/include/xo/webutil/Alist.hpp @@ -10,34 +10,34 @@ #include namespace xo { - namespace web { - /* assocation list, maps strings to strings - * use this for arguments to dynamic-endpoint-callbacks - */ - class Alist { - public: - Alist() = default; - - /* lookup association by name */ - std::string_view lookup(std::string n) const { - for (auto const & ix : this->assoc_v_) { - if (ix.first == n) { - return ix.second; - } - } + namespace web { + /* assocation list, maps strings to strings + * use this for arguments to dynamic-endpoint-callbacks + */ + class Alist { + public: + Alist() = default; - return ""; - } /*lookup*/ + /* lookup association by name */ + std::string_view lookup(std::string n) const { + for (auto const & ix : this->assoc_v_) { + if (ix.first == n) { + return ix.second; + } + } - void push_back(std::string n, std::string v) { - this->assoc_v_.push_back(std::make_pair(std::move(n), std::move(v))); - } + return ""; + } /*lookup*/ - private: - std::vector> assoc_v_; - }; /*Alist*/ - - } /*namespace web*/ + void push_back(std::string n, std::string v) { + this->assoc_v_.push_back(std::make_pair(std::move(n), std::move(v))); + } + + private: + std::vector> assoc_v_; + }; /*Alist*/ + + } /*namespace web*/ } /*namespace xo*/ /* end Alist.hpp */ diff --git a/include/xo/webutil/HttpEndpointDescr.hpp b/include/xo/webutil/HttpEndpointDescr.hpp index 79a7070f..97ff4cee 100644 --- a/include/xo/webutil/HttpEndpointDescr.hpp +++ b/include/xo/webutil/HttpEndpointDescr.hpp @@ -12,65 +12,65 @@ #include namespace xo { - namespace web { - /* a function that can deliver http content on demand. */ - using HttpEndpointFn = std::function; + namespace web { + /* a function that can deliver http content on demand. */ + using HttpEndpointFn = std::function; - /* describes an http endpoint -- - * this comprises: - * - a uri pattern. - * - a function that can deliver http content on demand - */ - class HttpEndpointDescr { - public: - HttpEndpointDescr(std::string uri_pattern, - HttpEndpointFn endpoint_fn) - : uri_pattern_{std::move(uri_pattern)}, - endpoint_fn_{std::move(endpoint_fn)} - {} + /* describes an http endpoint -- + * this comprises: + * - a uri pattern. + * - a function that can deliver http content on demand + */ + class HttpEndpointDescr { + public: + HttpEndpointDescr(std::string uri_pattern, + HttpEndpointFn endpoint_fn) + : uri_pattern_{std::move(uri_pattern)}, + endpoint_fn_{std::move(endpoint_fn)} + {} - std::string const & uri_pattern() const { return uri_pattern_; } - HttpEndpointFn const & endpoint_fn() const { return endpoint_fn_; } + std::string const & uri_pattern() const { return uri_pattern_; } + HttpEndpointFn const & endpoint_fn() const { return endpoint_fn_; } - void display(std::ostream & os) const { - using xo::xtag; + void display(std::ostream & os) const { + using xo::xtag; - os << ""; - } /*display*/ + os << ""; + } /*display*/ - std::string display_string() const { return xo::tostr(*this); } + std::string display_string() const { return xo::tostr(*this); } - private: - /* unique pattern in URI-space for this endpoint. - * for example - * .uri_pattern = /stem/${foo}/${bar} - * means this endpoint generates contents for uri's - * /stem/apple/banana - * /stem/aphid/green - * but not for - * /stem/apple/banana/carrot - */ - std::string uri_pattern_; - /* a function that can construct http output on demand - * .endpoint_fn(uri, alist, &os) - * writes http output to os. output is parameterized - * by name-value pairs in alist, and is prepared on behalf - * of .uri_pattern - * alist will report name-value pairs for each variable that - * appears in .uri_pattern (surrounded by ${..}) - */ - HttpEndpointFn endpoint_fn_; - }; /*HttpEndpointDescr*/ + private: + /* unique pattern in URI-space for this endpoint. + * for example + * .uri_pattern = /stem/${foo}/${bar} + * means this endpoint generates contents for uri's + * /stem/apple/banana + * /stem/aphid/green + * but not for + * /stem/apple/banana/carrot + */ + std::string uri_pattern_; + /* a function that can construct http output on demand + * .endpoint_fn(uri, alist, &os) + * writes http output to os. output is parameterized + * by name-value pairs in alist, and is prepared on behalf + * of .uri_pattern + * alist will report name-value pairs for each variable that + * appears in .uri_pattern (surrounded by ${..}) + */ + HttpEndpointFn endpoint_fn_; + }; /*HttpEndpointDescr*/ - inline std::ostream & - operator<<(std::ostream & os, HttpEndpointDescr const & x) { - x.display(os); - return os; - } /*operator<<*/ + inline std::ostream & + operator<<(std::ostream & os, HttpEndpointDescr const & x) { + x.display(os); + return os; + } /*operator<<*/ - } /*namespace web*/ + } /*namespace web*/ } /*namespace xo*/ /* end EndpointDescr.hpp */ diff --git a/include/xo/webutil/StreamEndpointDescr.hpp b/include/xo/webutil/StreamEndpointDescr.hpp index fe86b135..1b361610 100644 --- a/include/xo/webutil/StreamEndpointDescr.hpp +++ b/include/xo/webutil/StreamEndpointDescr.hpp @@ -5,7 +5,7 @@ #pragma once -#include "web_util/Alist.hpp" +#include "Alist.hpp" #include "callback/CallbackSet.hpp" #include "refcnt/Refcounted.hpp" #include "indentlog/print/tag.hpp" @@ -13,66 +13,66 @@ #include namespace xo { - namespace reactor { class AbstractSink; } + namespace reactor { class AbstractSink; } - namespace web { - /* a function that creates an event subscription */ - using StreamSubscribeFn = std::function const & ws_sink)>; - using StreamUnsubscribeFn = std::function; + namespace web { + /* a function that creates an event subscription */ + using StreamSubscribeFn = std::function const & ws_sink)>; + using StreamUnsubscribeFn = std::function; - /* describes a stream endpoint - * this comprises - * - a uri pattern (matches stream name) - * - a function that establishes subscription - * (by attaching supplied WebsocketSink to an event source) - */ - class StreamEndpointDescr { - public: - StreamEndpointDescr(std::string uri_pattern, - StreamSubscribeFn subscribe_fn, - StreamUnsubscribeFn unsubscribe_fn) - : uri_pattern_{std::move(uri_pattern)}, - subscribe_fn_{std::move(subscribe_fn)}, - unsubscribe_fn_{std::move(unsubscribe_fn)} {} + /* describes a stream endpoint + * this comprises + * - a uri pattern (matches stream name) + * - a function that establishes subscription + * (by attaching supplied WebsocketSink to an event source) + */ + class StreamEndpointDescr { + public: + StreamEndpointDescr(std::string uri_pattern, + StreamSubscribeFn subscribe_fn, + StreamUnsubscribeFn unsubscribe_fn) + : uri_pattern_{std::move(uri_pattern)}, + subscribe_fn_{std::move(subscribe_fn)}, + unsubscribe_fn_{std::move(unsubscribe_fn)} {} - std::string const & uri_pattern() const { return uri_pattern_; } - StreamSubscribeFn const & subscribe_fn() const { return subscribe_fn_; } - StreamUnsubscribeFn const & unsubscribe_fn() const { return unsubscribe_fn_; } + std::string const & uri_pattern() const { return uri_pattern_; } + StreamSubscribeFn const & subscribe_fn() const { return subscribe_fn_; } + StreamUnsubscribeFn const & unsubscribe_fn() const { return unsubscribe_fn_; } - void display(std::ostream & os) const { - using xo::xtag; + void display(std::ostream & os) const { + using xo::xtag; - os << ""; - } /*display*/ + os << ""; + } /*display*/ - std::string display_string() const { return xo::tostr(*this); } + std::string display_string() const { return xo::tostr(*this); } - private: - /* unique pattern in URI-space for this endpoint - * for example - * .uri_pattern = /stem/${foo}/${bar} - * means this endpoint generates contents for uri's - * /stem/apple/banana - * /stem/aphid/green - * but not for - * /stem/apple/banana/carrot - */ - std::string uri_pattern_; - /* a function that subscribes to an event stream - * (by attaching a websocket sink) - */ - StreamSubscribeFn subscribe_fn_; - /* reverses effect of a particular call to .subscribe_fn */ - StreamUnsubscribeFn unsubscribe_fn_; - }; /*StreamEndpointDescr*/ + private: + /* unique pattern in URI-space for this endpoint + * for example + * .uri_pattern = /stem/${foo}/${bar} + * means this endpoint generates contents for uri's + * /stem/apple/banana + * /stem/aphid/green + * but not for + * /stem/apple/banana/carrot + */ + std::string uri_pattern_; + /* a function that subscribes to an event stream + * (by attaching a websocket sink) + */ + StreamSubscribeFn subscribe_fn_; + /* reverses effect of a particular call to .subscribe_fn */ + StreamUnsubscribeFn unsubscribe_fn_; + }; /*StreamEndpointDescr*/ - inline std::ostream & - operator<<(std::ostream & os, StreamEndpointDescr const & x) { - x.display(os); - return os; - } /*operator<<*/ + inline std::ostream & + operator<<(std::ostream & os, StreamEndpointDescr const & x) { + x.display(os); + return os; + } /*operator<<*/ - } /*namespace web*/ + } /*namespace web*/ } /*namespace xo*/ /* end StreamEndpointDescr.hpp */