cosmetic: formatting
This commit is contained in:
parent
8759357ec7
commit
9a23b29c12
3 changed files with 131 additions and 131 deletions
|
|
@ -10,34 +10,34 @@
|
|||
#include <string_view>
|
||||
|
||||
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<std::pair<std::string, std::string>> 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<std::pair<std::string, std::string>> assoc_v_;
|
||||
}; /*Alist*/
|
||||
|
||||
} /*namespace web*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end Alist.hpp */
|
||||
|
|
|
|||
|
|
@ -12,65 +12,65 @@
|
|||
#include <functional>
|
||||
|
||||
namespace xo {
|
||||
namespace web {
|
||||
/* a function that can deliver http content on demand. */
|
||||
using HttpEndpointFn = std::function<void (std::string const &,
|
||||
Alist const &,
|
||||
std::ostream *)>;
|
||||
namespace web {
|
||||
/* a function that can deliver http content on demand. */
|
||||
using HttpEndpointFn = std::function<void (std::string const &,
|
||||
Alist const &,
|
||||
std::ostream *)>;
|
||||
|
||||
/* 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 << "<HttpEndpointDescr" << xtag("uri_pattern", uri_pattern_) << ">";
|
||||
} /*display*/
|
||||
os << "<HttpEndpointDescr" << xtag("uri_pattern", uri_pattern_) << ">";
|
||||
} /*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 */
|
||||
|
|
|
|||
|
|
@ -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 <functional>
|
||||
|
||||
namespace xo {
|
||||
namespace reactor { class AbstractSink; }
|
||||
namespace reactor { class AbstractSink; }
|
||||
|
||||
namespace web {
|
||||
/* a function that creates an event subscription */
|
||||
using StreamSubscribeFn = std::function<fn::CallbackId (ref::rp<reactor::AbstractSink> const & ws_sink)>;
|
||||
using StreamUnsubscribeFn = std::function<void (fn::CallbackId id)>;
|
||||
namespace web {
|
||||
/* a function that creates an event subscription */
|
||||
using StreamSubscribeFn = std::function<fn::CallbackId (ref::rp<reactor::AbstractSink> const & ws_sink)>;
|
||||
using StreamUnsubscribeFn = std::function<void (fn::CallbackId id)>;
|
||||
|
||||
/* 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 << "<StreamEndpointDescr" << xtag("uri_pattern", uri_pattern_) << ">";
|
||||
} /*display*/
|
||||
os << "<StreamEndpointDescr" << xtag("uri_pattern", uri_pattern_) << ">";
|
||||
} /*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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue