Newer
Older
push_archive_event(it->second.attr_name, &except);
} catch(Tango::DevFailed & ex)
{
WARN_STREAM << "Alarm::"<<__func__<<": EXCEPTION PUSHING EVENTS: " << ex.errors[0].desc << endl;

Graziano Scalamera
committed
}
}
else
{
#ifndef _RW_LOCK
alarms.unlock();
#else
alarms.vlock->readerOut();
#endif
ostringstream o;
//o << j->first << ": not found formula in alarm table" << ends;
o << (*j) << ": not found formula in alarm table" << ends;
WARN_STREAM << "Alarm::"<<__func__<<": " << o.str() << endl;
set_internal_alarm(INTERNAL_ERROR, gettime(), o.str());
try
{ //DevFailed for push events
Tango::DevErrorList errors(1);
errors.length(1);
it->second.ex_reason = string("NOT_FOUND");
it->second.ex_desc = e.ev_name + ": " + o.str();
it->second.ex_origin = e.ev_name;
errors[0].desc = CORBA::string_dup(it->second.ex_desc.c_str());
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);
} catch(Tango::DevFailed & ex)
{
WARN_STREAM << "Alarm::"<<__func__<<": EXCEPTION PUSHING EVENTS: " << ex.errors[0].desc << endl;

Graziano Scalamera
committed
}
j++;
}
prepare_alarm_attr();
if(num_changed==0)

