add unsubscribe #5

master
Hideaki Tai 4 years ago
parent 411a253d55
commit ac3c94811d

@ -397,6 +397,28 @@ namespace arduino
subscribe(u, func);
}
inline void unsubscribe(const uint32_t universe)
{
size_t idx = callbacks.size();
for (size_t i = 0; i < callbacks.size(); ++i)
if (callbacks[i].universe == universe) {
idx = i;
break;
}
if (idx != callbacks.size())
callbacks.erase(callbacks.begin() + idx);
}
inline void unsubscribe()
{
unsubscribe(0);
}
inline void unsubscribe(const uint8_t net, const uint8_t subnet, const uint8_t universe)
{
uint32_t u = ((uint32_t)net << 8) | ((uint32_t)subnet << 4) | (uint32_t)universe;
unsubscribe(u);
}
protected:
void attach(S& s) { stream = &s; }

@ -213,6 +213,9 @@ uint8_t data(const uint16_t i) const;
void subscribe(const uint32_t universe, const CallbackType& func);
void subscribe(const CallbackType& func);
void subscribe(const uint8_t net, const uint8_t subnet, const uint8_t universe, const CallbackType& func);
void unsubscribe(const uint32_t universe);
void unsubscribe();
void unsubscribe(const uint8_t net, const uint8_t subnet, const uint8_t universe);
```
## Supported Platform

Loading…
Cancel
Save