[PATCH] libosmocore[master]: fsm: add functions for unlinking and changing parents

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

dexter gerrit-no-reply at lists.osmocom.org
Wed Jan 17 13:23:52 UTC 2018


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/5832

to look at the new patch set (#2).

fsm: add functions for unlinking and changing parents

At the moment it is not possible to unlink a child from from
its parent, nor is it possible to assign a new parent to a
child FSM.

- osmo_fsm_inst_unlink_parent():
  Make it possible to unlink childs from a parent.

- osmo_fsm_inst_change_parent():
  Make it possible to change the parent of a child.

Change-Id: I6d18cbd4ada903cf3720b3ad2a89fc643085beef
---
M include/osmocom/core/fsm.h
M src/fsm.c
2 files changed, 37 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/32/5832/2

diff --git a/include/osmocom/core/fsm.h b/include/osmocom/core/fsm.h
index 2fbb250..83164cd 100644
--- a/include/osmocom/core/fsm.h
+++ b/include/osmocom/core/fsm.h
@@ -150,6 +150,10 @@
 struct osmo_fsm_inst *osmo_fsm_inst_alloc_child(struct osmo_fsm *fsm,
 						struct osmo_fsm_inst *parent,
 						uint32_t parent_term_event);
+void osmo_fsm_inst_unlink_parent(struct osmo_fsm_inst *fi);
+void osmo_fsm_inst_change_parent(struct osmo_fsm_inst *fi,
+				 struct osmo_fsm_inst *new_parent,
+				 uint32_t new_parent_term_event);
 void osmo_fsm_inst_free(struct osmo_fsm_inst *fi);
 
 const char *osmo_fsm_event_name(struct osmo_fsm *fsm, uint32_t event);
diff --git a/src/fsm.c b/src/fsm.c
index f9effc4..4b8e526 100644
--- a/src/fsm.c
+++ b/src/fsm.c
@@ -272,13 +272,43 @@
 
 	LOGPFSM(fi, "is child of %s\n", osmo_fsm_inst_name(parent));
 
-	fi->proc.parent = parent;
-	fi->proc.parent_term_event = parent_term_event;
-	llist_add(&fi->proc.child, &parent->proc.children);
+	osmo_fsm_inst_change_parent(fi, parent, parent_term_event);
 
 	return fi;
 }
 
+/*! unlink child FSM from its parent FSM.
+ *  \param[in] fi Descriptor of the child FSM to unlink. */
+void osmo_fsm_inst_unlink_parent(struct osmo_fsm_inst *fi)
+{
+	if (fi->proc.parent) {
+		talloc_steal(NULL, fi);
+		fi->proc.parent = NULL;
+		fi->proc.parent_term_event = 0;
+		llist_del(&fi->proc.child);
+	}
+}
+
+/*! change parent instance of an FSM.
+ *  \param[in] fi Descriptor of the to-be-allocated FSM.
+ *  \param[in] new_parent New parent FSM instance.
+ *  \param[in] new_parent_term_event Event to be sent to parent when terminating. */
+void osmo_fsm_inst_change_parent(struct osmo_fsm_inst *fi,
+				 struct osmo_fsm_inst *new_parent,
+				 uint32_t new_parent_term_event)
+{
+	/* Make sure a possibly existing old parent is unlinked first */
+	osmo_fsm_inst_unlink_parent(fi);
+
+	/* Add new parent */
+	if (new_parent) {
+		talloc_steal(new_parent, fi);
+		fi->proc.parent = new_parent;
+		fi->proc.parent_term_event = new_parent_term_event;
+		llist_add(&fi->proc.child, &new_parent->proc.children);
+	}
+}
+
 /*! delete a given instance of a FSM
  *  \param[in] fsm The FSM to be un-registered and deleted
  */

-- 
To view, visit https://gerrit.osmocom.org/5832
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6d18cbd4ada903cf3720b3ad2a89fc643085beef
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list