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 <memory>
23#include <mutex>
24#include <thread>
25#include <condition_variable>
26#include <queue>
27#include <fstream>
28#include <iostream>
29#include <vector>
30
31#include "dbe/macro.hpp"
32
33namespace lutils
34{
35namespace program
36{
37
41template<typename UI, typename M = std::mutex, typename T = std::thread, typename B = bool>
43{
44public:
45 typedef typename UI::t_str t_str;
46 typedef std::vector<t_str> t_levels;
47
53 static msghandler & ref();
54
62 void set ( t_str const & logfile );
63
71 void setlevel ( t_str const & level, t_levels levels );
72
78 void message ( t_str const & messagein );
79
86 void message ( t_str const & msglevel, t_str const & messagein );
87
88private:
89 typedef B t_bool;
90
91 typedef T t_thread;
92 typedef M t_mut;
93 typedef std::lock_guard<t_mut> t_lock;
94 typedef std::shared_ptr<t_str> t_str_ptr;
95
96 typedef std::ofstream t_file;
97 typedef std::unique_ptr<t_file> t_file_ptr;
98
99 template<typename E> using t_container = std::queue<E>;
101
105
106 std::condition_variable m_condition;
107 std::mutex m_cond_lock;
108
109
112
114
117
119
123 void on();
124
128 void handle();
129
134 template<typename TR = UI> typename TR::default_post_ret_type post ( t_str const & m,
135 t_str const & l );
136 template<typename TR = UI> typename TR::post_ret_type post ( t_str const & m,
137 t_str const & l );
138
143 void file ( t_str const & );
144
152 bool levelcheck ( t_str const & level ) const;
153
158 void reopen ( t_str const & );
159
160 ~msghandler();
161 msghandler();
162 msghandler ( msghandler const & ) = delete;
163 msghandler & operator= ( msghandler const & ) = delete;
164};
165
166}
167/* namespace program */
168} /* namespace lutils */
169
170#include "detail/msghandler.hxx"
171
172#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)