Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cs/ds/alarm-handler
  • francesco.tripaldi/alarm-handler
2 results
Show changes
Showing
with 1154 additions and 289 deletions
/* /*
* cmd_thread.cpp * cmd_thread.cpp
* *
* $Author: claudio $
*
* $Revision: 1.3 $
*
* $Log: cmd_thread.cpp,v $
* Revision 1.3 2015-07-21 13:40:59 claudio
* minor cleanups
*
* Revision 1.2 2008-11-17 13:13:21 graziano
* command action can be: without arguments or with string argument
*
* Revision 1.1 2008/11/10 10:53:31 graziano
* thread for execution of commands
*
*
*
*
*
* copyleft: Sincrotrone Trieste S.C.p.A. di interesse nazionale * copyleft: Sincrotrone Trieste S.C.p.A. di interesse nazionale
* Strada Statale 14 - km 163,5 in AREA Science Park * Strada Statale 14 - km 163,5 in AREA Science Park
* 34012 Basovizza, Trieste ITALY * 34012 Basovizza, Trieste ITALY
...@@ -32,8 +14,8 @@ static const char __FILE__rev[] = __FILE__ " $Revision: 1.3 $"; ...@@ -32,8 +14,8 @@ static const char __FILE__rev[] = __FILE__ " $Revision: 1.3 $";
*/ */
cmd_thread::cmd_thread() cmd_thread::cmd_thread()
{ {
cout << __FILE__rev << endl; TANGO_LOG << __FILE__rev << endl;
cout << gettime().tv_sec << " cmd_thread::cmd_thread(): constructor... !" << endl; TANGO_LOG << gettime().tv_sec << " cmd_thread::cmd_thread(): constructor... !" << endl;
//mutex_dp = new omni_mutex::omni_mutex(); //mutex_dp = new omni_mutex::omni_mutex();
} }
...@@ -42,7 +24,7 @@ cmd_thread::cmd_thread() ...@@ -42,7 +24,7 @@ cmd_thread::cmd_thread()
*/ */
cmd_thread::~cmd_thread() cmd_thread::~cmd_thread()
{ {
cout << gettime().tv_sec << " cmd_thread::~cmd_thread(): delete device entering..." << endl; TANGO_LOG << gettime().tv_sec << " cmd_thread::~cmd_thread(): delete device entering..." << endl;
//delete mutex_dp; //delete mutex_dp;
} }
...@@ -62,13 +44,13 @@ void cmd_thread::run(void *) ...@@ -62,13 +44,13 @@ void cmd_thread::run(void *)
switch(cmd.cmd_id) switch(cmd.cmd_id)
{ {
case CMD_THREAD_EXIT: case CMD_THREAD_EXIT:
cout << gettime().tv_sec << " cmd_thread::run(): received command THREAD_EXIT -> exiting..." << endl; TANGO_LOG << gettime().tv_sec << " cmd_thread::run(): received command THREAD_EXIT -> exiting..." << endl;
return; return;
case CMD_COMMAND: case CMD_COMMAND:
{ {
try { try {
cout << gettime().tv_sec << " cmd_thread::run(): COMMAND ... action=" << cmd.arg_s3 << endl; TANGO_LOG << gettime().tv_sec << " cmd_thread::run(): COMMAND ... action=" << cmd.arg_s3 << endl;
dp = (Tango::DeviceProxy *)cmd.dp_add; dp = (Tango::DeviceProxy *)cmd.dp_add;
if(cmd.arg_b) if(cmd.arg_b)
{ {
...@@ -82,7 +64,7 @@ void cmd_thread::run(void *) ...@@ -82,7 +64,7 @@ void cmd_thread::run(void *)
} }
else else
call_id = dp->command_inout_asynch(cmd.arg_s2); call_id = dp->command_inout_asynch(cmd.arg_s2);
cout << gettime().tv_sec << " cmd_thread::run() executed action: " << cmd.arg_s3 << " !!! call_id=" << call_id << endl; TANGO_LOG << gettime().tv_sec << " cmd_thread::run() executed action: " << cmd.arg_s3 << " !!! call_id=" << call_id << endl;
/*cmd_t arg; /*cmd_t arg;
arg.cmd_id = CMD_RESPONSE; arg.cmd_id = CMD_RESPONSE;
arg.call_id = call_id; arg.call_id = call_id;
...@@ -101,11 +83,11 @@ void cmd_thread::run(void *) ...@@ -101,11 +83,11 @@ void cmd_thread::run(void *)
if(err.find("is not yet arrived") == string::npos) //TODO: change this!! if(err.find("is not yet arrived") == string::npos) //TODO: change this!!
{ {
out_stream << "Failed to execute action " << cmd.arg_s3 << ", err=" << e.errors[0].desc << ends; out_stream << "Failed to execute action " << cmd.arg_s3 << ", err=" << e.errors[0].desc << ends;
cout << gettime().tv_sec << " cmd_thread::run() ERROR: " << out_stream.str() << endl; TANGO_LOG << gettime().tv_sec << " cmd_thread::run() ERROR: " << out_stream.str() << endl;
} }
else else
{ {
cout << gettime().tv_sec << " cmd_thread::run() exception 'is not yet arrived': pushing request of response, call_id=" << call_id << endl; TANGO_LOG << gettime().tv_sec << " cmd_thread::run() exception 'is not yet arrived': pushing request of response, call_id=" << call_id << endl;
cmd.cmd_id = CMD_RESPONSE; //if no exception till now push in list request of response cmd.cmd_id = CMD_RESPONSE; //if no exception till now push in list request of response
cmd.call_id = call_id; //if no exception till now push in list request of response cmd.call_id = call_id; //if no exception till now push in list request of response
list.push_back(cmd); //if no exception till now push in list request of response list.push_back(cmd); //if no exception till now push in list request of response
...@@ -117,12 +99,12 @@ void cmd_thread::run(void *) ...@@ -117,12 +99,12 @@ void cmd_thread::run(void *)
case CMD_RESPONSE: case CMD_RESPONSE:
{ {
//cout << gettime().tv_sec << " cmd_thread::run(): RESPONSE WAKE UP... action=" << cmd.arg_s3 << " call_id=" << cmd.call_id << endl; //TANGO_LOG << gettime().tv_sec << " cmd_thread::run(): RESPONSE WAKE UP... action=" << cmd.arg_s3 << " call_id=" << cmd.call_id << endl;
Tango::DeviceData resp; Tango::DeviceData resp;
dp = (Tango::DeviceProxy *)cmd.dp_add; dp = (Tango::DeviceProxy *)cmd.dp_add;
try { try {
resp = dp->command_inout_reply(cmd.call_id); resp = dp->command_inout_reply(cmd.call_id);
cout << gettime().tv_sec << " cmd_thread::run() RECEIVED response to action " << cmd.arg_s3 << endl; TANGO_LOG << gettime().tv_sec << " cmd_thread::run() RECEIVED response to action " << cmd.arg_s3 << endl;
} catch(Tango::DevFailed &e) } catch(Tango::DevFailed &e)
{ {
TangoSys_MemStream out_stream; TangoSys_MemStream out_stream;
...@@ -136,7 +118,7 @@ void cmd_thread::run(void *) ...@@ -136,7 +118,7 @@ void cmd_thread::run(void *)
} }
else else
{ {
cout << gettime().tv_sec << " cmd_thread::run() " << out_stream.str() << endl; TANGO_LOG << gettime().tv_sec << " cmd_thread::run() " << out_stream.str() << endl;
Tango::Except::print_exception(e); Tango::Except::print_exception(e);
} }
} }
...@@ -145,19 +127,19 @@ void cmd_thread::run(void *) ...@@ -145,19 +127,19 @@ void cmd_thread::run(void *)
} }
/* if(cmd.arg_s == CMD_THREAD_EXIT) /* if(cmd.arg_s == CMD_THREAD_EXIT)
{ {
cout << gettime().tv_sec << " cmd_thread::run(): received command THREAD_EXIT -> exiting..." << endl; TANGO_LOG << gettime().tv_sec << " cmd_thread::run(): received command THREAD_EXIT -> exiting..." << endl;
return; return;
} }
else else
{ {
cout << gettime().tv_sec << " cmd_thread::run(): WAKE UP... action=" << cmd.arg_s << endl; TANGO_LOG << gettime().tv_sec << " cmd_thread::run(): WAKE UP... action=" << cmd.arg_s << endl;
Tango::DeviceData resp; Tango::DeviceData resp;
dp = (Tango::DeviceProxy *)cmd.dp_add; dp = (Tango::DeviceProxy *)cmd.dp_add;
try { try {
mutex_dp->lock(); mutex_dp->lock();
resp = dp->command_inout_reply(cmd.cmd_id); resp = dp->command_inout_reply(cmd.cmd_id);
mutex_dp->unlock(); mutex_dp->unlock();
cout << gettime().tv_sec << " cmd_thread::run() received response to action " << cmd.arg_s << endl; TANGO_LOG << gettime().tv_sec << " cmd_thread::run() received response to action " << cmd.arg_s << endl;
} catch(Tango::DevFailed &e) } catch(Tango::DevFailed &e)
{ {
TangoSys_MemStream out_stream; TangoSys_MemStream out_stream;
...@@ -170,7 +152,7 @@ void cmd_thread::run(void *) ...@@ -170,7 +152,7 @@ void cmd_thread::run(void *)
omni_thread::sleep(0,300000000); //0.2 s omni_thread::sleep(0,300000000); //0.2 s
} }
else else
cout << gettime().tv_sec << " cmd_thread::run() " << out_stream.str() << endl; TANGO_LOG << gettime().tv_sec << " cmd_thread::run() " << out_stream.str() << endl;
} }
}*/ }*/
...@@ -196,7 +178,7 @@ void cmd_thread::run(void *) ...@@ -196,7 +178,7 @@ void cmd_thread::run(void *)
printf("cmd_thread::run(): catched unknown exception!!"); printf("cmd_thread::run(): catched unknown exception!!");
} }
} }
//cout << "alarm_thread::run(): returning" << endl; //TANGO_LOG << "alarm_thread::run(): returning" << endl;
} /* cmd_thread::run() */ } /* cmd_thread::run() */
/* /*
...@@ -206,7 +188,7 @@ void cmd_list::push_back(cmd_t& cmd) ...@@ -206,7 +188,7 @@ void cmd_list::push_back(cmd_t& cmd)
{ {
this->lock(); this->lock();
//cout << "cmd_list::push_back: cmd_id=" << cmd.cmd_id << " call_id=" << cmd.call_id << endl; //TANGO_LOG << "cmd_list::push_back: cmd_id=" << cmd.cmd_id << " call_id=" << cmd.call_id << endl;
try{ try{
l_cmd.push_back(cmd); l_cmd.push_back(cmd);
empty.signal(); empty.signal();
...@@ -273,7 +255,7 @@ const cmd_t cmd_list::pop_front(void) ...@@ -273,7 +255,7 @@ const cmd_t cmd_list::pop_front(void)
/*const*/ cmd_t cmd; /*const*/ cmd_t cmd;
cmd = *(l_cmd.begin()); cmd = *(l_cmd.begin());
//cout << "cmd_list::pop_front: " << e.name << " value=" << e.value[0] << endl; //TANGO_LOG << "cmd_list::pop_front: " << e.name << " value=" << e.value[0] << endl;
l_cmd.pop_front(); l_cmd.pop_front();
this->unlock(); this->unlock();
......
/* /*
*cmd_thread.h * cmd_thread.h
*
* $Author: graziano $
*
* $Revision: 1.2 $
*
* $Log: cmd_thread.h,v $
* Revision 1.2 2008-11-17 13:10:36 graziano
* command action can be: without arguments or with string argument
*
* Revision 1.1 2008/11/10 10:53:31 graziano
* thread for execution of commands
*
* Revision 1.2 2008/10/07 14:03:07 graziano
* added handling of multi axis groups and spindle groups
*
* Revision 1.1 2008/09/30 09:46:32 graziano
* first version
*
* Revision 1.3 2008/04/23 15:00:57 graziano
* small code cleanings
*
*
* *
* copyleft: Sincrotrone Trieste S.C.p.A. di interesse nazionale * copyleft: Sincrotrone Trieste S.C.p.A. di interesse nazionale
* Strada Statale 14 - km 163,5 in AREA Science Park * Strada Statale 14 - km 163,5 in AREA Science Park
...@@ -41,7 +19,7 @@ ...@@ -41,7 +19,7 @@
#define CMD_THREAD_EXIT 3 #define CMD_THREAD_EXIT 3
#include <omnithread.h> #include <omnithread.h>
#include <tango.h> #include <tango/tango.h>
#include "AlarmHandler.h" #include "AlarmHandler.h"
struct cmd_t struct cmd_t
......
This diff is collapsed.
/* /*
* event_table.h * event_table.h
* *
* $Author: graziano $
*
* $Revision: 1.2 $
*
* $Log: event_table.h,v $
*
*
* copyleft: Sincrotrone Trieste S.C.p.A. di interesse nazionale * copyleft: Sincrotrone Trieste S.C.p.A. di interesse nazionale
* Strada Statale 14 - km 163,5 in AREA Science Park * Strada Statale 14 - km 163,5 in AREA Science Park
* 34012 Basovizza, Trieste ITALY * 34012 Basovizza, Trieste ITALY
...@@ -19,8 +12,8 @@ ...@@ -19,8 +12,8 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <map> #include <map>
#include <atomic>
#include <tango.h> #include <tango/tango.h>
using namespace std; using namespace std;
...@@ -28,10 +21,25 @@ using namespace std; ...@@ -28,10 +21,25 @@ using namespace std;
#define INTERNAL_ERROR "internal_error" #define INTERNAL_ERROR "internal_error"
#define TYPE_TANGO_ERR -2 #define TYPE_TANGO_ERR -2
#define TYPE_GENERIC_ERR -3 #define TYPE_GENERIC_ERR -3
#define SUB_ERR -1 #define SUB_ERR -1
#define NOTHING 0 constexpr int NOTHING = 0;
#define UPDATE_PROP 1 constexpr int UPDATE_PROP = 1;
class alarm_list {
public:
alarm_list(void) {}
alarm_list(const alarm_list& la) {l_alarm = la.l_alarm;}
~alarm_list(void) {}
void push(string& a);
void pop(const string &a);
void clear(void);
list<string> show(void);
bool empty();
alarm_list& operator=(const alarm_list& other) {if (this != &other) {l_alarm = other.l_alarm;} return *this;}
protected:
list<string> l_alarm;
omni_mutex l;
};
class event; class event;
class event_list; class event_list;
...@@ -50,21 +58,20 @@ class event { ...@@ -50,21 +58,20 @@ class event {
string attname; string attname;
value_t value; /* event value */ value_t value; /* event value */
string value_string; //added for DevString attributes string value_string; //added for DevString attributes
int quality; int quality{Tango::ATTR_INVALID};
//Tango::DevErrorList errors;
string ex_reason; string ex_reason;
string ex_desc; string ex_desc;
string ex_origin; string ex_origin;
Tango::TimeVal ts; /* event timestamp */ Tango::TimeVal ts; /* event timestamp */
int type, /* attribute data type */ int type, /* attribute data type */
read_size, /* attribute size of read part */
counter, /* molteplicita' */ counter, /* molteplicita' */
err_counter; /* molteplicita' errore */ err_counter; /* molteplicita' errore */
//map<string, string> m_alarm; long dim_x, dim_y;
vector<string> m_alarm; alarm_list m_alarm;
bool valid; //TODO: old bool valid; //TODO: old
bool first;//TODO: new bool first;//TODO: new
bool first_err;//TODO: new bool first_err;//TODO: new
//Tango::DeviceProxy *dp;
Tango::AttributeProxy *attr; Tango::AttributeProxy *attr;
Tango::DevState evstate; Tango::DevState evstate;
unsigned int event_id; unsigned int event_id;
...@@ -88,8 +95,8 @@ class event { ...@@ -88,8 +95,8 @@ class event {
event(string& s); event(string& s);
event() {} event() {}
~event() {} ~event() {}
void push_alarm(string& n); //void push_alarm(string& n);
void pop_alarm(string& n); //void pop_alarm(string& n);
// bool event::operator==(const event& e); //TODO: gcc 4 problem?? // bool event::operator==(const event& e); //TODO: gcc 4 problem??
bool operator==(const event& e); bool operator==(const event& e);
// bool event::operator==(const string& s); //TODO: gcc 4 problem?? // bool event::operator==(const string& s); //TODO: gcc 4 problem??
...@@ -109,6 +116,9 @@ typedef struct basic_event_info_s { ...@@ -109,6 +116,9 @@ typedef struct basic_event_info_s {
string ex_desc; string ex_desc;
string ex_origin; string ex_origin;
int type; int type;
int read_size;
long dim_x;
long dim_y;
Tango::TimeVal ts; Tango::TimeVal ts;
string msg; string msg;
} bei_t; } bei_t;
...@@ -139,15 +149,16 @@ class event_list : public omni_mutex { ...@@ -139,15 +149,16 @@ class event_list : public omni_mutex {
class event_table : public Tango::TangoMonitor, public Tango::LogAdapter { class event_table : public Tango::TangoMonitor, public Tango::LogAdapter {
public: public:
event_table(Tango::DeviceImpl *s);//:Tango::LogAdapter(s) {mydev = s;} event_table(Tango::DeviceImpl *s);//:Tango::LogAdapter(s) {mydev = s;}
~event_table(void) {} ~event_table(void) {stop_thread();}
//void push_back(event e); //void push_back(event e);
void show(void); void show(list<string> &evl);
void summary(list<string> &evs);
unsigned int size(void); unsigned int size(void);
#if 0 #if 0
void init_proxy(void) throw(vector<string> &); void init_proxy(void) throw(vector<string> &);
void free_proxy(void); void free_proxy(void);
void subscribe(EventCallBack& ecb) throw(vector<string> &);//throw(string&); void subscribe(EventCallBack& ecb);
void unsubscribe(void) throw(string&); void unsubscribe(void);
#endif #endif
/** /**
* Add a new signal. * Add a new signal.
...@@ -170,6 +181,7 @@ class event_table : public Tango::TangoMonitor, public Tango::LogAdapter { ...@@ -170,6 +181,7 @@ class event_table : public Tango::TangoMonitor, public Tango::LogAdapter {
* build a list of signal to set HDB device property * build a list of signal to set HDB device property
*/ */
void put_signal_property(); void put_signal_property();
void check_signal_property();
bool is_initialized(); bool is_initialized();
bool get_if_stop(); bool get_if_stop();
void stop_thread(); void stop_thread();
...@@ -177,7 +189,7 @@ class event_table : public Tango::TangoMonitor, public Tango::LogAdapter { ...@@ -177,7 +189,7 @@ class event_table : public Tango::TangoMonitor, public Tango::LogAdapter {
ReadersWritersLock veclock; ReadersWritersLock veclock;
bool stop_it; bool stop_it;
bool initialized; bool initialized;
int action; atomic_int action;
private: private:
Tango::DeviceImpl *mydev; Tango::DeviceImpl *mydev;
}; /* class event_table */ }; /* class event_table */
...@@ -193,7 +205,7 @@ class EventCallBack : public Tango::CallBack, public Tango::LogAdapter ...@@ -193,7 +205,7 @@ class EventCallBack : public Tango::CallBack, public Tango::LogAdapter
~EventCallBack(void); ~EventCallBack(void);
void push_event(Tango::EventData* ev); void push_event(Tango::EventData* ev);
//void init(event_list* e); //void init(event_list* e);
void extract_values(Tango::DeviceAttribute *attr_value, vector<double> &val, string &val_string, int &type); void extract_values(Tango::DeviceAttribute *attr_value, vector<double> &val, string &val_string, int &type, int &read_size, long &dim_x, long &dim_y);
private: private:
//event_list* e_ptr; //event_list* e_ptr;
Tango::DeviceImpl *mydev; Tango::DeviceImpl *mydev;
......
This diff is collapsed.
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
// This file is generated by POGO // This file is generated by POGO
// (Program Obviously used to Generate tango Object) // (Program Obviously used to Generate tango Object)
//============================================================================= //=============================================================================
#include <tango.h> #include <tango/tango.h>
// Check if crash reporting is used. // Check if crash reporting is used.
#if defined(ENABLE_CRASH_REPORT) #if defined(ENABLE_CRASH_REPORT)
...@@ -43,8 +43,15 @@ ...@@ -43,8 +43,15 @@
DECLARE_CRASH_HANDLER; DECLARE_CRASH_HANDLER;
#ifndef TANGO_LOG
#define TANGO_LOG cout
#endif
int main(int argc,char *argv[]) int main(int argc,char *argv[])
{ {
using std::endl;
using std::bad_alloc;
INSTALL_CRASH_HANDLER INSTALL_CRASH_HANDLER
try try
{ {
...@@ -59,20 +66,20 @@ int main(int argc,char *argv[]) ...@@ -59,20 +66,20 @@ int main(int argc,char *argv[])
// Run the endless loop // Run the endless loop
//---------------------------------------- //----------------------------------------
cout << "Ready to accept request" << endl; TANGO_LOG << "Ready to accept request" << endl;
tg->server_run(); tg->server_run();
} }
catch (bad_alloc &) catch (bad_alloc &)
{ {
cout << "Can't allocate memory to store device object !!!" << endl; TANGO_LOG << "Can't allocate memory to store device object !!!" << endl;
cout << "Exiting" << endl; TANGO_LOG << "Exiting" << endl;
} }
catch (CORBA::Exception &e) catch (CORBA::Exception &e)
{ {
Tango::Except::print_exception(e); Tango::Except::print_exception(e);
cout << "Received a CORBA_Exception" << endl; TANGO_LOG << "Received a CORBA_Exception" << endl;
cout << "Exiting" << endl; TANGO_LOG << "Exiting" << endl;
} }
Tango::Util::instance()->server_cleanup(); Tango::Util::instance()->server_cleanup();
return(0); return(0);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
NAME_SRV = testdevice-srv
CXXFLAGS =
LDFLAGS =
include ./Make-9.3.4.in
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
cmake_minimum_required(VERSION 3.2)
# source files
set(SRC_FILES ${SRC_FILES}
${CMAKE_CURRENT_SOURCE_DIR}/TestDevice.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TestDeviceClass.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TestDeviceStateMachine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ClassFactory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
PARENT_SCOPE)