Loading...
Searching...
No Matches
NetworkDispatcher.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith.
2// Malena Framework — Licensed under PolyForm Noncommercial 1.0.0; commercial use requires a paid license. See LICENSE.
3
4#ifndef MALENA_NETWORK_DISPATCHER_H
5#define MALENA_NETWORK_DISPATCHER_H
6
7#pragma once
8
12#include <functional>
13#include <string>
14
15namespace ml
16{
38 {
39 public:
40 explicit NetworkDispatcher(const std::string& keyField = "type");
41
48 void on(const std::string& value, std::function<void(const json&)> callback);
49
58 void dispatch(const json& msg);
59
60 private:
61 std::string _keyField;
62 };
63
64} // namespace ml
65
66#endif // MALENA_NETWORK_DISPATCHER_H
Messenger()=default
void on(const std::string &value, std::function< void(const json &)> callback)
Subscribe a callback for a specific message value.
NetworkDispatcher(const std::string &keyField="type")
void dispatch(const json &msg)
Dispatch a JSON object to the matching subscriber.
nlohmann::json json
Alias for nlohmann::json.
Definition Json.h:32
#define MALENA_API
Definition Component.h:22