MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
NetworkEvents.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Core {
6struct NetworkMessage;
7}
8
9namespace MayaFlux::Vruta {
10class NetworkSource;
11class Event;
12}
13
14namespace MayaFlux::Kriya {
15
16/**
17 * @brief Creates an Event coroutine that fires on every message received by a source
18 * @param source Shared ownership of the NetworkSource; lifetime is tied to the coroutine frame
19 * @param callback Invoked with each received message
20 * @return Event coroutine suitable for EventManager::add_event()
21 *
22 * @code
23 * auto src = std::make_shared<Vruta::NetworkSource>(
24 * Core::EndpointInfo{ .transport = Core::NetworkTransport::UDP, .local_port = 8000 });
25 * auto task = Kriya::on_message(src, [](const Core::NetworkMessage& msg) { });
26 * @endcode
27 */
28MAYAFLUX_API Vruta::Event on_message(
29 std::shared_ptr<Vruta::NetworkSource> source,
30 std::function<void(const Core::NetworkMessage&)> callback);
31
32/**
33 * @brief Creates an Event coroutine that fires only for messages from a specific sender
34 * @param source Shared ownership of the NetworkSource
35 * @param sender_address IP address string matched against NetworkMessage::sender_address
36 * @param callback Invoked with each matching message
37 * @return Event coroutine suitable for EventManager::add_event()
38 *
39 * @code
40 * auto task = Kriya::on_message_from(src, "192.168.1.10",
41 * [](const Core::NetworkMessage& msg) { });
42 * @endcode
43 */
44MAYAFLUX_API Vruta::Event on_message_from(
45 std::shared_ptr<Vruta::NetworkSource> source,
46 std::string sender_address,
47 std::function<void(const Core::NetworkMessage&)> callback);
48
49/**
50 * @brief Creates an Event coroutine that fires only when a predicate matches
51 * @param source Shared ownership of the NetworkSource
52 * @param predicate Returns true for messages that should trigger the callback
53 * @param callback Invoked with each matching message
54 * @return Event coroutine suitable for EventManager::add_event()
55 *
56 * @code
57 * auto task = Kriya::on_message_matching(src,
58 * [](const Core::NetworkMessage& m) { return m.data.size() == 4; },
59 * [](const Core::NetworkMessage& msg) { });
60 * @endcode
61 */
62MAYAFLUX_API Vruta::Event on_message_matching(
63 std::shared_ptr<Vruta::NetworkSource> source,
64 std::function<bool(const Core::NetworkMessage&)> predicate,
65 std::function<void(const Core::NetworkMessage&)> callback);
66
67} // namespace MayaFlux::Kriya
Vruta::Event on_message_matching(std::shared_ptr< Vruta::NetworkSource > source, std::function< bool(const Core::NetworkMessage &)> predicate, std::function< void(const Core::NetworkMessage &)> callback)
Creates an Event coroutine that fires only when a predicate matches.
Vruta::Event on_message_from(std::shared_ptr< Vruta::NetworkSource > source, std::string sender_address, std::function< void(const Core::NetworkMessage &)> callback)
Creates an Event coroutine that fires only for messages from a specific sender.
Vruta::Event on_message(std::shared_ptr< Vruta::NetworkSource > source, std::function< void(const Core::NetworkMessage &)> callback)
Creates an Event coroutine that fires on every message received by a source.