11 #include "StMessageCounter.h"
12 #include "StMessageStream.h"
18 StMessageCounter::StMessageCounter() : std::ostringstream(),
19 limitMessage(
" - COUNT LIMIT REACHED!\n") {
20 messTypeList = StMessTypeList::Instance();
25 StMessageCounter::~StMessageCounter() {
35 void StMessageCounter::SetLimit(
const char* str,
int n) {
37 if (!yesLimits && (n >= 0)) yesLimits = 1;
38 const size_t len = strlen(str);
41 int typeN = messTypeList->FindTypeNum(str);
43 if (limitTList[typeN] != -5)
44 limitTList[typeN] = n;
46 if (limitWList.size()) {
48 for (curString=limitWList.begin(); curString!=limitWList.end();
50 if (*str == *(*curString)) {
51 if (limitWNList[index] != -5)
52 limitWNList[index] = n;
58 temp =
new char[len+1];
60 limitWList.push_back(strncpy(temp,str,len));
61 limitWNList.push_back(n);
65 for (curString=limitList.begin(); curString!=limitList.end();
67 if (!strcmp(str,(*curString))) {
68 if (limitNList[index] == -5)
return;
69 if ((n < 0) && (n != -5)) {
70 limitList.erase(curString);
71 limitNList.erase(limitNList.begin()+index);
72 limitNCountList.erase(limitNCountList.begin()+index);
74 limitNList[index] = n;
80 if ((n < 0) && (n != -5))
return;
81 temp =
new char[len+1];
83 limitList.push_back(strncpy(temp,str,len));
84 limitNList.push_back(n);
85 limitNCountList.push_back(0);
90 int StMessageCounter::GetLimit(
const char* str) {
91 const size_t len = strlen(str);
93 int typeN = messTypeList->FindTypeNum(str);
95 return limitTList[typeN];
97 if (limitWList.size()) {
99 for (curString=limitWList.begin(); curString!=limitWList.end();
101 if (*str == *(*curString))
return limitWNList[index];
108 for (curString=limitList.begin(); curString!=limitList.end();
110 if (!strcmp(str,(*curString)))
return limitNList[index];
117 void StMessageCounter::ListLimits() {
119 myout <<
"StMessage Limits: negative limit means no limit, ";
120 myout <<
"-5 means fixed with no limit\n";
121 myout <<
" Limits : counts : on message types" << endl;
123 for (index = 1; index < limitTList.size(); index++) {
125 myout << limitTList[index] <<
" : ";
127 myout << limitTCountList[index] <<
" : ";
128 myout << messTypeList->FindNumType(index) <<
" - ";
129 myout << messTypeList->FindNumText(index) << endl;
131 for (index = 0; index < limitWList.size(); index++) {
133 myout << limitWNList[index] <<
" : ";
136 myout << limitWList[index] <<
" - ";
137 myout <<
"???" << endl;
139 myout <<
" Limits : counts : on message strings" << endl;
141 for (curString=limitList.begin(); curString!=limitList.end();
144 myout << limitNList[index] <<
" : ";
146 myout << limitNCountList[index++] <<
" : ";
147 myout << (*curString) << endl;
150 myout <<
"No limits have been set on messages." << endl;
155 int StMessageCounter::CheckLimit(
char* mess,
const char* type) {
156 static const char* leader=
"St";
157 static const char* colon =
": ";
158 static const char* stmess=
"StMessage: ";
160 int typeN = messTypeList->FindTypeNum(type);
161 int typeNewSize = limitTCountList[typeN] + 1;
162 limitTCountList[typeN] = typeNewSize;
164 if (yesLimits && (! noLimits)) {
166 int limit = limitTList[typeN];
167 if (typeNewSize == limit) {
169 *
this << (messTypeList->FindType(type)->Text());
170 *
this << colon << limitMessage;
171 }
else if ((limit >= 0) && (typeNewSize > limit)) {
176 for (curString=limitList.begin(); curString!=limitList.end();
178 if (strstr(mess,(*curString))) {
179 int counts = limitNCountList[index] + 1;
180 limitNCountList[index] = counts;
181 limit = limitNList[index];
183 *
this << stmess << (*curString) << limitMessage;
184 }
else if ((limit >= 0) && (counts > limit)) {
194 void StMessageCounter::AddType(
const char* type) {
195 limitTList.push_back(-1);
196 limitTCountList.push_back(0);
197 if (limitWList.size()) {
199 for (curString=limitWList.begin(); curString!=limitWList.end();
201 if (*type == *(*curString)) {
202 SetLimit((*curString),limitWNList[index]);
203 limitWList.erase(curString);
204 limitWNList.erase(limitWNList.begin()+index);