Dbus and FSM's

Avery Pennarun apenwarr at gmail.com
Fri Feb 15 13:46:13 PST 2008


On 15/02/2008, Robert Rawlins <robert_rawlins at hotmail.com> wrote:
>  I do startProcess()
>  startProcess() calls back with processStarted()
>  processStarted() then starts soSomthing()
>  doSomthing calls back with somthingDone()
>  somethingDone() then started doAnotherThing()
>  doAnotherThing() calls back and starts doTheLastThing()
>
>  Do you see what I mean? a link of function calls and callbacks which cause
> a chain reaction and progress the particular element of the application to
> go through its states.
> [...]
> After looking around this morning it would seem that a
> Finite State Machine is designed to manage this kind of process for me, is
> that correct?

Actually, the process you described is already a finite state machine
:)  FSMs are really just a way of thinking about programs that go
through a series of states.  The math doesn't particularly help you
implement one.

I think what you might want are "continuations" or "coroutines."  In
C++, the WvStreams library contains a class called WvCont that does it
very nicely: http://alumnit.ca/wvstreams/docs/wvcont_8h-source.html

If you're using .net (mono / C#), I wrote a simple implementation of
the same thing using (weirdly enough) .net iterators:
http://www.advogato.org/person/apenwarr/diary/358.html

You can do something similar with raw setjmp/longjmp, but I'm not sure
you want to get into that :)

Another option is to use blocking dbus method calls in a thread,
although threads introduce their own set of problems.

Have fun,

Avery


More information about the dbus mailing list