Newer
Older

Graziano Scalamera
committed
/*
* for each event into the per-alarm event list find
* the event table entry and remove this alarm from
* per-event alarm list
*/
vector<event>::iterator k = \
find(events->v_event.begin(), events->v_event.end(), *j);
if (k != events->v_event.end()) {
DEBUG_STREAM << "AlarmHandler::"<<__func__<<": found event =" << *j << " in vector events, removing from its alarm list name=" << i->second.name << endl;

Graziano Scalamera
committed
/*
* remove alarm
*/
k->pop_alarm(i->second.name);
DEBUG_STREAM << "AlarmHandler::"<<__func__<<": after pop_alarm" << endl;

Graziano Scalamera
committed
if (k->m_alarm.empty()) {
/*
* no more alarms associated to this event, unsubscribe
* and remove from event table
*/
DEBUG_STREAM << "AlarmHandler::remove_alarm(): removing event '" \

Graziano Scalamera
committed
<< k->name << "' from event table" << endl;
try {
events->stop(k->name);
events->remove(k->name, false);

Graziano Scalamera
committed
} catch (...) {
ostringstream o;
o << "unsubscribe_event() failed for " \
<< k->name << ends;
WARN_STREAM << "AlarmHandler::remove_alarm(): " << o.str() << endl;

Graziano Scalamera
committed
alarms.vlock->writerOut();
throw o.str();
//return false;
}

Graziano Scalamera
committed
}
} else {
/*
* shouldn't happen!!!
*/
ostringstream o;
o << "event '" << *j \
<< "' not found in event table" << ends;
WARN_STREAM << "AlarmHandler::remove_alarm(): " << o.str() << endl;

Graziano Scalamera
committed
alarms.vlock->writerOut();
throw o.str();
//return false;
}
} /* for */

Graziano Scalamera
committed
//delete proxy for actions
if(i->second.dp_a)
delete i->second.dp_a;
i->second.dp_a = NULL;
if(i->second.dp_n)
delete i->second.dp_n;
i->second.dp_n = NULL;
try
{
remove_AlarmState_dynamic_attribute(i->second.attr_name);
}
catch(Tango::DevFailed &e)
{
ostringstream o;
o << "AlarmHandler::" << __func__<<": attname '" << i->second.attr_name << "' exception removing attribute err="<<e.errors[0].desc ;
INFO_STREAM << o.str() << endl;
}
#if _FORMULA_ATTR
CORBA::string_free(*(i->second.attr_value_formula));
try
{
remove_AlarmFormula_dynamic_attribute(i->second.attr_name_formula);
}
catch(Tango::DevFailed &e)
{
ostringstream o;
o << "AlarmHandler::" << __func__<<": attname '" << i->second.attr_name_formula << "' exception removing attribute err="<<e.errors[0].desc ;
INFO_STREAM << o.str() << endl;
}

Graziano Scalamera
committed
/*
* remove this alarm from alarm table
*/
alarms.erase(i);

Graziano Scalamera
committed
alarms.vlock->writerOut();
return true;
}
WARN_STREAM << "AlarmHandler::"<<__func__<<": NOT found in table alm name=" << s << endl;

Graziano Scalamera
committed
alarms.vlock->writerOut();
ostringstream o;
o << "alarm '" \
<< s << "' not found in alarm table" << ends;
WARN_STREAM << "AlarmHandler::remove_alarm(): " << o.str() << endl;

Graziano Scalamera
committed
throw o.str();
//return false;
} /* remove_alarm() */
/*void AlarmHandler::add_to_database(alarm_t& a) throw(string&)

Graziano Scalamera
committed
{
Tango::DbDatum alarm("alarm");
Tango::DbData db_data;
alarm << (short)1;
db_data.push_back(alarm);
string tmpname;
tmpname = a.name;
while (true) {
string::size_type j = tmpname.find_first_of("/.");
if (j == string::npos)
break;
tmpname.replace(j, 1, "_");
}
Tango::DbDatum property(tmpname);
ostringstream num;
num.clear();
num << a.grp << ends;
// sprintf(buf, "%02X-", buf2[j]);//change here the format of saved data
// string pro = a.name+"\t"+"$"+a.formula+"$"+"\t"+"\""+a.msg+"\""+"\t"+num.str();
//DEBUG_STREAM << "AlarmHandler::add_to_database(): a.name=" << a.name << " a.formula=" << a.formula << " a.lev=" << a.lev << " a.grp=" << a.grp2str() << " a.msg=" << a.msg << endl;

Graziano Scalamera
committed
string pro = a.name+"\t"+a.formula+"\t"+string(a.time_threshold)+"\t"+ a.lev+"\t"+a.grp2str()+"\t"+"\""+a.msg+"\""+"\t"+a.cmd_name+"\t"; //grp has been transformed to string
DEBUG_STREAM << "AlarmHandler::add_to_database(): adding to database property=" << pro << endl;

Graziano Scalamera
committed
property << pro;
db_data.push_back(property);
try {
get_db_device()->put_attribute_property(db_data);
} catch (...) {
ostringstream o;
o << "AlarmHandler::add_to_database(): put_device_attribute_property()" \

Graziano Scalamera
committed
<< " failed" << ends;
ERROR_STREAM << o.str() << endl;
throw o.str();
}
}*/
void AlarmHandler::set_internal_alarm(string name, Tango::TimeVal t, string msg, unsigned int count)

