~ubuntu-branches/ubuntu/wily/flrig/wily

« back to all changes in this revision

Viewing changes to .pc/0001-License-Declaration.patch/src/include/debug.h

  • Committer: Package Import Robot
  • Author(s): Kamal Mostafa
  • Date: 2014-10-25 11:17:10 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20141025111710-n32skgya3l9u1brw
Tags: 1.3.17-1
* New upstream release (Closes: #761839)
* Debian Standards-Version: 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ----------------------------------------------------------------------------
2
 
//        debug.h
3
 
//
4
 
// Copyright (C) 2008
5
 
//                        Stelios Bounanos, M0GLD
6
 
//
7
 
// This file is part of fldigi.
8
 
//
9
 
// fldigi is free software; you can redistribute it and/or modify
10
 
// it under the terms of the GNU General Public License as published by
11
 
// the Free Software Foundation; either version 3 of the License, or
12
 
// (at your option) any later version.
13
 
//
14
 
// fldigi is distributed in the hope that it will be useful,
15
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
// GNU General Public License for more details.
18
 
//
19
 
// You should have received a copy of the GNU General Public License
20
 
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 
// ----------------------------------------------------------------------------
22
 
 
23
 
#ifndef _DEBUG_H_
24
 
#define _DEBUG_H_
25
 
 
26
 
#include "util.h"
27
 
 
28
 
class debug
29
 
{
30
 
public:
31
 
        enum level_e { QUIET_LEVEL, ERROR_LEVEL, WARN_LEVEL, INFO_LEVEL, DEBUG_LEVEL, LOG_NLEVELS };
32
 
        enum source_e {
33
 
                LOG_RIGCONTROL = 1 << 0, LOG_RPC = 1 << 1, LOG_OTHER = 1 << 2
34
 
        };
35
 
        static void start(const char* filename);
36
 
        static void stop(void);
37
 
        static void log(level_e level, const char* func, const char* srcf, int line,
38
 
                        const char* format, ...) format__(printf, 5, 6);
39
 
        static void slog(level_e level, const char* func, const char* srcf, int line,
40
 
                        const char* format, ...) format__(printf, 5, 6);
41
 
 
42
 
        static void elog(const char* func, const char* srcf, int line, const char* text);
43
 
        static void show(void);
44
 
        static level_e level;
45
 
        static uint32_t mask;
46
 
private:
47
 
        static void sync_text(void*);
48
 
        debug(const char* filename);
49
 
        debug(const debug&);
50
 
        debug& operator=(const debug&);
51
 
        ~debug();
52
 
        static debug* inst;
53
 
};
54
 
 
55
 
#define LOG(level__, source__, ...)                                                     \
56
 
        do {                                                                            \
57
 
                if (level__ <= debug::level && source__ & debug::mask)                  \
58
 
                        debug::log(level__, __func__, __FILE__, __LINE__, __VA_ARGS__); \
59
 
        } while (0)
60
 
 
61
 
#define LOG_DEBUG(...) LOG(debug::DEBUG_LEVEL, log_source_, __VA_ARGS__)
62
 
#define LOG_INFO(...) LOG(debug::INFO_LEVEL, log_source_, __VA_ARGS__)
63
 
#define LOG_WARN(...) LOG(debug::WARN_LEVEL, log_source_, __VA_ARGS__)
64
 
#define LOG_ERROR(...) LOG(debug::ERROR_LEVEL, log_source_, __VA_ARGS__)
65
 
#define LOG_QUIET(...) LOG(debug::QUIET_LEVEL, log_source_, __VA_ARGS__)
66
 
 
67
 
#define SLOG(level__, source__, ...)                                                    \
68
 
        do {                                                                            \
69
 
                if (level__ <= debug::level && source__ & debug::mask)                  \
70
 
                        debug::slog(level__, __func__, __FILE__, __LINE__, __VA_ARGS__); \
71
 
        } while (0)
72
 
 
73
 
#define SLOG_DEBUG(...) SLOG(debug::DEBUG_LEVEL, log_source_, __VA_ARGS__)
74
 
#define SLOG_INFO(...) SLOG(debug::INFO_LEVEL, log_source_, __VA_ARGS__)
75
 
#define SLOG_WARN(...) SLOG(debug::WARN_LEVEL, log_source_, __VA_ARGS__)
76
 
#define SLOG_ERROR(...) SLOG(debug::ERROR_LEVEL, log_source_, __VA_ARGS__)
77
 
#define SLOG_QUIET(...) SLOG(debug::QUIET_LEVEL, log_source_, __VA_ARGS__)
78
 
 
79
 
#define LOG_PERROR(msg__)                                                               \
80
 
        do {                                                                            \
81
 
                if (debug::ERROR_LEVEL <= debug::level && log_source_ & debug::mask)    \
82
 
                        debug::elog(__func__, __FILE__, __LINE__, msg__);               \
83
 
        } while (0)
84
 
 
85
 
unused__ static uint32_t log_source_ = debug::LOG_OTHER;
86
 
#if defined(__GNUC__) && (__GNUC__ >= 3)
87
 
#  define LOG_FILE_SOURCE(source__)                                             \
88
 
        __attribute__((constructor))                                            \
89
 
        static void log_set_source_(void) { log_source_ = source__; }
90
 
#else
91
 
#  define LOG_FILE_SOURCE(source__)
92
 
#endif
93
 
 
94
 
#define LOG_SET_SOURCE(source__) log_source_ = source__
95
 
 
96
 
#endif // _DEBUG_H_
97
 
 
98
 
// Local Variables:
99
 
// mode: c++
100
 
// c-file-style: "linux"
101
 
// End: