rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
delivery.h
1#pragma once
2
3//
4// Copyright (c) 2019-2023 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
5//
6// Distributed under the MIT Software License
7//
8
9#include "plugin_base.h"
10#include "../message_stringifier.h"
11#include <string>
12
13#if !defined(NDEBUG) && !defined(ROTOR_DEBUG_DELIVERY)
14#define ROTOR_DO_DELIVERY_DEBUG 1
15#endif
16
17namespace rotor::plugin {
18
23struct ROTOR_API local_delivery_t {
24
35 static void delivery(message_ptr_t &message, const subscription_t::joint_handlers_t &local_recipients) noexcept;
36};
37
43
45 static void delivery(message_ptr_t &message, const subscription_t::joint_handlers_t &local_recipients,
46 const message_stringifier_t *stringifier) noexcept;
47
49 static void discard(message_ptr_t &message, const message_stringifier_t *stringifier) noexcept;
50};
51
52#if !defined(ROTOR_DO_DELIVERY_DEBUG)
54#else
56#endif
57
62struct ROTOR_API delivery_plugin_base_t : public plugin_base_t {
63 using plugin_base_t::plugin_base_t;
64
66 virtual size_t process() noexcept = 0;
67 void activate(actor_base_t *actor) noexcept override;
68
69 protected:
71 messages_queue_t *queue = nullptr;
72
74 address_t *address = nullptr;
75
77 subscription_t *subscription_map;
78
80 const message_stringifier_t *stringifier;
81};
82
84template <typename LocalDelivery = local_delivery_t> struct delivery_plugin_t : public delivery_plugin_base_t {
85 using delivery_plugin_base_t::delivery_plugin_base_t;
86
88 static const std::type_index class_identity;
89
90 const std::type_index &identity() const noexcept override { return class_identity; }
91
92 inline size_t process() noexcept override;
93};
94
95template <typename LocalDelivery>
96const std::type_index delivery_plugin_t<LocalDelivery>::class_identity = typeid(local_delivery_t);
97
98} // namespace rotor::plugin
intrusive_ptr_t< message_base_t > message_ptr_t
intrusive pointer for message
Definition message.h:118
std::deque< message_ptr_t > messages_queue_t
structure to hold messages (intrusive pointers)
Definition message.h:121
universal primitive of concurrent computation
Definition actor_base.h:47
Message subscription and delivery point.
Definition address.hpp:33
Abstract interface for making textual/string representation of a message.
Definition message_stringifier.h:36
base implementation for messages delivery plugin
Definition delivery.h:62
virtual size_t process() noexcept=0
main messages dispatcher interface
templated message delivery plugin, to allow local message delivery be customized
Definition delivery.h:84
static const std::type_index class_identity
Definition delivery.h:88
const std::type_index & identity() const noexcept override
returns pointer, which uniquely identifiess plugin type
Definition delivery.h:90
size_t process() noexcept override
main messages dispatcher interface
debugging local message delivery implementation with dumping details to stdout.
Definition delivery.h:42
static void discard(message_ptr_t &message, const message_stringifier_t *stringifier) noexcept
dumps discarded message
static void delivery(message_ptr_t &message, const subscription_t::joint_handlers_t &local_recipients, const message_stringifier_t *stringifier) noexcept
delivers the message to the recipients, possibly dumping it to console
basic local message delivery implementation
Definition delivery.h:23
static void delivery(message_ptr_t &message, const subscription_t::joint_handlers_t &local_recipients) noexcept
delivers an message for self of one of child-actors (non-supervisors)
base class for all actor plugins
Definition plugin_base.h:23
pair internal and external handler_t
Definition subscription.h:40
Holds and classifies message handlers on behalf of supervisor.
Definition subscription.h:30