mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-26 04:17:50 +02:00
Fixed other potential bug on OSX
This commit is contained in:
@ -2,34 +2,35 @@
|
||||
#include <vector>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
template <class T>
|
||||
struct EventHandler {
|
||||
EventHandler() {}
|
||||
EventHandler(void (*handler)(T, void*), void* ctx) {
|
||||
this->handler = handler;
|
||||
this->ctx = ctx;
|
||||
}
|
||||
|
||||
void (*handler)(T, void*);
|
||||
void* ctx;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class Event {
|
||||
public:
|
||||
Event() {}
|
||||
~Event() {}
|
||||
|
||||
struct EventHandler {
|
||||
EventHandler() {}
|
||||
EventHandler(void (*handler)(T, void*), void* ctx) {
|
||||
this->handler = handler;
|
||||
this->ctx = ctx;
|
||||
}
|
||||
|
||||
void (*handler)(T, void*);
|
||||
void* ctx;
|
||||
};
|
||||
|
||||
void emit(T value) {
|
||||
for (auto const& handler : handlers) {
|
||||
handler.handler(value, handler.ctx);
|
||||
}
|
||||
}
|
||||
|
||||
void bindHandler(const EventHandler& handler) {
|
||||
void bindHandler(const EventHandler<T>& handler) {
|
||||
handlers.push_back(handler);
|
||||
}
|
||||
|
||||
void unbindHandler(const EventHandler& handler) {
|
||||
void unbindHandler(const EventHandler<T>& handler) {
|
||||
if (handlers.find(handler) == handlers.end()) {
|
||||
spdlog::error("Tried to remove a non-existant event handler");
|
||||
return;
|
||||
@ -38,6 +39,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<EventHandler> handlers;
|
||||
std::vector<EventHandler<T>> handlers;
|
||||
|
||||
};
|
@ -14,11 +14,11 @@ SinkManager::SinkManager() {
|
||||
registerSinkProvider("None", prov);
|
||||
}
|
||||
|
||||
SinkManager::Stream::Stream(dsp::stream<dsp::stereo_t>* in, const Event<float>::EventHandler& srChangeHandler, float sampleRate) {
|
||||
SinkManager::Stream::Stream(dsp::stream<dsp::stereo_t>* in, const EventHandler<float>& srChangeHandler, float sampleRate) {
|
||||
init(in, srChangeHandler, sampleRate);
|
||||
}
|
||||
|
||||
void SinkManager::Stream::init(dsp::stream<dsp::stereo_t>* in, const Event<float>::EventHandler& srChangeHandler, float sampleRate) {
|
||||
void SinkManager::Stream::init(dsp::stream<dsp::stereo_t>* in, const EventHandler<float>& srChangeHandler, float sampleRate) {
|
||||
_in = in;
|
||||
srChange.bindHandler(srChangeHandler);
|
||||
_sampleRate = sampleRate;
|
||||
|
@ -25,9 +25,9 @@ public:
|
||||
class Stream {
|
||||
public:
|
||||
Stream() {}
|
||||
Stream(dsp::stream<dsp::stereo_t>* in, const Event<float>::EventHandler& srChangeHandler, float sampleRate);
|
||||
Stream(dsp::stream<dsp::stereo_t>* in, const EventHandler<float>& srChangeHandler, float sampleRate);
|
||||
|
||||
void init(dsp::stream<dsp::stereo_t>* in, const Event<float>::EventHandler& srChangeHandler, float sampleRate);
|
||||
void init(dsp::stream<dsp::stereo_t>* in, const EventHandler<float>& srChangeHandler, float sampleRate);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
Reference in New Issue
Block a user