pars
0.2.1
Loading...
Searching...
No Matches
lib
include
pars
app
single.h
Go to the documentation of this file.
1
/*
2
Copyright (c) 2025 Giuseppe Roberti.
3
All rights reserved.
4
5
Redistribution and use in source and binary forms, with or without modification,
6
are permitted provided that the following conditions are met:
7
8
1. Redistributions of source code must retain the above copyright notice, this
9
list of conditions and the following disclaimer.
10
11
2. Redistributions in binary form must reproduce the above copyright notice,
12
this list of conditions and the following disclaimer in the documentation and/or
13
other materials provided with the distribution.
14
15
3. Neither the name of the copyright holder nor the names of its contributors
16
may be used to endorse or promote products derived from this software without
17
specific prior written permission.
18
19
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
ANY 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
28
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
*/
30
#pragma once
31
32
#include "
pars/app/setup.h
"
33
#include "
pars/ev/dispatcher.h
"
34
#include "
pars/ev/enqueuer.h
"
35
#include "
pars/ev/hf_registry.h
"
36
#include "
pars/ev/runner.h
"
37
#include "
pars/log.h
"
38
39
namespace
pars::app
40
{
41
42
template
<
typename
component_t>
43
class
single
:
public
with_default_setup
44
{
45
public
:
46
using
component_type
= component_t;
47
using
self_type
=
single<component_type>
;
48
49
single
()
50
: runner_m{hf_registry_m}
51
, hf_registry_m{runner_m}
52
, dispatcher_m{runner_m}
53
, router_m{dispatcher_m, runner_m}
54
, component_m{hf_registry_m, router_m}
55
{
56
}
57
58
int
exec
(
int
argc,
char
** argv)
59
{
60
atexit(nng_fini);
61
62
setup
();
63
64
startup
(argc, argv);
65
66
return
run
();
67
}
68
69
protected
:
70
component_type
&
comp
() {
return
component_m; }
71
72
ev::enqueuer
&
router
() {
return
router_m; }
73
74
ev::hf_registry
&
hfs
() {
return
hf_registry_m; }
75
76
virtual
void
startup
(
int
argc,
char
** argv) = 0;
77
78
void
graceful_terminate
()
79
{
80
dispatcher_m.stop_running();
81
82
component_m.graceful_terminate();
83
84
dispatcher_m.terminate_now();
85
}
86
87
void
terminate_now
() { dispatcher_m.terminate_now(); }
88
89
void
stop_job_thread
(
const
int
j_id) { runner_m.stop_thread(j_id); }
90
91
int
run
()
92
{
93
try
94
{
95
dispatcher_m.run();
96
97
return
EXIT_SUCCESS;
98
}
99
catch
(std::exception& e)
100
{
101
pars::err
(
SL
,
lf::app
,
"Error while running single application: {}"
,
102
e.what());
103
104
return
EXIT_FAILURE;
105
}
106
}
107
108
private
:
109
ev::runner
runner_m;
110
ev::hf_registry
hf_registry_m;
111
ev::dispatcher
dispatcher_m;
112
ev::enqueuer
router_m;
113
component_type
component_m;
114
};
115
116
}
// namespace pars::app
pars::app::single::self_type
single< component_type > self_type
Definition
single.h:47
pars::app::single::component_type
component_t component_type
Definition
single.h:46
pars::app::single::router
ev::enqueuer & router()
Definition
single.h:72
pars::app::single::startup
virtual void startup(int argc, char **argv)=0
pars::app::single::stop_job_thread
void stop_job_thread(const int j_id)
Definition
single.h:89
pars::app::single::hfs
ev::hf_registry & hfs()
Definition
single.h:74
pars::app::single::single
single()
Definition
single.h:49
pars::app::single::comp
component_type & comp()
Definition
single.h:70
pars::app::single::run
int run()
Definition
single.h:91
pars::app::single::terminate_now
void terminate_now()
Definition
single.h:87
pars::app::single::exec
int exec(int argc, char **argv)
Definition
single.h:58
pars::app::single::graceful_terminate
void graceful_terminate()
Definition
single.h:78
pars::ev::dispatcher
Definition
dispatcher.h:47
pars::ev::enqueuer
Definition
enqueuer.h:43
dispatcher.h
enqueuer.h
hf_registry.h
log.h
SL
#define SL
Definition
log.h:58
pars::app
Definition
resources.h:40
pars::lf::app
@ app
Definition
flags.h:41
pars::err
void err(spdlog::source_loc loc, pars::lf lf, spdlog::format_string_t< args_t... > fmt, args_t &&... args)
Definition
log.h:211
runner.h
setup.h
pars::app::with_default_setup::with_default_setup
with_default_setup()=default
pars::app::with_default_setup::setup
void setup()
Definition
setup.h:56
pars::ev::hf_registry
Definition
hf_registry.h:64
pars::ev::runner
Definition
runner.h:46
Generated by
1.13.2