mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-17 05:36:39 +01:00
move plugins to sprocket
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <Sprocket.h>
|
||||
#include <MeshNet.h>
|
||||
#include <base/MeshMessage.h>
|
||||
#include <base/MeshSprocketConfig.h>
|
||||
#include <plugins/OtaTcpPlugin.cpp>
|
||||
#include "config.h"
|
||||
|
||||
@@ -16,37 +17,15 @@ using namespace std::placeholders;
|
||||
class MeshSprocket : public Sprocket {
|
||||
public:
|
||||
MeshNet* net;
|
||||
std::vector<Plugin*> plugins;
|
||||
|
||||
MeshSprocket(SprocketConfig cfg, OtaConfig otaCfg) : Sprocket(cfg) {
|
||||
addPlugin(new OtaTcpPlugin(otaCfg));
|
||||
}
|
||||
|
||||
void addPlugin(Plugin* p){
|
||||
plugins.reserve(1);
|
||||
plugins.push_back(p);
|
||||
}
|
||||
|
||||
void setupPlugins(Scheduler* scheduler, Network* network){
|
||||
for(Plugin* p : plugins){
|
||||
p->setup(scheduler, network);
|
||||
}
|
||||
}
|
||||
|
||||
void dispatchMessageToPlugins(MeshMessage msg){
|
||||
if(msg.type != MeshMessage::NONE){ // baaaa
|
||||
for(Plugin* p : plugins){
|
||||
Serial.println("dispatch to plugins");
|
||||
p->onMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||
Sprocket::activate(scheduler, network);
|
||||
net = static_cast<MeshNet*>(network);
|
||||
net->onReceive(bind(&MeshSprocket::dispatch,this, _1, _2));
|
||||
// setup plugins
|
||||
setupPlugins(scheduler, network);
|
||||
return this;
|
||||
} using Sprocket::activate;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user