Object-Oriented C Finite State Machine -


i have software state machine works using via event driven function calls. namely, have state machine handle struct contains function pointer representing current state:

typedef struct phandle_t phandle_t; typedef void(*pstate_f)(phandle_t *phandle, pevent_t pevent); struct phandle_t {     pstate_f curstate;     void *contextptr;       // needed? }; 

each state represented function takes handle , event input:

static void sm_init(phandle_t *phandle, pevent_t pevent); 

within each function there switch/case on pevent produces action changing curstate function pointer change function representing state. of code works while using global variables determine when state changes done. (this type of approach not work function instantiated variables try , know when stop).

however, in interest of reducing global variables , functions, implement more object oriented approach, globals , instruction memory go away once state machine has reached complete state. know there several examples of how make code appear object oriented in regular c, there 1 wrench in gears here: external modules need able send events state machine without having pointer state machine handle. how can without requiring overall state machine object declared global (which defeats original intent of trying free space once done it)?

i apologize in advance if of wording confusing. believe useful topic reword requested, please comment before downvoting me... before asks, existing code base c , suggesting c++ falls on deaf ears, despite efforts.

this terrible idea, such, may convince peers let store 1 little, measly pointer need it.

if have identify instances of state machine objects callback-function pointer, have multiple machines running, you'll need duplicates of functions different pointers can functionally-identical, compare differently when cast char *.

so 2 machines, you'll need double code size. 3 machines: triple. etc.

<shudder>


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -