[libpri-commits] rmudgett: branch rmudgett/q931_fsm r2247 - /team/rmudgett/q931_fsm/
SVN commits to the libpri project
libpri-commits at lists.digium.com
Thu Mar 10 10:53:10 CST 2011
Author: rmudgett
Date: Thu Mar 10 10:53:08 2011
New Revision: 2247
URL: http://svnview.digium.com/svn/libpri?view=rev&rev=2247
Log:
* Incorporated simple event post/push routines into FSM driver.
* Eliminated reserved event parameter space. If an event really needs
more parameters than the generic ones provided, then the event can attach
an allocated struct to the event using struct fsm_event.parms.ptr.
Modified:
team/rmudgett/q931_fsm/fsmtest.c
team/rmudgett/q931_fsm/pri_fsm.c
team/rmudgett/q931_fsm/pri_fsm.h
Modified: team/rmudgett/q931_fsm/fsmtest.c
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/q931_fsm/fsmtest.c?view=diff&rev=2247&r1=2246&r2=2247
==============================================================================
--- team/rmudgett/q931_fsm/fsmtest.c (original)
+++ team/rmudgett/q931_fsm/fsmtest.c Thu Mar 10 10:53:08 2011
@@ -105,44 +105,6 @@
}
}
-/*!
- * \internal
- * \brief Simple event posting.
- *
- * \param ctrl D channel controller.
- * \param fsm Event is sent to this FSM.
- * \param code Event code.
- *
- * \return Nothing
- */
-static void tst_simple_post(struct pri *ctrl, struct fsm_ctrl *fsm, int code)
-{
- struct fsm_event ev;
-
- memset(&ev, 0, sizeof(ev));
- ev.code = code;
- fsm_event_post(ctrl, fsm, &ev);
-}
-
-/*!
- * \internal
- * \brief Simple event pushing.
- *
- * \param ctrl D channel controller.
- * \param fsm Event is sent to this FSM.
- * \param code Event code.
- *
- * \return Nothing
- */
-static void tst_simple_push(struct pri *ctrl, struct fsm_ctrl *fsm, int code)
-{
- struct fsm_event ev;
-
- memset(&ev, 0, sizeof(ev));
- ev.code = code;
- fsm_event_push(ctrl, fsm, &ev);
-}
-
static void *tst_state_1(struct pri *ctrl, struct fsm_ctrl *fsm, struct fsm_event *event);
static void *tst_state_1_1(struct pri *ctrl, struct fsm_ctrl *fsm, struct fsm_event *event);
static void *tst_state_1_1_1(struct pri *ctrl, struct fsm_ctrl *fsm, struct fsm_event *event);
@@ -186,13 +148,13 @@
break;
case TST_EV_A:
ACT_DEBUG(ctrl, fsm, event);
- tst_simple_post(ctrl, fsm, TST_EV_B);
+ fsm_event_post(ctrl, fsm, TST_EV_B);
return NULL;
case TST_EV_B:
ACT_DEBUG(ctrl, fsm, event);
- tst_simple_push(ctrl, fsm, TST_EV_D);
- tst_simple_push(ctrl, fsm, TST_EV_C);
- tst_simple_post(ctrl, fsm, TST_EV_E);
+ fsm_event_push(ctrl, fsm, TST_EV_D);
+ fsm_event_push(ctrl, fsm, TST_EV_C);
+ fsm_event_post(ctrl, fsm, TST_EV_E);
fsm_transition(ctrl, ctrl->debug & PRI_DEBUG_Q931_STATE, fsm, tst_state_1_1_1);
return NULL;
case TST_EV_C:
@@ -201,7 +163,7 @@
return NULL;
case TST_EV_E:
ACT_DEBUG(ctrl, fsm, event);
- tst_simple_post(ctrl, fsm, TST_EV_F);
+ fsm_event_post(ctrl, fsm, TST_EV_F);
fsm_transition(ctrl, ctrl->debug & PRI_DEBUG_Q931_STATE, fsm, tst_state_1_2);
return NULL;
default:
@@ -322,7 +284,7 @@
break;
case TST_EV_F:
ACT_DEBUG(ctrl, fsm, event);
- tst_simple_post(ctrl, fsm, TST_EV_G);
+ fsm_event_post(ctrl, fsm, TST_EV_G);
fsm_transition(ctrl, ctrl->debug & PRI_DEBUG_Q931_STATE, fsm, tst_state_1_3);
return NULL;
default:
@@ -495,11 +457,11 @@
fsm_run(&dummy_ctrl, &ev_q);
/* Post event. */
- tst_simple_post(&dummy_ctrl, &fsm, TST_EV_A);
+ fsm_event_post(&dummy_ctrl, &fsm, TST_EV_A);
fsm_run(&dummy_ctrl, &ev_q);
/* Post event. */
- tst_simple_post(&dummy_ctrl, &fsm, TST_EV_H);
+ fsm_event_post(&dummy_ctrl, &fsm, TST_EV_H);
fsm_run(&dummy_ctrl, &ev_q);
if (fsm_destroyed != 1) {
Modified: team/rmudgett/q931_fsm/pri_fsm.c
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/q931_fsm/pri_fsm.c?view=diff&rev=2247&r1=2246&r2=2247
==============================================================================
--- team/rmudgett/q931_fsm/pri_fsm.c (original)
+++ team/rmudgett/q931_fsm/pri_fsm.c Thu Mar 10 10:53:08 2011
@@ -36,6 +36,8 @@
#include "libpri.h"
#include "pri_internal.h"
#include "pri_fsm.h" //BUGBUG
+
+#include <string.h>
/* ------------------------------------------------------------------- */
@@ -72,15 +74,15 @@
}
/*!
- * \brief Push an event on the head of the event queue.
- *
- * \param ctrl D channel controller.
- * \param fsm FSM controller.
+ * \brief Push an event with parameters on the head of the event queue.
+ *
+ * \param ctrl D channel controller.
+ * \param fsm Event is sent to this FSM.
* \param event Event to push.
*
* \return Nothing
*/
-void fsm_event_push(struct pri *ctrl, struct fsm_ctrl *fsm, struct fsm_event *event)
+void fsm_event_push_parms(struct pri *ctrl, struct fsm_ctrl *fsm, struct fsm_event *event)
{
unsigned next_head;
struct fsm_queue *que;
@@ -117,15 +119,33 @@
}
/*!
- * \brief Post an event on the tail of the event queue.
- *
- * \param ctrl D channel controller.
- * \param fsm FSM controller.
+ * \brief Push a simple event on the head of the event queue.
+ *
+ * \param ctrl D channel controller.
+ * \param fsm Event is sent to this FSM.
+ * \param code Event code.
+ *
+ * \return Nothing
+ */
+void fsm_event_push(struct pri *ctrl, struct fsm_ctrl *fsm, int code)
+{
+ struct fsm_event ev;
+
+ memset(&ev, 0, sizeof(ev));
+ ev.code = code;
+ fsm_event_push_parms(ctrl, fsm, &ev);
+}
+
+/*!
+ * \brief Post an event with parameters on the tail of the event queue.
+ *
+ * \param ctrl D channel controller.
+ * \param fsm Event is sent to this FSM.
* \param event Event to post.
*
* \return Nothing
*/
-void fsm_event_post(struct pri *ctrl, struct fsm_ctrl *fsm, struct fsm_event *event)
+void fsm_event_post_parms(struct pri *ctrl, struct fsm_ctrl *fsm, struct fsm_event *event)
{
unsigned next_tail;
struct fsm_queue *que;
@@ -158,6 +178,24 @@
que->events[que->tail].fsm = fsm;
que->events[que->tail].event = *event;
que->tail = next_tail;
+}
+
+/*!
+ * \brief Post a simple event on the tail of the event queue.
+ *
+ * \param ctrl D channel controller.
+ * \param fsm Event is sent to this FSM.
+ * \param code Event code.
+ *
+ * \return Nothing
+ */
+void fsm_event_post(struct pri *ctrl, struct fsm_ctrl *fsm, int code)
+{
+ struct fsm_event ev;
+
+ memset(&ev, 0, sizeof(ev));
+ ev.code = code;
+ fsm_event_post_parms(ctrl, fsm, &ev);
}
/*!
Modified: team/rmudgett/q931_fsm/pri_fsm.h
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/q931_fsm/pri_fsm.h?view=diff&rev=2247&r1=2246&r2=2247
==============================================================================
--- team/rmudgett/q931_fsm/pri_fsm.h (original)
+++ team/rmudgett/q931_fsm/pri_fsm.h Thu Mar 10 10:53:08 2011
@@ -42,7 +42,6 @@
/* ------------------------------------------------------------------- */
-#define FSM_MAX_EV_PARAM_BYTES 100 /*!< Max space available for any event parameters. */
#define FSM_MAX_Q_EVENTS 10 /*!< Max number of events the common Q can contain. */
#define FSM_MAX_SUPERSTATE_NESTING 10 /*!< Max number of nested superstates. */
@@ -174,19 +173,12 @@
struct fsm_event {
/*! FSM event code. */
int code;
-
- /* Any following parms elements are optional. */
-
- /*!
- * \brief Event parameters if needed.
- * \note Union done for alignment purposes.
- */
+ /*! \brief Event parameters if needed. */
union {
- /*! Generic pointer to guarantee pointer alignment. */
+ /*! \brief Generic pointer to extra event parameters. */
void *ptr;
- int num;
- /*! Reserve space for custom event parameters. */
- char filler[FSM_MAX_EV_PARAM_BYTES];
+ /*! \brief Simple extra numeric event parameter. */
+ long num;
} parms;
};
@@ -214,8 +206,10 @@
#define FSM_IS_DEBUG(is_debug) ((is_debug) ? (void *) 1 : (void *) 0)
const char *fsm_ev2str(enum fsm_ev event);
-void fsm_event_push(struct pri *ctrl, struct fsm_ctrl *fsm, struct fsm_event *event);
-void fsm_event_post(struct pri *ctrl, struct fsm_ctrl *fsm, struct fsm_event *event);
+void fsm_event_push_parms(struct pri *ctrl, struct fsm_ctrl *fsm, struct fsm_event *event);
+void fsm_event_post_parms(struct pri *ctrl, struct fsm_ctrl *fsm, struct fsm_event *event);
+void fsm_event_push(struct pri *ctrl, struct fsm_ctrl *fsm, int code);
+void fsm_event_post(struct pri *ctrl, struct fsm_ctrl *fsm, int code);
void *fsm_top_state(struct pri *ctrl, struct fsm_ctrl *fsm, struct fsm_event *event);
void fsm_transition(struct pri *ctrl, int debug, struct fsm_ctrl *fsm, fsm_state dest);
void fsm_run(struct pri *ctrl, struct fsm_queue *que);
More information about the libpri-commits
mailing list