mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-15 13:08:21 +01:00
rename mediator to EventChannel as it was named wrongly
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
|
||||||
|
... PubSub pattern
|
||||||
|
... plugin system
|
||||||
|
|
||||||
## Lifecycle
|
|
||||||
|
## Sprocket Lifecycle
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
# Useful commands
|
# Useful commands
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ using namespace std;
|
|||||||
|
|
||||||
typedef std::function<void(String msg)> subscriptionHandler_t;
|
typedef std::function<void(String msg)> subscriptionHandler_t;
|
||||||
|
|
||||||
class Mediator {
|
class EventChannel {
|
||||||
public:
|
public:
|
||||||
std::map<std::string, vector<subscriptionHandler_t>> subscriptions;
|
std::map<std::string, vector<subscriptionHandler_t>> subscriptions;
|
||||||
void subscribe(String topic, subscriptionHandler_t handler) {
|
void subscribe(String topic, subscriptionHandler_t handler) {
|
||||||
12
src/Plugin.h
12
src/Plugin.h
@@ -8,24 +8,24 @@
|
|||||||
#include <TaskSchedulerDeclarations.h>
|
#include <TaskSchedulerDeclarations.h>
|
||||||
#include <Network.h>
|
#include <Network.h>
|
||||||
#include <SprocketMessage.h>
|
#include <SprocketMessage.h>
|
||||||
#include <Mediator.h>
|
#include <EventChannel.h>
|
||||||
|
|
||||||
class Plugin {
|
class Plugin {
|
||||||
public:
|
public:
|
||||||
Mediator* mediator;
|
EventChannel* eventChannel;
|
||||||
virtual void activate(Scheduler*);
|
virtual void activate(Scheduler*);
|
||||||
virtual void enable(){}
|
virtual void enable(){}
|
||||||
virtual void disable(){}
|
virtual void disable(){}
|
||||||
virtual void onMessage(SprocketMessage msg){}
|
virtual void onMessage(SprocketMessage msg){}
|
||||||
Plugin* mediate(Mediator* m) {
|
Plugin* mount(EventChannel* ec) {
|
||||||
mediator = m;
|
eventChannel = ec;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
void subscribe(String topic, subscriptionHandler_t handler){
|
void subscribe(String topic, subscriptionHandler_t handler){
|
||||||
mediator->subscribe(topic, handler);
|
eventChannel->subscribe(topic, handler);
|
||||||
}
|
}
|
||||||
void publish(String topic, String str){
|
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){
|
void Sprocket::addPlugin(Plugin* p){
|
||||||
p->mediate(this);
|
p->mount(this);
|
||||||
plugins.reserve(1);
|
plugins.reserve(1);
|
||||||
plugins.push_back(p);
|
plugins.push_back(p);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
class Sprocket : public Mediator {
|
class Sprocket : public EventChannel {
|
||||||
protected:
|
protected:
|
||||||
// TODO move scheduler out of Sprocket
|
// TODO move scheduler out of Sprocket
|
||||||
// => see difference between standalone and mesh sprochet usage of scheduler
|
// => see difference between standalone and mesh sprochet usage of scheduler
|
||||||
|
|||||||
Reference in New Issue
Block a user