-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdatabase.cpp
More file actions
5088 lines (4509 loc) · 183 KB
/
Copy pathdatabase.cpp
File metadata and controls
5088 lines (4509 loc) · 183 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
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
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
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
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
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "database.hpp"
#include <algorithm>
#include <chrono>
#include <iostream>
#include <mutex> // For std::unique_lock
#include <shared_mutex>
#include <string>
#include <vector>
#include <fastdds_statistics_backend/exception/Exception.hpp>
#include <fastdds_statistics_backend/types/types.hpp>
#include <fastdds_statistics_backend/types/JSONTags.h>
#include <StatisticsBackendData.hpp>
#include "database_queue.hpp"
#include "samples.hpp"
namespace eprosima {
namespace statistics_backend {
namespace database {
template<typename E>
void clear_inactive_entities_from_map_(
std::map<EntityId, std::shared_ptr<E>>& map)
{
static_assert(std::is_base_of<Entity, E>::value, "Class does not inherit from Entity.");
// Iterate over whole loop and remove those entities that are not alive
for (auto it = map.cbegin(); it != map.cend(); /* no increment */)
{
if (!it->second->active)
{
// Remove it and have reference to next element
it = map.erase(it);
}
else
{
++it;
}
}
}
template<typename E>
void clear_inactive_entities_from_map_(
std::map<EntityId, std::map<EntityId, std::shared_ptr<E>>>& map)
{
// The higher map will not be removed because it holds the domain, so
// we should just iterate over the internal map.
for (auto& it : map)
{
clear_inactive_entities_from_map_(it.second);
}
}
template<typename E>
void clear_inactive_entities_from_map_(
std::map<EntityId, details::fragile_ptr<E>>& map)
{
static_assert(std::is_base_of<Entity, E>::value, "Class does not inherit from Entity.");
// Iterate over whole loop and remove those entities that are not alive
for (auto it = map.cbegin(); it != map.cend(); /* no increment */)
{
if (it->second.expired())
{
// Remove it and have reference to next element
it = map.erase(it);
}
else
{
++it;
}
}
}
EntityId Database::insert(
const std::shared_ptr<Entity>& entity)
{
std::lock_guard<std::shared_timed_mutex> guard(mutex_);
// Insert in the database with a unique ID
EntityId entity_id = EntityId::invalid();
insert_nts(entity, entity_id);
return entity_id;
}
void Database::insert_nts(
const std::shared_ptr<Entity>& entity,
EntityId& entity_id)
{
// Clear the entity
entity->clear();
switch (entity->kind)
{
case EntityKind::HOST:
{
std::shared_ptr<Host> host = std::static_pointer_cast<Host>(entity);
/* Check that host name is not empty */
if (host->name.empty())
{
throw BadParameter("Host name cannot be empty");
}
/* Check that this is indeed a new host, and that its name is unique */
for (const auto& host_it: hosts_)
{
if (host.get() == host_it.second.get())
{
throw BadParameter("Host already exists in the database");
}
if (host->name == host_it.second->name)
{
throw BadParameter("Host with name " + host->name + " already exists in the database");
}
}
// Add id to the entity
if (!entity_id.is_valid_and_unique())
{
entity_id = generate_entity_id();
}
else if (entity_id.value() >= next_id_)
{
next_id_ = entity_id.value() + 1;
}
host->id = entity_id;
/* Insert host in the database */
hosts_[host->id] = host;
break;
}
case EntityKind::USER:
{
std::shared_ptr<User> user = std::static_pointer_cast<User>(entity);
/* Check that user name is not empty */
if (user->name.empty())
{
throw BadParameter("User name cannot be empty");
}
/* Check that this is indeed a new user */
for (const auto& user_it: users_)
{
if (user.get() == user_it.second.get())
{
throw BadParameter("User already exists in the database");
}
}
/* Check that host exits */
bool host_exists = false;
for (const auto& host_it : hosts_)
{
if (user->host.get() == host_it.second.get())
{
host_exists = true;
break;
}
}
if (!host_exists)
{
throw BadParameter("Parent host does not exist in the database");
}
/* Check that a user with the same name does not exist in the host collection */
for (const auto& user_it : user->host->users)
{
if (user->name == user_it.second->name)
{
throw BadParameter(
"Another User with name '" + user->name
+ "' already exists in parent host collection");
}
}
// Add id to the entity
if (!entity_id.is_valid_and_unique())
{
entity_id = generate_entity_id();
}
else if (entity_id.value() >= next_id_)
{
next_id_ = entity_id.value() + 1;
}
user->id = entity_id;
/* Add user to users collection */
users_[user->id] = user;
/* Add user to host's users collection */
user->host->users[user->id] = user;
break;
}
case EntityKind::PROCESS:
{
std::shared_ptr<Process> process = std::static_pointer_cast<Process>(entity);
/* Check that process name is not empty */
if (process->name.empty())
{
throw BadParameter("Process name cannot be empty");
}
/* Check that PID is not empty */
if (process->pid.empty())
{
throw BadParameter("Process PID cannot be empty");
}
/* Check that this is indeed a new process */
for (const auto& process_it: processes_)
{
if (process.get() == process_it.second.get())
{
throw BadParameter("Process already exists in the database");
}
}
/* Check that user exits */
bool user_exists = false;
for (const auto& user_it : users_)
{
if (process->user.get() == user_it.second.get())
{
user_exists = true;
break;
}
}
if (!user_exists)
{
throw BadParameter("Parent user does not exist in the database");
}
/* Check that a process with the same pid does not exist in the same host */
for (const auto& user_it : hosts_[process->user->host->id]->users)
{
for (const auto& process_it : user_it.second->processes)
{
if (process->pid == process_it.second->pid)
{
throw BadParameter(
"Another process with PID '" + process->pid
+ "' already exists in the same host");
}
}
}
// Add id to the entity
if (!entity_id.is_valid_and_unique())
{
entity_id = generate_entity_id();
}
else if (entity_id.value() >= next_id_)
{
next_id_ = entity_id.value() + 1;
}
process->id = entity_id;
/* Add process to processes collection */
processes_[process->id] = process;
/* Add process to user's processes collection */
process->user->processes[process->id] = process;
break;
}
case EntityKind::DOMAIN_ENTITY:
{
std::shared_ptr<Domain> domain = std::static_pointer_cast<Domain>(entity);
/* Check that domain name is not empty */
if (domain->name.empty())
{
throw BadParameter("Domain name cannot be empty");
}
/* Check that this is indeed a new domain and that its name is unique */
for (const auto& domain_it: domains_)
{
if (domain.get() == domain_it.second.get())
{
throw BadParameter("Domain already exists in the database");
}
if (domain->name == domain_it.second->name)
{
throw BadParameter(
"A Domain with name '" + domain->name + "' already exists in the database");
}
}
// Add id to the entity
if (!entity_id.is_valid_and_unique())
{
entity_id = generate_entity_id();
}
else if (entity_id.value() >= next_id_)
{
next_id_ = entity_id.value() + 1;
}
domain->id = entity_id;
/* Insert domain in the database */
domains_[domain->id] = domain;
break;
}
case EntityKind::TOPIC:
{
std::shared_ptr<Topic> topic = std::static_pointer_cast<Topic>(entity);
/* Check that topic name is not empty */
if (topic->name.empty())
{
throw BadParameter("Topic name cannot be empty");
}
/* Check that topic data type is not empty */
if (topic->data_type.empty())
{
throw BadParameter("Topic data type cannot be empty");
}
/* Check that domain exits */
bool domain_exists = false;
for (const auto& domain_it : domains_)
{
if (topic->domain.get() == domain_it.second.get())
{
domain_exists = true;
break;
}
}
if (!domain_exists)
{
throw BadParameter("Parent domain does not exist in the database");
}
/* Check that this is indeed a new topic and that its name and type combination is unique in the domain */
auto domain_topics = topics_.find(topic->domain->id);
if (domain_topics != topics_.end())
{
for (const auto& topic_it: domain_topics->second)
{
if (topic.get() == topic_it.second.get())
{
throw BadParameter("Topic already exists in the database");
}
if (topic->name == topic_it.second->name &&
topic->data_type == topic_it.second->data_type)
{
throw BadParameter(
"A topic with name '" + topic->name +
"' and type '" + topic->data_type +
"' already exists in the database for the same domain");
}
}
}
// Add id to the entity
if (!entity_id.is_valid_and_unique())
{
entity_id = generate_entity_id();
}
else if (entity_id.value() >= next_id_)
{
next_id_ = entity_id.value() + 1;
}
topic->id = entity_id;
/* Add topic to domain's collection */
domains_[topic->domain->id]->topics[topic->id] = topic;
/* Insert topic in the database */
topics_[topic->domain->id][topic->id] = topic;
break;
}
case EntityKind::PARTICIPANT:
{
std::shared_ptr<DomainParticipant> participant = std::static_pointer_cast<DomainParticipant>(entity);
/* Check that name is not empty */
if (participant->name.empty())
{
throw BadParameter("Participant name cannot be empty");
}
/* Check that qos is not empty */
if (participant->qos.empty())
{
throw BadParameter("Participant QoS cannot be empty");
}
/* Check that GUID is not empty */
if (participant->guid.empty())
{
throw BadParameter("Participant GUID cannot be empty");
}
/* Check that domain exits */
bool domain_exists = false;
for (const auto& domain_it : domains_)
{
if (participant->domain.get() == domain_it.second.get())
{
domain_exists = true;
break;
}
}
if (!domain_exists)
{
throw BadParameter("Parent domain does not exist in the database");
}
/* Check that this is indeed a new participant and that its GUID is unique */
for (const auto& domain_it : participants_)
{
for (const auto& participant_it : domain_it.second)
{
// Check that participant is new
if (participant.get() == participant_it.second.get())
{
throw BadParameter("Participant already exists in the database");
}
// Check GUID uniqueness
if (participant->guid == participant_it.second->guid)
{
throw BadParameter(
"A participant with GUID '" + participant->guid +
"' already exists in the database for the same domain");
}
}
}
// Add id to the entity
if (!entity_id.is_valid_and_unique())
{
entity_id = generate_entity_id();
}
else if (entity_id.value() >= next_id_)
{
next_id_ = entity_id.value() + 1;
}
participant->id = entity_id;
/* Add participant to domain's collection */
participant->domain->participants[participant->id] = participant;
/* Insert participant in the database */
participants_[participant->domain->id][participant->id] = participant;
break;
}
case EntityKind::DATAREADER:
{
auto data_reader = std::static_pointer_cast<DataReader>(entity);
insert_ddsendpoint<DataReader>(data_reader, entity_id);
break;
}
case EntityKind::DATAWRITER:
{
auto data_writer = std::static_pointer_cast<DataWriter>(entity);
insert_ddsendpoint<DataWriter>(data_writer, entity_id);
break;
}
case EntityKind::LOCATOR:
{
std::shared_ptr<Locator> locator = std::static_pointer_cast<Locator>(entity);
/* Check that locator name is not empty */
if (locator->name.empty())
{
throw BadParameter("Locator name cannot be empty");
}
/* Check that this is indeed a new locator, and that its name is unique */
for (const auto& locator_it: locators_)
{
if (locator.get() == locator_it.second.get())
{
throw BadParameter("Locator already exists in the database");
}
if (locator->name == locator_it.second->name)
{
throw BadParameter("Locator with name " + locator->name + " already exists in the database");
}
}
// Add id to the entity
if (!entity_id.is_valid_and_unique())
{
entity_id = generate_entity_id();
}
else if (entity_id.value() >= next_id_)
{
next_id_ = entity_id.value() + 1;
}
locator->id = entity_id;
/* Insert locator in the database */
locators_[locator->id] = locator;
break;
}
default:
{
break;
}
}
}
void Database::insert(
const EntityId& domain_id,
const EntityId& entity_id,
const StatisticsSample& sample)
{
std::lock_guard<std::shared_timed_mutex> guard(mutex_);
insert_nts(domain_id, entity_id, sample);
}
std::shared_ptr<Locator> Database::get_locator_nts(
EntityId const& entity_id)
{
std::shared_ptr<Locator> locator;
// Check if the entity is a known locator
auto locator_it = locators_.find(entity_id);
// If the locator has not been discovered, create it
if (locator_it == locators_.end())
{
// Give him a unique name, including his id
locator = std::make_shared<Locator>("locator_" + std::to_string(entity_id.value()));
EntityId locator_id = entity_id;
insert_nts(locator, locator_id);
notify_locator_discovery(locator_id);
}
else
{
locator = locator_it->second;
}
return locator;
}
void Database::notify_locator_discovery (
const EntityId& locator_id)
{
details::StatisticsBackendData::get_instance()->on_physical_entity_discovery(
locator_id, EntityKind::LOCATOR,
details::StatisticsBackendData::DiscoveryStatus::DISCOVERY);
}
void Database::insert_nts(
const EntityId& domain_id,
const EntityId& entity_id,
const StatisticsSample& sample,
const bool loading,
const bool last_reported)
{
/* Check that domain_id refers to a known domain */
if (sample.kind != DataKind::NETWORK_LATENCY)
{
if (domains_.find(domain_id) == domains_.end())
{
throw BadParameter(std::to_string(domain_id.value()) + " does not refer to a known domain");
}
}
switch (sample.kind)
{
case DataKind::FASTDDS_LATENCY:
{
/* Check that the entity is a known writer */
auto domain_writers = datawriters_.find(domain_id);
if (domain_writers != datawriters_.end())
{
auto writer = domain_writers->second.find(entity_id);
if (writer != domain_writers->second.end())
{
const HistoryLatencySample& fastdds_latency = dynamic_cast<const HistoryLatencySample&>(sample);
writer->second->data.history2history_latency[fastdds_latency.reader].push_back(fastdds_latency);
break;
}
}
throw BadParameter(std::to_string(
entity_id.value()) + " does not refer to a known datawriter in domain " + std::to_string(
domain_id.value()));
}
case DataKind::NETWORK_LATENCY:
{
/* Check that the entity is a known participant */
auto domain_participants = participants_.find(domain_id);
if (domain_participants != participants_.end())
{
auto participant = domain_participants->second.find(entity_id);
if (participant != domain_participants->second.end())
{
const NetworkLatencySample& network_latency = dynamic_cast<const NetworkLatencySample&>(sample);
participant->second->data.network_latency_per_locator[network_latency.remote_locator].push_back(
network_latency);
break;
}
}
throw BadParameter(std::to_string(
entity_id.value()) + " does not refer to a known participant in domain " + std::to_string(
domain_id.value()));
}
case DataKind::PUBLICATION_THROUGHPUT:
{
/* Check that the entity is a known writer */
auto domain_writers = datawriters_.find(domain_id);
if (domain_writers != datawriters_.end())
{
auto writer = domain_writers->second.find(entity_id);
if (writer != domain_writers->second.end())
{
const PublicationThroughputSample& publication_throughput =
dynamic_cast<const PublicationThroughputSample&>(sample);
writer->second->data.publication_throughput.push_back(publication_throughput);
break;
}
}
throw BadParameter(std::to_string(
entity_id.value()) + " does not refer to a known datawriter in domain " + std::to_string(
domain_id.value()));
}
case DataKind::SUBSCRIPTION_THROUGHPUT:
{
/* Check that the entity is a known reader */
auto domain_readers = datareaders_.find(domain_id);
if (domain_readers != datareaders_.end())
{
auto reader = domain_readers->second.find(entity_id);
if (reader != domain_readers->second.end())
{
const SubscriptionThroughputSample& subscription_throughput =
dynamic_cast<const SubscriptionThroughputSample&>(sample);
reader->second->data.subscription_throughput.push_back(subscription_throughput);
break;
}
}
throw BadParameter(std::to_string(
entity_id.value()) + " does not refer to a known datareader in domain " + std::to_string(
domain_id.value()));
}
case DataKind::RTPS_PACKETS_SENT:
{
/* Check that the entity is a known participant */
auto domain_participants = participants_.find(domain_id);
if (domain_participants != participants_.end())
{
auto participant = domain_participants->second.find(entity_id);
if (participant != domain_participants->second.end())
{
const RtpsPacketsSentSample& rtps_packets_sent = dynamic_cast<const RtpsPacketsSentSample&>(sample);
// Create remote_locator if it does not exist
get_locator_nts(rtps_packets_sent.remote_locator);
// Check if the insertion is from the load
if (loading)
{
if (last_reported)
{
// Store last reported
participant->second->data.last_reported_rtps_packets_sent_count[rtps_packets_sent.
remote_locator] =
rtps_packets_sent;
}
else
{
// Store data directly
participant->second->data.rtps_packets_sent[rtps_packets_sent.remote_locator].push_back(
rtps_packets_sent);
}
}
else
{
// Store the increment since the last report
participant->second->data.rtps_packets_sent[rtps_packets_sent.remote_locator].push_back(
rtps_packets_sent -
participant->second->data.last_reported_rtps_packets_sent_count[rtps_packets_sent.
remote_locator]);
// Update last report
participant->second->data.last_reported_rtps_packets_sent_count[rtps_packets_sent.remote_locator
] =
rtps_packets_sent;
}
break;
}
}
throw BadParameter(std::to_string(
entity_id.value()) + " does not refer to a known participant in domain " + std::to_string(
domain_id.value()));
}
case DataKind::RTPS_BYTES_SENT:
{
/* Check that the entity is a known participant */
auto domain_participants = participants_.find(domain_id);
if (domain_participants != participants_.end())
{
auto participant = domain_participants->second.find(entity_id);
if (participant != domain_participants->second.end())
{
const RtpsBytesSentSample& rtps_bytes_sent = dynamic_cast<const RtpsBytesSentSample&>(sample);
// Create remote_locator if it does not exist
get_locator_nts(rtps_bytes_sent.remote_locator);
// Check if the insertion is from the load
if (loading)
{
if (last_reported)
{
// Store last reported
participant->second->data.last_reported_rtps_bytes_sent_count[rtps_bytes_sent.remote_locator
] =
rtps_bytes_sent;
}
else
{
// Store data directly
participant->second->data.rtps_bytes_sent[rtps_bytes_sent.remote_locator].push_back(
rtps_bytes_sent);
}
}
else
{
// Store the increment since the last report
participant->second->data.rtps_bytes_sent[rtps_bytes_sent.remote_locator].push_back(
rtps_bytes_sent -
participant->second->data.last_reported_rtps_bytes_sent_count[rtps_bytes_sent.remote_locator]);
// Update last report
participant->second->data.last_reported_rtps_bytes_sent_count[rtps_bytes_sent.remote_locator] =
rtps_bytes_sent;
}
break;
}
}
throw BadParameter(std::to_string(
entity_id.value()) + " does not refer to a known participant in domain " + std::to_string(
domain_id.value()));
}
case DataKind::RTPS_PACKETS_LOST:
{
/* Check that the entity is a known participant */
auto domain_participants = participants_.find(domain_id);
if (domain_participants != participants_.end())
{
auto participant = domain_participants->second.find(entity_id);
if (participant != domain_participants->second.end())
{
const RtpsPacketsLostSample& rtps_packets_lost = dynamic_cast<const RtpsPacketsLostSample&>(sample);
// Create remote_locator if it does not exist
get_locator_nts(rtps_packets_lost.remote_locator);
// Check if the insertion is from the load
if (loading)
{
if (last_reported)
{
// Store last reported
participant->second->data.last_reported_rtps_packets_lost_count[rtps_packets_lost.
remote_locator] =
rtps_packets_lost;
}
else
{
// Store data directly
participant->second->data.rtps_packets_lost[rtps_packets_lost.remote_locator].push_back(
rtps_packets_lost);
}
}
else
{
// Store the increment since the last report
participant->second->data.rtps_packets_lost[rtps_packets_lost.remote_locator].push_back(
rtps_packets_lost -
participant->second->data.last_reported_rtps_packets_lost_count[rtps_packets_lost.
remote_locator]);
// Update last report
participant->second->data.last_reported_rtps_packets_lost_count[rtps_packets_lost.remote_locator
] =
rtps_packets_lost;
}
break;
}
}
throw BadParameter(std::to_string(
entity_id.value()) + " does not refer to a known participant in domain " + std::to_string(
domain_id.value()));
}
case DataKind::RTPS_BYTES_LOST:
{
/* Check that the entity is a known participant */
auto domain_participants = participants_.find(domain_id);
if (domain_participants != participants_.end())
{
auto participant = domain_participants->second.find(entity_id);
if (participant != domain_participants->second.end())
{
const RtpsBytesLostSample& rtps_bytes_lost = dynamic_cast<const RtpsBytesLostSample&>(sample);
// Create remote_locator if it does not exist
get_locator_nts(rtps_bytes_lost.remote_locator);
// Check if the insertion is from the load
if (loading)
{
if (last_reported)
{
// Store last reported
participant->second->data.last_reported_rtps_bytes_lost_count[rtps_bytes_lost.remote_locator
] =
rtps_bytes_lost;
}
else
{
// Store data directly
participant->second->data.rtps_bytes_lost[rtps_bytes_lost.remote_locator].push_back(
rtps_bytes_lost);
}
}
else
{
// Store the increment since the last report
participant->second->data.rtps_bytes_lost[rtps_bytes_lost.remote_locator].push_back(
rtps_bytes_lost -
participant->second->data.last_reported_rtps_bytes_lost_count[rtps_bytes_lost.remote_locator]);
// Update last report
participant->second->data.last_reported_rtps_bytes_lost_count[rtps_bytes_lost.remote_locator] =
rtps_bytes_lost;
}
break;
}
}
throw BadParameter(std::to_string(
entity_id.value()) + " does not refer to a known participant in domain " + std::to_string(
domain_id.value()));
}
case DataKind::RESENT_DATA:
{
/* Check that the entity is a known writer */
auto domain_writers = datawriters_.find(domain_id);
if (domain_writers != datawriters_.end())
{
auto writer = domain_writers->second.find(entity_id);
if (writer != domain_writers->second.end())
{
const ResentDataSample& resent_datas = dynamic_cast<const ResentDataSample&>(sample);
// Check if the insertion is from the load
if (loading)
{
if (last_reported)
{
// Store last reported
writer->second->data.last_reported_resent_datas = resent_datas;
}
else
{
// Store data directly
writer->second->data.resent_datas.push_back(resent_datas);
}
}
else
{
// Store the increment since the last report
writer->second->data.resent_datas.push_back(
resent_datas - writer->second->data.last_reported_resent_datas);
// Update last report
writer->second->data.last_reported_resent_datas = resent_datas;
}
break;
}
}
throw BadParameter(std::to_string(
entity_id.value()) + " does not refer to a known datawriter in domain " + std::to_string(
domain_id.value()));
}
case DataKind::HEARTBEAT_COUNT:
{
/* Check that the entity is a known writer */
auto domain_writers = datawriters_.find(domain_id);
if (domain_writers != datawriters_.end())
{
auto writer = domain_writers->second.find(entity_id);
if (writer != domain_writers->second.end())
{
const HeartbeatCountSample& heartbeat_count = dynamic_cast<const HeartbeatCountSample&>(sample);
// Check if the insertion is from the load
if (loading)
{
if (last_reported)
{
// Store last reported
writer->second->data.last_reported_heartbeat_count = heartbeat_count;
}
else
{
// Store data directly
writer->second->data.heartbeat_count.push_back(heartbeat_count);
}
}
else
{
// Store the increment since the last report
writer->second->data.heartbeat_count.push_back(heartbeat_count -
writer->second->data.last_reported_heartbeat_count);
// Update last report
writer->second->data.last_reported_heartbeat_count = heartbeat_count;
}
break;
}
}
throw BadParameter(std::to_string(
entity_id.value()) + " does not refer to a known datawriter in domain " + std::to_string(
domain_id.value()));
}
case DataKind::ACKNACK_COUNT:
{
/* Check that the entity is a known reader */
auto domain_readers = datareaders_.find(domain_id);
if (domain_readers != datareaders_.end())
{
auto reader = domain_readers->second.find(entity_id);
if (reader != domain_readers->second.end())
{
const AcknackCountSample& acknack_count = dynamic_cast<const AcknackCountSample&>(sample);
// Check if the insertion is from the load
if (loading)
{
if (last_reported)
{
// Store last reported
reader->second->data.last_reported_acknack_count = acknack_count;
}
else
{
// Store data directly
reader->second->data.acknack_count.push_back(acknack_count);
}
}
else
{
// Store the increment since the last report
reader->second->data.acknack_count.push_back(
acknack_count - reader->second->data.last_reported_acknack_count);
// Update last report
reader->second->data.last_reported_acknack_count = acknack_count;
}
break;
}
}
throw BadParameter(std::to_string(
entity_id.value()) + " does not refer to a known datareader in domain " + std::to_string(
domain_id.value()));
}
case DataKind::NACKFRAG_COUNT:
{
/* Check that the entity is a known reader */
auto domain_readers = datareaders_.find(domain_id);
if (domain_readers != datareaders_.end())
{
auto reader = domain_readers->second.find(entity_id);
if (reader != domain_readers->second.end())
{
const NackfragCountSample& nackfrag_count = dynamic_cast<const NackfragCountSample&>(sample);
// Check if the insertion is from the load