Fix a warning reported by -Wextra

/home/peterke/DEV/zoneminder/src/zm_monitor.h: In member function ‘Monitor::TriggerState Monitor::GetTriggerState() const’:
/home/peterke/DEV/zoneminder/src/zm_monitor.h:499:76: warning: enumerated and non-enumerated type in conditional expression [-Wextra]
  499 |   TriggerState GetTriggerState() const { return (TriggerState)(trigger_data?trigger_data->trigger_state:TRIGGER_CANCEL); }
      |                                                                ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This commit is contained in:
Peter Keresztes Schmidt 2021-02-27 01:27:58 +01:00
parent 814953b331
commit 6a47780f60
3 changed files with 18 additions and 14 deletions

View File

@ -992,7 +992,7 @@ bool Monitor::connect() {
shared_data->alarm_cause[0] = 0;
shared_data->last_frame_score = 0;
trigger_data->size = sizeof(TriggerData);
trigger_data->trigger_state = TRIGGER_CANCEL;
trigger_data->trigger_state = TriggerState::TRIGGER_CANCEL;
trigger_data->trigger_score = 0;
trigger_data->trigger_cause[0] = 0;
trigger_data->trigger_text[0] = 0;
@ -1295,18 +1295,18 @@ void Monitor::UpdateAdaptiveSkip() {
}
void Monitor::ForceAlarmOn( int force_score, const char *force_cause, const char *force_text ) {
trigger_data->trigger_state = TRIGGER_ON;
trigger_data->trigger_state = TriggerState::TRIGGER_ON;
trigger_data->trigger_score = force_score;
strncpy(trigger_data->trigger_cause, force_cause, sizeof(trigger_data->trigger_cause)-1);
strncpy(trigger_data->trigger_text, force_text, sizeof(trigger_data->trigger_text)-1);
}
void Monitor::ForceAlarmOff() {
trigger_data->trigger_state = TRIGGER_OFF;
trigger_data->trigger_state = TriggerState::TRIGGER_OFF;
}
void Monitor::CancelForced() {
trigger_data->trigger_state = TRIGGER_CANCEL;
trigger_data->trigger_state = TriggerState::TRIGGER_CANCEL;
}
void Monitor::actionReload() {
@ -1795,14 +1795,14 @@ bool Monitor::Analyse() {
bool signal_change = (signal != last_signal);
Debug(3, "Motion detection is enabled signal(%d) signal_change(%d) trigger state(%d) image index %d",
signal, signal_change, trigger_data->trigger_state, snap->image_index);
signal, signal_change, int(trigger_data->trigger_state), snap->image_index);
// Need to guard around event creation/deletion from Reload()
std::lock_guard<std::mutex> lck(event_mutex);
// if we have been told to be OFF, then we are off and don't do any processing.
if ( trigger_data->trigger_state != TRIGGER_OFF ) {
Debug(4, "Trigger not OFF state is (%d)", trigger_data->trigger_state);
if ( trigger_data->trigger_state != TriggerState::TRIGGER_OFF ) {
Debug(4, "Trigger not OFF state is (%d)", int(trigger_data->trigger_state));
int score = 0;
// Ready means that we have captured the warmup # of frames
if ( !Ready() ) {
@ -1816,7 +1816,7 @@ bool Monitor::Analyse() {
Event::StringSetMap noteSetMap;
// Specifically told to be on. Setting the score here will trigger the alarm.
if ( trigger_data->trigger_state == TRIGGER_ON ) {
if ( trigger_data->trigger_state == TriggerState::TRIGGER_ON ) {
score += trigger_data->trigger_score;
Debug(1, "Triggered on score += %d => %d", trigger_data->trigger_score, score);
if ( !event ) {
@ -2200,7 +2200,7 @@ bool Monitor::Analyse() {
closeEvent();
}
shared_data->state = state = IDLE;
trigger_data->trigger_state = TRIGGER_CANCEL;
trigger_data->trigger_state = TriggerState::TRIGGER_CANCEL;
} // end if ( trigger_data->trigger_state != TRIGGER_OFF )
if ( event ) event->AddPacket(snap);

View File

@ -157,12 +157,16 @@ protected:
} SharedData;
typedef enum { TRIGGER_CANCEL, TRIGGER_ON, TRIGGER_OFF } TriggerState;
enum TriggerState : uint32 {
TRIGGER_CANCEL,
TRIGGER_ON,
TRIGGER_OFF
};
/* sizeof(TriggerData) expected to be 560 on 32bit & and 64bit */
typedef struct {
uint32_t size;
uint32_t trigger_state;
TriggerState trigger_state;
uint32_t trigger_score;
uint32_t padding;
char trigger_cause[32];
@ -496,7 +500,7 @@ public:
void ForceAlarmOn( int force_score, const char *force_case, const char *force_text="" );
void ForceAlarmOff();
void CancelForced();
TriggerState GetTriggerState() const { return (TriggerState)(trigger_data?trigger_data->trigger_state:TRIGGER_CANCEL); }
TriggerState GetTriggerState() const { return trigger_data ? trigger_data->trigger_state : TRIGGER_CANCEL; }
inline time_t getStartupTime() const { return shared_data->startup_time; }
inline void setStartupTime( time_t p_time ) { shared_data->startup_time = p_time; }
void get_ref_image();

View File

@ -270,8 +270,8 @@ void MonitorStream::processCommand(const CmdMsg *msg) {
status_data.analysis_fps = monitor->get_analysis_fps();
status_data.state = monitor->shared_data->state;
//status_data.enabled = monitor->shared_data->active;
status_data.enabled = monitor->trigger_data->trigger_state!=Monitor::TRIGGER_OFF;
status_data.forced = monitor->trigger_data->trigger_state==Monitor::TRIGGER_ON;
status_data.enabled = monitor->trigger_data->trigger_state != Monitor::TriggerState::TRIGGER_OFF;
status_data.forced = monitor->trigger_data->trigger_state == Monitor::TriggerState::TRIGGER_ON;
if ( playback_buffer > 0 )
status_data.buffer_level = (MOD_ADD( (temp_write_index-temp_read_index), 0, temp_image_buffer_count )*100)/temp_image_buffer_count;
else