Newer
Older
/*v_event[i].siglock->writerOut();
return;*/
}
}
v_event[i].running=true;
if(v_event[i].paused)
static_cast<AlarmHandler_ns::AlarmHandler *>(mydev)->attr_AttributePausedNumber_read--;
static_cast<AlarmHandler_ns::AlarmHandler *>(mydev)->attr_AttributeStartedNumber_read++;
v_event[i].paused=false;
v_event[i].stopped=false;
}
v_event[i].siglock->writerOut();
return;
}
}
for (unsigned int i=0 ; i<v_event.size() ; i++)
{
#ifndef _MULTI_TANGO_HOST
if (static_cast<AlarmHandler_ns::AlarmHandler *>(mydev)->compare_without_domain(v_event[i].name,signame))
if (!static_cast<AlarmHandler_ns::AlarmHandler *>(mydev)->compare_tango_names(v_event[i].name,signame))
#endif
{
v_event[i].siglock->writerIn();
if(!v_event[i].running)
{
if(v_event[i].stopped)
{
static_cast<AlarmHandler_ns::AlarmHandler *>(mydev)->attr_AttributeStoppedNumber_read--;
try
{
add(signame, contexts, NOTHING, true);
}
catch (Tango::DevFailed &e)
{
//Tango::Except::print_exception(e);
INFO_STREAM << "event_table::start: error adding " << signame << endl;
v_event[i].ex_reason = e.errors[0].reason;
v_event[i].ex_desc = e.errors[0].desc;
v_event[i].ex_origin = e.errors[0].origin;
/*signals[i].siglock->writerOut();
return;*/
}
}
v_event[i].running=true;
if(v_event[i].paused)
static_cast<AlarmHandler_ns::AlarmHandler *>(mydev)->attr_AttributePausedNumber_read--;
static_cast<AlarmHandler_ns::AlarmHandler *>(mydev)->attr_AttributeStartedNumber_read++;
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
v_event[i].paused=false;
v_event[i].stopped=false;
}
v_event[i].siglock->writerOut();
return;
}
}
// if not found
Tango::Except::throw_exception(
(const char *)"BadSignalName",
"Signal " + signame + " NOT subscribed",
(const char *)"event_table::start()");
}
void event_table::start_all()
{
ReaderLock lock(veclock);
vector<string> contexts;
for (unsigned int i=0 ; i<v_event.size() ; i++)
{
v_event[i].siglock->writerIn();
if(!v_event[i].running)
{
if(v_event[i].stopped)
{
string signame = v_event[i].name;
static_cast<AlarmHandler_ns::AlarmHandler *>(mydev)->attr_AttributeStoppedNumber_read--;
try
{
add(signame, contexts, NOTHING, true);
}
catch (Tango::DevFailed &e)
{
//Tango::Except::print_exception(e);
INFO_STREAM << "event_table::start: error adding " << signame <<" err="<< e.errors[0].desc << endl;
v_event[i].ex_reason = e.errors[0].reason;
v_event[i].ex_desc = e.errors[0].desc;
v_event[i].ex_origin = e.errors[0].origin;
/*v_event[i].siglock->writerOut();
return;*/
}
}
v_event[i].running=true;
if(v_event[i].paused)
static_cast<AlarmHandler_ns::AlarmHandler *>(mydev)->attr_AttributePausedNumber_read--;
static_cast<AlarmHandler_ns::AlarmHandler *>(mydev)->attr_AttributeStartedNumber_read++;
v_event[i].paused=false;
v_event[i].stopped=false;
}
v_event[i].siglock->writerOut();
}
}

Graziano Scalamera
committed
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
//=============================================================================
//=============================================================================
bool event_table::get_if_stop()
{
//omni_mutex_lock sync(*this);
return stop_it;
}
//=============================================================================
//=============================================================================
void event_table::stop_thread()
{
//omni_mutex_lock sync(*this);
stop_it = true;
signal();
//condition.signal();
}
//=============================================================================
/**
* return number of signals to be subscribed
*/
//=============================================================================
int event_table::nb_sig_to_subscribe()
{
ReaderLock lock(veclock);
int nb = 0;
for (unsigned int i=0 ; i<v_event.size() ; i++)
{
v_event[i].siglock->readerIn();
if (v_event[i].event_id == SUB_ERR && !v_event[i].stopped)
{
nb++;
}
v_event[i].siglock->readerOut();
}
return nb;
}
//=============================================================================
/**
* build a list of signal to set HDB device property
*/
//=============================================================================
void event_table::put_signal_property()
{
DEBUG_STREAM << "event_table::"<<__func__<<": put_signal_property entering action=" << action << endl;
//ReaderLock lock(veclock);
if (action>NOTHING)
{
static_cast<AlarmHandler_ns::AlarmHandler *>(mydev)->put_signal_property();
if(action >= UPDATE_PROP)
action--;
}
DEBUG_STREAM << "event_table::"<<__func__<<": put_signal_property exiting action=" << action << endl;
}

