[sysprof/wip/chergert/sysprof-3] libsysprof-capture: add or condition



commit da881bf14cc7b27b7f7d4bb6c97bf530fb4806a2
Author: Christian Hergert <chergert redhat com>
Date:   Mon May 13 23:58:50 2019 -0700

    libsysprof-capture: add or condition

 src/libsysprof-capture/sysprof-capture-condition.c | 46 +++++++++++++++++++++-
 src/libsysprof-capture/sysprof-capture-condition.h |  3 ++
 2 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/src/libsysprof-capture/sysprof-capture-condition.c 
b/src/libsysprof-capture/sysprof-capture-condition.c
index 0bfd25e..c2c7378 100644
--- a/src/libsysprof-capture/sysprof-capture-condition.c
+++ b/src/libsysprof-capture/sysprof-capture-condition.c
@@ -40,6 +40,7 @@
 typedef enum
 {
   SYSPROF_CAPTURE_CONDITION_AND,
+  SYSPROF_CAPTURE_CONDITION_OR,
   SYSPROF_CAPTURE_CONDITION_WHERE_TYPE_IN,
   SYSPROF_CAPTURE_CONDITION_WHERE_TIME_BETWEEN,
   SYSPROF_CAPTURE_CONDITION_WHERE_PID_IN,
@@ -61,7 +62,7 @@ struct _SysprofCaptureCondition
     struct {
       SysprofCaptureCondition *left;
       SysprofCaptureCondition *right;
-    } and;
+    } and, or;
   } u;
 };
 
@@ -78,6 +79,10 @@ sysprof_capture_condition_match (const SysprofCaptureCondition *self,
       return sysprof_capture_condition_match (self->u.and.left, frame) &&
              sysprof_capture_condition_match (self->u.and.right, frame);
 
+    case SYSPROF_CAPTURE_CONDITION_OR:
+      return sysprof_capture_condition_match (self->u.or.left, frame) ||
+             sysprof_capture_condition_match (self->u.or.right, frame);
+
     case SYSPROF_CAPTURE_CONDITION_WHERE_TYPE_IN:
       for (guint i = 0; i < self->u.where_type_in->len; i++)
         {
@@ -173,6 +178,11 @@ sysprof_capture_condition_copy (const SysprofCaptureCondition *self)
         sysprof_capture_condition_copy (self->u.and.left),
         sysprof_capture_condition_copy (self->u.and.right));
 
+    case SYSPROF_CAPTURE_CONDITION_OR:
+      return sysprof_capture_condition_new_or (
+        sysprof_capture_condition_copy (self->u.or.left),
+        sysprof_capture_condition_copy (self->u.or.right));
+
     case SYSPROF_CAPTURE_CONDITION_WHERE_TYPE_IN:
       return sysprof_capture_condition_new_where_type_in (
           self->u.where_type_in->len,
@@ -209,6 +219,11 @@ sysprof_capture_condition_finalize (SysprofCaptureCondition *self)
       sysprof_capture_condition_unref (self->u.and.right);
       break;
 
+    case SYSPROF_CAPTURE_CONDITION_OR:
+      sysprof_capture_condition_unref (self->u.or.left);
+      sysprof_capture_condition_unref (self->u.or.right);
+      break;
+
     case SYSPROF_CAPTURE_CONDITION_WHERE_TYPE_IN:
       g_array_free (self->u.where_type_in, TRUE);
       break;
@@ -340,7 +355,7 @@ sysprof_capture_condition_new_where_counter_in (guint        n_counters,
  */
 SysprofCaptureCondition *
 sysprof_capture_condition_new_and (SysprofCaptureCondition *left,
-                              SysprofCaptureCondition *right)
+                                   SysprofCaptureCondition *right)
 {
   SysprofCaptureCondition *self;
 
@@ -354,3 +369,30 @@ sysprof_capture_condition_new_and (SysprofCaptureCondition *left,
 
   return self;
 }
+
+/**
+ * sysprof_capture_condition_new_or:
+ * @left: (transfer full): An #SysprofCaptureCondition
+ * @right: (transfer full): An #SysprofCaptureCondition
+ *
+ * Creates a new #SysprofCaptureCondition that requires either left and right
+ * to evaluate to %TRUE.
+ *
+ * Returns: (transfer full): A new #SysprofCaptureCondition.
+ */
+SysprofCaptureCondition *
+sysprof_capture_condition_new_or (SysprofCaptureCondition *left,
+                                  SysprofCaptureCondition *right)
+{
+  SysprofCaptureCondition *self;
+
+  g_return_val_if_fail (left != NULL, NULL);
+  g_return_val_if_fail (right != NULL, NULL);
+
+  self = sysprof_capture_condition_init ();
+  self->type = SYSPROF_CAPTURE_CONDITION_OR;
+  self->u.or.left = left;
+  self->u.or.right = right;
+
+  return self;
+}
diff --git a/src/libsysprof-capture/sysprof-capture-condition.h 
b/src/libsysprof-capture/sysprof-capture-condition.h
index 5a5d52a..280b6e6 100644
--- a/src/libsysprof-capture/sysprof-capture-condition.h
+++ b/src/libsysprof-capture/sysprof-capture-condition.h
@@ -35,6 +35,9 @@ SYSPROF_AVAILABLE_IN_ALL
 SysprofCaptureCondition *sysprof_capture_condition_new_and                (SysprofCaptureCondition       
*left,
                                                                            SysprofCaptureCondition       
*right);
 SYSPROF_AVAILABLE_IN_ALL
+SysprofCaptureCondition *sysprof_capture_condition_new_or                 (SysprofCaptureCondition       
*left,
+                                                                           SysprofCaptureCondition       
*right);
+SYSPROF_AVAILABLE_IN_ALL
 SysprofCaptureCondition *sysprof_capture_condition_new_where_type_in      (guint                          
n_types,
                                                                            const SysprofCaptureFrameType 
*types);
 SYSPROF_AVAILABLE_IN_ALL


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]