mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 21:34:08 +01:00
use mediator for internal messaging
This commit is contained in:
@@ -44,12 +44,14 @@ void Sprocket::loop(){
|
||||
|
||||
void Sprocket::dispatch( uint32_t from, String &msg ) {
|
||||
SprocketMessage mMsg;
|
||||
if(mMsg.fromJsonString(msg)){
|
||||
mMsg.fromJsonString(msg);
|
||||
if(mMsg.valid){
|
||||
dispatchMessageToPlugins(mMsg);
|
||||
}
|
||||
}
|
||||
|
||||
void Sprocket::addPlugin(Plugin* p){
|
||||
p->mediate(this);
|
||||
plugins.reserve(1);
|
||||
plugins.push_back(p);
|
||||
}
|
||||
@@ -60,10 +62,11 @@ void Sprocket::activatePlugins(Scheduler* scheduler, Network* network){
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove plugin dispatching and onMessage in favor of mediator pub/sub
|
||||
void Sprocket::dispatchMessageToPlugins(SprocketMessage msg){
|
||||
if(msg.type != SprocketMessage::NONE){ // baaaa
|
||||
for(Plugin* p : plugins){
|
||||
Serial.println("dispatch to plugins");
|
||||
//Serial.println("dispatch to plugins");
|
||||
p->onMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user