GNU Radio Manual and C++ API Reference 3.7.14.0
The Free & Open Software Radio Ecosystem
log.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 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_LOG_LOG_H
23#define INCLUDED_GR_RUNTIME_RUNTIME_LOG_LOG_H
24
25#include <gnuradio/api.h>
27#include <gnuradio/log/entry.h>
28#include <zmq.hpp>
29#include <atomic>
30/* #include <memory> */
31/* #include <mutex> */
32#include <set>
33#include <thread>
34namespace gr {
35namespace log {
36
37/*! logger singleton class
38 */
40{
41 friend logger& instance();
42
43private:
44 zmq::context_t ctx;
45 zmq::socket_t rx_socket;
46 /*! The private constructor
47 */
48 logger();
49 /*! The private destructor
50 */
51 ~logger() noexcept;
52 /*! enqueue a message.
53 * This is meant to be called asynchronously, as it's a blocking call.
54 */
55 void enqueue(entry&& what) noexcept;
56
57 /*! worker thread
58 */
59 void work();
60
61private:
62 std::set<std::shared_ptr<backend> > backends;
63 /*! internal message queue */
64 std::atomic<bool> running;
65 std::thread worker;
66
67public:
68 /*! Log a log entry
69 * \param what the entry to log.
70 */
71 void operator()(entry&& what) noexcept;
72 /*! we're deleting the copy constructor on a singleton object
73 */
74 logger(logger&) = delete;
75 /*! we're deleting the assignment operator on a singleton object
76 */
77 void operator=(logger const&) = delete;
78 /*! register a logger
79 * \param log_backend the backend to register
80 */
81 void attach(std::shared_ptr<backend> log_backend);
82 /*! unregister a logger
83 * \param log_backend the backend to unregister
84 */
85 void detach(std::shared_ptr<backend> log_backend);
86};
87/*! returns the global logger instance.
88 Initialization on first call.
89*/
91} // namespace log
92} // namespace gr
93#endif /* INCLUDED_GR_RUNTIME_RUNTIME_LOG_LOG_H */
Definition: backend.h:31
Definition: log.h:40
friend logger & instance()
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
GR_RUNTIME_API logger & instance()
boost::thread thread
Definition: thread.h:47
Include this header to use the message passing features.
Definition: basic_block.h:45
STL namespace.