Newer
Older

Graziano Scalamera
committed
/*
* event_table.h
*
* $Author: graziano $
*
* $Revision: 1.2 $
*
* $Log: event_table.h,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
*/
#ifndef EVENT_TABLE_H
#define EVENT_TABLE_H
#include <iostream>
#include <string>
#include <map>
#include <tango.h>
using namespace std;
#define INTERNAL_ERROR "internal_error"
#define TYPE_TANGO_ERR -2
#define TYPE_GENERIC_ERR -3
#define SUB_ERR -1
#define NOTHING 0
#define UPDATE_PROP 1

Graziano Scalamera
committed
class event;
class event_list;
class event_table;
class EventCallBack;
typedef vector<Tango::DevDouble> value_t;
/*
* basic event type
*/
class event {
public:
string name; /* event name */
string devname;
string attname;

Graziano Scalamera
committed
value_t value; /* event value */
int quality;
//Tango::DevErrorList errors;
string ex_reason;
string ex_desc;
string ex_origin;

Graziano Scalamera
committed
Tango::TimeVal ts; /* event timestamp */
int type, /* attribute data type */
counter, /* molteplicita' */
err_counter; /* molteplicita' errore */
//map<string, string> m_alarm;
vector<string> m_alarm;
bool valid; //TODO: old
bool first;//TODO: new
bool first_err;//TODO: new
//Tango::DeviceProxy *dp;
Tango::AttributeProxy *attr;
Tango::DevState evstate;
unsigned int event_id;
bool isZMQ;
EventCallBack *event_cb;
bool running;
bool paused;
bool stopped;
uint32_t okev_counter;
uint32_t okev_counter_freq;
timeval last_okev;
uint32_t nokev_counter;
uint32_t nokev_counter_freq;
timeval last_nokev;
timespec last_ev;

Graziano Scalamera
committed
vector<string> filter;
/*
* methods
*/
event(string& s, value_t& v, Tango::TimeVal& t);
event(string& s);
event() {}
~event() {}
void push_alarm(string& n);
void pop_alarm(string& n);
// bool event::operator==(const event& e); //TODO: gcc 4 problem??
bool operator==(const event& e);
// bool event::operator==(const string& s); //TODO: gcc 4 problem??
bool operator==(const string& s);

Graziano Scalamera
committed
protected:
private:
};
typedef struct basic_event_info_s {
string ev_name;
value_t value;
int quality;
//Tango::DevErrorList errors;
string ex_reason;
string ex_desc;
string ex_origin;

Graziano Scalamera
committed
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
int type;
Tango::TimeVal ts;
string msg;
} bei_t;
/*
* here the event callback handler will store the relevant
* events info coming from subscribed events for the
* processing thread
*/
class event_list : public omni_mutex {
public:
event_list(void): full(this), empty(this) {}
~event_list(void) {}
void push_back(bei_t& e);
const bei_t pop_front(void);
void clear(void);
list<bei_t> show(void);
protected:
list<bei_t> l_event;
private:
omni_condition full,
empty;
};
/*
* store all the events
*/
class event_table : public Tango::TangoMonitor, public Tango::LogAdapter {

Graziano Scalamera
committed
public:
event_table(Tango::DeviceImpl *s);//:Tango::LogAdapter(s) {mydev = s;}

Graziano Scalamera
committed
~event_table(void) {}

Graziano Scalamera
committed
void show(void);
unsigned int size(void);

Graziano Scalamera
committed
void init_proxy(void) throw(vector<string> &);
void free_proxy(void);
void subscribe(EventCallBack& ecb) throw(vector<string> &);//throw(string&);
void unsubscribe(void) throw(string&);
#endif
/**
* Add a new signal.
*/
void add(string &signame, vector<string> contexts);
void add(string &signame, vector<string> contexts, int to_do, bool start);
event *get_signal(string signame);
void stop(string &signame);
void remove(string &signame, bool stop);
void subscribe_events();
void unsubscribe_events();
void start(string &signame);
void start_all();

Graziano Scalamera
committed
void update_events(bei_t& e) throw(string&);
void update_property();
/**
* return number of signals to be subscribed
*/
int nb_sig_to_subscribe();
/**
* build a list of signal to set HDB device property
*/
void put_signal_property();
bool is_initialized();
bool get_if_stop();
void stop_thread();

Graziano Scalamera
committed
vector<event> v_event;
ReadersWritersLock veclock;
bool stop_it;
bool initialized;
int action;

Graziano Scalamera
committed
private:

Graziano Scalamera
committed
}; /* class event_table */
/*
* event callback
*/
class EventCallBack : public Tango::CallBack, public Tango::LogAdapter
{

Graziano Scalamera
committed
public:
EventCallBack(Tango::DeviceImpl *s);

Graziano Scalamera
committed
~EventCallBack(void);
void push_event(Tango::EventData* ev);

Graziano Scalamera
committed
void extract_values(Tango::DeviceAttribute *attr_value, vector<double> &val, int &type);
private:
//event_list* e_ptr;
Tango::DeviceImpl *mydev;

Graziano Scalamera
committed
};
/*
* utility function
*/
Tango::TimeVal gettime(void);
#endif /* EVENT_TABLE_H */