GNU Radio Manual and C++ API Reference  3.7.14.0
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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>
30 namespace gr {
31 namespace log {
32 class eom_t
33 {
34 };
35 class purpose_t
36 {
37 };
38 static eom_t eom;
39 static purpose_t msg;
40 template <severity level>
42 {
43 public:
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 
75 private:
76  const std::string src;
77  const std::string purpose;
78  bool sent;
79  std::stringstream string_builder;
80 };
81 template <>
83 {
84 public:
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 */
~source_logger()
Definition: source_logger.h:68
source_logger(const std::string &)
Definition: source_logger.h:85
static purpose_t msg
Definition: source_logger.h:39
source_logger & operator<<(purpose_t &)
Definition: source_logger.h:60
Definition: source_logger.h:41
Definition: source_logger.h:32
source_logger & operator<<(eom_t &)
Definition: source_logger.h:52
Definition: source_logger.h:35
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
static eom_t eom
Definition: source_logger.h:38
source_logger(const std::string &src)
Definition: source_logger.h:44
GR_RUNTIME_API logger & instance()
source_logger & operator<<(T &what)
Definition: source_logger.h:46