DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
msghandler.hpp
Go to the documentation of this file.
1/************************************************************
2 * msghandler.h
3 *
4 * Created on: Dec 3, 2014
5 * Author: Leonidas Georgopoulos
6 *
7 * Copyright (C) 2014 Leonidas Georgopoulos
8 * Distributed under the Boost Software License, Version 1.0.
9 * (See accompanying file LICENSE_1_0.txt or
10 * copy at http://www.boost.org/LICENSE_1_0.txt)
11 *
12 ************************************************************/
13
14#ifndef LUTILS_MSGHANDLER_H_
15#define LUTILS_MSGHANDLER_H_
16
17#include <memory>
18#include <mutex>
19#include <thread>
20#include <condition_variable>
21#include <queue>
22#include <fstream>
23#include <iostream>
24#include <vector>
25
26#include "dbe/macro.hpp"
27
28namespace lutils
29{
30namespace program
31{
32
36template<typename UI, typename M = std::mutex, typename T = std::thread, typename B = bool>
38{
39public:
40 typedef typename UI::t_str t_str;
41 typedef std::vector<t_str> t_levels;
42
48 static msghandler & ref();
49
57 void set ( t_str const & logfile );
58
66 void setlevel ( t_str const & level, t_levels levels );
67
73 void message ( t_str const & messagein );
74
81 void message ( t_str const & msglevel, t_str const & messagein );
82
83private:
84 typedef B t_bool;
85
86 typedef T t_thread;
87 typedef M t_mut;
88 typedef std::lock_guard<t_mut> t_lock;
89 typedef std::shared_ptr<t_str> t_str_ptr;
90
91 typedef std::ofstream t_file;
92 typedef std::unique_ptr<t_file> t_file_ptr;
93
94 template<typename E> using t_container = std::queue<E>;
96
100
101 std::condition_variable m_condition;
102 std::mutex m_cond_lock;
103
104
107
109
112
114
118 void on();
119
123 void handle();
124
129 template<typename TR = UI> typename TR::default_post_ret_type post ( t_str const & m,
130 t_str const & l );
131 template<typename TR = UI> typename TR::post_ret_type post ( t_str const & m,
132 t_str const & l );
133
138 void file ( t_str const & );
139
147 bool levelcheck ( t_str const & level ) const;
148
153 void reopen ( t_str const & );
154
155 ~msghandler();
156 msghandler();
157 msghandler ( msghandler const & ) = delete;
158 msghandler & operator= ( msghandler const & ) = delete;
159};
160
161}
162/* namespace program */
163} /* namespace lutils */
164
165#include "detail/msghandler.hxx"
166
167#endif /* LUTILS_MSGHANDLER_H_ */
bool levelcheck(t_str const &level) const
void message(t_str const &messagein)
std::vector< t_str > t_levels
TR::default_post_ret_type post(t_str const &m, t_str const &l)
msghandler & operator=(msghandler const &)=delete
std::lock_guard< t_mut > t_lock
static msghandler & ref()
msghandler(msghandler const &)=delete
std::unique_ptr< t_file > t_file_ptr
std::queue< E > t_container
std::condition_variable m_condition
void reopen(t_str const &)
void file(t_str const &)
void set(t_str const &logfile)
std::shared_ptr< t_str > t_str_ptr
void setlevel(t_str const &level, t_levels levels)
t_container< std::pair< t_str, t_str > > t_messages