pars 0.2.1
Loading...
Searching...
No Matches
pars::net::context_registry Class Reference

#include <context_registry.h>

Public Member Functions

 context_registry (ev::enqueuer &r, net::socket &s)
 
void stop_all ()
 
contextemplace ()
 
contextof (const net::tool_view &t)
 
void start_recv (int num_ctxs)
 

Detailed Description

Definition at line 45 of file context_registry.h.

Constructor & Destructor Documentation

◆ context_registry()

pars::net::context_registry::context_registry ( ev::enqueuer & r,
net::socket & s )
inline

Definition at line 48 of file context_registry.h.

49 : router_m{r}
50 , sock_m{s}
51 {
52 }

Member Function Documentation

◆ emplace()

context & pars::net::context_registry::emplace ( )
inline

Definition at line 60 of file context_registry.h.

61 {
62 auto ctx = sock_m.make_ctx();
63
64 auto id = ctx.id();
65
66 auto res = ctx_map_m.try_emplace(id, router_m, std::move(ctx), sock_m);
67
68 if (!res.second)
69 throw std::runtime_error("Unable to emplace a context");
70
71 return res.first->second;
72 }
clev::own< nng_ctx > ctx
Definition ctx.h:39

Referenced by start_recv().

Here is the caller graph for this function:

◆ of()

context & pars::net::context_registry::of ( const net::tool_view & t)
inline

Definition at line 74 of file context_registry.h.

75 {
76 if (t.type() != typeid(nngxx::ctx_view))
77 throw std::runtime_error("We need a context here");
78
79 if (ctx_map_m.find(t.id()) == ctx_map_m.end())
80 throw std::runtime_error(std::format("Unknown context {}", t.id()));
81
82 return ctx_map_m.at(t.id());
83 }
clev::iface< nng_ctx > ctx_view
Definition ctx.h:37

References pars::net::tool_view::id(), and pars::net::tool_view::type().

Here is the call graph for this function:

◆ start_recv()

void pars::net::context_registry::start_recv ( int num_ctxs)
inline

Definition at line 85 of file context_registry.h.

86 {
87 for (int i = 0; i < num_ctxs; ++i)
88 emplace().recv();
89 }

References emplace(), and pars::net::context::recv().

Here is the call graph for this function:

◆ stop_all()

void pars::net::context_registry::stop_all ( )
inline

Definition at line 54 of file context_registry.h.

55 {
56 for (auto& c : ctx_map_m)
57 c.second.stop();
58 }

The documentation for this class was generated from the following file: