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