Sync with 5.4.0
[deliverable/titan.core.git] / core / LoggingBits.cc
CommitLineData
970ed795 1///////////////////////////////////////////////////////////////////////////////
3abe9331 2// Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
3// All rights reserved. This program and the accompanying materials
4// are made available under the terms of the Eclipse Public License v1.0
5// which accompanies this distribution, and is available at
6// http://www.eclipse.org/legal/epl-v10.html
7///////////////////////////////////////////////////////////////////////////////
8#include "LoggingBits.hh"
9#include <stdio.h>
10#include <string.h>
11#include <assert.h>
12
13
14void Logging_Bits::clear()
15{
16 memset( bits, 0, sizeof(bits) );
17}
18
19
20void Logging_Bits::merge( const Logging_Bits & other )
21{
22 for( size_t i = 0; i < TTCN_Logger::NUMBER_OF_LOGSEVERITIES; ++i )
23 {
24 bits[i] = bits[i] || other.bits[i];
25 }
26}
27
28void Logging_Bits::add_sev( TTCN_Logger::Severity sev )
29{
30 assert(sev >= 0);
31 assert(sev < TTCN_Logger::NUMBER_OF_LOGSEVERITIES);
32 // Note that the assert and the comparison below are different.
33 // 0==LOG_NOTHING which is valid but it means nothing to do.
34 if (sev > 0 && sev < TTCN_Logger::NUMBER_OF_LOGSEVERITIES) {
35 bits[sev] = true;
36 }
37}
38
39
40bool Logging_Bits::operator==( const Logging_Bits& other ) const
41{
42 return memcmp( bits, other.bits, sizeof(bits) ) == 0;
43}
44
45
46
47expstring_t Logging_Bits::describe() const
48{
49 expstring_t result = memptystr(); // not NULL
50 size_t categ = 1; // skip LOG_NOTHING
51
52 // First check whether the bits that make up LOG_ALL are all set
53 // (by comparing with log_all, which has those bits set).
54 // Remember to skip +1 for LOG_NOTHING
55 if( memcmp(bits+1, log_all.bits+1, TTCN_Logger::WARNING_UNQUALIFIED) == 0 )
56 {
57 result = mputstr(result, "LOG_ALL");
58 categ = TTCN_Logger::number_of_categories - 2; // only MATCHING and DEBUG left
59 }
60
61 for( ; categ < TTCN_Logger::number_of_categories; ++categ ) {
62 // sev_categories[categ-1] is the non-inclusive lower end
63 // sev_categories[categ ] is the inclusive upper end
64 // these two form a half-closed range (the opposite of what the STL uses)
65
66 size_t low_inc = TTCN_Logger::sev_categories[categ-1] + 1;
67 size_t high_inc= TTCN_Logger::sev_categories[categ];
68
69 const bool * first = bits + low_inc;
70 size_t length= high_inc - low_inc + 1;
71 assert(length < TTCN_Logger::NUMBER_OF_LOGSEVERITIES-1);
72 // Comparing a segment of our bits with the "all 1s" of log_everything
73 if( memcmp(first, log_everything.bits+1, length) == 0 ) {
74 // all bits for this main severity are on
75 if( result[0] != '\0' ) {
76 // string not empty, append separator
77 result = mputstr(result, " | ");
78 }
79 // append main severity name
80 result = mputstr(result, TTCN_Logger::severity_category_names[categ]);
81 }
82 else {
83 // not all bits are on, have to append them one by one
84 for( size_t subcat = low_inc; subcat <= high_inc; ++subcat ) {
85 if( bits[subcat] ) {
86 if( result[0] != '\0' ) {
87 // string not empty, append separator
88 result = mputstr(result, " | ");
89 }
90 result = mputstr(result, TTCN_Logger::severity_category_names[categ]);
91 result = mputc (result, '_');
92 result = mputstr(result, TTCN_Logger::severity_subcategory_names[subcat]);
93 }
94 } // next subcat
95 }
96 } // next categ
97
98 if( result[0] == '\0' ) {
99 result = mputstr(result, "LOG_NOTHING");
100 }
101 return result;
102}
103
104/********************** "Well-known" values **********************/
105
106const Logging_Bits Logging_Bits::log_nothing = { {0} };
107
108const Logging_Bits Logging_Bits::log_all = {
109 { 0, // NOTHING
110 1, // ACTION
111 1,1,1,1, // DEFAULTOP
112 1, // ERROR
113 1,1,1,1,1,1, // EXECUTOR
114 1,1, // FUNCTION
115 1,1,1,1, // PARALLEL
116 1,1,1, // TESTCASE
117 1,1,1,1,1,1,1,1,1,1,1,1,1,1, // PORTEVENT
118 1,1, // STATISTICS
119 1,1,1,1,1,1, // TIMEROP
120 1, // USER
121 1,1,1,1, // VERDICTOP
122 1, // WARNING
123 0,0,0,0,0,0,0,0,0,0,0,0, // MATCHING
124 0,0,0 // DEBUG
125 }
126};
127
128const Logging_Bits Logging_Bits::log_everything = {
129 { 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
130 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }
131};
132
133// TTCN_ERROR | TTCN_WARNING | TTCN_ACTION | TTCN_TESTCASE | TTCN_STATISTICS
134const Logging_Bits Logging_Bits::default_console_mask = {
135 { 0, // NOTHING
136 1, // ACTION
137 0,0,0,0, // DEFAULTOP
138 1, // ERROR
139 0,0,0,0,0,0, // EXECUTOR
140 0,0, // FUNCTION
141 0,0,0,0, // PARALLEL
142 1,1,1, // TESTCASE
143 0,0,0,0,0,0,0,0,0,0,0,0,0,0, // PORTEVENT
144 1,1, // STATISTICS
145 0,0,0,0,0,0, // TIMEROP
146 0, // USER
147 0,0,0,0, // VERDICTOP
148 1, // WARNING
149 0,0,0,0,0,0,0,0,0,0,0,0, // MATCHING
150 0,0,0 // DEBUG
151 }
152};
This page took 0.050163 seconds and 5 git commands to generate.