From 1f07467800fc005dd2e8419151cdddb444a10072 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Sun, 25 Sep 2016 13:32:14 -0700 Subject: [PATCH] capture-condition: add new AND condition This requires that both the left and right condition evaluate to TRUE. We obviously will want to add more of these for things like OR, NOT, etc. However, we can add them as necessary since they are fairly self contained patches. --- lib/sp-capture-condition.c | 46 ++++++++++++++++++++++++++++++++++++++ lib/sp-capture-condition.h | 2 ++ 2 files changed, 48 insertions(+) diff --git a/lib/sp-capture-condition.c b/lib/sp-capture-condition.c index 7a8045cf..8213e3f1 100644 --- a/lib/sp-capture-condition.c +++ b/lib/sp-capture-condition.c @@ -35,6 +35,7 @@ typedef enum { + SP_CAPTURE_CONDITION_AND, SP_CAPTURE_CONDITION_WHERE_TYPE_IN, SP_CAPTURE_CONDITION_WHERE_TIME_BETWEEN, SP_CAPTURE_CONDITION_WHERE_PID_IN, @@ -52,6 +53,10 @@ struct _SpCaptureCondition } where_time_between; GArray *where_pid_in; GArray *where_counter_in; + struct { + SpCaptureCondition *left; + SpCaptureCondition *right; + } and; } u; }; @@ -64,6 +69,10 @@ sp_capture_condition_match (const SpCaptureCondition *self, switch (self->type) { + case SP_CAPTURE_CONDITION_AND: + return sp_capture_condition_match (self->u.and.left, frame) && + sp_capture_condition_match (self->u.and.right, frame); + case SP_CAPTURE_CONDITION_WHERE_TYPE_IN: for (guint i = 0; i < self->u.where_type_in->len; i++) { @@ -143,6 +152,11 @@ sp_capture_condition_copy (const SpCaptureCondition *self) switch (self->type) { + case SP_CAPTURE_CONDITION_AND: + return sp_capture_condition_new_and ( + sp_capture_condition_copy (self->u.and.left), + sp_capture_condition_copy (self->u.and.right)); + case SP_CAPTURE_CONDITION_WHERE_TYPE_IN: return sp_capture_condition_new_where_type_in ( self->u.where_type_in->len, @@ -172,6 +186,11 @@ sp_capture_condition_free (SpCaptureCondition *self) { switch (self->type) { + case SP_CAPTURE_CONDITION_AND: + sp_capture_condition_free (self->u.and.left); + sp_capture_condition_free (self->u.and.right); + break; + case SP_CAPTURE_CONDITION_WHERE_TYPE_IN: g_array_free (self->u.where_type_in, TRUE); break; @@ -271,3 +290,30 @@ sp_capture_condition_new_where_counter_in (guint n_counters, return self; } + +/** + * sp_capture_condition_new_and: + * @left: (transfer full): An #SpCaptureCondition + * @right: (transfer full): An #SpCaptureCondition + * + * Creates a new #SpCaptureCondition that requires both left and right + * to evaluate to %TRUE. + * + * Returns: (transfer full): A new #SpCaptureCondition. + */ +SpCaptureCondition * +sp_capture_condition_new_and (SpCaptureCondition *left, + SpCaptureCondition *right) +{ + SpCaptureCondition *self; + + g_return_val_if_fail (left != NULL, NULL); + g_return_val_if_fail (right != NULL, NULL); + + self = g_slice_new0 (SpCaptureCondition); + self->type = SP_CAPTURE_CONDITION_AND; + self->u.and.left = left; + self->u.and.right = right; + + return self; +} diff --git a/lib/sp-capture-condition.h b/lib/sp-capture-condition.h index 6901a44b..3752ea4d 100644 --- a/lib/sp-capture-condition.h +++ b/lib/sp-capture-condition.h @@ -26,6 +26,8 @@ G_BEGIN_DECLS #define SP_TYPE_CAPTURE_CONDITION (sp_capture_condition_get_type()) GType sp_capture_condition_get_type (void); +SpCaptureCondition *sp_capture_condition_new_and (SpCaptureCondition *left, + SpCaptureCondition *right); SpCaptureCondition *sp_capture_condition_new_where_type_in (guint n_types, const SpCaptureFrameType *types); SpCaptureCondition *sp_capture_condition_new_where_time_between (gint64 begin_time,