2
3
4
5
6
10#include <so_5_extra/error_ranges.hpp>
12#include <so_5/impl/msg_tracing_helpers.hpp>
14#include <so_5/environment.hpp>
15#include <so_5/mbox.hpp>
33
34
35
36
41
42
43
44
45
46
47
52
53
54
55
56
57
58
63
64
65
66
67
68
69
70
77
78
79
80
81
94 "nullptr can't be used as the default destination mbox" );
108 dest()
const noexcept {
return m_dest; }
112
113
114
115
116
117
118
119
124
125
126
127
128
129
130
135
136
137
138
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
168 return { redirect_to_if_not_found_case_t{ dest_mbox } };
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
194 return { throw_if_not_found_case_t{} };
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
219 return { drop_if_not_found_case_t{} };
228
229
230
231
232
233
234
250
251
252
253
257
258
259
260
262 [](
const target_t & target,
const std::type_index & msg_type ) ->
bool {
263 return target.m_msg_type < msg_type;
270
271
272
273
274
282 const std::type_index & msg_type,
283 abstract_message_sink_t & subscriber )
291 c.dest()->subscribe_event_handler(
299 SO_5_THROW_EXCEPTION(
300 errors::rc_no_sink_for_message_type,
301 "no destination for this message type, "
302 "msg_type=" + std::string(m_msg_type.name()) );
313
314
315
316
317
325 const std::type_index & msg_type,
326 abstract_message_sink_t & subscriber )
334 c.dest()->unsubscribe_event_handler(
353
354
355
356
357
358template<
typename Tracer >
370 message_delivery_mode_t delivery_mode,
371 const std::type_index & msg_type,
372 const message_ref_t & msg,
373 unsigned int overlimit_deep )
387 "redirect_to_default_destination",
401 "no_destination.throw_exception" );
404 "no destination for this message type, "
412 "no_destination.drop_message" );
417
418
419
420
421
430 const std::type_index & msg_type,
431 const delivery_filter_t & filter,
432 abstract_message_sink_t & subscriber )
441 c.dest()->set_delivery_filter(
450 SO_5_THROW_EXCEPTION(
451 errors::rc_no_sink_for_message_type,
452 "no destination for this message type, "
453 "msg_type=" + std::string(m_msg_type.name()) );
464
465
466
467
468
476 const std::type_index & msg_type,
477 abstract_message_sink_t & subscriber )
noexcept
485 c.dest()->drop_delivery_filter(
506
507
508
509
530 mbox_type_t mbox_type,
531 type_not_found_reaction_t unknown_type_reaction,
532 target_container_t targets )
542
543
544
545
546
547
548
549
550template<
typename Tracing_Base >
551class actual_mbox_t
final
552 :
public abstract_message_box_t
553 ,
private Tracing_Base
558
559
560
561
562
563 template<
typename... Tracing_Args >
567 Tracing_Args &&... tracing_args )
568 : Tracing_Base{ std::forward<Tracing_Args>(tracing_args)... }
569 , m_data{ std::move(mbox_data) }
578 return this->m_data.m_id;
583 const std::type_index & msg_type,
584 abstract_message_sink_t & subscriber )
override
586 const auto opt_target = try_find_target_for_msg_type( msg_type );
589 (*opt_target)->m_dest->subscribe_event_handler(
596 unknown_msg_type_handlers::subscribe_event_t{
599 this->m_data.m_unknown_type_reaction );
605 const std::type_index & msg_type,
606 abstract_message_sink_t & subscriber )
noexcept override
608 const auto opt_target = try_find_target_for_msg_type( msg_type );
611 (*opt_target)->m_dest->unsubscribe_event_handler(
618 unknown_msg_type_handlers::unsubscribe_event_t{
621 this->m_data.m_unknown_type_reaction );
628 std::ostringstream s;
629 s <<
"<mbox:type=COMPOSITE";
631 switch(
this->m_data.m_mbox_type )
633 case mbox_type_t::multi_producer_multi_consumer:
637 case mbox_type_t::multi_producer_single_consumer:
642 s <<
":id=" <<
this->m_data.m_id <<
">";
650 return this->m_data.m_mbox_type;
655 message_delivery_mode_t delivery_mode,
656 const std::type_index & msg_type,
657 const message_ref_t & message,
658 unsigned int redirection_deep )
override
660 ensure_immutable_message( msg_type, message );
662 typename Tracing_Base::deliver_op_tracer tracer{
667 msg_type, message, redirection_deep };
669 const auto opt_target = try_find_target_for_msg_type( msg_type );
672 using namespace ::so_5::impl::msg_tracing_helpers::details;
675 "redirect_to_destination",
676 mbox_as_msg_destination{ *( (*opt_target)->m_dest ) } );
678 (*opt_target)->m_dest->do_deliver_message(
686 using handler_t = unknown_msg_type_handlers::deliver_message_t<
687 typename Tracing_Base::deliver_op_tracer >;
696 this->m_data.m_unknown_type_reaction );
702 const std::type_index & msg_type,
703 const delivery_filter_t & filter,
704 abstract_message_sink_t & subscriber )
override
706 const auto opt_target = try_find_target_for_msg_type( msg_type );
709 (*opt_target)->m_dest->set_delivery_filter(
717 unknown_msg_type_handlers::set_delivery_filter_t{
721 this->m_data.m_unknown_type_reaction );
727 const std::type_index & msg_type,
728 abstract_message_sink_t & subscriber )
noexcept override
730 const auto opt_target = try_find_target_for_msg_type( msg_type );
733 (*opt_target)->m_dest->drop_delivery_filter(
740 unknown_msg_type_handlers::drop_delivery_filter_t{
743 this->m_data.m_unknown_type_reaction );
750 return *(
this->m_data.m_env_ptr);
758
759
760
761
762
763
764
765
770 const auto last = end( m_data.m_targets );
771 const auto it = std::lower_bound(
772 begin( m_data.m_targets ), last,
776 if( !( it == last ) && msg_type == it->m_msg_type )
777 return { std::addressof( *it ) };
783
784
785
786
787
790 const std::type_index & msg_type,
791 const message_ref_t & what )
const
793 if( (mbox_type_t::multi_producer_multi_consumer ==
794 this->m_data.m_mbox_type) &&
795 (message_mutability_t::immutable_message !=
796 message_mutability( what )) )
797 SO_5_THROW_EXCEPTION(
798 so_5::rc_mutable_msg_cannot_be_delivered_via_mpmc_mbox,
799 "an attempt to deliver mutable message via MPMC mbox"
800 ", msg_type=" + std::string(msg_type.name()) );
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
874 mbox_type_t mbox_type,
875 type_not_found_reaction_t unknown_type_reaction );
880 mbox_type_t mbox_type,
882 type_not_found_reaction_t unknown_type_reaction )
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942 template<
typename Msg_Type >
954 "mutable message can't handled with MPMC composite, "
967 "MPMC mbox can't be added as a target to MPSC "
968 "composite and mutable message, "
979 "message type already has a destination mbox, "
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035 template<
typename Msg_Type >
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1070 return env.make_custom_mbox(
1071 [
this](
const mbox_creation_data_t & data )
1073 impl::mbox_data_t mbox_data{
1077 std::move(m_unknown_type_reaction),
1082 if( data.m_tracer.get().is_msg_tracing_enabled() )
1084 using ::so_5::impl::msg_tracing_helpers::
1085 tracing_enabled_base;
1086 using T = impl::actual_mbox_t< tracing_enabled_base >;
1088 result = mbox_t{
new T{
1089 std::move(mbox_data),
1095 using ::so_5::impl::msg_tracing_helpers::
1096 tracing_disabled_base;
1097 using T = impl::actual_mbox_t< tracing_disabled_base >;
1099 result = mbox_t{
new T{ std::move(mbox_data) } };
1108
1109
1110
1111
1112
1125
1126
1127
1128
1133 impl::target_container_t result;
1134 result.reserve( m_targets.size() );
1137 for(
const auto & [k, v] : m_targets )
1138 result.emplace_back( k, v );
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1166 mbox_type_t mbox_type,
1168 type_not_found_reaction_t unknown_type_reaction )
1170 return { mbox_type, std::move(unknown_type_reaction) };
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1195 type_not_found_reaction_t unknown_type_reaction )
1198 mbox_type_t::multi_producer_multi_consumer,
1199 std::move(unknown_type_reaction) );
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1223 type_not_found_reaction_t unknown_type_reaction )
1226 mbox_type_t::multi_producer_single_consumer,
1227 std::move(unknown_type_reaction) );
Function object to be used with std::visit.
void operator()(const throw_if_not_found_case_t &) const
const std::type_index & m_msg_type
const message_delivery_mode_t m_delivery_mode
void operator()(const redirect_to_if_not_found_case_t &c) const
const message_ref_t & m_msg
unsigned int m_overlimit_deep
void operator()(const drop_if_not_found_case_t &) const
deliver_message_t(Tracer &tracer, message_delivery_mode_t delivery_mode, const std::type_index &msg_type, const message_ref_t &msg, unsigned int overlimit_deep)
Function object to be used with std::visit.
const std::type_index & m_msg_type
void operator()(const redirect_to_if_not_found_case_t &c) const noexcept
drop_delivery_filter_t(const std::type_index &msg_type, abstract_message_sink_t &subscriber) noexcept
void operator()(const throw_if_not_found_case_t &) const noexcept
void operator()(const drop_if_not_found_case_t &) const noexcept
abstract_message_sink_t & m_subscriber
Function object to be used with std::visit.
abstract_message_sink_t & m_subscriber
void operator()(const redirect_to_if_not_found_case_t &c) const
const std::type_index & m_msg_type
void operator()(const throw_if_not_found_case_t &) const
void operator()(const drop_if_not_found_case_t &) const
const delivery_filter_t & m_filter
set_delivery_filter_t(const std::type_index &msg_type, const delivery_filter_t &filter, abstract_message_sink_t &subscriber)
Function object to be used with std::visit.
void operator()(const throw_if_not_found_case_t &) const
void operator()(const redirect_to_if_not_found_case_t &c) const
abstract_message_sink_t & m_subscriber
void operator()(const drop_if_not_found_case_t &) const
subscribe_event_t(const std::type_index &msg_type, abstract_message_sink_t &subscriber)
const std::type_index & m_msg_type
Function object to be used with std::visit.
abstract_message_sink_t & m_subscriber
unsubscribe_event_t(const std::type_index &msg_type, abstract_message_sink_t &subscriber)
void operator()(const throw_if_not_found_case_t &) const
const std::type_index & m_msg_type
void operator()(const redirect_to_if_not_found_case_t &c) const noexcept
void operator()(const drop_if_not_found_case_t &) const
Ranges for error codes of each submodules.