Graziano Scalamera
committed
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
{
alarm_t alm;
bool existing=false;
ostringstream o;
//o << (internal.size() + 1);
if(internal.size() == 0)
internal_counter = 0;
o << internal_counter;
internallock->writerIn();
vector<alarm_t>::iterator it;
for(it = internal.begin(); it != internal.end(); it++)
{
if(name == INTERNAL_ERROR)
{
if(it->msg == msg)
{
existing=true;
break;
}
}
else //for tango error log only one internal error per event
{
if(it->msg.find(name) != string::npos)
{
existing=true;
if(it->on_counter < count)
it->on_counter = count;

Graziano Scalamera
committed
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
break;
}
}
}
if(existing)
{
/*size_t index;
int count;
index = it->stat.find("*");
ostringstream temp;
if((index != std::string::npos) && (index+1 != std::string::npos))
{
size_t last = it->stat.size();
string str_count= it->stat.substr(index+1, last - index+1);
count = strtol(str_count.c_str(), 0,10);
count++;
temp << it->stat.substr(0,index+1) << count;
it->stat = temp.str();
}
else
it->stat += "*2";*/
it->on_counter++;

Graziano Scalamera
committed
it->msg = msg; //update with the last message
}
else
{
alm.name = string(INTERNAL_ERROR) + "_" + o.str();
internal_counter++;
alm.ts = t;
/*ostringstream stat;
if(count==0)
stat << S_ALARM;
else
stat << S_ALARM << "*" << count;*/
alm.on_counter = count;

Graziano Scalamera
committed
//alm.stat = stat.str();
alm.stat = S_ALARM;
alm.ack = NOT_ACK;
alm.done = false;
alm.msg = msg;
//alm.grp = GR_DEFAULT;
if(!alm.grp_str.empty())
alm.grp = (alm.grp_str.begin())->second; //set groupe 'none' to internal alarms
else
alm.grp = GR_DEFAULT;
//alm.lev = LEV_DEFAULT;
alm.lev = LEV_LOG;
internal.push_back(alm);
}
internallock->writerOut();
}
//==============================================================
//------------------- AST evaluation methods -------------------
//==============================================================
formula_res_t AlarmHandler::eval_formula(tree_parse_info_t tree, string &attr_values)

Graziano Scalamera
committed
{
return eval_expression(tree.trees.begin(), attr_values);
}
formula_res_t AlarmHandler::eval_expression(iter_t const& i, string &attr_values, int ev_ind) //throw (string &), std::out_of_range

