drone_sound_alarm as event listener

This commit is contained in:
Sassa NF
2024-10-06 17:26:08 +01:00
parent bdd00039b2
commit b9e2bffb93
3 changed files with 36 additions and 9 deletions
+15
View File
@@ -154,6 +154,21 @@ size_t Scan::addEventListener(EventType t, Listener &l)
return c;
}
struct CallbackFunction : Listener
{
void (*cb)(void *arg, Event &e);
void *arg;
CallbackFunction(void cb(void *arg, Event &e), void *arg) : cb(cb), arg(arg) {}
void onEvent(Event &e) { cb(arg, e); }
};
size_t Scan::addEventListener(EventType t, void cb(void *arg, Event &e), void *arg)
{
return addEventListener(t, *(new CallbackFunction(cb, arg)));
}
void Scan::fireEvent(Event &event)
{
Listener **list = eventListeners[(size_t)event.type];
+1
View File
@@ -69,6 +69,7 @@ struct Scan
int samples);
size_t addEventListener(EventType t, Listener &l);
size_t addEventListener(EventType t, void cb(void *, Event &), void *arg);
void fireEvent(Event &e);
};