[libdazzle] statemachine: add dzl_state_machine_is_state()



commit 5bc06bae4a3bb4d834613d9a1279eb88f0767e64
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 17 14:16:20 2017 -0800

    statemachine: add dzl_state_machine_is_state()
    
    This is a helper to check the current state of the state machine
    without having to wrap calls to get_state() in a g_strcmp0.

 src/statemachine/dzl-state-machine.c |   22 ++++++++++++++++++++++
 src/statemachine/dzl-state-machine.h |    3 +++
 2 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/src/statemachine/dzl-state-machine.c b/src/statemachine/dzl-state-machine.c
index 204cb35..f9dee99 100644
--- a/src/statemachine/dzl-state-machine.c
+++ b/src/statemachine/dzl-state-machine.c
@@ -744,3 +744,25 @@ dzl_state_machine_connect_object (DzlStateMachine *self,
 
   dzl_signal_group_connect_object (signals, detailed_signal, callback, user_data, flags);
 }
+
+/**
+ * dzl_state_machine_is_state:
+ * @self: a #DzlStateMachine
+ * @state: (nullable): the name of the state to check
+ *
+ * Checks to see if the current state of the #DzlStateMachine matches @state.
+ *
+ * Returns: %TRUE if @self is currently set to @state.
+ *
+ * Since: 3.28
+ */
+gboolean
+dzl_state_machine_is_state (DzlStateMachine *self,
+                            const gchar     *state)
+{
+  DzlStateMachinePrivate *priv = dzl_state_machine_get_instance_private (self);
+
+  g_return_val_if_fail (DZL_IS_STATE_MACHINE (self), FALSE);
+
+  return g_strcmp0 (priv->state, state) == 0;
+}
diff --git a/src/statemachine/dzl-state-machine.h b/src/statemachine/dzl-state-machine.h
index eee858c..0865b7f 100644
--- a/src/statemachine/dzl-state-machine.h
+++ b/src/statemachine/dzl-state-machine.h
@@ -41,6 +41,9 @@ const gchar     *dzl_state_machine_get_state         (DzlStateMachine *self);
 DZL_AVAILABLE_IN_ALL
 void             dzl_state_machine_set_state         (DzlStateMachine *self,
                                                       const gchar     *state);
+DZL_AVAILABLE_IN_3_28
+gboolean         dzl_state_machine_is_state          (DzlStateMachine *self,
+                                                      const gchar     *state);
 DZL_AVAILABLE_IN_ALL
 GAction         *dzl_state_machine_create_action     (DzlStateMachine *self,
                                                       const gchar     *name);


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