-
Notifications
You must be signed in to change notification settings - Fork 45
/
pub.hpp
175 lines (144 loc) · 3.42 KB
/
pub.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
SObjectizer 5.
*/
/*!
\file
\brief Functions for creating and binding of the single thread dispatcher.
*/
#pragma once
#include <so_5/declspec.hpp>
#include <so_5/disp_binder.hpp>
#include <so_5/nonempty_name.hpp>
#include <so_5/disp/one_thread/params.hpp>
#include <string_view>
namespace so_5
{
namespace disp
{
namespace one_thread
{
namespace impl
{
class dispatcher_handle_maker_t;
} /* namespace impl */
//
// dispatcher_handle_t
//
/*!
* \since
* v.5.6.0
*
* \brief A handle for %one_thread dispatcher.
*/
class [[nodiscard]] dispatcher_handle_t
{
friend class impl::dispatcher_handle_maker_t;
//! Binder for the dispatcher.
disp_binder_shptr_t m_binder;
dispatcher_handle_t( disp_binder_shptr_t binder ) noexcept
: m_binder{ std::move(binder) }
{}
//! Is this handle empty?
bool
empty() const noexcept { return !m_binder; }
public :
dispatcher_handle_t() noexcept = default;
//! Get a binder for that dispatcher.
[[nodiscard]]
disp_binder_shptr_t
binder() const noexcept
{
return m_binder;
}
//! Is this handle empty?
operator bool() const noexcept { return empty(); }
//! Does this handle contain a reference to dispatcher?
bool
operator!() const noexcept { return !empty(); }
//! Drop the content of handle.
void
reset() noexcept { m_binder.reset(); }
};
//
// make_dispatcher
//
/*!
* \brief Create an instance of %one_thread dispatcher.
*
* \par Usage sample
\code
auto one_thread_disp = so_5::disp::one_thread::make_dispatcher(
env,
"file_handler",
so_5::disp::one_thread::disp_params_t{}.tune_queue_params(
[]( so_5::disp::one_thread::queue_traits::queue_params_t & p ) {
p.lock_factory( so_5::disp::one_thread::queue_traits::simple_lock_factory();
} ) );
auto coop = env.make_coop(
// The main dispatcher for that coop will be
// this instance of one_thread dispatcher.
one_thread_disp.binder() );
\endcode
*
* \since
* v.5.6.0
*/
SO_5_FUNC dispatcher_handle_t
make_dispatcher(
//! SObjectizer Environment to work in.
environment_t & env,
//! Value for creating names of data sources for
//! run-time monitoring.
const std::string_view data_sources_name_base,
//! Parameters for the dispatcher.
disp_params_t params );
/*!
* \brief Create an instance of %one_thread dispatcher.
*
* \par Usage sample
\code
auto one_thread_disp = so_5::disp::one_thread::make_dispatcher(
env,
"file_handler" );
auto coop = env.make_coop(
// The main dispatcher for that coop will be
// this instance of one_thread dispatcher.
one_thread_disp.binder() );
\endcode
*
* \since
* v.5.6.0
*/
inline dispatcher_handle_t
make_dispatcher(
//! SObjectizer Environment to work in.
environment_t & env,
//! Value for creating names of data sources for
//! run-time monitoring.
const std::string_view data_sources_name_base )
{
return make_dispatcher( env, data_sources_name_base, disp_params_t{} );
}
/*!
* \brief Create an instance of %one_thread dispatcher.
*
* \par Usage sample
\code
auto one_thread_disp = so_5::disp::one_thread::make_dispatcher( env );
auto coop = env.make_coop(
// The main dispatcher for that coop will be
// this instance of one_thread dispatcher.
one_thread_disp.binder() );
\endcode
*
* \since
* v.5.6.0
*/
inline dispatcher_handle_t
make_dispatcher( environment_t & env )
{
return make_dispatcher( env, std::string_view{}, disp_params_t{} );
}
} /* namespace one_thread */
} /* namespace disp */
} /* namespace so_5 */