Graziano Scalamera
committed
/*
* EventCallBack class methods
*/
EventCallBack::EventCallBack(Tango::DeviceImpl *s):Tango::LogAdapter(s)

Graziano Scalamera
committed
{
//e_ptr = NULL;
mydev = s;

Graziano Scalamera
committed
}
EventCallBack::~EventCallBack(void)
{

Graziano Scalamera
committed
}
void EventCallBack::push_event(Tango::EventData* ev)
{
string temp_name;
bei_t e;
e.ex_reason = string("");
e.ex_desc = string("");
e.ex_origin = string("");

Graziano Scalamera
committed
try {
//e.errors = ev->errors;
e.quality = Tango::ATTR_VALID;
//cout << "EVENT="<<ev->attr_name<<" quality="<<e.quality<<endl;

Graziano Scalamera
committed
if (!ev->err) {
e.quality = (int)ev->attr_value->get_quality();

Graziano Scalamera
committed
#if 0//TANGO_VER >= 711
string ev_name_str(ev->attr_name);
string::size_type pos = ev_name_str.find("tango://");
if (pos != string::npos)
{
pos = ev_name_str.find('/',8);
ev_name_str = ev_name_str.substr(pos + 1);
}
e.ev_name = ev_name_str.c_str();
#else
e.ev_name = ev->attr_name;
#endif
e.ts = ev->attr_value->time;
extract_values(ev->attr_value, e.value, e.value_string, e.type, e.read_size);

Graziano Scalamera
committed
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
} else {
#if 0//TANGO_VER >= 711
string ev_name_str(ev->attr_name);
string::size_type pos = ev_name_str.find("tango://");
if (pos != string::npos)
{
pos = ev_name_str.find('/',8);
ev_name_str = ev_name_str.substr(pos + 1);
}
temp_name = ev_name_str.c_str() + string(".") + ev->event;
#else
temp_name = ev->attr_name + string(".") + ev->event; //TODO: BUG IN TANGO: part of attr_name after first dot continues in field event
#endif
size_t pos_change = temp_name.find(".change");
if(pos_change != string::npos)
{
temp_name = temp_name.substr(0,pos_change);
}
ostringstream o;
o << "Tango error for '" << temp_name << "'=" << ev->errors[0].desc.in() << ends;
e.ev_name = temp_name;
e.type = TYPE_TANGO_ERR;
//e.ev_name = INTERNAL_ERROR;
//e.type = -1;
e.msg = o.str();
e.msg = std::regex_replace(e.msg, std::regex(R"((\n)|(\t))"), " "); //match raw string "\n" or "\t" and replace with " "

Graziano Scalamera
committed
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
}
}
catch (string &err) {
e.msg = err + " for event '" + ev->attr_name + "'";
e.ev_name = ev->attr_name;
e.type = TYPE_GENERIC_ERR;
//e.value.i = 0;
e.ts = gettime();
//cerr << o.str() << endl;
} catch(Tango::DevFailed& Terr)
{
ostringstream o;
o << "Event exception for'" \
<< ev->attr_name << "' error=" << Terr.errors[0].desc << ends;
e.ev_name = ev->attr_name;
e.type = TYPE_GENERIC_ERR;
//e.value.i = 0;
e.ts = gettime();
e.msg = o.str();
//cerr << o.str() << endl;
}
catch (...) {
ostringstream o;
o << "Generic Event exception for'" \
<< ev->attr_name << "'" << ends;
e.ev_name = ev->attr_name;
e.type = TYPE_GENERIC_ERR;
//e.value.i = 0;
e.ts = gettime();
e.msg = o.str();
//cerr << o.str() << endl;
}
static_cast<AlarmHandler_ns::AlarmHandler *>(mydev)->evlist.push_back(e);

Graziano Scalamera
committed
} /* push_event() */
void EventCallBack::extract_values(Tango::DeviceAttribute *attr_value, vector<double> &val, string &val_string, int &type, int &read_size)

