Modifier event predicate

This commit is contained in:
Vftdan 2024-08-17 15:04:20 +02:00
parent 8e6795a051
commit f67a8842cc
4 changed files with 24 additions and 0 deletions

View File

@ -275,6 +275,9 @@ parse_event_predicate_type(const char *name)
if (strcmp(name, "disjunction") == 0 || strcmp(name, "or") == 0) {
return EVPRED_DISJUNCTION;
}
if (strcmp(name, "modifier") == 0) {
return EVPRED_MODIFIER;
}
return EVPRED_INVALID;
}
@ -324,6 +327,15 @@ load_single_predicate(const config_setting_t * setting, EventPredicateHandleRegi
predicate.aggregate_data.handles = handles;
}
break;
case EVPRED_MODIFIER:
{
long long modifier = resolve_constant_or(constants, config_setting_get_member(setting, "modifier"), -1);
if (modifier < 0 || modifier > MODIFIER_MAX) {
return -1;
}
predicate.single_modifier = modifier;
}
break;
default:
return -1;
}

View File

@ -168,6 +168,14 @@ event_predicate_apply(EventPredicateHandle handle, EventNode * event)
}
}
break;
case EVPRED_MODIFIER:
if (!event) {
return EVPREDRES_DISABLED;
}
{
accepted = modifier_set_has(event->data.modifiers, ptr->single_modifier);
}
break;
default:
return EVPREDRES_DISABLED;
}

View File

@ -18,6 +18,8 @@ typedef enum {
// Aggregation
EVPRED_CONJUNCTION,
EVPRED_DISJUNCTION,
// Modifier
EVPRED_MODIFIER,
} EventPredicateType;
typedef enum {
@ -39,6 +41,7 @@ struct event_predicate {
size_t length;
EventPredicateHandle *handles;
} aggregate_data;
Modifier single_modifier;
};
};

View File

@ -12,6 +12,7 @@ typedef struct {
typedef int32_t Modifier;
#define EMPTY_MODIFIER_SET ((ModifierSet) {.byte_length = 0, .bits = NULL})
#define MODIFIER_MAX ((Modifier) 0xFFFFF)
__attribute__((unused)) inline static ModifierSet
modifier_set_copy(const ModifierSet old)