mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-18 06:06:40 +01:00
use mediator to distribute messages via dispatch method
This commit is contained in:
@@ -44,10 +44,10 @@ void Sprocket::loop(){
|
||||
}
|
||||
|
||||
void Sprocket::dispatch( uint32_t from, String &msg ) {
|
||||
SprocketMessage mMsg;
|
||||
mMsg.fromJsonString(msg);
|
||||
if(mMsg.valid){
|
||||
dispatchMessageToPlugins(mMsg);
|
||||
currentMessage.fromJsonString(msg);
|
||||
if(currentMessage.valid){
|
||||
currentMessage.from = from;
|
||||
publish(currentMessage.topic, currentMessage.payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,14 +61,4 @@ void Sprocket::activatePlugins(Scheduler* scheduler, Network* network){
|
||||
for(Plugin* p : plugins){
|
||||
p->activate(scheduler, 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");
|
||||
p->onMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user