2
3
6
7
8
9
10
14#include <so_5/all.hpp>
18#if defined( SO_5_MSVC
)
20 #pragma warning(disable: 4251
)
38class scenario_in_progress_accessor_t;
41
42
43
44
45
46
47
48struct incident_info_t
final
59 const std::type_index & msg_type,
60 mbox_id_t src_mbox_id )
68
69
70
71
72
73
74
75
76
86
87
88
89
90
91
92
93
94
95
96
97
98
106
107
108
109
110
111
112
113
114
115
116
117
118
119
137
138
139
140
141
142
143
148 using completion_function_t = std::function<
149 void(
const trigger_completion_context_t &) >;
153
154
155 using activation_function_t = std::function<
156 void(
const trigger_activation_context_t &) >;
163
164
165
166
167
168
169
170
174
175
176
177
186
187
188
189
194
195
207 std::type_index msg_type,
208 mbox_id_t src_mbox_id );
213
214
215
216
223
224
225
226
227
233
234
235
236
237
238
239
245
246
247
248
255 const incident_info_t & info )
const noexcept;
264
265
266
267
279
280
281
282
286
287
288
289
293
294
295
296
297
298
299
300
302struct trigger_source_t
final
308 std::type_index msg_type,
309 mbox_id_t src_mbox_id)
310 : m_msg_type( std::move(msg_type) )
311 , m_src_mbox_id( src_mbox_id )
315 std::type_index msg_type )
316 : m_msg_type( std::move(msg_type) )
321
322
323
324
332
333
334
335
336
343
344
345
346
347
358
359
360
361
376
377
378
379
380
386
387
388
389
395
396
397
398
405 const incident_info_t & info )
const noexcept = 0;
409
410
411
412
416
417
418
419
423
424
425
426
427class not_before_constraint_t
final
435
436
441 std::chrono::steady_clock::duration pause )
448 m_started_at = std::chrono::steady_clock::now();
458 const incident_info_t & )
const noexcept override
460 return m_started_at + m_pause <=
461 std::chrono::steady_clock::now();
466
467
468
469
470class not_after_constraint_t
final
478
479
484 std::chrono::steady_clock::duration pause )
491 m_started_at = std::chrono::steady_clock::now();
501 const incident_info_t & )
const noexcept override
503 return m_started_at + m_pause >
504 std::chrono::steady_clock::now();
509
510
511
512
516
517
518
519
520
521
522
523
524
550
551
552
553
554
555
556
557
562
563
564
565
566
567
568
569
570
571
572
589
590
591
613
614
615
616
617
618
619
620
626
627
628
629
630
631
632
633
634
635
636
640 const scenario_in_progress_accessor_t & scenario_accessor,
641 const incident_info_t & info,
642 const message_ref_t & incoming_msg )
noexcept = 0;
646
647
648
649
652 const scenario_in_progress_accessor_t & scenario_accessor,
653 token_t token )
noexcept = 0;
658
659
660
661
662
665 const scenario_in_progress_accessor_t & scenario_accessor,
666 const incident_info_t & info,
667 const message_ref_t & incoming_msg )
noexcept = 0;
676
677
678
681 preactivate_action_t action ) = 0;
685
686
687
688
689
690
691
692
693
694
697 trigger_container_t triggers,
698 std::size_t triggers_to_activate )
noexcept = 0;
702
703
704
705
708 constraint_container_t constraints )
noexcept = 0;
712
713
714
715
719
720
721
722
723
724
725
726
728class trigger_holder_t
final
734 : m_trigger( std::move(trigger) )
738 trigger_holder_t &
operator=( trigger_holder_t && )
noexcept =
default;
741 trigger_holder_t &
operator=(
const trigger_holder_t & ) =
delete;
745
746
747
748
752 return std::move(m_trigger);
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
842 details::trigger_container_t & to,
843 details::trigger_holder_t<Status> event,
853 template<
typename... Args >
856 details::constraint_container_t & to,
857 details::constraint_unique_ptr_t head,
867
868
869
870
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
906 impact( Target && target, Args && ...args )
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966 template<
typename Lambda >
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
996 details::trigger_holder_t<Status> event )
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1031 details::trigger_holder_t<Status> event,
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1072 details::trigger_holder_t<Status> event,
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114 template<
typename... Args >
1117 details::constraint_unique_ptr_t head,
1135
1136
1137
1138
1139
1140
1141
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1210 std::string description )
1217
1218
1219
1229
1230
1231
1243 const auto status_name =
1245 const char * result{};
1249 result =
"not_started";
1252 result =
"in_progress";
1255 result =
"completed";
1258 result =
"timed_out";
1264 to <<
"[" << status_name( v.m_status );
1265 if( v.m_description )
1266 to <<
",{" << *v.m_description <<
"}";
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309template<
typename Msg_Type>
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331template<
typename Msg_Type>
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1365 return { std::move(tag) };
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418template<
typename Lambda >
1425 Lambda && inspector )
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499template<
typename Msg_Type>
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528template<
typename Msg_Type>
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1567 return std::make_unique< details::not_before_constraint_t >(pause);
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1598 return std::make_unique< details::not_after_constraint_t >(pause);
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614class scenario_in_progress_accessor_t
final
1627 const scenario_in_progress_accessor_t & ) =
delete;
1629 const scenario_in_progress_accessor_t & ) =
delete;
1632 scenario_in_progress_accessor_t && ) =
delete;
1634 scenario_in_progress_accessor_t && ) =
delete;
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1662 scenario_in_progress_accessor_t
1665 return { outliving_mutable(*
this) };
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1745 run_for( std::chrono::steady_clock::duration run_time ) = 0;
1749
1750
1751
1752
1753
1758 const incident_info_t & info,
1761 const message_ref_t & incoming_msg )
noexcept = 0;
1765
1766
1767
1771 token_t token )
noexcept = 0;
1778 const incident_info_t & info,
1781 const message_ref_t & incoming_msg )
noexcept = 0;
1785
1786
1789 const scenario_in_progress_accessor_t & ,
1791 const std::string & tag,
1792 const std::string & state_name ) = 0;
1796
1797
1798
1799
1800
1809
1810
1811
1812
1816 const std::string & step_name,
1817 const std::string & tag )
const = 0;
1821
1822
1823
1824
1827 const scenario_in_progress_accessor_t & ,
1829 const std::string & tag,
1830 const std::string & inspection_result ) = 0;
1834
1835
1836
1837
1838
1839
1840
1848
1849
1850
1851
1852
1853
1854
1855
1859 const std::string & step_name,
1860 const std::string & tag )
const = 0;
1864
1865
1866
1867
1869trigger_holder_t<Status>
1872 const trigger_source_t<Status> & src )
1887
1888
1889
1890
1891
1897 auto trigger_ptr = old_holder.giveout_trigger();
1898 auto * target_agent = &(trigger_ptr->target_agent());
1899 trigger_ptr->set_completion(
1900 [data = std::move(data_to_store), target_agent](
1901 const trigger_completion_context_t & ctx )
noexcept
1903 ctx.m_scenario_accessor.scenario().store_state_name(
1904 ctx.m_scenario_accessor,
1907 target_agent->so_current_state().query_name() );
1910 return { std::move(trigger_ptr) };
1914
1915
1916
1917
1918
1920trigger_holder_t< Status >
1922 trigger_holder_t<Status> && old_holder,
1942
1943
1944
1945
1946
1952 auto trigger_ptr = old_holder.giveout_trigger();
1953 trigger_ptr->set_completion(
1954 [](
const trigger_completion_context_t & )
noexcept
1961 return { std::move(trigger_ptr) };
1968
1969
1970
1971
1972
1973
1974
1975
1976template<
typename Msg >
1988 : agent_t{ std::move(ctx) }
1989 , m_from{ std::move(from) }
1995 so_subscribe( m_from ).event( &a_msg_catcher_t::evt_msg_arrived );
2049 const agent_t * target_agent )
2056 using catcher_key_t = std::tuple<
2064 using agents_map_t = std::map< catcher_key_t, catcher_info_t >;
2073 template<
typename Msg >
2076 const so_5::mbox_t & from )
const
2079 return this->so_environment().introduce_coop(
2080 [&from]( coop_t & coop ) ->
const agent_t * {
2081 using agent_to_create_t = a_msg_catcher_t< Msg >;
2083 return coop.make_agent< agent_to_create_t >( from );
2096 template<
typename Msg >
2099 const so_5::mbox_t & from )
2101 std::lock_guard< std::mutex > lock{ m_lock };
2103 const catcher_key_t key{
2104 message_payload_type< Msg >::subscription_type_index(),
2107 auto it = m_agents.find( key );
2108 if( it == m_agents.end() )
2113 it = m_agents.emplace(
2115 catcher_info_t{
nullptr } )
2118 ::so_5::details::do_with_rollback_on_exception(
2121 const agent_t * catcher_agent =
2122 register_new_catcher< Msg >( from );
2126 it->second.m_target_agent = catcher_agent;
2131 m_agents.erase( it );
2143
2144
2145
2146
2147
2148
2149template<
typename Msg >
2154
2155
2156
2157
2158
2159
2160
2161template<
typename Msg >
2165 const mbox_t & from,
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234template<
typename Msg >
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2337
2338
2339
2340
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2376 run_for( std::chrono::steady_clock::duration run_time );
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2461 const std::string & step_name,
2462 const std::string & tag )
const;
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2556 const std::string & step_name,
2557 const std::string & tag )
const;
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2646
2647
2648
2649
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2671 so_5::generic_simple_so_env_params_tuner_t env_params_tuner );
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2707
2708
2709
2710
2711
2750#if defined( SO_5_MSVC
)
2751 #pragma warning(pop)
static demand_handler_pfn_t get_demand_handler_on_message_ptr() noexcept
static demand_handler_pfn_t get_demand_handler_on_enveloped_msg_ptr() noexcept
An interface of envelope with some message/signal inside.
virtual void access_hook(access_context_t context, handler_invoker_t &invoker) noexcept=0
An extended version of handling_context which can be used for calling event handler.
An information about payload inside envelope.
message_ref_t & message() const noexcept
Parameters for the SObjectizer Environment initialization.
environment_params_t()
Constructor.
Interface of event_queue_hook object.
An interface of event queue for agent.
trigger_t & trigger() const noexcept
Get a reference to activated trigger.
token_t(trigger_t *trigger) noexcept
trigger_t * m_trigger
Activated trigger.
bool valid() const noexcept
An interface of testing scenario step.
virtual void no_handler_hook(const scenario_in_progress_accessor_t &scenario_accessor, const incident_info_t &info, const message_ref_t &incoming_msg) noexcept=0
abstract_scenario_step_t & operator=(const abstract_scenario_step_t &)=delete
virtual ~abstract_scenario_step_t()=default
virtual void add_preactivate_action(preactivate_action_t action)=0
Add another preactivation action.
virtual void setup_triggers(trigger_container_t triggers, std::size_t triggers_to_activate) noexcept=0
Setup triggers for the step.
abstract_scenario_step_t(abstract_scenario_step_t &&)=delete
virtual void setup_constraints(constraint_container_t constraints) noexcept=0
Setup constraints for the step.
virtual const std::string & name() const noexcept=0
Get the name of the step.
virtual void post_handler_hook(const scenario_in_progress_accessor_t &scenario_accessor, token_t token) noexcept=0
Hook that should be called just after completion of event-handler.
abstract_scenario_step_t & operator=(abstract_scenario_step_t &&)=delete
virtual void preactivate() noexcept=0
Perform preactivation of the step.
virtual token_t pre_handler_hook(const scenario_in_progress_accessor_t &scenario_accessor, const incident_info_t &info, const message_ref_t &incoming_msg) noexcept=0
Hook that should be called before invocation of event-handler.
abstract_scenario_step_t(const abstract_scenario_step_t &)=delete
virtual status_t status() const noexcept=0
Get the current status of the step.
abstract_scenario_step_t()=default
abstract_scenario_step_t & activated_step() const noexcept
abstract_scenario_step_t::token_t m_step_token
abstract_scenario_step_t::token_t step_token() const noexcept
abstract_scenario_step_t * m_activated_step
token_t(abstract_scenario_step_t *activated_step, abstract_scenario_step_t::token_t step_token)
bool valid() const noexcept
An interface of testing scenario.
virtual void store_msg_inspection_result(const scenario_in_progress_accessor_t &, const abstract_scenario_step_t &step, const std::string &tag, const std::string &inspection_result)=0
Store msg inspection result in the scenario.
scenario_in_progress_accessor_t make_accessor() noexcept
Helper method for creation of scenario_in_progress_accessor instance.
abstract_scenario_t(abstract_scenario_t &&)=delete
virtual void run_for(std::chrono::steady_clock::duration run_time)=0
Run the scenario until completion or for specific amount of time.
virtual token_t pre_handler_hook(const incident_info_t &info, const message_ref_t &incoming_msg) noexcept=0
Hook that should be called before invocation of event-handler.
abstract_scenario_t()=default
virtual std::string stored_msg_inspection_result(const std::string &step_name, const std::string &tag) const =0
Get a value of stored msg inspection result.
virtual ~abstract_scenario_t()=default
virtual void post_handler_hook(token_t token) noexcept=0
Hook that should be called just after completion of event-handler.
virtual void no_handler_hook(const incident_info_t &info, const message_ref_t &incoming_msg) noexcept=0
abstract_scenario_t & operator=(const abstract_scenario_t &)=delete
virtual void store_state_name(const scenario_in_progress_accessor_t &, const abstract_scenario_step_t &step, const std::string &tag, const std::string &state_name)=0
Store a name of an agent state in the scenario.
virtual bool has_stored_state_name(const std::string &step_name, const std::string &tag) const =0
Check presence of the stored state name.
virtual std::string stored_state_name(const std::string &step_name, const std::string &tag) const =0
Get the stored state name.
abstract_scenario_t & operator=(abstract_scenario_t &&)=delete
virtual scenario_result_t result() const noexcept=0
Get the result of scenario execution.
virtual step_definition_proxy_t define_step(nonempty_name_t step_name)=0
Create a new step and return proxy for it.
abstract_scenario_t(const abstract_scenario_t &)=delete
virtual bool has_stored_msg_inspection_result(const std::string &step_name, const std::string &tag) const =0
Is there the inspection result?
An interface for object that will unfreeze all registered agents when testing scenario starts.
agent_unfreezer_t(const agent_unfreezer_t &)=delete
agent_unfreezer_t & operator=(const agent_unfreezer_t &)=delete
agent_unfreezer_t()=default
virtual void unfreeze() noexcept=0
Issue a command to unfreeze all frozen agents.
agent_unfreezer_t(agent_unfreezer_t &&)=delete
agent_unfreezer_t & operator=(agent_unfreezer_t &&)=delete
virtual ~agent_unfreezer_t()=default
An interface of step's constraints.
constraint_t & operator=(constraint_t &&)=delete
virtual void start() noexcept=0
Hook for step preactivation.
constraint_t & operator=(const constraint_t &)=delete
virtual ~constraint_t() noexcept=default
constraint_t(constraint_t &&)=delete
constraint_t(const constraint_t &)=delete
virtual bool check(const incident_status_t incident_status, const incident_info_t &info) const noexcept=0
Check for fulfillment of constraint.
virtual void finish() noexcept=0
Hook for step completion.
const mbox_t m_from
Source for a message.
void so_define_agent() override
Hook on define agent for SObjectizer.
void evt_msg_arrived(mhood_t< Msg >)
a_msg_catcher_t(context_t ctx, mbox_t from)
std::mutex m_lock
The lock for thread safety.
msg_catcher_map_layer_t()
~msg_catcher_map_layer_t() noexcept override
agents_map_t m_agents
The map of already created catcher agents.
const agent_t * register_new_catcher(const so_5::mbox_t &from) const
Helper for registration of a new agent.
catcher_info_t catcher_for_mbox(const so_5::mbox_t &from)
void start() noexcept override
Hook for step preactivation.
const std::chrono::steady_clock::duration m_pause
Value to be used.
void finish() noexcept override
Hook for step completion.
std::chrono::steady_clock::time_point m_started_at
Time point of step preactivation.
bool check(const incident_status_t, const incident_info_t &) const noexcept override
Check for fulfillment of constraint.
not_after_constraint_t(std::chrono::steady_clock::duration pause)
void start() noexcept override
Hook for step preactivation.
std::chrono::steady_clock::time_point m_started_at
Time point of step preactivation.
const std::chrono::steady_clock::duration m_pause
Value to be used.
void finish() noexcept override
Hook for step completion.
bool check(const incident_status_t, const incident_info_t &) const noexcept override
Check for fulfillment of constraint.
not_before_constraint_t(std::chrono::steady_clock::duration pause)
preactivate_actions_container_t m_preactivate_actions
All preactivation actions.
std::size_t m_triggers_activated
Count of triggers those are activated.
void no_handler_hook(const scenario_in_progress_accessor_t &scenario_accessor, const incident_info_t &info, const message_ref_t &incoming_msg) noexcept override
token_t pre_handler_hook(const scenario_in_progress_accessor_t &scenario_accessor, const incident_info_t &info, const message_ref_t &incoming_msg) noexcept override
Hook that should be called before invocation of event-handler.
bool try_pass_constraints(const incident_status_t incident_status, const incident_info_t &info) const noexcept
An attempt to check constraints for a new incident.
void setup_constraints(constraint_container_t constraints) noexcept override
Setup constraints for the step.
void preactivate() noexcept override
Perform preactivation of the step.
const std::string m_name
Name of a step.
std::size_t m_last_non_activated_trigger
Index of last trigger in the first part of trigger's container.
std::size_t m_triggers_to_activate
status_t status() const noexcept override
Get the current status of the step.
std::size_t m_triggers_to_completion
Count of activated triggers those are not completed yet.
status_t m_status
The current state of the step.
void post_handler_hook(const scenario_in_progress_accessor_t &scenario_accessor, token_t token) noexcept override
Hook that should be called just after completion of event-handler.
const std::string & name() const noexcept override
Get the name of the step.
token_t try_activate(const trigger_activation_context_t &context, const incident_status_t incident_status, const incident_info_t &info) noexcept
An attempt to activate the step when a new incident arrives.
constraint_container_t m_constraints
All constraints.
trigger_container_t m_triggers
All triggers.
real_scenario_step_t(std::string name)
void add_preactivate_action(preactivate_action_t action) override
Add another preactivation action.
void setup_triggers(trigger_container_t triggers, std::size_t triggers_to_activate) noexcept override
Setup triggers for the step.
void change_status(status_t status) noexcept
void no_handler_hook(const incident_info_t &info, const message_ref_t &incoming_msg) noexcept override
std::string stored_msg_inspection_result(const std::string &step_name, const std::string &tag) const override
Get a value of stored msg inspection result.
bool has_stored_state_name(const std::string &step_name, const std::string &tag) const override
Check presence of the stored state name.
void check_scenario_completion() noexcept
std::size_t m_waiting_step_index
Index of the current preactivated step.
void switch_to_next_step_if_possible()
std::set< abstract_scenario_step_t * > m_active_steps
Set of active step those are not completed yet.
scenario_result_t result() const noexcept override
Get the result of scenario execution.
void store_msg_inspection_result(const scenario_in_progress_accessor_t &, const abstract_scenario_step_t &step, const std::string &tag, const std::string &inspection_result) override
Store msg inspection result in the scenario.
std::string describe_current_state() const
bool has_stored_msg_inspection_result(const std::string &step_name, const std::string &tag) const override
Is there the inspection result?
std::string stored_state_name(const std::string &step_name, const std::string &tag) const override
Get the stored state name.
token_t react_on_pre_handler_hook(const incident_info_t &info, const message_ref_t &incoming_msg) noexcept
std::condition_variable m_completion_cv
Condition variable for waiting completion of the scenario.
void react_on_no_handler_hook(const incident_info_t &info, const message_ref_t &incoming_msg) noexcept
void preactivate_current_step()
void post_handler_hook(token_t token) noexcept override
Hook that should be called just after completion of event-handler.
void run_for(std::chrono::steady_clock::duration run_time) override
Run the scenario until completion or for specific amount of time.
agent_unfreezer_t * m_unfreezer
Unfreezer for registered agents.
real_scenario_t()=default
void setup_unfreezer(agent_unfreezer_t &unfreezer) noexcept
Set the unfreezer for registered agents.
inspection_result_map_t m_stored_inspection_results
Container for holding stored inspection results for messages.
void store_state_name(const scenario_in_progress_accessor_t &, const abstract_scenario_step_t &step, const std::string &tag, const std::string &state_name) override
Store a name of an agent state in the scenario.
token_t pre_handler_hook(const incident_info_t &info, const message_ref_t &incoming_msg) noexcept override
Hook that should be called before invocation of event-handler.
std::mutex m_lock
Object lock.
step_definition_proxy_t define_step(nonempty_name_t step_name) override
Create a new step and return proxy for it.
state_name_map_t m_stored_states
Container for holding stored state names.
scenario_status_t m_status
The current state of the scenario.
std::vector< step_unique_ptr_t > m_steps
Scenario's steps.
scenario_in_progress_accessor_t & operator=(scenario_in_progress_accessor_t &&)=delete
scenario_in_progress_accessor_t(outliving_reference_t< abstract_scenario_t > scenario)
scenario_in_progress_accessor_t(scenario_in_progress_accessor_t &&)=delete
abstract_scenario_t & scenario() const noexcept
scenario_in_progress_accessor_t & operator=(const scenario_in_progress_accessor_t &)=delete
scenario_in_progress_accessor_t(const scenario_in_progress_accessor_t &)=delete
outliving_reference_t< abstract_scenario_t > m_scenario
trigger_holder_t(const trigger_holder_t &)=delete
trigger_holder_t & operator=(trigger_holder_t &&) noexcept=default
trigger_holder_t & operator=(const trigger_holder_t &)=delete
trigger_holder_t(trigger_holder_t &&) noexcept=default
trigger_holder_t(trigger_unique_ptr_t trigger) noexcept
trigger_unique_ptr_t m_trigger
trigger_unique_ptr_t giveout_trigger() noexcept
Get the trigger object from the holder.
activation_function_t m_activation
Optional function for activation of the trigger.
const std::type_index m_msg_type
Type of message/signal to activate the trigger.
completion_function_t m_completion
Optional function for completion of the trigger.
trigger_t(trigger_t &&)=delete
void set_completion(completion_function_t fn)
Setter for completion function.
void set_activation(activation_function_t fn)
Setter for activation function.
void activate(const trigger_activation_context_t &context) noexcept
Do activation of the trigger.
bool check(const incident_status_t incident_status, const incident_info_t &info) const noexcept
Check for activation of the trigger.
const mbox_id_t m_src_mbox_id
ID of source mbox of message/signal to activate the trigger.
trigger_t(incident_status_t incident_status, const agent_t &target, std::type_index msg_type, mbox_id_t src_mbox_id)
Initializing constructor.
const agent_t & target_agent() const noexcept
Get the reference of the target agent.
const incident_status_t m_incident_status
What should happen with initial message/signal.
bool requires_completion() const noexcept
Does this trigger require separate completion action?
const mbox_id_t m_target_id
The unique ID of target's direct mbox.
void complete(const trigger_completion_context_t &context) noexcept
Do completion of a trigger.
trigger_t(const trigger_t &)=delete
const agent_t & m_target_agent
A reference to the target agent.
void invoke(const payload_info_t &payload) noexcept override
Call an actual handler for the enveloped message/signal.
no_handler_invoker_t(outliving_reference_t< special_envelope_t > owner)
Initializing constructor.
outliving_reference_t< special_envelope_t > m_owner
Owner of this invoker.
outliving_reference_t< handler_invoker_t > m_actual_invoker
Invoker to be used to call the actual event handler.
void invoke(const payload_info_t &payload) noexcept override
Call an actual handler for the enveloped message/signal.
pre_handler_hook_invoker_t(outliving_reference_t< special_envelope_t > owner, outliving_reference_t< handler_invoker_t > actual_invoker)
Intializing constructor.
outliving_reference_t< special_envelope_t > m_owner
Owner of this invoker.
outliving_reference_t< details::abstract_scenario_t > m_scenario
A testing scenario for that envelope.
~special_envelope_t() noexcept override
@ delivered
Message delivered to the destination agent.
@ suppressed_by_envelope
Message suppressed by a nested envelope.
@ ignored
Message ignored by the destination agent.
special_envelope_t(outliving_reference_t< details::abstract_scenario_t > scenario, const execution_demand_t &demand)
Initializing constructor.
message_ref_t m_message
Enveloped message.
details::incident_info_t m_demand_info
Information about enveloped message.
void access_hook(access_context_t context, handler_invoker_t &invoker) noexcept override
delivery_result_t m_delivery_result
Was this message handled by a receiver?
void unfreeze() noexcept override
Issue a command to unfreeze all frozen agents.
std::mutex m_lock
Lock for this object.
outliving_reference_t< details::abstract_scenario_t > m_scenario
Testing scenario for that this object is created.
void on_unbind(agent_t *, event_queue_t *queue) noexcept override
A reaction to unbinding of an agent from some event_queue.
queue_mode_t m_mode
Mode of operation for new queues.
std::vector< special_event_queue_t * > m_created_queues
List of all queues created before unfreeze was called.
special_event_queue_hook_t(outliving_reference_t< details::abstract_scenario_t > scenario)
event_queue_t * on_bind(agent_t *, event_queue_t *original_queue) noexcept override
A reaction to binding of an agent to some event_queue.
std::vector< execution_demand_t > m_buffer
Local storage for demands to be used in buffered mode.
static bool is_ordinary_demand(const execution_demand_t &demand) noexcept
special_event_queue_t(outliving_reference_t< details::abstract_scenario_t > scenario, outliving_reference_t< event_queue_t > original_queue, queue_mode_t queue_mode)
void push_to_queue(execution_demand_t demand)
void push_evt_finish(execution_demand_t demand) noexcept override
Enqueue a demand for evt_finish event.
queue_mode_t m_mode
The current mode of operation.
std::mutex m_lock
Object lock.
void push_evt_start(execution_demand_t demand) override
Enqueue a demand for evt_start event.
outliving_reference_t< event_queue_t > m_original_queue
Original event_queue.
void switch_to_direct_mode()
void push(execution_demand_t demand) override
Enqueue new event to the queue.
outliving_reference_t< details::abstract_scenario_t > m_scenario
Testing scenario for that this queue was created.
stop_guard_for_unfreezer_t(outliving_reference_t< details::agent_unfreezer_t > unfreezer, outliving_reference_t< environment_t > env)
outliving_reference_t< details::agent_unfreezer_t > m_unfreezer
outliving_reference_t< environment_t > m_env
void stop() noexcept override
Perform stop-related actions.
step_definition_proxy_t define_step(nonempty_name_t step_name)
Start definition of a new scenario's step.
std::string stored_state_name(const std::string &step_name, const std::string &tag) const
Try to get stored name of an agent's state.
std::string stored_msg_inspection_result(const std::string &step_name, const std::string &tag) const
Try to get stored msg inspection result.
outliving_reference_t< details::abstract_scenario_t > m_scenario
bool has_stored_state_name(const std::string &step_name, const std::string &tag) const
Is there the inspection result?
bool has_stored_msg_inspection_result(const std::string &step_name, const std::string &tag) const
Is there the inspection result?
void run_for(std::chrono::steady_clock::duration run_time)
Runs the scenario for specified amount of time.
scenario_proxy_t(outliving_reference_t< details::abstract_scenario_t > scenario)
scenario_result_t result() const
Get the result of scenario execution.
The result of run of testing scenario.
scenario_result_t(scenario_status_t status)
The constructor for a case when there is only status of scenario.
scenario_result_t(scenario_status_t status, std::string description)
scenario_status_t m_status
friend std::ostream & operator<<(std::ostream &to, const scenario_result_t &v)
Dump of object's content to ostream.
optional< std::string > m_description
bool operator!=(const scenario_result_t &o) const noexcept
Check for inequality.
bool operator==(const scenario_result_t &o) const noexcept
Check for equality.
A special object that should be used for definition of a step of a testing scenario.
details::abstract_scenario_step_t * m_step
step_definition_proxy_t(details::abstract_scenario_step_t *step)
Initializing constructor.
step_definition_proxy_t & impact(Lambda &&lambda)
Add preactivation action in form of lambda-object.
step_definition_proxy_t & when_all(details::trigger_holder_t< Status > event, Args &&...args)
Add a list of tiggers for activation of that step.
void append_constraint_to(details::constraint_container_t &)
void append_trigger_to(details::trigger_container_t &to, details::trigger_holder_t< Status > event, Args &&...args)
void append_constraint_to(details::constraint_container_t &to, details::constraint_unique_ptr_t head, Args &&...tail)
step_definition_proxy_t & impact(Target &&target, Args &&...args)
Define a preactivation action in form of sending a message/signal to the specified target.
void append_trigger_to(details::trigger_container_t &)
step_definition_proxy_t & constraints(details::constraint_unique_ptr_t head, Args &&...tail)
Add a list of constraints for that step.
step_definition_proxy_t & when_any(details::trigger_holder_t< Status > event, Args &&...args)
Add a list of tiggers for activation of that step.
step_definition_proxy_t & when(details::trigger_holder_t< Status > event)
Add a tigger for activation of that step.
A special testing environment that should be used for testing of agents.
void stop()
Send stop signal to environment.
environment_t & environment() const
Access to wrapped environment.
testing_env_t()
Default constructor.
testing_env_t(environment_params_t &&env_params)
void wait_init_completion()
scenario_proxy_t scenario() noexcept
Access to the associated scenario.
void join()
Wait for complete finish of environment's work.
wrapped_env_t m_sobjectizer
std::unique_ptr< internals_t > m_internals
void tune_environment_on_start(environment_t &env)
void stop_then_join()
Send stop signal and wait for complete finish of environment's work.
testing_env_t(so_5::generic_simple_so_env_params_tuner_t env_params_tuner)
A constructor that allows to tune environment's parameters.
An interface of the additional SObjectizer Environment layer.
A base class for agent messages.
friend message_kind_t message_kind(const so_5::intrusive_ptr_t< message_t > &what)
Helper method for quering kind of the message.
A class for the name which cannot be empty.
Helper class for indication of long-lived reference via its type.
An interface of stop_guard entity.
#define SO_5_THROW_EXCEPTION(error_code, desc)
Some reusable and low-level classes/functions which can be used in public header files.
envelope_t & message_to_envelope(const message_ref_t &src_msg)
A helper function for casting message instance to envelope instance.
access_context_t
Information about context on that enveloped message is handled.
trigger_holder_t< incident_status_t::handled > operator&(trigger_holder_t< incident_status_t::handled > &&old_holder, wait_event_handler_completion_t)
A helper operator to create a tigger that requires the completion of an event handler.
trigger_holder_t< Status > operator&(trigger_holder_t< Status > &&old_holder, store_msg_inspection_result_t inspection_info)
A helper operator to create a tigger that inspects the incoming message and stores the result into th...
trigger_holder_t< incident_status_t::handled > operator&(const mbox_t &from, receives_indicator_t< Msg >)
A helper operator to create a tigger that receives a message/signal from specified mbox.
trigger_holder_t< Status > operator&(const so_5::agent_t &agent, const trigger_source_t< Status > &src)
A helper operator to create a trigger for the specified agent.
incident_status_t
What happened with source of an event.
@ handled
Message or signal has been handled.
@ ignored
Message or signal has been ignored.
trigger_holder_t< incident_status_t::handled > operator&(trigger_holder_t< incident_status_t::handled > &&old_holder, store_agent_state_name_t data_to_store)
A helper operator to create a tigger that stores the name of the current agent's state.
environment_params_t make_special_params(outliving_reference_t< testing_env_t::internals_t > internals, environment_params_t &¶ms)
void setup_special_queue_hook(outliving_reference_t< testing_env_t::internals_t > internals, environment_params_t &to)
environment_params_t make_tuned_params(so_5::generic_simple_so_env_params_tuner_t env_params_tuner)
queue_mode_t
A mode of work for special_event_queue.
@ direct
All messages should go to the original queue without buffering.
@ buffer
All messages must be stored locally.
scenario_result_t completed()
Create a value that means that scenario completed successfuly.
details::receives_indicator_t< Msg > receives()
Helper function to be used for a trigger that receives a message/singal from a mbox.
details::trigger_source_t< details::incident_status_t::ignored > ignores()
Define a trigger that activates when an agent rejects a message from the direct mbox.
scenario_status_t
Status of testing scenario.
@ completed
Testing scenario is successfuly completed.
details::constraint_unique_ptr_t not_after(std::chrono::steady_clock::duration pause)
Create a constraint not-after.
details::store_msg_inspection_result_t inspect_msg(std::string tag, Lambda &&inspector)
Create a special marker for a trigger for inspecting an incoming message and storing the inspection r...
details::store_agent_state_name_t store_state_name(std::string tag)
Create a special marker for a trigger for storing agent's state name inside scenario.
details::trigger_source_t< details::incident_status_t::handled > reacts_to()
Define a trigger that activates when an agent receives and handles a message from the direct mbox.
details::trigger_source_t< details::incident_status_t::handled > reacts_to(const so_5::mbox_t &mbox)
Define a trigger that activates when an agent receives and handles a message from the specific mbox.
details::constraint_unique_ptr_t not_before(std::chrono::steady_clock::duration pause)
Create a constraint not-before.
details::trigger_source_t< details::incident_status_t::ignored > ignores(const so_5::mbox_t &mbox)
Define a trigger that activates when an agent rejects a message from the direct mbox.
details::wait_event_handler_completion_t wait_event_handler_completion()
Create a special marker for a trigger that requires waiting for completion of an event handler.
Private part of message limit implementation.
@ user_type_message
Message is an user type message.
@ enveloped_msg
Message is an envelope with some other message inside.
A description of event execution demand.
demand_handler_pfn_t m_demand_handler
Demand handler.
const agent_t * m_agent
Target of an event.
const std::type_index m_msg_type
Type of message or signal.
incident_info_t(const agent_t *agent, const std::type_index &msg_type, mbox_id_t src_mbox_id)
mbox_id_t m_src_mbox_id
ID of mbox from that message/signal was received.
catcher_info_t(const agent_t *target_agent)
Initializing constructor.
const agent_t * m_target_agent
Pointer to the agent.
Special indicator to be used in implementation of receives trigger.
A special data object for case of store-state-name completion action.
std::string m_tag
Name of tag for store-state-name action.
A special data object for case when a message inspector has to be used on an incoming message.
std::function< std::string(const message_ref_t &) > m_inspector
Inspector for a message.
std::string m_tag
Name of a tag for store-msg-inspection action.
Description of context on that an attempt to activate a trigger is performing.
const scenario_in_progress_accessor_t & m_scenario_accessor
Access to the running scenario.
abstract_scenario_step_t & m_step
The current step for that activation is being performed.
const message_ref_t & m_incoming_msg
Incoming message or signal.
Description of context on that a trigger is completed.
abstract_scenario_step_t & m_step
const scenario_in_progress_accessor_t & m_scenario_accessor
std::type_index m_msg_type
trigger_source_t(std::type_index msg_type)
optional< mbox_id_t > m_src_mbox_id
trigger_source_t(std::type_index msg_type, mbox_id_t src_mbox_id)
A special data object for case when a step should be completed only after returning from the event ha...
A helper object for synchronization between helper worker where testing environment is launched and u...
std::promise< void > m_completed
Internal data for testing environment.
impl::init_completed_data_t m_init_completed
impl::special_event_queue_hook_t m_special_hook
details::real_scenario_t m_scenario
static std::unique_ptr< internals_t > make()
A helper class for detection of payload type of message.