Graziano Scalamera
committed
{
Tango::DevState stval;
vector<Tango::DevState> v_st;
vector<Tango::DevULong> v_ulo;
vector<Tango::DevUChar> v_uch;
vector<Tango::DevShort> v_sh;
vector<Tango::DevUShort> v_ush;
vector<Tango::DevLong> v_lo;
vector<Tango::DevDouble> v_do;
vector<Tango::DevFloat> v_fl;
vector<Tango::DevBoolean> v_bo;
vector<Tango::DevLong64> v_lo64;
vector<Tango::DevULong64> v_ulo64;
vector<string> v_string;
val_string = string("");

Graziano Scalamera
committed
//Tango::AttributeDimension attr_w_dim;
Tango::AttributeDimension attr_r_dim;
//attr_value->reset_exceptions(Tango::DeviceAttribute::isempty_flag); //disable is_empty exception //commented to throw exceptions if empty
if(!attr_value->is_empty())
{
//attr_w_dim = data->attr_value->get_w_dimension();
attr_r_dim = attr_value->get_r_dimension();
}
else
{
attr_r_dim.dim_x = 0;
//attr_w_dim.dim_x = 0;
attr_r_dim.dim_y = 0;
//attr_w_dim.dim_y = 0;
}
read_size = attr_r_dim.dim_x;
if(attr_r_dim.dim_y > 1)
read_size *= attr_r_dim.dim_y;

Graziano Scalamera
committed
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
if (attr_value->get_type() == Tango::DEV_UCHAR) {
*(attr_value) >> v_uch;
for(vector<Tango::DevUChar>::iterator it = v_uch.begin(); it != v_uch.end(); it++)
val.push_back((double)(*it)); //convert all to double
type = Tango::DEV_UCHAR;
} else if (attr_value->get_type() == Tango::DEV_SHORT) {
*(attr_value) >> v_sh;
for(vector<Tango::DevShort>::iterator it = v_sh.begin(); it != v_sh.end(); it++)
val.push_back((double)(*it)); //convert all to double
type = Tango::DEV_SHORT;
} else if (attr_value->get_type() == Tango::DEV_USHORT) {
*(attr_value) >> v_ush;
for(vector<Tango::DevUShort>::iterator it = v_ush.begin(); it != v_ush.end(); it++)
val.push_back((double)(*it)); //convert all to double
type = Tango::DEV_USHORT;
} else if (attr_value->get_type() == Tango::DEV_LONG) {
*(attr_value) >> v_lo;
for(vector<Tango::DevLong>::iterator it = v_lo.begin(); it != v_lo.end(); it++)
val.push_back((double)(*it)); //convert all to double
type = Tango::DEV_LONG;
} else if (attr_value->get_type() == Tango::DEV_STATE) {
//*(attr_value) >> v_st; //doesn't work in tango 5
*(attr_value) >> stval;
v_st.push_back(stval);
for(vector<Tango::DevState>::iterator it = v_st.begin(); it != v_st.end(); it++)
val.push_back((double)(*it)); //convert all to double
type = Tango::DEV_STATE;

Graziano Scalamera
committed
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
} else if (attr_value->get_type() == Tango::DEV_ULONG) {
*(attr_value) >> v_ulo;
for(vector<Tango::DevULong>::iterator it = v_ulo.begin(); it != v_ulo.end(); it++)
val.push_back((double)(*it)); //convert all to double
type = Tango::DEV_ULONG;
#endif //TANGO_VER >= 600
} else if (attr_value->get_type() == Tango::DEV_DOUBLE) {
*(attr_value) >> v_do;
for(vector<Tango::DevDouble>::iterator it = v_do.begin(); it != v_do.end(); it++)
val.push_back((double)(*it)); //convert all to double
type = Tango::DEV_DOUBLE;
} else if (attr_value->get_type() == Tango::DEV_FLOAT) {
*(attr_value) >> v_fl;
for(vector<Tango::DevFloat>::iterator it = v_fl.begin(); it != v_fl.end(); it++)
val.push_back((double)(*it)); //convert all to double
type = Tango::DEV_FLOAT;
} else if (attr_value->get_type() == Tango::DEV_BOOLEAN) {
*(attr_value) >> v_bo;
for(vector<Tango::DevBoolean>::iterator it = v_bo.begin(); it != v_bo.end(); it++)
val.push_back((double)(*it)); //convert all to double
type = Tango::DEV_BOOLEAN;
} else if (attr_value->get_type() == Tango::DEV_LONG64) {
*(attr_value) >> v_lo64;
for(vector<Tango::DevLong64>::iterator it = v_lo64.begin(); it != v_lo64.end(); it++)
val.push_back((double)(*it)); //convert all to double
type = Tango::DEV_LONG64;
} else if (attr_value->get_type() == Tango::DEV_ULONG64) {
*(attr_value) >> v_ulo64;
for(vector<Tango::DevULong64>::iterator it = v_ulo64.begin(); it != v_ulo64.end(); it++)
val.push_back((double)(*it)); //convert all to double
type = Tango::DEV_ULONG64;
} else if (attr_value->get_type() == Tango::DEV_STRING) {
*(attr_value) >> v_string;
val_string = *(v_string.begin()); //TODO: support string spectrum attrbutes
type = Tango::DEV_STRING;

Graziano Scalamera
committed
}
else {
ostringstream o;
o << "unknown type" << ends;
throw o.str();
}
}
/*void EventCallBack::init(event_list* e)

Graziano Scalamera
committed
{

Graziano Scalamera
committed
Tango::TimeVal gettime(void)
{
struct timeval tv;
struct timezone tz;
Tango::TimeVal t;
gettimeofday(&tv, &tz);
t.tv_sec = tv.tv_sec;
t.tv_usec = tv.tv_usec;
t.tv_nsec = 0;
return t;
}
/* EOF */