Newer
Older
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
1041
1042
1043
1044
1045
1046
1047
1048
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
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
//=============================================================================
//=============================================================================
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);

Graziano Scalamera
committed
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
} 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();
}
}
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)

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
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
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
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
} 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 */