Graziano Scalamera
committed
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
return;
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);
}
} /* do_alarm() */
void Alarm::timer_update()
{
bool changed=true;
//DEBUG_STREAM << "Alarm::timer_update(): entering..." << endl;
try {
changed=alarms.timer_update();
} catch(string & e)
{
ostringstream o;
o << "Error checking time thresholds and updating alarm status=" << e << ends;
WARN_STREAM << "Alarm::timer_update(): " << o.str() << endl;
set_internal_alarm(INTERNAL_ERROR, gettime(), o.str());
/* Tango::DevErrorList errors(1);
errors.length(1);
it->second.ex_reason = string("INTERNAL_ERROR");
it->second.ex_desc = o.str();
it->second.ex_origin = string("Alarm::timer_update");
errors[0].desc = CORBA::string_dup(it->second.ex_desc.c_str());
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
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
}
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
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
#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->counter < count)
it->counter = count;
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->counter++;
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.counter = count;
//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
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
3408
3409
3410
3411
3412
3413
3414
3415
3416
}
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());
#ifndef _ACCESS_NODE_D
Tango::DevState st;
if(val_st == "ON")
st = Tango::ON;
else if(val_st == "OFF")
st = Tango::OFF;
else if(val_st == "CLOSE")
st = Tango::CLOSE;
else if(val_st == "OPEN")
st = Tango::OPEN;
else if(val_st == "INSERT")
st = Tango::INSERT;
else if(val_st == "EXTRACT")
st = Tango::EXTRACT;
else if(val_st == "MOVING")
st = Tango::MOVING;
else if(val_st == "STANDBY")
st = Tango::STANDBY;
else if(val_st == "FAULT")
st = Tango::FAULT;
else if(val_st == "INIT")
st = Tango::INIT;
else if(val_st == "RUNNING")
st = Tango::RUNNING;
else if(val_st == "ALARM")
st = Tango::ALARM;
else if(val_st == "DISABLE")
st = Tango::DISABLE;
else if(val_st == "UNKNOWN")
st = Tango::UNKNOWN;
#else
double st = i->value.value(); //get value directly from node saved with access_node_d
#endif //_ACCESS_NODE_D
DEBUG_STREAM << " node value state : " << val_st << "=" << st << endl;
formula_res_t res;
res.value = st;
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;

Graziano Scalamera
committed
if (*i->value.begin() == '-')
res.value = - res.value;

Graziano Scalamera
committed
if (*i->value.begin() == '!')
res.value = ! res.value;
return res;

Graziano Scalamera
committed
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
}
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

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
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
}
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->value.empty())
{
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
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
}
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
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
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
3743
3744
3745
3746
3747
3748
}
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();
}
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();
}
}
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);
res.value = fabs(res.value);
return res; //now handled only abs as function

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
3766
3767
3768
3769
3770
3771
3772
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
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
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
3921
3922
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
3957
3958
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
}
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->counter = ai->second.counter;
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->counter = ai->second.counter;
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)
{
Tango::TimeVal now = gettime();
double dnow = now.tv_sec + ((double)now.tv_usec) / 1000000;
double dsilent = aid->ts_time_silenced.tv_sec + ((double)aid->ts_time_silenced.tv_usec) / 1000000;
double dminutes = (dnow - dsilent)/60;
//silenced already calculated in alarm_table::update, but here updated for panel also if state not changed:
//to see minutes countdown
if(dminutes < aid->silent_time)
aid->silenced = aid->silent_time - floor(dminutes);
else
aid->silenced = 0;
}
ostringstream os;
os.clear();
is_new.clear();
is_new = (aid->is_new && aid->silenced <= 0) ? "NEW" : " ";
os << aid->ts.tv_sec << "\t" << aid->ts.tv_usec << "\t" \
<< aid->name << "\t" << aid->stat << "\t" << aid->ack \
<< "\t" << aid->counter << "\t" << aid->lev << "\t" << aid->silenced << "\t" << aid->grp2str() << "\t" << aid->msg << "\t" << is_new << ends;
tmp_alarm_table.push_back(os.str());
}
}
alarmedlock->readerOut();
internallock->readerIn();
if (internal.empty() == false) {
for (aid = internal.begin(); aid != internal.end(); aid++) {
/* size_t index;
int count = 1;
index = aid->stat.find("*");
if((index != std::string::npos) && (index+1 != std::string::npos))
{
size_t last = aid->stat.size();
string str_count= aid->stat.substr(index+1, last - index+1);
count = strtol(str_count.c_str(), 0,10);
}
//do not show internal alarms that have a molteplicity less then errThreshold
if((aid->msg.find()) && (count < errThreshold))
continue;*/
ostringstream os;
os.clear();
os << aid->ts.tv_sec << "\t" << aid->ts.tv_usec << "\t" \
<< aid->name << "\t" << aid->stat << "\t" << aid->ack \
<< "\t" << aid->counter << "\t" << aid->lev << "\t"<< -1/*silenced*/ <<"\t" << aid->grp2str() << "\t" << aid->msg << "\t "<< ends; //TODO: silenced for internal errors?
tmp_alarm_table.push_back(os.str());
}
}
internallock->readerOut();
dslock->writerIn();
int i;
// for (i = ds_num - 1; i >= 0; i--) {
// CORBA::string_free(ds[i]);
// //ds_num--;
// }
/* for (i = 0; i < ds_num; i++) {
if (ds[i] != 0) {
CORBA::string_free(ds[i]);
ds[i] = 0;
}
}*/
ds_num = tmp_alarm_table.size();
if(ds_num > MAX_ALARMS)
ds_num = MAX_ALARMS;
for (i = 0; i < ds_num; i++) {
//ds[i] = CORBA::string_dup(tmp_alarm_table[i].c_str());
size_t len=tmp_alarm_table[i].length();
if(len >= 10124) len = 10124-1;
strncpy(dss[i],tmp_alarm_table[i].c_str(), len);
dss[i][len]=0;
}
if(ds_num == 0)
{
ostringstream os1;
ds_num++;
os1.clear();
os1 << 0 << "\t" << 0 << "\t" << 0 << "\t" << 0 << "\t" << 0 << "\t" << 0 << "\t" << 0 << "\t" << -1 << "\t" << 0 << "\t" << 0 << "\t "<< ends;
//ds[0] = CORBA::string_dup(os1.str().c_str());
size_t len=os1.str().length();
if(len >= 10124) len = 10124-1;
strncpy(dss[i],os1.str().c_str(), len);
dss[i][len]=0;
}
dslock->writerOut();
}