Newer
Older

Graziano Scalamera
committed
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
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
}
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
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
}
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();
}
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
//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
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
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
}
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);
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
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
}
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
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
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
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
}
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;

Graziano Scalamera
committed
bool is_audible=false;

Graziano Scalamera
committed
#ifndef _RW_LOCK
alarms.lock();
#else
alarms.vlock->readerIn();
#endif

Graziano Scalamera
committed
outOfServiceAlarms_read.clear();
shelvedAlarms_read.clear();
acknowledgedAlarms_read.clear();
unacknowledgedAlarms_read.clear();
unacknowledgedNormalAlarms_read.clear();
normalAlarms_read.clear();
silencedAlarms_read.clear();
listAlarms_read.clear();
outOfServiceAlarms_sz=0;
shelvedAlarms_sz=0;
acknowledgedAlarms_sz=0;
unacknowledgedAlarms_sz=0;
unacknowledgedNormalAlarms_sz=0;
normalAlarms_sz=0;
silencedAlarms_sz=0;
listAlarms_sz=0;

Graziano Scalamera
committed
for (ai = alarms.v_alarm.begin(); ai != alarms.v_alarm.end(); ai++) {

Graziano Scalamera
committed
4700
4701
4702
4703
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
4746
4747
4748
4749
4750
4751
4752
4753
if(ai->second.enabled == false)
{
outOfServiceAlarms_read.push_back(ai->second.name);
attr_outOfServiceAlarms_read[outOfServiceAlarms_sz] = const_cast<char*>(outOfServiceAlarms_read[outOfServiceAlarms_sz].c_str());
outOfServiceAlarms_sz++;
}
else if(ai->second.shelved)
{
shelvedAlarms_read.push_back(ai->second.name);
attr_shelvedAlarms_read[shelvedAlarms_sz] = const_cast<char*>(shelvedAlarms_read[shelvedAlarms_sz].c_str());
shelvedAlarms_sz++;
}
else
{
if(ai->second.stat == S_ALARM && ai->second.ack == ACK)
{
acknowledgedAlarms_read.push_back(ai->second.name);
attr_acknowledgedAlarms_read[acknowledgedAlarms_sz] = const_cast<char*>(acknowledgedAlarms_read[acknowledgedAlarms_sz].c_str());
acknowledgedAlarms_sz++;
}
else if(ai->second.stat == S_ALARM && ai->second.ack == NOT_ACK)
{
unacknowledgedAlarms_read.push_back(ai->second.name);
attr_unacknowledgedAlarms_read[unacknowledgedAlarms_sz] = const_cast<char*>(unacknowledgedAlarms_read[unacknowledgedAlarms_sz].c_str());
unacknowledgedAlarms_sz++;
}
else if(ai->second.stat == S_NORMAL && ai->second.ack == NOT_ACK)
{
unacknowledgedNormalAlarms_read.push_back(ai->second.name);
attr_unacknowledgedNormalAlarms_read[unacknowledgedNormalAlarms_sz] = const_cast<char*>(unacknowledgedNormalAlarms_read[unacknowledgedNormalAlarms_sz].c_str());
unacknowledgedNormalAlarms_sz++;
}
else if(ai->second.stat == S_NORMAL && ai->second.ack == ACK)
{
normalAlarms_read.push_back(ai->second.name);
attr_normalAlarms_read[normalAlarms_sz] = const_cast<char*>(normalAlarms_read[normalAlarms_sz].c_str());
normalAlarms_sz++;
}
if(ai->second.silenced > 0)
{
silencedAlarms_read.push_back(ai->second.name);
attr_silencedAlarms_read[silencedAlarms_sz] = const_cast<char*>(silencedAlarms_read[silencedAlarms_sz].c_str());
silencedAlarms_sz++;
}
}
attr_frequencyAlarms_read[listAlarms_sz] = ai->second.freq_counter;
listAlarms_read.push_back(ai->second.name);
attr_listAlarms_read[listAlarms_sz] = const_cast<char*>(listAlarms_read[listAlarms_sz].c_str());
listAlarms_sz++;
if(!is_audible && ai->second.is_new && ai->second.silenced <= 0 && ai->second.enabled && !ai->second.shelved)
is_audible = true;
if (ai->second.stat == S_ALARM && ai->second.enabled && !ai->second.shelved) {

Graziano Scalamera
committed
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
/*
* 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
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
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
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
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 */

Graziano Scalamera
committed
*attr_audibleAlarm_read = is_audible;

Graziano Scalamera
committed
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
#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)

Graziano Scalamera
committed
{

Graziano Scalamera
committed
aid->silenced = aid->silent_time - floor(dminutes);

Graziano Scalamera
committed
}

Graziano Scalamera
committed
else

Graziano Scalamera
committed
{

Graziano Scalamera
committed
aid->silenced = 0;

Graziano Scalamera
committed
aid->shelved = false;
}

Graziano Scalamera
committed
}
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->on_counter << "\t" << aid->lev << "\t" << aid->silenced << "\t" << aid->grp2str() << "\t" << aid->msg << "\t" << is_new << ends;

Graziano Scalamera
committed
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
tmp_alarm_table.push_back(os.str());
}
}
alarmedlock->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();
}
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
//=============================================================================
string Alarm::remove_domain(string str)
{
string::size_type end1 = str.find(".");
if (end1 == string::npos)
{
return str;
}
else
{
string::size_type start = str.find("tango://");
if (start == string::npos)
{
start = 0;
}
else
{
start = 8; //tango:// len
}
string::size_type end2 = str.find(":", start);
if(end1 > end2) //'.' not in the tango host part
return str;
string th = str.substr(0, end1);
th += str.substr(end2, str.size()-end2);
return th;
}
}
//=============================================================================
//=============================================================================
bool Alarm::compare_without_domain(string str1, string str2)
{
string str1_nd = remove_domain(str1);
string str2_nd = remove_domain(str2);
return (str1_nd==str2_nd);
}
//=============================================================================
//=============================================================================
void Alarm::put_signal_property()
{
vector<string> prop;
#ifndef _RW_LOCK
alarms.lock();
#else
alarms.vlock->readerIn();
#endif
alarm_container_t::iterator it;
for(it = alarms.v_alarm.begin(); it != alarms.v_alarm.end(); it++)
{
prop.push_back(it->first);
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
string conf_str;
it->second.confstr(conf_str);
map<string,string>::iterator itmap = saved_alarms.find(it->first);
if(itmap == saved_alarms.end())
{
DEBUG_STREAM << __func__<<": SAVING " << it->first << endl;
alarms.save_alarm_conf_db(it->second.attr_name, it->second.name, it->second.stat, it->second.ack, it->second.enabled,
it->second.formula, it->second.on_delay, it->second.off_delay, it->second.grp2str(), it->second.lev, it->second.msg, it->second.cmd_name_a, it->second.cmd_name_n, it->second.silent_time);
saved_alarms.insert(make_pair(it->first,conf_str));
}
else
{
string conf_string;
it->second.confstr(conf_string);
//alarm found but configuration changed
if(conf_string != itmap->second)
{
DEBUG_STREAM << __func__<<": UPDATING " << it->first << endl;
alarms.save_alarm_conf_db(it->second.attr_name, it->second.name, it->second.stat, it->second.ack, it->second.enabled,
it->second.formula, it->second.on_delay, it->second.off_delay, it->second.grp2str(), it->second.lev, it->second.msg, it->second.cmd_name_a, it->second.cmd_name_n, it->second.silent_time);
itmap->second = conf_string;
}
}
}
map<string, string>::iterator it2=saved_alarms.begin();
while(it2 != saved_alarms.end())
{
alarm_container_t::iterator found = alarms.v_alarm.find(it2->first);