Newer
Older
errors[0].severity = Tango::ERR;
errors[0].reason = CORBA::string_dup(it->second.ex_reason.c_str());
errors[0].origin = CORBA::string_dup(it->second.ex_origin.c_str());
Tango::DevFailed except(errors);
push_change_event(it->second.attr_name, &except);
push_archive_event(it->second.attr_name, &except);*/

Graziano Scalamera
committed
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
}
prepare_alarm_attr();
if(!changed)
return;
try
{
if(ds_num == 0)
{
//attr.set_value_date_quality(ds,0/*gettime()*/,Tango::ATTR_WARNING, ds_num, 0, false);
struct timeval now;
gettimeofday(&now,NULL);
push_change_event("alarm",(char**)ds,now,Tango::ATTR_WARNING, ds_num, 0, false);
}
else
//attr.set_value(ds, ds_num, 0, false);
push_change_event("alarm",ds, ds_num, 0, false);
} catch(Tango::DevFailed& e)
{
ostringstream err;
err << "error pushing alarm change event err=" << e.errors[0].desc;
INFO_STREAM << __func__<<": " << err.str() << endl;
}
}
bool Alarm::remove_alarm(string& s) throw(string&)
{
DEBUG_STREAM << "Alarm::"<<__func__<<": entering alm name=" << s << endl;

Graziano Scalamera
committed
#ifndef _RW_LOCK
alarms.lock();
#else
alarms.vlock->writerIn();
#endif
alarm_container_t::iterator i = alarms.v_alarm.find(s);
if (i != alarms.v_alarm.end()) {
DEBUG_STREAM << "Alarm::"<<__func__<<": found in table alm name=" << s << endl;

Graziano Scalamera
committed
for (set<string>::iterator j = i->second.s_event.begin(); \
j != i->second.s_event.end(); j++) {
DEBUG_STREAM << "Alarm::"<<__func__<<": looping event =" << *j << endl;

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 << "Alarm::"<<__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 << "Alarm::"<<__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 << "Alarm::remove_alarm(): removing event '" \
<< 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 << "Alarm::remove_alarm(): " << o.str() << endl;
#ifndef _RW_LOCK
alarms.unlock();
#else
alarms.vlock->writerOut();
#endif
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 << "Alarm::remove_alarm(): " << o.str() << endl;
#ifndef _RW_LOCK
alarms.unlock();
#else
alarms.vlock->writerOut();
#endif
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;
/*
* remove this alarm from alarm table
*/
remove_AlarmState_dynamic_attribute(i->second.attr_name);
alarms.erase(i);

Graziano Scalamera
committed
#ifndef _RW_LOCK
alarms.unlock();
#else
alarms.vlock->writerOut();
#endif
return true;
}
else
{
WARN_STREAM << "Alarm::"<<__func__<<": NOT found in table alm name=" << s << endl;
}

Graziano Scalamera
committed
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
#ifndef _RW_LOCK
alarms.unlock();
#else
alarms.vlock->writerOut();
#endif
ostringstream o;
o << "alarm '" \
<< s << "' not found in alarm table" << ends;
WARN_STREAM << "Alarm::remove_alarm(): " << o.str() << endl;
throw o.str();
//return false;
} /* remove_alarm() */
/*void Alarm::add_to_database(alarm_t& a) throw(string&)
{
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 << "Alarm::add_to_database(): a.name=" << a.name << " a.formula=" << a.formula << " a.lev=" << a.lev << " a.grp=" << a.grp2str() << " a.msg=" << a.msg << endl;
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 << "Alarm::add_to_database(): adding to database property=" << pro << endl;
property << pro;
db_data.push_back(property);
try {
get_db_device()->put_attribute_property(db_data);
} catch (...) {
ostringstream o;
o << "Alarm::add_to_database(): put_device_attribute_property()" \
<< " failed" << ends;
ERROR_STREAM << o.str() << endl;
throw o.str();
}
}*/
void Alarm::set_internal_alarm(string name, Tango::TimeVal t, string msg, unsigned int count)
{
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
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
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 Alarm::eval_formula(tree_parse_info_t tree, string &attr_values)

Graziano Scalamera
committed
{
return eval_expression(tree.trees.begin(), attr_values);
}
formula_res_t Alarm::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_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
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
}
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(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;
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)
{
err << "in node nameID(" << string(i->value.begin(), i->value.end()) << ") value not valid!" << ends;
throw err.str();
}
else if(it->type != Tango::DEV_STRING && it->value.empty())

Graziano Scalamera
committed
{
err << "in node nameID(" << string(i->value.begin(), i->value.end()) << ") value not initialized!!" << ends;
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
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
}
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();
}
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
//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 nameID(" << string(i2_1->value.begin(), i2_1->value.end()) << ") value not valid!" << ends;
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!!" << ends;
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
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
}
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);
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
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
}
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
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
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
}
void Alarm::find_event_formula(tree_parse_info_t tree, vector<string> & ev)
{
eval_node_event(tree.trees.begin(), ev);
return;
}
void Alarm::eval_node_event(iter_t const& i, vector<string> & ev)
{
/* DEBUG_STREAM << "In eval_node_event. i->value = " <<
string(i->value.begin(), i->value.end()) <<
" i->children.size() = " << i->children.size() << " NODE=" << rule_names[i->value.id()] << endl;*/
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 Alarm::prepare_alarm_attr()
{
alarm_container_t::iterator ai;
vector<alarm_t>::iterator aid;
#ifndef _RW_LOCK
alarms.lock();
#else
alarms.vlock->readerIn();
#endif
for (ai = alarms.v_alarm.begin(); ai != alarms.v_alarm.end(); ai++) {
if (ai->second.stat == S_ALARM) {
/*
* alarm status is S_ALARM
*/
alarmedlock->readerIn();
aid = find(alarmed.begin(), alarmed.end(),ai->second.name);
if (aid != alarmed.end()) {
/*
* found, change stat only if switching from
* S_NORMAL to S_ALARM status
*/
//cout << "read_attr(): S_ALARM: found: " << aid->name << endl;
if (aid->stat == S_NORMAL) {
aid->stat = S_ALARM;
aid->ack = NOT_ACK;
aid->ts = ai->second.ts;
aid->msg = ai->second.msg;
}
aid->grp = ai->second.grp;
aid->lev = ai->second.lev;
aid->is_new = ai->second.is_new; //copy is_new state
//ai->second.is_new = 0; //and set state as not more new //12-06-08: StopNew command set it to 0
aid->on_counter = ai->second.on_counter;
aid->off_counter = ai->second.off_counter;

Graziano Scalamera
committed
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
aid->ack = ai->second.ack; //if already acknowledged but has arrived new alarm ack is reset
aid->silenced = ai->second.silenced; //update silenced from alarm table (maybe not necessary)
aid->silent_time = ai->second.silent_time; //if already alarmed and not saved correctly in properties needed to update
} else {
/*
* not found: new "alarmed" item
*/
DEBUG_STREAM << __func__<<": S_ALARM: pushing new alarm: " \
<< ai->second.name << "\t" << ai->second.stat << endl;
alarmedlock->readerOut();
alarmedlock->writerIn();
alarmed.push_back(ai->second);
//ai->second.is_new = 0; //set state as not more new //12-06-08: StopNew command set it to 0
alarmedlock->writerOut();
alarmedlock->readerIn();
}
alarmedlock->readerOut();
} else if (ai->second.stat == S_NORMAL) {
/*
* alarm status is S_NORMAL
*/
alarmedlock->readerIn();
aid = find(alarmed.begin(), alarmed.end(), ai->second.name);
if (aid != alarmed.end()) {
/*
* found, as it should;
* switching from S_ALARM to S_NORMAL
*/
aid->stat = S_NORMAL;
aid->ts = ai->second.ts;
//aid->msg = " "; /* no message again */
aid->msg =ai->second.msg;
aid->grp = ai->second.grp;
aid->lev = ai->second.lev;
aid->on_counter = ai->second.on_counter;
aid->off_counter = ai->second.off_counter;

Graziano Scalamera
committed
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
aid->ack = ai->second.ack; //if already acknowledged but has arrived new alarm ack is reset
aid->is_new = ai->second.is_new; //copy is_new state
aid->silenced = ai->second.silenced; //update silenced from alarm table (maybe not necessary)
aid->silent_time = ai->second.silent_time; //if already alarmed and not saved correctly in properties needed to update
//ai->second.is_new = 0; //and set state as not more new //12-06-08: StopNew command set it to 0
if (aid->ack == ACK) {
if (aid->done) {
/*
* if already ACKnowledged and visualized
* remove from "alarmed" list
*/
DEBUG_STREAM << __func__<<": S_NORMAL: " << aid->name \
<< " ACKnowledged: removing" << endl;
alarmedlock->readerOut();
alarmedlock->writerIn();
alarmed.erase(aid);
alarmedlock->writerOut();
alarmedlock->readerIn();
} else {
aid->done = true;
}
} /* if */
} /* if */
alarmedlock->readerOut();
} /* if else if */
} /* for */
#ifndef _RW_LOCK
alarms.unlock();
#else
alarms.vlock->readerOut();
#endif
vector<string> tmp_alarm_table;
string is_new;
ostringstream os1;
/*os1.clear();
os1 << header << "\t" << alarmed.size() << ends;*/
//tmp_alarm_table.push_back(os1.str());
alarmedlock->readerIn();
if (alarmed.empty() == false) {
for (aid = alarmed.begin(); aid != alarmed.end(); aid++) {
if(aid->silenced > 0)