Graziano Scalamera
committed
{
ostringstream err;
err << "Evaluating formula: ";
//iter_t it = i->children.begin();
if (i->value.id() == formula_grammar::val_rID)
{
if(i->children.size() != 0)
{
err << "in node val_rID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
string val_d(i->value.begin(), i->value.end());
formula_res_t res;
res.value = strtod(val_d.c_str(), 0);
DEBUG_STREAM << " node value real = " << val_d << "(value="<<res.value<<" quality="<<res.quality<<")" << endl;
return res;

Graziano Scalamera
committed
}
else if (i->value.id() == formula_grammar::val_hID)
{
if(i->children.size() != 0)
{
err << "in node val_hID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
string val_d(i->value.begin(), i->value.end());
DEBUG_STREAM << " node value hex = " << val_d << endl;
formula_res_t res;
res.value = strtod(val_d.c_str(), 0);
return res;

Graziano Scalamera
committed
}
else if (i->value.id() == formula_grammar::val_stID)
{
if(i->children.size() != 0)
{
err << "in node val_stID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
string val_st(i->value.begin(), i->value.end());
double st = i->value.value(); //get value directly from node saved with access_node_d
DEBUG_STREAM << " node value state : " << val_st << "=" << st << endl;
formula_res_t res;
res.value = st;
return res;
}
else if (i->value.id() == formula_grammar::val_alarm_enum_stID)
{
if(i->children.size() != 0)
{
err << "in node val_alarm_enum_stID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
string val_st(i->value.begin(), i->value.end());
double st = i->value.value(); //get value directly from node saved with access_node_d
DEBUG_STREAM << " node value alarm enum state : " << val_st << "=" << st << endl;
formula_res_t res;
res.value = st;
return res;
}
else if (i->value.id() == formula_grammar::val_qualityID)
{
if(i->children.size() != 0)
{
err << "in node val_qualityID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
string val_quality(i->value.begin(), i->value.end());
double quality = i->value.value(); //get value directly from node saved with access_node_d
DEBUG_STREAM << " node value quality : " << val_quality << "=" << quality << endl;
formula_res_t res;
res.value = quality;
return res;
}

Graziano Scalamera
committed
else if (i->value.id() == formula_grammar::unary_exprID)
{
DEBUG_STREAM << " node unary expression: " << string(i->value.begin(), i->value.end()) << endl;
if(i->children.size() != 1)
{
err << "in node unary_exprID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
formula_res_t res;
res = eval_expression(i->children.begin(), attr_values);

Graziano Scalamera
committed
if (*i->value.begin() == '+')
res.value = + res.value;
}
else if (*i->value.begin() == '-')
{
res.value = - res.value;
}
else if (*i->value.begin() == '!')
{
res.value = ! res.value;
}
else
{
err << "in node unary_exprID(" << string(i->value.begin(), i->value.end()) << ") value not allowed" << ends;
throw err.str();
}
return res;

Graziano Scalamera
committed
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
}
else if (i->value.id() == formula_grammar::mult_exprID)
{
DEBUG_STREAM << " node mult expression: " << string(i->value.begin(), i->value.end()) << endl;
if(i->children.size() != 2)
{
err << "in node mult_exprID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
if (*i->value.begin() == '*')
{
return eval_expression(i->children.begin(), attr_values) *
eval_expression(i->children.begin()+1, attr_values);
}
else if (*i->value.begin() == '/')
{
return eval_expression(i->children.begin(), attr_values) /
eval_expression(i->children.begin()+1, attr_values);
}
else
{
err << "in node mult_exprID(" << string(i->value.begin(), i->value.end()) << ") value not allowed" << ends;
throw err.str();
}
}
else if (i->value.id() == formula_grammar::add_exprID)
{
DEBUG_STREAM << " node add expression: " << string(i->value.begin(), i->value.end()) << endl;
if(i->children.size() != 2)
{
err << "in node add_exprID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
if (*i->value.begin() == '+')
{
return eval_expression(i->children.begin(), attr_values) +
eval_expression(i->children.begin()+1, attr_values);
}
else if (*i->value.begin() == '-')
{
return eval_expression(i->children.begin(), attr_values) -
eval_expression(i->children.begin()+1, attr_values);
}
else
{
err << "in node add_exprID(" << string(i->value.begin(), i->value.end()) << ") value not allowed" << ends;
throw err.str();
}
}
else if (i->value.id() == formula_grammar::event_ID)
{
DEBUG_STREAM << " node event" << string(i->value.begin(), i->value.end()) << endl;
formula_res_t ind;

Graziano Scalamera
committed
if(i->children.size() != 2)
{
err << "in node event_ID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;;
throw err.str();

Graziano Scalamera
committed
if((i->children.begin()+1)->value.id() == formula_grammar::indexID)
ind = eval_expression(i->children.begin()+1, attr_values); //array index
else if((i->children.begin()+1)->value.id() == formula_grammar::propertyID)
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
if(string((i->children.begin()+1)->value.begin(), (i->children.begin()+1)->value.end()) == ".quality")
{
formula_res_t res = eval_expression(i->children.begin(), attr_values, (int)ind.value);
res.value = res.quality;
DEBUG_STREAM << " node event.quality -> " << res.value << endl;
return res;
}
else if(string((i->children.begin()+1)->value.begin(), (i->children.begin()+1)->value.end()) == ".alarm")
{
formula_res_t res = eval_expression(i->children.begin(), attr_values, (int)ind.value);
res.value = (res.value == _UNACK) || (res.value == _ACKED);
DEBUG_STREAM << " node event.alarm -> " << res.value << endl;
return res;
}
else if(string((i->children.begin()+1)->value.begin(), (i->children.begin()+1)->value.end()) == ".normal")
{
formula_res_t res = eval_expression(i->children.begin(), attr_values, (int)ind.value);
res.value = (res.value == _NORM) || (res.value == _RTNUN);
DEBUG_STREAM << " node event.normal -> " << res.value << endl;
return res;
}

Graziano Scalamera
committed
else
{
err << "in node event_ID(" << string(i->value.begin(), i->value.end()) << ") children2 is not an index ->" << string((i->children.begin()+1)->value.begin(), (i->children.begin()+1)->value.end()) << ends;;
throw err.str();
}
return eval_expression(i->children.begin(), attr_values, (int)ind.value);

Graziano Scalamera
committed
}
else if (i->value.id() == formula_grammar::nameID)
{
if(i->children.size() != 0)
{
err << "in node nameID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
vector<event>::iterator it = events->v_event.begin();
string s(i->value.begin(), i->value.end());
std::transform(s.begin(), s.end(), s.begin(), (int(*)(int))tolower); //transform to lowercase
while ((it != events->v_event.end()) && (it->name != s))
it++;
if (it != events->v_event.end())
{
if(!it->valid)
{
if(it->ex_desc.length() > 0)
err << "attribute '" << string(i->value.begin(), i->value.end()) << "' exception: '" << it->ex_desc << "'";
else
err << "attribute '" << string(i->value.begin(), i->value.end()) << "' value not valid!";

Graziano Scalamera
committed
throw err.str();
}
else if(it->type != Tango::DEV_STRING && it->value.empty())

Graziano Scalamera
committed
{
if(it->ex_desc.length() > 0)
err << "attribute '" << string(i->value.begin(), i->value.end()) << "' exception: '" << it->ex_desc << "'";
else
err << "attribute '" << string(i->value.begin(), i->value.end()) << "' value not initialized!!";

Graziano Scalamera
committed
throw err.str();
}
ostringstream temp_attr_val;
temp_attr_val << it->name << "[" << ev_ind << "]=" <<it->value.at(ev_ind) << ";";
attr_values += temp_attr_val.str();
formula_res_t res;
res.quality = it->quality;
res.ex_reason = it->ex_reason;
res.ex_desc = it->ex_desc;
res.ex_origin = it->ex_origin;
DEBUG_STREAM << " node name -> " << temp_attr_val.str() << " quality=" << res.quality << endl;
res.value = it->value.at(ev_ind); //throw std::out_of_range
return res;

Graziano Scalamera
committed
}
else
{
err << "in event: (" << string(i->value.begin(), i->value.end()) << ") not found in event table" << ends;
throw err.str();
}
}
else if (i->value.id() == formula_grammar::indexID)
{
if(i->children.size() != 0)
{
err << "in node indexID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
string val_d(i->value.begin(), i->value.end());
DEBUG_STREAM << " node index = " << val_d << endl;
formula_res_t res;
res.value = strtod(val_d.c_str(), 0);
return res;

Graziano Scalamera
committed
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
}
else if (i->value.id() == formula_grammar::logical_exprID)
{
DEBUG_STREAM << " node logical expression: " << string(i->value.begin(), i->value.end()) << endl;
if(i->children.size() != 2)
{
err << "in node logical_exprID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
if (string(i->value.begin(), i->value.end()) == string("&&"))
{
return eval_expression(i->children.begin(), attr_values) &&
eval_expression(i->children.begin()+1, attr_values);
}
else if (string(i->value.begin(), i->value.end()) == string("||"))
{
return eval_expression(i->children.begin(), attr_values) ||
eval_expression(i->children.begin()+1, attr_values);
}
else
{
err << "in node logical_exprID(" << string(i->value.begin(), i->value.end()) << ") value not allowed" << ends;
throw err.str();
}
}
else if (i->value.id() == formula_grammar::bitwise_exprID)
{
DEBUG_STREAM << " node bitwise expression: " << string(i->value.begin(), i->value.end()) << endl;
if(i->children.size() != 2)
{
err << "in node bitwise_exprID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
formula_res_t res_1=eval_expression(i->children.begin(), attr_values),
res_2=eval_expression(i->children.begin()+1, attr_values);

Graziano Scalamera
committed
long val_l1,val_l2;
string err2("ERROR: non-int value in bitwise operation!");
val_l1 = (long)trunc(res_1.value); //transform to long
val_l2 = (long)trunc(res_2.value); //transform to long

Graziano Scalamera
committed
if((val_l1 != res_1.value) || (val_l2 != res_2.value)) //if different, lost something with truncf

Graziano Scalamera
committed
throw err2;
if (*i->value.begin() == '&')
{
formula_res_t res;
res.value = (double)(val_l1 & val_l2);
res.quality = res.combine_quality(res_1.quality, res_2.quality);
res.ex_reason = res.combine_exception(res_1.ex_reason, res_2.ex_reason);
res.ex_desc = res.combine_exception(res_1.ex_desc, res_2.ex_desc);
res.ex_origin = res.combine_exception(res_1.ex_origin, res_2.ex_origin);
return res;

Graziano Scalamera
committed
}
else if (*i->value.begin() == '|')
{
formula_res_t res;
res.value = (double)(val_l1 | val_l2);
res.quality = res.combine_quality(res_1.quality, res_2.quality);
res.ex_reason = res.combine_exception(res_1.ex_reason, res_2.ex_reason);
res.ex_desc = res.combine_exception(res_1.ex_desc, res_2.ex_desc);
res.ex_origin = res.combine_exception(res_1.ex_origin, res_2.ex_origin);
return res;

Graziano Scalamera
committed
}
else if (*i->value.begin() == '^')
{
formula_res_t res;
res.value = (double)(val_l1 ^ val_l2);
res.quality = res.combine_quality(res_1.quality, res_2.quality);
res.ex_reason = res.combine_exception(res_1.ex_reason, res_2.ex_reason);
res.ex_desc = res.combine_exception(res_1.ex_desc, res_2.ex_desc);
res.ex_origin = res.combine_exception(res_1.ex_origin, res_2.ex_origin);
return res;

Graziano Scalamera
committed
}
else
{
err << "in node bitwise_exprID(" << string(i->value.begin(), i->value.end()) << ") value not allowed" << ends;
throw err.str();
}
}
else if (i->value.id() == formula_grammar::shift_exprID)
{
DEBUG_STREAM << " node shift expression: " << string(i->value.begin(), i->value.end()) << endl;
if(i->children.size() != 2)
{
err << "in node shift_exprID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
formula_res_t res_1=eval_expression(i->children.begin(), attr_values),
res_2=eval_expression(i->children.begin()+1, attr_values);

Graziano Scalamera
committed
long val_l1,val_l2;
string err2("ERROR: non-int value in bitwise operation!");
val_l1 = (long)trunc(res_1.value); //transform to long
val_l2 = (long)trunc(res_2.value); //transform to long

Graziano Scalamera
committed
if((val_l1 != res_1.value) || (val_l2 != res_2.value)) //if different, lost something with truncf

Graziano Scalamera
committed
throw err2;
if (string(i->value.begin(), i->value.end()) == string("<<"))
{
formula_res_t res;
res.value = (double)(val_l1 << val_l2);
res.quality = res.combine_quality(res_1.quality, res_2.quality);
res.ex_reason = res.combine_exception(res_1.ex_reason, res_2.ex_reason);
res.ex_desc = res.combine_exception(res_1.ex_desc, res_2.ex_desc);
res.ex_origin = res.combine_exception(res_1.ex_origin, res_2.ex_origin);
return res;

Graziano Scalamera
committed
}
else if (string(i->value.begin(), i->value.end()) == string(">>"))
{
formula_res_t res;
res.value = (double)(val_l1 >> val_l2);
res.quality = res.combine_quality(res_1.quality, res_2.quality);
res.ex_reason = res.combine_exception(res_1.ex_reason, res_2.ex_reason);
res.ex_desc = res.combine_exception(res_1.ex_desc, res_2.ex_desc);
res.ex_origin = res.combine_exception(res_1.ex_origin, res_2.ex_origin);
return res;

Graziano Scalamera
committed
}
else
{
err << "in node shift_exprID(" << string(i->value.begin(), i->value.end()) << ") value not allowed" << ends;
throw err.str();
}
}
else if (i->value.id() == formula_grammar::equality_exprID)
{
DEBUG_STREAM << " node equality expression: " << string(i->value.begin(), i->value.end()) << endl;
if(i->children.size() != 2)
{
err << "in node equality_exprID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
//string comparison here
iter_t const& i2_1 = i->children.begin();
iter_t const& i2_2 = i->children.begin()+1;
//OK only attr == 'string' or attr != 'string'
if(i2_1->value.id() == formula_grammar::nameID && i2_2->value.id() == formula_grammar::val_stringID)
{
if(i2_1->children.size() == 0 && i2_2->children.size() == 0)
{
//retrieve string from attribute:
string attr_val = "";
string name_id(i2_1->value.begin(), i2_1->value.end());
std::transform(name_id.begin(), name_id.end(), name_id.begin(), (int(*)(int))tolower); //transform to lowercase
formula_res_t res;
vector<event>::iterator it = events->v_event.begin();
while ((it != events->v_event.end()) && (it->name != name_id))
it++;
if (it != events->v_event.end())
{
if(!it->valid)
{
err << "in node equality_exprID -> nameID(" << string(i2_1->value.begin(), i2_1->value.end()) << ") value not valid!";
if(it->ex_desc.length() > 0)
err << " EX: '" << it->ex_desc << "'";
throw err.str();
}
else if(it->type != Tango::DEV_STRING && it->value.empty())
{
err << "in node nameID(" << string(i2_1->value.begin(), i2_1->value.end()) << ") value not initialized!!";
if(it->ex_desc.length() > 0)
err << " EX: '" << it->ex_desc << "'";
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
throw err.str();
}
ostringstream temp_attr_val;
temp_attr_val << it->name << "=" <<it->value_string << ";";
attr_values += temp_attr_val.str();
res.quality = it->quality;
res.ex_reason = it->ex_reason;
res.ex_desc = it->ex_desc;
res.ex_origin = it->ex_origin;
DEBUG_STREAM << " node name -> " << temp_attr_val.str() << " quality=" << res.quality << endl;
attr_val = string("'") + it->value_string + string("'");
}
else
{
err << "in event: (" << string(i->value.begin(), i->value.end()) << ") not found in event table" << ends;
throw err.str();
}
//retrieve string from formula
string val_string(i2_2->value.begin(), i2_2->value.end());
if (string(i->value.begin(), i->value.end()) == string("!="))
{
res.value = attr_val != val_string;
return res;
}
else if (string(i->value.begin(), i->value.end()) == string("=="))
{
res.value = attr_val == val_string;
return res;
}
else
{
err << "in node equality_exprID(" << string(i->value.begin(), i->value.end()) << ") value not allowed (val_stringID)" << ends;
throw err.str();
}
}
}
else
{
if (string(i->value.begin(), i->value.end()) == string("!="))
{
return eval_expression(i->children.begin(), attr_values) !=
eval_expression(i->children.begin()+1, attr_values);
}
else if (string(i->value.begin(), i->value.end()) == string("=="))
{
return eval_expression(i->children.begin(), attr_values) ==
eval_expression(i->children.begin()+1, attr_values);
}
else
{
err << "in node equality_exprID(" << string(i->value.begin(), i->value.end()) << ") value not allowed" << ends;
throw err.str();
}
}

Graziano Scalamera
committed
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
}
else if (i->value.id() == formula_grammar::compare_exprID)
{
DEBUG_STREAM << " node compare expression: " << string(i->value.begin(), i->value.end()) << endl;
if(i->children.size() != 2)
{
err << "in node compare_exprID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
if (string(i->value.begin(), i->value.end()) == string("<="))
{
return eval_expression(i->children.begin(), attr_values) <=
eval_expression(i->children.begin()+1, attr_values);
}
else if (string(i->value.begin(), i->value.end()) == string(">="))
{
return eval_expression(i->children.begin(), attr_values) >=
eval_expression(i->children.begin()+1, attr_values);
}
else if (*i->value.begin() == '<')
{
return eval_expression(i->children.begin(), attr_values) <
eval_expression(i->children.begin()+1, attr_values);
}
else if (*i->value.begin() == '>')
{
return eval_expression(i->children.begin(), attr_values) >
eval_expression(i->children.begin()+1, attr_values);
}
else
{
err << "in node equality_exprID(" << string(i->value.begin(), i->value.end()) << ") value not allowed" << ends;
throw err.str();
}
}
else if (i->value.id() == formula_grammar::funcID)
{
DEBUG_STREAM << " node function: " << string(i->value.begin(), i->value.end()) << endl;
if(i->children.size() != 1)
{
err << "in node funcID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
formula_res_t res;
res = eval_expression(i->children.begin(), attr_values);
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
if (string(i->value.begin(), i->value.end()) == string("abs"))
{
res.value = fabs(res.value);
return res;
}
else if (string(i->value.begin(), i->value.end()) == string("cos"))
{
res.value = cos(res.value);
return res;
}
else if (string(i->value.begin(), i->value.end()) == string("sin"))
{
res.value = sin(res.value);
return res;
}
else if (string(i->value.begin(), i->value.end()) == string("quality"))
{
res.value = res.quality;
return res;
}
else
{
err << "in node funcID(" << string(i->value.begin(), i->value.end()) << ") value not allowed" << ends;
throw err.str();
}

Graziano Scalamera
committed
}
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
else if (i->value.id() == formula_grammar::func_dualID)
{
DEBUG_STREAM << " node function dual: " << string(i->value.begin(), i->value.end()) << endl;
if(i->children.size() != 2)
{
err << "in node func_dualID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
formula_res_t res_1=eval_expression(i->children.begin(), attr_values),
res_2=eval_expression(i->children.begin()+1, attr_values);
if (string(i->value.begin(), i->value.end()) == string("min"))
{
formula_res_t res;
res.value = min(res_1.value, res_2.value);
res.quality = res.combine_quality(res_1.quality, res_2.quality);
res.ex_reason = res.combine_exception(res_1.ex_reason, res_2.ex_reason);
res.ex_desc = res.combine_exception(res_1.ex_desc, res_2.ex_desc);
res.ex_origin = res.combine_exception(res_1.ex_origin, res_2.ex_origin);
return res;
}
else if (string(i->value.begin(), i->value.end()) == string("max"))
{
formula_res_t res;
res.value = max(res_1.value, res_2.value);
res.quality = res.combine_quality(res_1.quality, res_2.quality);
res.ex_reason = res.combine_exception(res_1.ex_reason, res_2.ex_reason);
res.ex_desc = res.combine_exception(res_1.ex_desc, res_2.ex_desc);
res.ex_origin = res.combine_exception(res_1.ex_origin, res_2.ex_origin);
return res;
}
else if (string(i->value.begin(), i->value.end()) == string("pow"))
{
formula_res_t res;
res.value = pow(res_1.value, res_2.value);
res.quality = res.combine_quality(res_1.quality, res_2.quality);
res.ex_reason = res.combine_exception(res_1.ex_reason, res_2.ex_reason);
res.ex_desc = res.combine_exception(res_1.ex_desc, res_2.ex_desc);
res.ex_origin = res.combine_exception(res_1.ex_origin, res_2.ex_origin);
return res;
}
else
{
err << "in node func_dualID(" << string(i->value.begin(), i->value.end()) << ") value not allowed" << ends;
throw err.str();
}
}
else if (i->value.id() == formula_grammar::cond_exprID)
{
DEBUG_STREAM << " node ternary_if expression: " << string(i->value.begin(), i->value.end()) << endl;
if(i->children.size() != 3)
{
err << "in node ternary_ifID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
formula_res_t res_1=eval_expression(i->children.begin(), attr_values);
if(res_1.value)
{
formula_res_t res = eval_expression(i->children.begin()+1, attr_values);
return res;
}
else
{
formula_res_t res = eval_expression(i->children.begin()+2, attr_values);
return res;
}
}

Graziano Scalamera
committed
else
{
DEBUG_STREAM << " node unknown id: " << string(i->value.begin(), i->value.end()) << endl;
{
err << "node unknown!! value=" << string(i->value.begin(), i->value.end()) << ends;
throw err.str();
}
}
formula_res_t res;
res.value = 0;
return res;

Graziano Scalamera
committed
}
void AlarmHandler::find_event_formula(tree_parse_info_t tree, vector<string> & ev)

Graziano Scalamera
committed
{
eval_node_event(tree.trees.begin(), ev);
return;
}
void AlarmHandler::eval_node_event(iter_t const& i, vector<string> & ev)

Graziano Scalamera
committed
{
DEBUG_STREAM << "In eval_node_event. i->value = '" <<

Graziano Scalamera
committed
string(i->value.begin(), i->value.end()) <<
"' i->children.size() = " << i->children.size() << " NODE=" << rule_names[i->value.id()] << endl;

Graziano Scalamera
committed
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
ostringstream err;
err << "Looking for event in formula tree: ";
/*if (i->value.id() == formula_grammar::event_ID)
{
DEBUG_STREAM << "eval_node_event(): in eventID!!!=" << string(i->value.begin(), i->value.end()) << endl;
}
else*/ if (i->value.id() == formula_grammar::nameID)
{
DEBUG_STREAM << "eval_node_event(): find event name=" << string(i->value.begin(), i->value.end()) << endl;
if(i->children.size() != 0)
{
err << "in node nameID(" << string(i->value.begin(), i->value.end()) << ") children=" << i->children.size() << ends;
throw err.str();
}
string s(i->value.begin(), i->value.end());
std::transform(s.begin(), s.end(), s.begin(), (int(*)(int))tolower); //transform to lowercase
ev.push_back(s);
}
//cout << endl;
//iter_t it = i->children.begin();
for(iter_t it = i->children.begin(); it != i->children.end(); it++)
eval_node_event(it, ev);
return;
}
void AlarmHandler::prepare_alarm_attr()

Graziano Scalamera
committed
{
prepare_alm_mtx->lock();

Graziano Scalamera
committed
alarm_container_t::iterator ai;
vector<alarm_t>::iterator aid;

Graziano Scalamera
committed
bool is_audible=false;

Graziano Scalamera
committed
alarms.vlock->readerIn();

Graziano Scalamera
committed
outOfServiceAlarms_sz=0;
shelvedAlarms_sz=0;
acknowledgedAlarms_sz=0;
unacknowledgedAlarms_sz=0;
unacknowledgedNormalAlarms_sz=0;
normalAlarms_sz=0;
silencedAlarms_sz=0;
listAlarms_sz=0;
for (ai = alarms.v_alarm.begin(); ai != alarms.v_alarm.end(); ai++) {
#ifndef ALM_SUM_STR
stringstream alm_summary;
alm_summary << KEY(NAME_KEY) << ai->first << SEP;
#else
string alm_summary;
alm_summary += KEY(NAME_KEY) + ai->first + SEP;
#endif

Graziano Scalamera
committed
if(ai->second.enabled == false)
{
outOfServiceAlarms_read[outOfServiceAlarms_sz] = ai->second.name;

Graziano Scalamera
committed
attr_outOfServiceAlarms_read[outOfServiceAlarms_sz] = const_cast<char*>(outOfServiceAlarms_read[outOfServiceAlarms_sz].c_str());
/*strcpy(c_outOfServiceAlarms_read[outOfServiceAlarms_sz], ai->second.name.c_str());
attr_outOfServiceAlarms_read[outOfServiceAlarms_sz] = c_outOfServiceAlarms_read[outOfServiceAlarms_sz];*/
//attr_outOfServiceAlarms_read[outOfServiceAlarms_sz] = CORBA::string_dup(ai->second.name.c_str());

Graziano Scalamera
committed
outOfServiceAlarms_sz++;

Graziano Scalamera
committed
}
else if(ai->second.shelved)
{
shelvedAlarms_read[shelvedAlarms_sz] = ai->second.name;

Graziano Scalamera
committed
attr_shelvedAlarms_read[shelvedAlarms_sz] = const_cast<char*>(shelvedAlarms_read[shelvedAlarms_sz].c_str());
/*strcpy(c_shelvedAlarms_read[shelvedAlarms_sz], ai->second.name.c_str());
attr_shelvedAlarms_read[shelvedAlarms_sz] = c_shelvedAlarms_read[shelvedAlarms_sz];*/
//attr_shelvedAlarms_read[shelvedAlarms_sz] = CORBA::string_dup(ai->second.name.c_str());

Graziano Scalamera
committed
shelvedAlarms_sz++;

Graziano Scalamera
committed
}
else
{
if(ai->second.stat == S_ALARM && ai->second.ack == ACK)
{
acknowledgedAlarms_read[acknowledgedAlarms_sz] = ai->second.name;

Graziano Scalamera
committed
attr_acknowledgedAlarms_read[acknowledgedAlarms_sz] = const_cast<char*>(acknowledgedAlarms_read[acknowledgedAlarms_sz].c_str());
/*strcpy(c_acknowledgedAlarms_read[acknowledgedAlarms_sz], ai->second.name.c_str());
attr_acknowledgedAlarms_read[acknowledgedAlarms_sz] = c_acknowledgedAlarms_read[acknowledgedAlarms_sz];*/
//attr_acknowledgedAlarms_read[acknowledgedAlarms_sz] = CORBA::string_dup(ai->second.name.c_str());

Graziano Scalamera
committed
acknowledgedAlarms_sz++;

Graziano Scalamera
committed
}
else if(ai->second.stat == S_ALARM && ai->second.ack == NOT_ACK)
{
unacknowledgedAlarms_read[unacknowledgedAlarms_sz] = ai->second.name;

Graziano Scalamera
committed
attr_unacknowledgedAlarms_read[unacknowledgedAlarms_sz] = const_cast<char*>(unacknowledgedAlarms_read[unacknowledgedAlarms_sz].c_str());
/*strcpy(c_unacknowledgedAlarms_read[unacknowledgedAlarms_sz], ai->second.name.c_str());
attr_unacknowledgedAlarms_read[unacknowledgedAlarms_sz] = c_unacknowledgedAlarms_read[unacknowledgedAlarms_sz];*/
//attr_unacknowledgedAlarms_read[unacknowledgedAlarms_sz] = CORBA::string_dup(ai->second.name.c_str());

Graziano Scalamera
committed
unacknowledgedAlarms_sz++;

Graziano Scalamera
committed
}
else if(ai->second.stat == S_NORMAL && ai->second.ack == NOT_ACK)
{
unacknowledgedNormalAlarms_read[unacknowledgedNormalAlarms_sz] = ai->second.name;

Graziano Scalamera
committed
attr_unacknowledgedNormalAlarms_read[unacknowledgedNormalAlarms_sz] = const_cast<char*>(unacknowledgedNormalAlarms_read[unacknowledgedNormalAlarms_sz].c_str());
/*strcpy(c_unacknowledgedNormalAlarms_read[unacknowledgedNormalAlarms_sz], ai->second.name.c_str());
attr_unacknowledgedNormalAlarms_read[unacknowledgedNormalAlarms_sz] = c_unacknowledgedNormalAlarms_read[unacknowledgedNormalAlarms_sz];*/
//attr_unacknowledgedNormalAlarms_read[unacknowledgedNormalAlarms_sz] = CORBA::string_dup(ai->second.name.c_str());

Graziano Scalamera
committed
unacknowledgedNormalAlarms_sz++;

Graziano Scalamera
committed
}
else if(ai->second.stat == S_NORMAL && ai->second.ack == ACK)
{
normalAlarms_read[normalAlarms_sz] = ai->second.name;

Graziano Scalamera
committed
attr_normalAlarms_read[normalAlarms_sz] = const_cast<char*>(normalAlarms_read[normalAlarms_sz].c_str());
/*strcpy(c_normalAlarms_read[normalAlarms_sz], ai->second.name.c_str());
attr_normalAlarms_read[normalAlarms_sz] = c_normalAlarms_read[normalAlarms_sz];*/
//attr_normalAlarms_read[normalAlarms_sz] = CORBA::string_dup(ai->second.name.c_str());

Graziano Scalamera
committed
normalAlarms_sz++;

Graziano Scalamera
committed
}
if(ai->second.silenced > 0)
{
silencedAlarms_read[silencedAlarms_sz] = ai->second.name;

Graziano Scalamera
committed
attr_silencedAlarms_read[silencedAlarms_sz] = const_cast<char*>(silencedAlarms_read[silencedAlarms_sz].c_str());
/*strcpy(c_silencedAlarms_read[silencedAlarms_sz], ai->second.name.c_str());
attr_silencedAlarms_read[silencedAlarms_sz] = c_silencedAlarms_read[silencedAlarms_sz];*/
//attr_silencedAlarms_read[silencedAlarms_sz] = CORBA::string_dup(ai->second.name.c_str());

Graziano Scalamera
committed
silencedAlarms_sz++;
}
}
ostringstream tmp_ex;
//tmp_ex.str("");
if(ai->second.ex_reason.length() > 0 || ai->second.ex_desc.length() > 0 || ai->second.ex_origin.length() > 0)
{
tmp_ex << "Reason: '" << ai->second.ex_reason << "' Desc: '" << ai->second.ex_desc << "' Origin: '" << ai->second.ex_origin << "'";
DEBUG_STREAM << __func__ << ": " << tmp_ex.str();
if(almstate != "SHLVD" && almstate != "OOSRV")
{
almstate = "ERROR";
}