Commit a5db3b84 authored by luz's avatar luz

p44utils: mainloop: added cleanup handlers, which components can register and...

p44utils: mainloop: added cleanup handlers, which components can register and will be called after mainloop has terminated.
parent 870de46b
......@@ -364,6 +364,12 @@ void MainLoop::childAnswerCollected(ExecCB aCallback, FdStringCollectorPtr aAnsw
void MainLoop::registerCleanupHandler(SimpleCB aCleanupHandler)
{
cleanupHandlers.push_back(aCleanupHandler);
}
void MainLoop::terminate(int aExitCode)
{
......@@ -644,6 +650,11 @@ int MainLoop::run()
statisticsCycles ++; // one cycle completed
#endif
} // not terminated
// run mainloop termination handlers
for (CleanupHandlersList::iterator pos = cleanupHandlers.begin(); pos!=cleanupHandlers.end(); ++pos) {
SimpleCB cb = *pos;
if (cb) cb();
}
return exitCode;
}
......
......@@ -130,6 +130,10 @@ namespace p44 {
{
friend class ChildThreadWrapper;
typedef std::list<SimpleCB> CleanupHandlersList;
CleanupHandlersList cleanupHandlers;
typedef struct {
void *subscriberP;
IdleCB callback;
......@@ -318,6 +322,12 @@ namespace p44 {
/// @param aExitCode the code to return from run()
void terminate(int aExitCode);
/// register a cleanup handler, which will be called when the main loop has terminated
/// @param aCleanupHandler the routine to be called
/// @note the code in cleanup handlers cannot use mailoop services any more, because at time of calling the
/// mainloop has already terminated running
void registerCleanupHandler(SimpleCB aCleanupHandler);
/// run the mainloop
/// @return returns a exit code
int run();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment