pars 0.2.1.99
Loading...
Searching...
No Matches
metadata.h
Go to the documentation of this file.
1/*
2Copyright (c) 2025 Giuseppe Roberti.
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without modification,
6are permitted provided that the following conditions are met:
7
81. Redistributions of source code must retain the above copyright notice, this
9list of conditions and the following disclaimer.
10
112. Redistributions in binary form must reproduce the above copyright notice,
12this list of conditions and the following disclaimer in the documentation and/or
13other materials provided with the distribution.
14
153. Neither the name of the copyright holder nor the names of its contributors
16may be used to endorse or promote products derived from this software without
17specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*/
30#pragma once
31
32#include "pars/concept/event.h"
33#include "pars/concept/kind.h"
34#include "pars/net/pipe.h"
35#include "pars/net/tool_view.h"
36
37#include <format>
38#include <stop_token>
39
40namespace pars::ev
41{
42
43template<template<typename> typename kind_of, event_c event_t>
44 requires kind_c<kind_of>
46{
47 template<typename event2_t>
48 using kind_type = kind_of<event2_t>;
49
50 using event_type = event_t;
51
52 int job_id() const { return job_id_m; }
53
54 void set_job_id(int j_id) { job_id_m = j_id; }
55
56private:
57 int job_id_m;
58};
59
61{
63
64 int socket_id() const { return 0; }
65
66 auto format_to(std::format_context& ctx) const -> decltype(ctx.out())
67 {
68 return std::format_to(ctx.out(), "<internal-metadata>");
69 }
70};
71
73{
75 : id_m{s_id}
76 , tool_m{t}
77 , pipe_m{p}
78 {
79 }
80
81 const net::tool_view& tool() const { return tool_m; }
82
83 const net::pipe& pipe() const { return pipe_m; }
84
85 int socket_id() const { return id_m; }
86
87 auto format_to(std::format_context& ctx) const -> decltype(ctx.out())
88 {
89 // FIXME: duplicated
90 return std::format_to(ctx.out(), "Pipe #{:X} {} {}", pipe().id(),
91 tool().who(), tool().id());
92 }
93
94private:
95 int id_m;
96 net::tool_view tool_m;
97 net::pipe pipe_m;
98};
99
101{
102};
103
105{
106 std::stop_token stop_token() const { return stop_token_m; }
107
108 void set_stop_token(std::stop_token tk) { stop_token_m = tk; }
109
110private:
111 std::stop_token stop_token_m;
112};
113
114template<template<typename> typename kind_of, event_c event_t>
115 requires kind_c<kind_of>
116struct metadata;
117
118template<template<typename> typename kind_of,
120 requires kind_c<kind_of>
121struct metadata<kind_of, event_t> : base_internal_metadata,
123 common_metadata<kind_of, event_t>
124{
126};
127
128template<template<typename> typename kind_of,
130 requires kind_c<kind_of>
131struct metadata<kind_of, event_t>
133{
135};
136
137template<template<typename> typename kind_of,
138 async_internal_event_c<kind_of> event_t>
139 requires kind_c<kind_of>
140struct metadata<kind_of, event_t> : base_internal_metadata,
141 base_async_metadata,
142 common_metadata<kind_of, event_t>
143{
145};
146
147template<template<typename> typename kind_of,
148 async_network_event_c<kind_of> event_t>
149 requires kind_c<kind_of>
150struct metadata<kind_of, event_t> : base_network_metadata,
151 base_async_metadata,
152 common_metadata<kind_of, event_t>
153{
155};
156
157} // namespace pars::ev
158
159#define PARS_MD(ke) \
160 decltype([]<template<typename> typename kind_of, event_c event_t>( \
161 kind_of<event_t> ke) -> pars::ev::METADATA<kind_of, event_t> { \
162 }(ke))
Represents an nng_socket or nng_ctx view.
Definition tool_view.h:48
void set_stop_token(std::stop_token tk)
Definition metadata.h:108
std::stop_token stop_token() const
Definition metadata.h:106
auto format_to(std::format_context &ctx) const -> decltype(ctx.out())
Definition metadata.h:66
const net::tool_view & tool() const
Definition metadata.h:81
auto format_to(std::format_context &ctx) const -> decltype(ctx.out())
Definition metadata.h:87
const net::pipe & pipe() const
Definition metadata.h:83
base_network_metadata(int s_id, net::tool_view t, net::pipe p)
Definition metadata.h:74
kind_of< event2_t > kind_type
Definition metadata.h:48
void set_job_id(int j_id)
Definition metadata.h:54