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
*
* $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
* Strada Statale 14 - km 163,5 in AREA Science Park
* 34012 Basovizza, Trieste ITALY
......@@ -32,8 +14,8 @@ static const char __FILE__rev[] = __FILE__ " $Revision: 1.3 $";
*/
cmd_thread::cmd_thread()
{
cout << __FILE__rev << endl;
cout << gettime().tv_sec << " cmd_thread::cmd_thread(): constructor... !" << endl;
TANGO_LOG << __FILE__rev << endl;
TANGO_LOG << gettime().tv_sec << " cmd_thread::cmd_thread(): constructor... !" << endl;
//mutex_dp = new omni_mutex::omni_mutex();
}
......@@ -42,7 +24,7 @@ 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;
}
......@@ -62,13 +44,13 @@ void cmd_thread::run(void *)
switch(cmd.cmd_id)
{
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;
case CMD_COMMAND:
{
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;
if(cmd.arg_b)
{
......@@ -82,7 +64,7 @@ void cmd_thread::run(void *)
}
else
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;
arg.cmd_id = CMD_RESPONSE;
arg.call_id = call_id;
......@@ -101,11 +83,11 @@ void cmd_thread::run(void *)
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;
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
{
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.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
......@@ -117,12 +99,12 @@ void cmd_thread::run(void *)
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;
dp = (Tango::DeviceProxy *)cmd.dp_add;
try {
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)
{
TangoSys_MemStream out_stream;
......@@ -136,7 +118,7 @@ void cmd_thread::run(void *)
}
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);
}
}
......@@ -145,19 +127,19 @@ void cmd_thread::run(void *)
}
/* 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;
}
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;
dp = (Tango::DeviceProxy *)cmd.dp_add;
try {
mutex_dp->lock();
resp = dp->command_inout_reply(cmd.cmd_id);
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)
{
TangoSys_MemStream out_stream;
......@@ -170,7 +152,7 @@ void cmd_thread::run(void *)
omni_thread::sleep(0,300000000); //0.2 s
}
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 *)
printf("cmd_thread::run(): catched unknown exception!!");
}
}
//cout << "alarm_thread::run(): returning" << endl;
//TANGO_LOG << "alarm_thread::run(): returning" << endl;
} /* cmd_thread::run() */
/*
......@@ -206,7 +188,7 @@ void cmd_list::push_back(cmd_t& cmd)
{
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{
l_cmd.push_back(cmd);
empty.signal();
......@@ -273,7 +255,7 @@ const cmd_t cmd_list::pop_front(void)
/*const*/ cmd_t cmd;
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();
this->unlock();
......
/*
*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
*
*
* cmd_thread.h
*
* copyleft: Sincrotrone Trieste S.C.p.A. di interesse nazionale
* Strada Statale 14 - km 163,5 in AREA Science Park
......@@ -41,7 +19,7 @@
#define CMD_THREAD_EXIT 3
#include <omnithread.h>
#include <tango.h>
#include <tango/tango.h>
#include "AlarmHandler.h"
struct cmd_t
......
This diff is collapsed.
/*
* 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
......@@ -19,8 +12,8 @@
#include <iostream>
#include <string>
#include <map>
#include <tango.h>
#include <atomic>
#include <tango/tango.h>
using namespace std;
......@@ -28,10 +21,25 @@ 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
constexpr int NOTHING = 0;
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_list;
......@@ -50,21 +58,20 @@ class event {
string attname;
value_t value; /* event value */
string value_string; //added for DevString attributes
int quality;
//Tango::DevErrorList errors;
int quality{Tango::ATTR_INVALID};
string ex_reason;
string ex_desc;
string ex_origin;
Tango::TimeVal ts; /* event timestamp */
int type, /* attribute data type */
read_size, /* attribute size of read part */
counter, /* molteplicita' */
err_counter; /* molteplicita' errore */
//map<string, string> m_alarm;
vector<string> m_alarm;
err_counter; /* molteplicita' errore */
long dim_x, dim_y;
alarm_list 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;
......@@ -88,8 +95,8 @@ class event {
event(string& s);
event() {}
~event() {}
void push_alarm(string& n);
void pop_alarm(string& n);
//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??
......@@ -109,6 +116,9 @@ typedef struct basic_event_info_s {
string ex_desc;
string ex_origin;
int type;
int read_size;
long dim_x;
long dim_y;
Tango::TimeVal ts;
string msg;
} bei_t;
......@@ -139,15 +149,16 @@ class event_list : public omni_mutex {
class event_table : public Tango::TangoMonitor, public Tango::LogAdapter {
public:
event_table(Tango::DeviceImpl *s);//:Tango::LogAdapter(s) {mydev = s;}
~event_table(void) {}
~event_table(void) {stop_thread();}
//void push_back(event e);
void show(void);
void show(list<string> &evl);
void summary(list<string> &evs);
unsigned int size(void);
#if 0
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&);
void subscribe(EventCallBack& ecb);
void unsubscribe(void);
#endif
/**
* Add a new signal.
......@@ -170,6 +181,7 @@ class event_table : public Tango::TangoMonitor, public Tango::LogAdapter {
* build a list of signal to set HDB device property
*/
void put_signal_property();
void check_signal_property();
bool is_initialized();
bool get_if_stop();
void stop_thread();
......@@ -177,7 +189,7 @@ class event_table : public Tango::TangoMonitor, public Tango::LogAdapter {
ReadersWritersLock veclock;
bool stop_it;
bool initialized;
int action;
atomic_int action;
private:
Tango::DeviceImpl *mydev;
}; /* class event_table */
......@@ -193,7 +205,7 @@ class EventCallBack : public Tango::CallBack, public Tango::LogAdapter
~EventCallBack(void);
void push_event(Tango::EventData* ev);
//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:
//event_list* e_ptr;
Tango::DeviceImpl *mydev;
......
This diff is collapsed.
......@@ -31,7 +31,7 @@
// This file is generated by POGO
// (Program Obviously used to Generate tango Object)
//=============================================================================
#include <tango.h>
#include <tango/tango.h>
// Check if crash reporting is used.
#if defined(ENABLE_CRASH_REPORT)
......@@ -43,8 +43,15 @@
DECLARE_CRASH_HANDLER;
#ifndef TANGO_LOG
#define TANGO_LOG cout
#endif
int main(int argc,char *argv[])
{
using std::endl;
using std::bad_alloc;
INSTALL_CRASH_HANDLER
try
{
......@@ -59,20 +66,20 @@ int main(int argc,char *argv[])
// Run the endless loop
//----------------------------------------
cout << "Ready to accept request" << endl;
TANGO_LOG << "Ready to accept request" << endl;
tg->server_run();
}
catch (bad_alloc &)
{
cout << "Can't allocate memory to store device object !!!" << endl;
cout << "Exiting" << endl;
TANGO_LOG << "Can't allocate memory to store device object !!!" << endl;
TANGO_LOG << "Exiting" << endl;
}
catch (CORBA::Exception &e)
{
Tango::Except::print_exception(e);
cout << "Received a CORBA_Exception" << endl;
cout << "Exiting" << endl;
TANGO_LOG << "Received a CORBA_Exception" << endl;
TANGO_LOG << "Exiting" << endl;
}
Tango::Util::instance()->server_cleanup();
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)