Toyomasa Watarai
/
Mbed-example-WS-W27
Mbed Cloud example program for workshop in W27 2018.
Diff: easy-connect/wifi-x-nucleo-idw01m1/BlockExecuter.h
- Revision:
- 0:119624335925
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/easy-connect/wifi-x-nucleo-idw01m1/BlockExecuter.h Sat Jun 30 01:40:30 2018 +0000 @@ -0,0 +1,22 @@ +#ifndef BLOCK_EXEC_H +#define BLOCK_EXEC_H + +#include "mbed.h" + +/* Helper class to execute something whenever entering/leaving a basic block */ +class BlockExecuter { +public: + BlockExecuter(Callback<void()> exit_cb, Callback<void()> enter_cb = Callback<void()>()) : + _exit_cb(exit_cb) { + if((bool)enter_cb) enter_cb(); + } + + ~BlockExecuter(void) { + _exit_cb(); + } + +private: + Callback<void()> _exit_cb; +}; + +#endif //BLOCK_EXEC_H