malena
Why malena
Quick start
Tutorials
API docs
GitHub
GitHub
Tutorials
Loading...
Searching...
No Matches
Providers
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
9
#include <
Malena/Core/malena_export.h
>
10
#include <
Malena/Traits/Communication/Messenger.h
>
11
#include <
Malena/Utilities/Json.h
>
12
#include <functional>
13
#include <string>
14
15
namespace
ml
16
{
37
class
MALENA_API
NetworkDispatcher
:
public
Messenger
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
Json.h
Messenger.h
ml::Messenger::Messenger
Messenger()=default
ml::NetworkDispatcher::on
void on(const std::string &value, std::function< void(const json &)> callback)
Subscribe a callback for a specific message value.
ml::NetworkDispatcher::NetworkDispatcher
NetworkDispatcher(const std::string &keyField="type")
ml::NetworkDispatcher::dispatch
void dispatch(const json &msg)
Dispatch a JSON object to the matching subscriber.
ml::json
nlohmann::json json
Alias for nlohmann::json.
Definition
Json.h:32
malena_export.h
MALENA_API
#define MALENA_API
Definition
malena_export.h:18
ml
Definition
Component.h:22