simple thread
inc
reply.hpp
1
//SPDX-License-Identifier: LicenseRef-Apache-License-2.0
2
//Author: Blayne Dennis
3
4
#ifndef __SIMPLE_THREADING_REPLY__
5
#define __SIMPLE_THREADING_REPLY__
6
7
#include <memory>
8
#include <deque>
9
10
#include "utility.hpp"
11
#include "context.hpp"
12
#include "channel.hpp"
13
14
namespace
st {
// simple thread
15
namespace
detail {
16
namespace
reply {
17
18
struct
context {
19
context(
st::channel
ch, std::size_t
id
) :
20
m_ch(std::move(ch)),
21
m_id(id)
22
{ }
23
24
virtual
~context(){ }
25
26
template
<
typename
T>
27
bool
send(T&& t) {
28
return
m_ch.send(m_id, std::forward<T>(t));
29
}
30
31
st::channel
m_ch;
32
std::size_t m_id;
33
};
34
35
}
36
}
37
47
struct
reply
:
public
st::shared_context
<reply, detail::reply::context> {
48
virtual
~
reply
(){}
49
56
template
<
typename
CHANNEL>
57
static
reply
make
(CHANNEL&& ch, std::size_t
id
= 0) {
58
reply
r;
59
r.ctx(std::make_shared<detail::reply::context>(std::forward<CHANNEL>(ch),
id
));
60
return
r;
61
}
62
68
template
<
typename
T>
69
bool
send
(T&& t) {
70
return
ctx
() ?
ctx
()->send(std::forward<T>(t)) :
false
;
71
}
72
};
73
74
}
75
76
#endif
st::channel
Interthread message passing queue.
Definition:
channel.hpp:170
st::reply
object capable of sending a st::message back to an st::channel
Definition:
reply.hpp:47
st::reply::make
static reply make(CHANNEL &&ch, std::size_t id=0)
construct a reply
Definition:
reply.hpp:57
st::reply::send
bool send(T &&t)
send an st::message back to the st::channel
Definition:
reply.hpp:69
st::shared_context
CRTP-templated interface to provide shared context api.
Definition:
context.hpp:43
st::shared_context< reply, detail::reply::context >::ctx
std::shared_ptr< detail::reply::context > & ctx() const
Definition:
context.hpp:50
Generated by
1.9.1