#include <cstdio>
#include <cstdlib>
#include <cstring>
+#include <thread>
#include <libhomescreen.hpp>
#include "hmi-debug.h"
}
+static void event_loop_run(struct sd_event* loop){
+ sd_event_loop(loop);
+ sd_event_unref(loop);
+}
+
+
/**
* constructor
*/
*/
LibHomeScreen::~LibHomeScreen()
{
- if(mploop)
- {
- sd_event_unref(mploop);
- }
if(sp_websock != NULL)
{
afb_wsj1_unref(sp_websock);
}
+ if(mploop)
+ {
+ sd_event_exit(mploop, 0);
+ }
}
/**
mploop = NULL;
onEvent = nullptr;
onReply = nullptr;
- int ret = sd_event_default(&mploop);
+ int ret = sd_event_new(&mploop);
if(ret < 0)
{
HMI_ERROR("libhomescreen","Failed to create event loop");
goto END;
}
+ {
+ // enforce context to avoid initialization/goto error
+ std::thread th(event_loop_run, mploop);
+ th.detach();
+ }
+
/* Initialize interface from websocket */
minterface.on_hangup = _on_hangup_static;
minterface.on_call = _on_call_static;
return 0;
END:
- if(mploop)
- {
- sd_event_unref(mploop);
- }
return -1;
}