DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
msghandler.hpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: yes (from dbe/msghandler.h to include/dbe/msghandler.hpp).
5
6/************************************************************
7 * msghandler.h
8 *
9 * Created on: Dec 3, 2014
10 * Author: Leonidas Georgopoulos
11 *
12 * Copyright (C) 2014 Leonidas Georgopoulos
13 * Distributed under the Boost Software License, Version 1.0.
14 * (See accompanying file LICENSE_1_0.txt or
15 * copy at http://www.boost.org/LICENSE_1_0.txt)
16 *
17 ************************************************************/
18
19#ifndef LUTILS_MSGHANDLER_H_
20#define LUTILS_MSGHANDLER_H_
21
22#include <condition_variable>
23#include <fstream>
24#include <iostream>
25#include <memory>
26#include <mutex>
27#include <queue>
28#include <thread>
29#include <vector>
30
31#include "dbe/macro.hpp"
32
33namespace lutils {
34namespace program {
35
39template<typename UI, typename M = std::mutex, typename T = std::thread, typename B = bool>
41{
42public:
43 typedef typename UI::t_str t_str;
44 typedef std::vector<t_str> t_levels;
45
51 static msghandler& ref();
52
60 void set(t_str const& logfile);
61
69 void setlevel(t_str const& level, t_levels levels);
70
76 void message(t_str const& messagein);
77
84 void message(t_str const& msglevel, t_str const& messagein);
85
86private:
87 typedef B t_bool;
88
89 typedef T t_thread;
90 typedef M t_mut;
91 typedef std::lock_guard<t_mut> t_lock;
92 typedef std::shared_ptr<t_str> t_str_ptr;
93
94 typedef std::ofstream t_file;
95 typedef std::unique_ptr<t_file> t_file_ptr;
96
97 template<typename E>
98 using t_container = std::queue<E>;
100
104
105 std::condition_variable m_condition;
106 std::mutex m_cond_lock;
107
110
112
115
117
121 void on();
122
126 void handle();
127
132 template<typename TR = UI>
133 typename TR::default_post_ret_type post(t_str const& m, t_str const& l);
134 template<typename TR = UI>
135 typename TR::post_ret_type post(t_str const& m, t_str const& l);
136
141 void file(t_str const&);
142
150 bool levelcheck(t_str const& level) const;
151
156 void reopen(t_str const&);
157
158 ~msghandler();
159 msghandler();
160 msghandler(msghandler const&) = delete;
161 msghandler& operator=(msghandler const&) = delete;
162};
163
164}
165/* namespace program */
166} /* namespace lutils */
167
168#include "detail/msghandler.hxx"
169
170#endif /* LUTILS_MSGHANDLER_H_ */
bool levelcheck(t_str const &level) const
void message(t_str const &messagein)
TR::default_post_ret_type post(t_str const &m, t_str const &l)
msghandler & operator=(msghandler const &)=delete
static msghandler & ref()
msghandler(msghandler const &)=delete
std::queue< E > t_container
std::lock_guard< t_mut > t_lock
std::condition_variable m_condition
std::shared_ptr< t_str > t_str_ptr
void reopen(t_str const &)
void file(t_str const &)
t_container< std::pair< t_str, t_str > > t_messages
void set(t_str const &logfile)
std::unique_ptr< t_file > t_file_ptr
std::vector< t_str > t_levels
void setlevel(t_str const &level, t_levels levels)