GNU Radio Manual and C++ API Reference 3.7.14.0
The Free & Open Software Radio Ecosystem
source_logger.h
Go to the documentation of this file.
1/*
2 * Copyright 2018 Free Software Foundation, Inc.
3 *
4 * This file is part of GNU Radio
5 *
6 * GNU Radio is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3, or (at your option)
9 * any later version.
10 *
11 * GNU Radio is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Radio; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#ifndef INCLUDED_GR_RUNTIME_RUNTIME_SOURCE_LOGGER_H
23#define INCLUDED_GR_RUNTIME_RUNTIME_SOURCE_LOGGER_H
24
25#include <gnuradio/api.h>
26#include <gnuradio/log/entry.h>
27#include <gnuradio/log/log.h>
28#include <sstream>
29#include <string>
30namespace gr {
31namespace log {
32class eom_t
33{
34};
36{
37};
38static eom_t eom;
40template <severity level>
42{
43public:
44 source_logger(const std::string& src) : src(src), sent(false) {}
45 template <typename T>
47 {
48 sent = false;
49 string_builder << what;
50 return *this;
51 }
53 {
54 if (!sent) {
55 instance()(entry(level, src, purpose, string_builder.str()));
56 sent = true;
57 }
58 return *this;
59 }
61 {
62 purpose = string_builder.str();
63 string_builder.str(std::string());
64 string_builder.clear();
65 sent = true;
66 return *this;
67 }
69 {
70 if (!sent) {
71 instance()(entry(level, src, purpose, string_builder.str()));
72 }
73 }
74
75private:
76 const std::string src;
77 const std::string purpose;
78 bool sent;
79 std::stringstream string_builder;
80};
81template <>
83{
84public:
85 source_logger(const std::string&)
86 { /*NOP*/
87 }
88};
89} // namespace log
90} // namespace gr
91#endif /* INCLUDED_GR_RUNTIME_RUNTIME_LOG_SOURCE_LOGGER_H */
Definition: source_logger.h:33
Definition: source_logger.h:36
source_logger(const std::string &)
Definition: source_logger.h:85
Definition: source_logger.h:42
source_logger & operator<<(eom_t &)
Definition: source_logger.h:52
source_logger(const std::string &src)
Definition: source_logger.h:44
source_logger & operator<<(purpose_t &)
Definition: source_logger.h:60
source_logger & operator<<(T &what)
Definition: source_logger.h:46
~source_logger()
Definition: source_logger.h:68
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
static purpose_t msg
Definition: source_logger.h:39
GR_RUNTIME_API logger & instance()
static eom_t eom
Definition: source_logger.h:38
Include this header to use the message passing features.
Definition: basic_block.h:45