From 236fefe1b5cac1e6ba246352a81e81d8f9300e07 Mon Sep 17 00:00:00 2001
From: gscalamera <graziano.scalamera@elettra.eu>
Date: Mon, 20 Apr 2020 21:40:18 +0200
Subject: [PATCH] Fix wrong state in alarm attribute and GetAlarmInfo command
 when shelving ands

---
 src/AlarmHandler.cpp |  2 +-
 src/alarm_table.cpp  | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/AlarmHandler.cpp b/src/AlarmHandler.cpp
index 2099760..bb84f30 100644
--- a/src/AlarmHandler.cpp
+++ b/src/AlarmHandler.cpp
@@ -3978,7 +3978,7 @@ bool AlarmHandler::do_alarm_eval(string alm_name, string ev_name, Tango::TimeVal
 void AlarmHandler::timer_update()
 {
 	bool changed=true;
-	DEBUG_STREAM << "AlarmHandler::timer_update(): entering..." << endl;
+	//DEBUG_STREAM << "AlarmHandler::timer_update(): entering..." << endl;
 	try {
 		changed=alarms.timer_update();
 	} catch(string & e)
diff --git a/src/alarm_table.cpp b/src/alarm_table.cpp
index d785afa..fc57f58 100644
--- a/src/alarm_table.cpp
+++ b/src/alarm_table.cpp
@@ -531,7 +531,7 @@ bool alarm_table::timer_update()
 		bool status_on_delay=false;
 		bool status_off_delay=false;
 		if(i->second.on_delay == 0 && i->second.off_delay == 0 && !i->second.shelved && i->second.silenced <=0)
-			continue;	//if not enabled on or off delay, nothing to do in timer
+			continue;	//if not enabled on or off delay or not shelved, nothing to do in timer
 		if(i->second.on_delay > 0)		//if enabled on delay
 			status_on_delay = (i->second.on_counter >= 1) && ((ts.tv_sec - i->second.on_delay) > i->second.ts_on_delay.tv_sec);	//waiting for on delay has passed
 		if(i->second.off_delay > 0)		//if enabled off delay
@@ -561,7 +561,10 @@ bool alarm_table::timer_update()
 		//if just ended silence time, set ret_changed to true so to push events
 		//TODO: not interested in executing commands?
 		if(old_silenced>0 && i->second.silenced == 0)
+		{
 			ret_changed = true;
+
+		}
 		//if status changed:
 		// - from S_NORMAL to S_ALARM considering also on delay
 		//or
@@ -570,6 +573,11 @@ bool alarm_table::timer_update()
 		// - from shelved to not shelved
 		if((status_on_delay && (i->second.stat == S_NORMAL)) || (status_off_delay && (i->second.stat == S_ALARM)) || (old_shelved && !i->second.shelved))
 		{
+			if(old_shelved && !i->second.shelved)	//TODO: ok to execute on command and off command after shelving ends?
+			{
+				status_on_delay = i->second.stat == S_ALARM;
+				status_off_delay = i->second.stat == S_NORMAL;
+			}
 			ret_changed = true;
 
 			if(status_on_delay)
-- 
GitLab