mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-14 12:46:50 +01:00
Merge branch 'refactor-pubsub' into 'develop'
Refactor pubsub See merge request wirelos/sprocket-lib!16
This commit is contained in:
10
README.md
10
README.md
@@ -1,6 +1,12 @@
|
||||
# Sprocket-Lib
|
||||
# Sprocket-Core
|
||||
A lightweight Arduino framework for event driven programming.
|
||||
|
||||
## Concepts
|
||||
... topic based event channel / pubsub-pattern
|
||||
... plugin system
|
||||
|
||||
## Lifecycle
|
||||
|
||||
## Sprocket Lifecycle
|
||||
TODO
|
||||
|
||||
# Useful commands
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __MEDIATOR__
|
||||
#define __MEDIATOR__
|
||||
#ifndef __SPROCKET_EVENT_CHANNEL__
|
||||
#define __SPROCKET_EVENT_CHANNEL__
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
@@ -12,7 +12,7 @@ using namespace std;
|
||||
|
||||
typedef std::function<void(String msg)> subscriptionHandler_t;
|
||||
|
||||
class Mediator {
|
||||
class EventChannel {
|
||||
public:
|
||||
std::map<std::string, vector<subscriptionHandler_t>> subscriptions;
|
||||
void subscribe(String topic, subscriptionHandler_t handler) {
|
||||
12
src/Plugin.h
12
src/Plugin.h
@@ -8,24 +8,24 @@
|
||||
#include <TaskSchedulerDeclarations.h>
|
||||
#include <Network.h>
|
||||
#include <SprocketMessage.h>
|
||||
#include <Mediator.h>
|
||||
#include <EventChannel.h>
|
||||
|
||||
class Plugin {
|
||||
public:
|
||||
Mediator* mediator;
|
||||
EventChannel* eventChannel;
|
||||
virtual void activate(Scheduler*);
|
||||
virtual void enable(){}
|
||||
virtual void disable(){}
|
||||
virtual void onMessage(SprocketMessage msg){}
|
||||
Plugin* mediate(Mediator* m) {
|
||||
mediator = m;
|
||||
Plugin* mount(EventChannel* ec) {
|
||||
eventChannel = ec;
|
||||
return this;
|
||||
}
|
||||
void subscribe(String topic, subscriptionHandler_t handler){
|
||||
mediator->subscribe(topic, handler);
|
||||
eventChannel->subscribe(topic, handler);
|
||||
}
|
||||
void publish(String topic, String str){
|
||||
mediator->publish(topic, str);
|
||||
eventChannel->publish(topic, str);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ void Sprocket::dispatch( uint32_t from, String &msg ) {
|
||||
}
|
||||
|
||||
void Sprocket::addPlugin(Plugin* p){
|
||||
p->mediate(this);
|
||||
p->mount(this);
|
||||
plugins.reserve(1);
|
||||
plugins.push_back(p);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
class Sprocket : public Mediator {
|
||||
class Sprocket : public EventChannel {
|
||||
protected:
|
||||
// TODO move scheduler out of Sprocket
|
||||
// => see difference between standalone and mesh sprochet usage of scheduler
|
||||
|
||||
Reference in New Issue
Block a user