GNU Radio Manual and C++ API Reference
v3.9.2.0-89-gb7c7001e
The Free & Open Software Radio Ecosystem
thread_body_wrapper.h
Go to the documentation of this file.
1
/* -*- c++ -*- */
2
/*
3
* Copyright 2008,2009,2013 Free Software Foundation, Inc.
4
*
5
* This file is part of GNU Radio
6
*
7
* SPDX-License-Identifier: GPL-3.0-or-later
8
*
9
*/
10
11
#ifndef INCLUDED_THREAD_BODY_WRAPPER_H
12
#define INCLUDED_THREAD_BODY_WRAPPER_H
13
14
#include <
gnuradio/api.h
>
15
#include <
gnuradio/logger.h
>
16
#include <
gnuradio/thread/thread.h
>
17
#include <exception>
18
#include <iostream>
19
20
namespace
gr
{
21
namespace
thread
{
22
23
GR_RUNTIME_API
void
mask_signals
();
24
25
template
<
class
F>
26
class
thread_body_wrapper
27
{
28
private
:
29
F d_f;
30
std::string d_name;
31
bool
d_catch_exceptions;
32
gr::logger_ptr
d_logger;
33
gr::logger_ptr
d_debug_logger;
34
35
public
:
36
explicit
thread_body_wrapper
(F f,
37
const
std::string& name =
""
,
38
bool
catch_exceptions =
true
)
39
: d_f(f), d_name(name), d_catch_exceptions(catch_exceptions)
40
{
41
gr::configure_default_loggers
(d_logger, d_debug_logger,
"thread_body_wrapper"
);
42
}
43
44
void
operator()
()
45
{
46
mask_signals
();
47
48
if
(d_catch_exceptions) {
49
try
{
50
d_f();
51
}
catch
(boost::thread_interrupted
const
&) {
52
}
catch
(std::exception
const
& e) {
53
std::ostringstream msg;
54
msg <<
"ERROR thread["
<< d_name <<
"]: "
<< e.what();
55
GR_LOG_ERROR
(d_logger, msg.str());
56
}
catch
(...) {
57
std::ostringstream msg;
58
msg <<
"ERROR thread["
<< d_name <<
"]: caught unrecognized exception"
;
59
GR_LOG_ERROR
(d_logger, msg.str());
60
}
61
62
}
else
{
63
try
{
64
d_f();
65
}
catch
(boost::thread_interrupted
const
&) {
66
}
67
}
68
}
69
};
70
71
}
/* namespace thread */
72
}
/* namespace gr */
73
74
#endif
/* INCLUDED_THREAD_BODY_WRAPPER_H */
gr::thread::thread_body_wrapper
Definition:
thread_body_wrapper.h:27
gr::thread::thread_body_wrapper::thread_body_wrapper
thread_body_wrapper(F f, const std::string &name="", bool catch_exceptions=true)
Definition:
thread_body_wrapper.h:36
gr::thread::thread_body_wrapper::operator()
void operator()()
Definition:
thread_body_wrapper.h:44
api.h
GR_RUNTIME_API
#define GR_RUNTIME_API
Definition:
gnuradio-runtime/include/gnuradio/api.h:18
logger.h
GR_LOG_ERROR
#define GR_LOG_ERROR(logger, msg)
Definition:
logger.h:251
gr::thread::thread
boost::thread thread
Definition:
thread.h:36
gr::thread::mask_signals
GR_RUNTIME_API void mask_signals()
gr
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition:
basic_block.h:29
gr::configure_default_loggers
GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, const std::string name)
gr::logger_ptr
log4cpp::Category * logger_ptr
GR_LOG macros.
Definition:
logger.h:60
thread.h
gnuradio-runtime
include
gnuradio
thread
thread_body_wrapper.h
Generated by
1.9.1