Newer
Older

Graziano Scalamera
committed
/*
* event_table.cpp
*
* $Author: graziano $
*
* $Revision: 1.5 $
*
* $Log: event_table.cpp,v $
*
*
* copyleft: Sincrotrone Trieste S.C.p.A. di interesse nazionale
* Strada Statale 14 - km 163,5 in AREA Science Park
* 34012 Basovizza, Trieste ITALY
*/
#include <sys/time.h>
#include <tango.h>
#include "event_table.h"
#include "alarm_grammar.h"
//for get_event_system_for_event_id, to know if ZMQ
#include <eventconsumer.h>

Graziano Scalamera
committed
static const char __FILE__rev[] = __FILE__ " $Revision: 1.5 $";
/*
* event_list class methods
*/
void event_list::push_back(bei_t& e)
{
this->lock();
try{
l_event.push_back(e);
empty.signal();
}
catch(omni_thread_fatal& ex)
{
ostringstream err;
err << "omni_thread_fatal exception signaling omni_condition, err=" << ex.error;

Graziano Scalamera
committed
//WARN_STREAM << "event_list::push_back(): " << err.str() << endl;
printf("event_list::push_back(): %s", err.str().c_str());
}
catch(Tango::DevFailed& ex)
{
ostringstream err;
err << "exception signaling omni_condition: '" << ex.errors[0].desc << "'";

Graziano Scalamera
committed
//WARN_STREAM << "event_list::push_back(): " << err.str() << endl;
printf("event_list::push_back: %s", err.str().c_str());
Tango::Except::print_exception(ex);
}
catch(...)
{
//WARN_STREAM << "event_list::push_back(): catched unknown exception!!" << endl;
printf("event_list::push_back(): catched unknown exception signaling omni_condition!!");
}
this->unlock();
}
const bei_t event_list::pop_front(void)
{
this->lock();
//omni_mutex_lock l((omni_mutex)this); //call automatically unlock on destructor and on exception
try{
while (l_event.empty() == true)
empty.wait(); //wait release mutex while is waiting, then reacquire when signaled
}
catch(omni_thread_fatal& ex)
{
ostringstream err;
err << "omni_thread_fatal exception waiting on omni_condition, err=" << ex.error;

Graziano Scalamera
committed
//WARN_STREAM << "event_list::pop_front(): " << err.str() << endl;
printf("event_list::pop_front(): %s", err.str().c_str());
bei_t e;
this->unlock();
sleep(1);
return(e);
}
catch(Tango::DevFailed& ex)
{
ostringstream err;
err << "exception waiting on omni_condition: '" << ex.errors[0].desc << "'";

Graziano Scalamera
committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//WARN_STREAM << "event_list::pop_front(): " << err.str() << endl;
printf("event_list::pop_front: %s", err.str().c_str());
Tango::Except::print_exception(ex);
bei_t e;
this->unlock();
sleep(1);
return(e);
}
catch(...)
{
//WARN_STREAM << "event_list::pop_front(): catched unknown exception!!" << endl;
printf("event_list::pop_front(): catched unknown exception waiting on omni_condition!!");
bei_t e;
this->unlock();
sleep(1);
return(e);
}
/*const*/ bei_t e;
e = *(l_event.begin());
l_event.pop_front();
this->unlock();
return(e);
}
void event_list::clear(void)
{
//this->lock();
l_event.clear();
//this->unlock();
}
list<bei_t> event_list::show(void)
{
list<bei_t> el;
this->lock();
el = l_event;
this->unlock();
return(el);
}
size_t event_list::size(void)
{
size_t res;
this->lock();
res = l_event.size();
this->unlock();
return(res);
}

Graziano Scalamera
committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* alarm_list class methods
*/
void alarm_list::push(string& a)
{
l.lock();
l_alarm.push_back(a);
l.unlock();
}
void alarm_list::pop(const string& a)
{
l.lock();
list<string>::iterator it = find(l_alarm.begin(), l_alarm.end(), a);
if(it != l_alarm.end())
l_alarm.erase(it);
else
cout << "alarm_list::"<<__func__<< ": ALARM '"<< a << "' NOT FOUND!"<< endl;
l.unlock();
return;
}
void alarm_list::clear(void)
{
l.lock();
l_alarm.clear();
l.unlock();
}
list<string> alarm_list::show(void)
{
list<string> al;
l.lock();
al = l_alarm;
l.unlock();
return(al);
}
bool alarm_list::empty(void)
{
bool res;
l.lock();
res = l_alarm.empty();
l.unlock();
return(res);
}

Graziano Scalamera
committed
/*
* event class methods
*/
event::event(string& s, value_t& v, Tango::TimeVal& t) : \
name(s), value(v), ts(t)
{
const char *c = name.c_str();
int j = 0;
int num_slashes=3; //not FQDN
if(name.find("tango://") != string::npos) //FQDN!!
num_slashes = 6;
while (*c) {
Loading full blame...