Skip to content

Commit

Permalink
Upgrade blinker
Browse files Browse the repository at this point in the history
  • Loading branch information
hit9 committed May 15, 2024
1 parent dec9e42 commit 820ae27
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions example/onsignal/third_party/blinker.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
// board.Flip();
// }

// Version: 0.1.7
// Version: 0.1.8

#ifndef HIT9_BLINKER_H
#define HIT9_BLINKER_H
Expand Down Expand Up @@ -172,7 +172,7 @@ class Buffer {
void Emit(SignalId id, std::any data) { fired[id] = 1, d[id] = data; }

// Poll fired signals matching given signature.
int Poll(const Signature<N>& signature, Callback cb, SignalId maxId) {
int Poll(const Signature<N>& signature, const Callback& cb, SignalId maxId) {
auto match = signature & fired;
for (int i = 1; i < maxId; i++)
if (match[i]) cb(i, d[i]);
Expand All @@ -190,7 +190,7 @@ template <std::size_t N = DefaultNSignal>
class IBoardPoller {
public:
// Poll fired signals matching given signature from frontend buffer.
virtual int Poll(const Signature<N>& signature, Callback cb) = 0;
virtual int Poll(const Signature<N>& signature, Callback& cb) = 0;
};

class Signal {
Expand All @@ -202,7 +202,7 @@ class Signal {

public:
Signal(std::string_view name, const SignalId id, IBoardEmitter* board) : name(name), id(id), board(board) {}
std::string_view Name() const { return name; }
std::string_view Name() const { return name; } // cppcheck-suppress returnByReference
SignalId Id() const { return id; }
// Emits this signal.
void Emit(std::any data) { board->Emit(id, data); }
Expand All @@ -221,7 +221,8 @@ class Connection {
// Poll from board's frontend buffer for subscribed signals.
// If there's some signal fired, the given callback function will be called, and returns a positive count of
// fired signals.
int Poll(Callback cb) { return board->Poll(signature, cb); }
int Poll(Callback& cb) { return board->Poll(signature, cb); }
inline int Poll(Callback&& cb) { return board->Poll(signature, cb); }
};

// The board of signals.
Expand Down Expand Up @@ -268,7 +269,7 @@ class Board : public IBoardPoller<N>, public IBoardEmitter {
// Emits a signal to backend buffer by signal id.
void Emit(SignalId id, std::any data) override final { backend->Emit(id, data); }
// Poll fired signals matching given signature from frontend buffer.
int Poll(const Signature<N>& signature, Callback cb) override final {
int Poll(const Signature<N>& signature, Callback& cb) override final {
return frontend->Poll(signature, cb, nextId);
}
// Flips the internal double buffers.
Expand Down

0 comments on commit 820ae27

Please sign in to comment.