[Qt-interest] Initializing application modules in sequence
Sean Harmer
sean.harmer at maps-technology.com
Mon Apr 25 13:32:33 CEST 2011
Hi,
On 25/04/2011 12:12, Mandeep Sandhu wrote:
> I'm working on a fairly large Qt app for an embedded Linux platform.
>
> Before the application presents any UI to a user, we have to
> initialize the various application modules that the app uses. Some of
> these modules do n/w IO, some init a h/w interface in a specific
> manner etc.
It sounds as if QStateMachine would be a good candidate here. We do
something similar with hardware devices (usb or Ethernet based).
* The sequence of states would determine the ordering of the subsystem
initialisations.
* The synchronous subsystems can be initialised in a custom state's
onEntry() function in a very simple manner. The state could post a
custom event to the state machine for success in which case a transition
to the next init state would follow. In the case of failure post another
custom event that the parent state handles to transition to some error
state.
* Asynchronous initialisations can also be handled naturally too since
the SM operates via the owning thread's event queue. In this case, the
subsystem state may have additional child states. Perhaps one for
sending out a network request and another that gets transitioned to upon
a network response. This allows your receiving/processing state to
verify the response was successful. Then you either emit a custom event
indicating success or failure.
So what I have in mind are 3 states at the top-level: Initialising,
InitialisationFailed and Initialised.
InitialisationFailed and Initialised can be simple QStates with no children.
The InitialisingState can also be a QState but one thta has child states
- one for each subsystem. The initial state should be set to the first
subsystem to be initialised. There should be transitions based upon a
custom SubsystemInitialisedEvent to the next subsystem init state.
The InitialisingState should also have a final state that gets
transitioned to upon the last subsystem beign successfully initialised.
Then the Initialising state's finished() signal can be used to
transition to the top-level Initialised state.
The InitialisingState itself should have a single transition based upon
a custom SubystemInitFailedEvent class. This will cover the case of any
of the child states failing to initialise.
Hope that helps but feel free to come back with more questions if
anything is not clear from those ramblings ;-)
Sean
More information about the Qt-interest-old
mailing list