Newer
Older

Graziano Scalamera
committed
<< 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
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
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->on_counter << "\t" << aid->lev << "\t"<< -1/*silenced*/ <<"\t" << aid->grp2str() << "\t" << aid->msg << "\t "<< ends; //TODO: silenced for internal errors?

Graziano Scalamera
committed
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
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();
}
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
//=============================================================================
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);
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
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);
if (found == alarms.v_alarm.end())
{
DEBUG_STREAM << __func__<<": DELETING " << it2->first << endl;
alarms.delete_alarm_conf_db(it2->first);
saved_alarms.erase(it2);
}
if(it2 != saved_alarms.end())
it2++;
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
4192
4193
4194
4195
4196
4197
4198
}
#ifndef _RW_LOCK
alarms.unlock();
#else
alarms.vlock->readerOut();
#endif
Tango::DbData data;
data.push_back(Tango::DbDatum("AlarmList"));
data[0] << prop;
#ifndef _USE_ELETTRA_DB_RW
Tango::Database *db = new Tango::Database();
#else
//save properties using host_rw e port_rw to connect to database
Tango::Database *db;
if(host_rw != "")
db = new Tango::Database(host_rw,port_rw);
else
db = new Tango::Database();
DEBUG_STREAM << __func__<<": connecting to db "<<host_rw<<":"<<port_rw;
#endif
try
{
DECLARE_TIME_VAR t0, t1;
GET_TIME(t0);
db->set_timeout_millis(10000);
db->put_device_property(get_name(), data);
GET_TIME(t1);
DEBUG_STREAM << __func__ << ": saving properties size="<<prop.size()<<" -> " << ELAPSED(t0, t1) << " ms" << endl;
}
catch(Tango::DevFailed &e)
{
stringstream o;
o << " Error saving properties='" << e.errors[0].desc << "'";
WARN_STREAM << __FUNCTION__<< o.str();
}
delete db;
}

Graziano Scalamera
committed
/*----- PROTECTED REGION END -----*/ // Alarm::namespace_ending
} // namespace