c++ - Managing asynchronous communication: how to examine response received in another thread -
i have dispatcher thread , listener thread. when dispatch command, want wait response before send follow command. need examine respond before can proceed 2nd command, least of confirm response received , okay. pseudo code below:
void mainwindow::downloaddata() { dispatcher->getinfo(); // sends command // qstring response = receiver->response() // idealy check response since async, can't that! dipatcher->askdata(); // 2nd command , forth }
is there elegant way solve issue? way can think of if use same thread , calls blocking that's not solution.
in qt, use signals , slots connect them in cascading manner when first signal triggered initiates whole sequence of operation (each slot emitting new signal) seems rather dirty well.
one of robust ways handle asynchronous events , process chains/graphs of actions upon these events fsms. qt provides basis implementing fsms qt-state machine framework. i'd suggest go way. unfortunately examples provided qt fsm dealing guis , animations.
the advantage of fsm approach is, fsms can represented both graphs , tables. first option great understanding, second validation, there no endless loops , "dead" ends.
i've built on basis of qt-fsm framework own framework defining fsms in domain specific language. use controlling complex machine having couple of sensors actors working asynchronously. using dsl helps me implement in higher abstraction - in abstraction level of fsm-graphs.
Comments
Post a Comment