Coverage Report

Created: 2026-04-01 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Fast-DDS/src/cpp/fastdds/domain/DomainParticipantImpl.hpp
Line
Count
Source
1
// Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/**
16
 * @file DomainParticipantImpl.h
17
 *
18
 */
19
20
#ifndef FASTDDS_DOMAIN__DOMAINPARTICIPANTIMPL_HPP
21
#define FASTDDS_DOMAIN__DOMAINPARTICIPANTIMPL_HPP
22
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
23
24
#include <atomic>
25
#include <condition_variable>
26
#include <mutex>
27
28
#include "fastdds/topic/DDSSQLFilter/DDSFilterFactory.hpp"
29
#include <fastdds/dds/builtin/topic/ParticipantBuiltinTopicData.hpp>
30
#include <fastdds/dds/core/ReturnCode.hpp>
31
#include <fastdds/dds/core/status/StatusMask.hpp>
32
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
33
#include <fastdds/dds/domain/qos/ReplierQos.hpp>
34
#include <fastdds/dds/domain/qos/RequesterQos.hpp>
35
#include <fastdds/dds/publisher/qos/PublisherQos.hpp>
36
#include <fastdds/dds/rpc/ServiceTypeSupport.hpp>
37
#include <fastdds/dds/subscriber/qos/SubscriberQos.hpp>
38
#include <fastdds/dds/topic/ContentFilteredTopic.hpp>
39
#include <fastdds/dds/topic/IContentFilterFactory.hpp>
40
#include <fastdds/dds/topic/qos/TopicQos.hpp>
41
#include <fastdds/dds/topic/Topic.hpp>
42
#include <fastdds/dds/topic/TypeSupport.hpp>
43
#include <fastdds/rtps/common/Guid.hpp>
44
#include <fastdds/rtps/participant/RTPSParticipantListener.hpp>
45
#include <fastdds/topic/TopicProxyFactory.hpp>
46
#include <rtps/reader/StatefulReader.hpp>
47
48
namespace eprosima {
49
namespace fastdds {
50
51
namespace rtps {
52
53
struct PublicationBuiltinTopicData;
54
class RTPSParticipant;
55
struct SubscriptionBuiltinTopicData;
56
57
} // namespace rtps
58
59
class PublisherAttributes;
60
class SubscriberAttributes;
61
62
namespace dds {
63
namespace rpc {
64
class Replier;
65
class Requester;
66
class Service;
67
class ServiceImpl;
68
} // namespace rpc
69
70
class DomainParticipant;
71
class DomainParticipantListener;
72
class Publisher;
73
class PublisherImpl;
74
class PublisherListener;
75
class Subscriber;
76
class SubscriberImpl;
77
class SubscriberListener;
78
class ReaderFilterCollection;
79
80
/**
81
 * This is the implementation class of the DomainParticipant.
82
 * @ingroup FASTDDS_MODULE
83
 */
84
class DomainParticipantImpl
85
{
86
    friend class DomainParticipantFactory;
87
    friend class DomainParticipant;
88
    friend class ReaderFilterCollection;
89
90
protected:
91
92
    DomainParticipantImpl(
93
            DomainParticipant* dp,
94
            DomainId_t did,
95
            const DomainParticipantQos& qos,
96
            DomainParticipantListener* listen = nullptr);
97
98
    virtual ~DomainParticipantImpl();
99
100
public:
101
102
    virtual ReturnCode_t enable();
103
104
    ReturnCode_t get_qos(
105
            DomainParticipantQos& qos) const;
106
107
    const DomainParticipantQos& get_qos() const;
108
109
    ReturnCode_t set_qos(
110
            const DomainParticipantQos& qos);
111
112
    ReturnCode_t set_listener(
113
            DomainParticipantListener* listener,
114
            const std::chrono::seconds timeout = std::chrono::seconds::max())
115
0
    {
116
0
        auto time_out = std::chrono::time_point<std::chrono::steady_clock>::max();
117
0
        if (timeout < std::chrono::seconds::max())
118
0
        {
119
0
            auto now = std::chrono::steady_clock::now();
120
0
            time_out = now + timeout;
121
0
        }
122
123
0
        std::unique_lock<std::mutex> lock(mtx_gs_);
124
0
        if (!cv_gs_.wait_until(lock, time_out, [this]
125
0
                {
126
                    // Proceed if no callbacks are being executed
127
0
                    return !(rtps_listener_.callback_counter_ > 0);
128
0
                }))
129
0
        {
130
0
            return RETCODE_ERROR;
131
0
        }
132
133
0
        rtps_listener_.callback_counter_ = (listener == nullptr) ? -1 : 0;
134
0
        listener_ = listener;
135
0
        return RETCODE_OK;
136
0
    }
137
138
    DomainParticipantListener* get_listener() const
139
0
    {
140
0
        std::lock_guard<std::mutex> _(mtx_gs_);
141
0
        return listener_;
142
0
    }
143
144
    /**
145
     * Create a Publisher in this Participant.
146
     *
147
     * @param qos QoS of the Publisher.
148
     * @param [out] ret_code Return code of the operation, RETCODE_OK if the publisher is created, RETCODE_ERROR otherwise.
149
     * @param listener Pointer to the listener (default: nullptr)
150
     * @param mask StatusMask that holds statuses the listener responds to (default: all)
151
     * @return Pointer to the created Publisher.
152
     */
153
    Publisher* create_publisher(
154
            const PublisherQos& qos,
155
            ReturnCode_t& ret_code,
156
            PublisherListener* listener = nullptr,
157
            const StatusMask& mask = StatusMask::all());
158
159
    /**
160
     * Create a Publisher in this Participant.
161
     * @param qos QoS of the Publisher.
162
     * @param listenerer Pointer to the listener.
163
     * @param mask StatusMask
164
     * @return Pointer to the created Publisher.
165
     */
166
    Publisher* create_publisher(
167
            const PublisherQos& qos,
168
            PublisherListener* listener = nullptr,
169
            const StatusMask& mask = StatusMask::all());
170
171
    /**
172
     * Create a Publisher in this Participant.
173
     * @param qos QoS of the Publisher.
174
     * @param [out] impl Return a pointer to the created Publisher's implementation.
175
     * @param listenerer Pointer to the listener.
176
     * @param mask StatusMask
177
     * @return Pointer to the created Publisher.
178
     */
179
    Publisher* create_publisher(
180
            const PublisherQos& qos,
181
            PublisherImpl** impl,
182
            PublisherListener* listener = nullptr,
183
            const StatusMask& mask = StatusMask::all());
184
185
    /**
186
     * Create a Publisher in this Participant.
187
     *
188
     * @param profile_name Publisher profile name.
189
     * @param [out] ret_code Return code of the operation, RETCODE_OK if the publisher is created, RETCODE_ERROR otherwise.
190
     * @param listener Pointer to the listener (default: nullptr)
191
     * @param mask StatusMask that holds statuses the listener responds to (default: all)
192
     * @return Pointer to the created Publisher.
193
     */
194
    Publisher* create_publisher_with_profile(
195
            const std::string& profile_name,
196
            ReturnCode_t& ret_code,
197
            PublisherListener* listener = nullptr,
198
            const StatusMask& mask = StatusMask::all());
199
200
    /**
201
     * Create a Publisher in this Participant.
202
     * @param profile_name Publisher profile name.
203
     * @param listener Pointer to the listener.
204
     * @param mask StatusMask
205
     * @return Pointer to the created Publisher.
206
     */
207
    Publisher* create_publisher_with_profile(
208
            const std::string& profile_name,
209
            PublisherListener* listener = nullptr,
210
            const StatusMask& mask = StatusMask::all());
211
212
    ReturnCode_t delete_publisher(
213
            const Publisher* publisher);
214
215
    /**
216
     * Create a Subscriber in this Participant.
217
     *
218
     * @param qos QoS of the Subscriber.
219
     * @param [out] ret_code Return code of the operation, RETCODE_OK if the subscriber is created, RETCODE_ERROR otherwise.
220
     * @param listener Pointer to the listener (default: nullptr)
221
     * @param mask StatusMask that holds statuses the listener responds to (default: all)
222
     * @return Pointer to the created Subscriber.
223
     */
224
    Subscriber* create_subscriber(
225
            const SubscriberQos& qos,
226
            ReturnCode_t& ret_code,
227
            SubscriberListener* listener = nullptr,
228
            const StatusMask& mask = StatusMask::all());
229
230
    /**
231
     * Create a Subscriber in this Participant.
232
     * @param qos QoS of the Subscriber.
233
     * @param listener Pointer to the listener.
234
     * @param mask StatusMask that holds statuses the listener responds to
235
     * @return Pointer to the created Subscriber.
236
     */
237
    Subscriber* create_subscriber(
238
            const SubscriberQos& qos,
239
            SubscriberListener* listener = nullptr,
240
            const StatusMask& mask = StatusMask::all());
241
242
    /**
243
     * Create a Subscriber in this Participant.
244
     *
245
     * @param profile_name Subscriber profile name.
246
     * @param [out] ret_code Return code of the operation, RETCODE_OK if the subscriber is created, RETCODE_ERROR otherwise.
247
     * @param listener Pointer to the listener (default: nullptr)
248
     * @param mask StatusMask that holds statuses the listener responds to (default: all)
249
     * @return Pointer to the created Subscriber.
250
     */
251
    Subscriber* create_subscriber_with_profile(
252
            const std::string& profile_name,
253
            ReturnCode_t& ret_code,
254
            SubscriberListener* listener = nullptr,
255
            const StatusMask& mask = StatusMask::all());
256
257
    /**
258
     * Create a Subscriber in this Participant.
259
     * @param profile Subscriber profile name.
260
     * @param listener Pointer to the listener.
261
     * @param mask StatusMask
262
     * @return Pointer to the created Subscriber.
263
     */
264
    Subscriber* create_subscriber_with_profile(
265
            const std::string& profile_name,
266
            SubscriberListener* listener,
267
            const StatusMask& mask);
268
269
    ReturnCode_t delete_subscriber(
270
            const Subscriber* subscriber);
271
272
    /**
273
     * Create a Topic in this Participant.
274
     *
275
     * @param topic_name Name of the Topic.
276
     * @param type_name Data type of the Topic.
277
     * @param qos QoS of the Topic.
278
     * @param [out] ret_code Return code of the operation, RETCODE_OK if the topic is created, RETCODE_ERROR otherwise.
279
     * @param listener Pointer to the listener (default: nullptr)
280
     * @param mask StatusMask that holds statuses the listener responds to (default: all)
281
     * @return Pointer to the created Topic.
282
     */
283
    Topic* create_topic(
284
            const std::string& topic_name,
285
            const std::string& type_name,
286
            const TopicQos& qos,
287
            ReturnCode_t& ret_code,
288
            TopicListener* listener = nullptr,
289
            const StatusMask& mask = StatusMask::all());
290
291
    /**
292
     * Create a Topic in this Participant.
293
     * @param topic_name Name of the Topic.
294
     * @param type_name Data type of the Topic.
295
     * @param qos QoS of the Topic.
296
     * @param listener Pointer to the listener.
297
     * @param mask StatusMask that holds statuses the listener responds to
298
     * @return Pointer to the created Topic.
299
     */
300
    Topic* create_topic(
301
            const std::string& topic_name,
302
            const std::string& type_name,
303
            const TopicQos& qos = TOPIC_QOS_DEFAULT,
304
            TopicListener* listener = nullptr,
305
            const StatusMask& mask = StatusMask::all());
306
307
    /**
308
     * Create a Topic in this Participant.
309
     *
310
     * @param topic_name Name of the Topic.
311
     * @param type_name Data type of the Topic.
312
     * @param profile_name Topic profile name.
313
     * @param [out] ret_code Return code of the operation, RETCODE_OK if the topic is created, RETCODE_ERROR otherwise.
314
     * @param listener Pointer to the listener (default: nullptr)
315
     * @param mask StatusMask that holds statuses the listener responds to (default: all)
316
     * @return Pointer to the created Topic.
317
     */
318
    Topic* create_topic_with_profile(
319
            const std::string& topic_name,
320
            const std::string& type_name,
321
            const std::string& profile_name,
322
            ReturnCode_t& ret_code,
323
            TopicListener* listener = nullptr,
324
            const StatusMask& mask = StatusMask::all());
325
326
    /**
327
     * Create a Topic in this Participant.
328
     * @param topic_name Name of the Topic.
329
     * @param type_name Data type of the Topic.
330
     * @param profile Topic profile name.
331
     * @param listener Pointer to the listener.
332
     * @param mask StatusMask that holds statuses the listener responds to
333
     * @return Pointer to the created Topic.
334
     */
335
    Topic* create_topic_with_profile(
336
            const std::string& topic_name,
337
            const std::string& type_name,
338
            const std::string& profile_name,
339
            TopicListener* listener = nullptr,
340
            const StatusMask& mask = StatusMask::all());
341
342
    /**
343
     * Gives access to an existing (or ready to exist) enabled Topic.
344
     * It should be noted that the returned Topic is a local object that acts as a proxy to designate the global
345
     * concept of topic.
346
     * Topics obtained by means of find_topic, must also be deleted by means of delete_topic so that the local
347
     * resources can be released.
348
     * If a Topic is obtained multiple times by means of find_topic or create_topic, it must also be deleted that same
349
     * number of times using delete_topic.
350
     *
351
     * @param topic_name Topic name
352
     * @param timeout Maximum time to wait for the Topic
353
     * @return Pointer to the existing Topic, nullptr in case of error or timeout
354
     */
355
    Topic* find_topic(
356
            const std::string& topic_name,
357
            const fastdds::dds::Duration_t& timeout);
358
359
    /**
360
     * Implementation of Topic::set_listener that propagates the listener and mask to all the TopicProxy
361
     * objects held by the same TopicProxy factory in a thread-safe way.
362
     *
363
     * @param factory  TopicProxyFactory managing the topic on which the listener should be changed.
364
     * @param listener Listener to assign to all the TopicProxy objects owned by the factory.
365
     * @param mask     StatusMask to assign to all the TopicProxy objects owned by the factory.
366
     */
367
    void set_topic_listener(
368
            const TopicProxyFactory* factory,
369
            TopicImpl* topic,
370
            TopicListener* listener,
371
            const StatusMask& mask);
372
373
    ReturnCode_t delete_topic(
374
            const Topic* topic);
375
376
    /**
377
     * Create a ContentFilteredTopic in this Participant.
378
     *
379
     * @param name Name of the ContentFilteredTopic.
380
     * @param related_topic Pointer to the related Topic.
381
     * @param filter_expression Filter expression to be associated with the ContentFilteredTopic.
382
     * @param expression_parameters Expression parameters to be associated with the ContentFilteredTopic.
383
     * @param filter_class_name Name of the content filter class to be associated with the Content
384
     * FilteredTopic. This class must have been registered in the participant with register_content_filter_factory.
385
     * @param [out] ret_code Return code of the operation, RETCODE_OK if the content filtered topic is created, RETCODE_ERROR otherwise.
386
     * @return Pointer to the created ContentFilteredTopic
387
     */
388
    ContentFilteredTopic* create_contentfilteredtopic(
389
            const std::string& name,
390
            Topic* related_topic,
391
            const std::string& filter_expression,
392
            const std::vector<std::string>& expression_parameters,
393
            const char* filter_class_name,
394
            ReturnCode_t& ret_code);
395
396
    /**
397
     * Create a ContentFilteredTopic in this Participant.
398
     *
399
     * @param name Name of the ContentFilteredTopic.
400
     * @param related_topic Pointer to the related Topic.
401
     * @param filter_expression Filter expression to be associated with the ContentFilteredTopic.
402
     * @param expression_parameters Expression parameters to be associated with the ContentFilteredTopic.
403
     * @param filter_class_name Name of the content filter class to be associated with the Content
404
     * FilteredTopic. This class must have been registered in the participant with register_content_filter_factory.
405
     * @return Pointer to the created ContentFilteredTopic
406
     */
407
    ContentFilteredTopic* create_contentfilteredtopic(
408
            const std::string& name,
409
            Topic* related_topic,
410
            const std::string& filter_expression,
411
            const std::vector<std::string>& expression_parameters,
412
            const char* filter_class_name);
413
414
    ReturnCode_t delete_contentfilteredtopic(
415
            const ContentFilteredTopic* topic);
416
417
    ReturnCode_t register_content_filter_factory(
418
            const char* filter_class_name,
419
            IContentFilterFactory* const filter_factory);
420
421
    IContentFilterFactory* lookup_content_filter_factory(
422
            const char* filter_class_name);
423
424
    ReturnCode_t unregister_content_filter_factory(
425
            const char* filter_class_name);
426
427
    /**
428
     * Looks up an existing, locally created @ref TopicDescription, based on its name.
429
     * May be called on a disabled participant.
430
     *
431
     * @param topic_name Name of the @ref TopicDescription to search for.
432
     *
433
     * @return Pointer to the topic description, if it has been created locally. Otherwhise, nullptr is returned.
434
     *
435
     * @remark UNSAFE. It is unsafe to lookup a topic description while another thread is creating a topic.
436
     */
437
    TopicDescription* lookup_topicdescription(
438
            const std::string& topic_name) const;
439
440
    /**
441
     * Register a type in this participant.
442
     * @param type The TypeSupport to register. A copy will be kept by the participant until removed.
443
     * @param type_name The name that will be used to identify the Type.
444
     * @return True if registered.
445
     */
446
    ReturnCode_t register_type(
447
            TypeSupport type,
448
            const std::string& type_name);
449
450
    /**
451
     * Unregister a type in this participant.
452
     * @param typeName Name of the type
453
     * @return True if unregistered.
454
     */
455
    ReturnCode_t unregister_type(
456
            const std::string& typeName);
457
458
    /**
459
     * Register a service type in this participant.
460
     * @param service_type The ServiceTypeSupport to register. A copy will be kept by the participant until removed.
461
     * @param service_type_name The name that will be used to identify the ServiceType.
462
     */
463
    ReturnCode_t register_service_type(
464
            rpc::ServiceTypeSupport service_type,
465
            const std::string& service_type_name);
466
467
    /**
468
     * Unregister a service type in this participant.
469
     * @param service_type_name Name of the service type
470
     */
471
    ReturnCode_t unregister_service_type(
472
            const std::string& service_type_name);
473
474
    /**
475
     * Create an enabled RPC service.
476
     *
477
     * @param service_name Name of the service.
478
     * @param service_type_name Type name of the service (Request & reply types)
479
     * @param [out] ret_code Return code indicating the result of the operation.
480
     * @return Pointer to the created service. nullptr in error case.
481
     */
482
    rpc::Service* create_service(
483
            const std::string& service_name,
484
            const std::string& service_type_name,
485
            ReturnCode_t& ret_code);
486
487
    /**
488
     * Create an enabled RPC service.
489
     *
490
     * @param service_name Name of the service.
491
     * @param service_type_name Type name of the service (Request & reply types)
492
     * @return Pointer to the created service. nullptr in error case.
493
     */
494
    rpc::Service* create_service(
495
            const std::string& service_name,
496
            const std::string& service_type_name);
497
498
    /**
499
     * Find a registered RPC service by name
500
     *
501
     * @param service_name Name of the service to search for.
502
     * @return Pointer to the service object if found, nullptr if not found.
503
     */
504
    rpc::Service* find_service(
505
            const std::string& service_name) const;
506
507
    /**
508
     * Delete a registered RPC service.
509
     *
510
     * @param service Pointer to the service object to be deleted.
511
     * @return RETCODE_OK if the service was deleted successfully, RETCODE_ERROR otherwise.
512
     */
513
    ReturnCode_t delete_service(
514
            const rpc::Service* service);
515
516
    /**
517
     * Create a RPC Requester in a given Service.
518
     * @param service Pointer to a service object where the requester will be created.
519
     * @param requester_qos QoS of the requester.
520
     * @param [out] ret_code Return code indicating the result of the operation.
521
     * @return Pointer to the created requester. nullptr in error case.
522
     */
523
    rpc::Requester* create_service_requester(
524
            rpc::Service* service,
525
            const RequesterQos& requester_qos,
526
            ReturnCode_t& ret_code);
527
528
    /**
529
     * Create a RPC Requester in a given Service.
530
     *
531
     * @param service Pointer to a service object where the requester will be created.
532
     * @param requester_qos QoS of the requester.
533
     *
534
     * @return Pointer to the created requester. nullptr in error case.
535
     */
536
    rpc::Requester* create_service_requester(
537
            rpc::Service* service,
538
            const RequesterQos& requester_qos);
539
540
    /**
541
     * Deletes an existing RPC Requester
542
     *
543
     * @param service_name Name of the service where the requester is created.
544
     * @param requester Pointer to the requester to be deleted.
545
     * @return RETCODE_OK if the requester was deleted, or an specific error code otherwise.
546
     */
547
    ReturnCode_t delete_service_requester(
548
            const std::string& service_name,
549
            rpc::Requester* requester);
550
551
    /**
552
     * Create a RPC Replier in a given Service.
553
     *
554
     * @param service Pointer to a service object where the Replier will be created.
555
     * @param requester_qos QoS of the requester.
556
     * @param [out] ret_code Return code indicating the result of the operation.
557
     *
558
     * @return Pointer to the created replier. nullptr in error case.
559
     */
560
    rpc::Replier* create_service_replier(
561
            rpc::Service* service,
562
            const ReplierQos& replier_qos,
563
            ReturnCode_t& ret_code);
564
565
    /**
566
     * Create a RPC Replier in a given Service.
567
     *
568
     * @param service Pointer to a service object where the Replier will be created.
569
     * @param requester_qos QoS of the requester.
570
     *
571
     * @return Pointer to the created replier. nullptr in error case.
572
     */
573
    rpc::Replier* create_service_replier(
574
            rpc::Service* service,
575
            const ReplierQos& replier_qos);
576
577
    /**
578
     * Deletes an existing RPC Replier
579
     *
580
     * @param service_name Name of the service where the replier is created.
581
     * @param replier Pointer to the replier to be deleted.
582
     * @return RETCODE_OK if the replier was deleted, or an specific error code otherwise.
583
     */
584
    ReturnCode_t delete_service_replier(
585
            const std::string& service_name,
586
            rpc::Replier* replier);
587
588
    // TODO create/delete topic
589
590
    // TODO Subscriber* get_builtin_subscriber();
591
592
    /**
593
     * @brief Locally ignore a remote domain participant.
594
     *
595
     * @param [in] handle Identifier of the remote participant to ignore.
596
     * @return RETCODE_NOT_ENABLED if the participant is not enabled.
597
     *         RETCODE_ERROR if unable to ignore.
598
     *         RETCODE_OK if successful.
599
     *
600
     */
601
    ReturnCode_t ignore_participant(
602
            const InstanceHandle_t& handle);
603
604
    /* TODO
605
       bool ignore_topic(
606
            const InstanceHandle_t& handle);
607
     */
608
609
    /**
610
     * @brief Locally ignore a remote datawriter.
611
     *
612
     * @param [in] handle Identifier of the remote datawriter to ignore.
613
     * @return true if correctly ignored. False otherwise.
614
     */
615
    bool ignore_publication(
616
            const InstanceHandle_t& handle);
617
618
    /**
619
     * @brief Locally ignore a remote datareader.
620
     *
621
     * @param [in] handle Identifier of the remote datareader to ignore.
622
     * @return true if correctly ignored. False otherwise.
623
     */
624
    bool ignore_subscription(
625
            const InstanceHandle_t& handle);
626
627
    DomainId_t get_domain_id() const;
628
629
    virtual ReturnCode_t delete_contained_entities();
630
631
    ReturnCode_t assert_liveliness();
632
633
    ReturnCode_t set_default_publisher_qos(
634
            const PublisherQos& qos);
635
636
    void reset_default_publisher_qos();
637
638
    const PublisherQos& get_default_publisher_qos() const;
639
640
    ReturnCode_t get_publisher_qos_from_profile(
641
            const std::string& profile_name,
642
            PublisherQos& qos) const;
643
644
    ReturnCode_t get_publisher_qos_from_xml(
645
            const std::string& xml,
646
            PublisherQos& qos) const;
647
648
    ReturnCode_t get_publisher_qos_from_xml(
649
            const std::string& xml,
650
            PublisherQos& qos,
651
            const std::string& profile_name ) const;
652
653
    ReturnCode_t get_default_publisher_qos_from_xml(
654
            const std::string& xml,
655
            PublisherQos& qos) const;
656
657
    ReturnCode_t set_default_subscriber_qos(
658
            const SubscriberQos& qos);
659
660
    void reset_default_subscriber_qos();
661
662
    const SubscriberQos& get_default_subscriber_qos() const;
663
664
    ReturnCode_t get_subscriber_qos_from_profile(
665
            const std::string& profile_name,
666
            SubscriberQos& qos) const;
667
668
    ReturnCode_t get_subscriber_qos_from_xml(
669
            const std::string& xml,
670
            SubscriberQos& qos) const;
671
672
    ReturnCode_t get_subscriber_qos_from_xml(
673
            const std::string& xml,
674
            SubscriberQos& qos,
675
            const std::string& profile_name) const;
676
677
    ReturnCode_t get_default_subscriber_qos_from_xml(
678
            const std::string& xml,
679
            SubscriberQos& qos) const;
680
681
    ReturnCode_t set_default_topic_qos(
682
            const TopicQos& qos);
683
684
    void reset_default_topic_qos();
685
686
    const TopicQos& get_default_topic_qos() const;
687
688
    ReturnCode_t get_topic_qos_from_profile(
689
            const std::string& profile_name,
690
            TopicQos& qos) const;
691
692
    ReturnCode_t get_topic_qos_from_profile(
693
            const std::string& profile_name,
694
            TopicQos& qos,
695
            std::string& topic_name,
696
            std::string& topic_data_type) const;
697
698
    ReturnCode_t get_topic_qos_from_xml(
699
            const std::string& xml,
700
            TopicQos& qos) const;
701
702
    ReturnCode_t get_topic_qos_from_xml(
703
            const std::string& xml,
704
            TopicQos& qos,
705
            std::string& topic_name,
706
            std::string& topic_data_type) const;
707
708
    ReturnCode_t get_topic_qos_from_xml(
709
            const std::string& xml,
710
            TopicQos& qos,
711
            const std::string& profile_name) const;
712
713
    ReturnCode_t get_topic_qos_from_xml(
714
            const std::string& xml,
715
            TopicQos& qos,
716
            std::string& topic_name,
717
            std::string& topic_data_type,
718
            const std::string& profile_name) const;
719
720
    ReturnCode_t get_default_topic_qos_from_xml(
721
            const std::string& xml,
722
            TopicQos& qos) const;
723
724
    ReturnCode_t get_default_topic_qos_from_xml(
725
            const std::string& xml,
726
            TopicQos& qos,
727
            std::string& topic_name,
728
            std::string& topic_data_type) const;
729
730
    ReturnCode_t get_replier_qos_from_profile(
731
            const std::string& profile_name,
732
            ReplierQos& qos) const;
733
734
    ReturnCode_t get_replier_qos_from_xml(
735
            const std::string& xml,
736
            ReplierQos& qos) const;
737
738
    ReturnCode_t get_replier_qos_from_xml(
739
            const std::string& xml,
740
            ReplierQos& qos,
741
            const std::string& profile_name) const;
742
743
    ReturnCode_t get_default_replier_qos_from_xml(
744
            const std::string& xml,
745
            ReplierQos& qos) const;
746
747
    ReturnCode_t get_requester_qos_from_profile(
748
            const std::string& profile_name,
749
            RequesterQos& qos) const;
750
751
    ReturnCode_t get_requester_qos_from_xml(
752
            const std::string& xml,
753
            RequesterQos& qos) const;
754
755
    ReturnCode_t get_requester_qos_from_xml(
756
            const std::string& xml,
757
            RequesterQos& qos,
758
            const std::string& profile_name) const;
759
760
    ReturnCode_t get_default_requester_qos_from_xml(
761
            const std::string& xml,
762
            RequesterQos& qos) const;
763
764
    /* TODO
765
       bool get_discovered_participants(
766
            std::vector<InstanceHandle_t>& participant_handles) const;
767
     */
768
769
    /* TODO
770
       bool get_discovered_participant_data(
771
            ParticipantBuiltinTopicData& participant_data,
772
            const InstanceHandle_t& participant_handle) const;
773
     */
774
775
    /* TODO
776
       bool get_discovered_topics(
777
            std::vector<InstanceHandle_t>& topic_handles) const;
778
     */
779
780
    /* TODO
781
       bool get_discovered_topic_data(
782
            TopicBuiltinTopicData& topic_data,
783
            const InstanceHandle_t& topic_handle) const;
784
     */
785
786
    bool contains_entity(
787
            const InstanceHandle_t& handle,
788
            bool recursive = true) const;
789
790
    ReturnCode_t get_current_time(
791
            fastdds::dds::Time_t& current_time) const;
792
793
    const DomainParticipant* get_participant() const
794
0
    {
795
0
        std::lock_guard<std::mutex> _(mtx_gs_);
796
0
        return participant_;
797
0
    }
798
799
    DomainParticipant* get_participant()
800
0
    {
801
0
        std::lock_guard<std::mutex> _(mtx_gs_);
802
0
        return participant_;
803
0
    }
804
805
    const fastdds::rtps::RTPSParticipant* get_rtps_participant() const
806
0
    {
807
0
        std::lock_guard<std::mutex> _(mtx_gs_);
808
0
        return rtps_participant_;
809
0
    }
810
811
    fastdds::rtps::RTPSParticipant* get_rtps_participant()
812
0
    {
813
0
        std::lock_guard<std::mutex> _(mtx_gs_);
814
0
        return rtps_participant_;
815
0
    }
816
817
    const TypeSupport find_type(
818
            const std::string& type_name) const;
819
820
    const rpc::ServiceTypeSupport find_service_type(
821
            const std::string& service_name) const;
822
823
    InstanceHandle_t get_instance_handle() const;
824
825
    // From here legacy RTPS methods.
826
827
    const fastdds::rtps::GUID_t& guid() const;
828
829
    std::vector<std::string> get_participant_names() const;
830
831
    /**
832
     * This method can be used when using a StaticEndpointDiscovery mechanism different that the one
833
     * included in Fast DDS, for example when communicating with other implementations.
834
     * It indicates the Participant that an Endpoint from the XML has been discovered and
835
     * should be activated.
836
     * @param partguid Participant GUID_t.
837
     * @param userId User defined ID as shown in the XML file.
838
     * @param kind EndpointKind (WRITER or READER)
839
     * @return True if correctly found and activated.
840
     */
841
    bool new_remote_endpoint_discovered(
842
            const fastdds::rtps::GUID_t& partguid,
843
            uint16_t userId,
844
            fastdds::rtps::EndpointKind_t kind);
845
846
    fastdds::rtps::ResourceEvent& get_resource_event() const;
847
848
    //! Remove all listeners in the hierarchy to allow a quiet destruction
849
    virtual void disable();
850
851
    /**
852
     * This method checks if the DomainParticipant has created an entity that has not been
853
     * deleted.
854
     * @return true if the participant has no deleted entities, false otherwise
855
     */
856
    bool has_active_entities();
857
858
    /**
859
     * Returns the most appropriate listener to handle the callback for the given status,
860
     * or nullptr if there is no appropriate listener.
861
     */
862
    DomainParticipantListener* get_listener_for(
863
            const StatusMask& status);
864
865
    std::atomic<uint32_t>& id_counter()
866
0
    {
867
0
        return id_counter_;
868
0
    }
869
870
    /**
871
     * @brief Fill a TypeInformationParameter with the type information of a TypeSupport.
872
     *
873
     * @param type              TypeSupport to get the type information from.
874
     * @param type_information  TypeInformationParameter to fill.
875
     *
876
     * @return true if the constraints for propagating the type information are met.
877
     */
878
    bool fill_type_information(
879
            const TypeSupport& type,
880
            xtypes::TypeInformationParameter& type_information);
881
882
protected:
883
884
    //!Domain id
885
    DomainId_t domain_id_;
886
887
    //!Participant id
888
    int32_t participant_id_ = -1;
889
890
    //!Pre-calculated guid
891
    fastdds::rtps::GUID_t guid_;
892
893
    //!Translation into InstanceHandle_t of the guid
894
    InstanceHandle_t handle_;
895
896
    //!For instance handle creation
897
    std::atomic<uint32_t> next_instance_id_;
898
899
    //!Participant Qos
900
    DomainParticipantQos qos_;
901
902
    //!RTPSParticipant
903
    fastdds::rtps::RTPSParticipant* rtps_participant_;
904
905
    //!Participant*
906
    DomainParticipant* participant_;
907
908
    //!Participant Listener
909
    DomainParticipantListener* listener_;
910
911
    //! getter/setter mutex
912
    mutable std::mutex mtx_gs_;
913
914
    //! getter/setter condition variable
915
    std::condition_variable cv_gs_;
916
917
    //!Publisher maps
918
    std::map<Publisher*, PublisherImpl*> publishers_;
919
    std::map<InstanceHandle_t, Publisher*> publishers_by_handle_;
920
    mutable std::mutex mtx_pubs_;
921
922
    PublisherQos default_pub_qos_;
923
924
    //!Subscriber maps
925
    std::map<Subscriber*, SubscriberImpl*> subscribers_;
926
    std::map<InstanceHandle_t, Subscriber*> subscribers_by_handle_;
927
    mutable std::mutex mtx_subs_;
928
929
    SubscriberQos default_sub_qos_;
930
931
    //!TopicDataType map
932
    std::map<std::string, TypeSupport> types_;
933
    mutable std::mutex mtx_types_;
934
935
    //!Topic map
936
    std::map<std::string, TopicProxyFactory*> topics_;
937
    std::map<InstanceHandle_t, Topic*> topics_by_handle_;
938
    std::map<std::string, std::unique_ptr<ContentFilteredTopic>> filtered_topics_;
939
    std::map<std::string, IContentFilterFactory*> filter_factories_;
940
    DDSSQLFilter::DDSFilterFactory dds_sql_filter_factory_;
941
    mutable std::mutex mtx_topics_;
942
    std::condition_variable cond_topics_;
943
944
    TopicQos default_topic_qos_;
945
946
    std::atomic<uint32_t> id_counter_;
947
948
    class MyRTPSParticipantListener : public fastdds::rtps::RTPSParticipantListener
949
    {
950
        struct Sentry
951
        {
952
            Sentry(
953
                    MyRTPSParticipantListener* listener)
954
0
                : listener_(listener)
955
0
                , on_guard_(false)
956
0
            {
957
0
                std::lock_guard<std::mutex> _(listener_->participant_->mtx_gs_);
958
0
                if (listener_ != nullptr && listener_->participant_ != nullptr &&
959
0
                        listener_->participant_->listener_ != nullptr &&
960
0
                        listener_->participant_->participant_ != nullptr)
961
0
                {
962
0
                    if (listener_->callback_counter_ >= 0)
963
0
                    {
964
0
                        ++listener_->callback_counter_;
965
0
                        on_guard_ = true;
966
0
                    }
967
0
                }
968
0
            }
969
970
            ~Sentry()
971
0
            {
972
0
                if (on_guard_)
973
0
                {
974
0
                    bool notify = false;
975
0
                    {
976
0
                        std::lock_guard<std::mutex> lock(listener_->participant_->mtx_gs_);
977
0
                        assert(
978
0
                            listener_ != nullptr && listener_->participant_ != nullptr &&
979
0
                            listener_->participant_->listener_ != nullptr &&
980
0
                            listener_->participant_->participant_ != nullptr);
981
0
                        --listener_->callback_counter_;
982
0
                        notify = !listener_->callback_counter_;
983
0
                    }
984
0
                    if (notify)
985
0
                    {
986
0
                        listener_->participant_->cv_gs_.notify_all();
987
0
                    }
988
0
                }
989
0
            }
990
991
            operator bool () const
992
0
            {
993
0
                return on_guard_;
994
0
            }
995
996
            MyRTPSParticipantListener* listener_ = nullptr;
997
            bool on_guard_;
998
        };
999
1000
    public:
1001
1002
        MyRTPSParticipantListener(
1003
                DomainParticipantImpl* impl)
1004
0
            : participant_(impl)
1005
0
        {
1006
0
        }
1007
1008
        virtual ~MyRTPSParticipantListener() override
1009
0
        {
1010
            assert(!(callback_counter_ > 0));
1011
0
        }
1012
1013
        void on_participant_discovery(
1014
                fastdds::rtps::RTPSParticipant* participant,
1015
                fastdds::rtps::ParticipantDiscoveryStatus reason,
1016
                const ParticipantBuiltinTopicData& info,
1017
                bool& should_be_ignored) override;
1018
1019
#if HAVE_SECURITY
1020
        void onParticipantAuthentication(
1021
                fastdds::rtps::RTPSParticipant* participant,
1022
                fastdds::rtps::ParticipantAuthenticationInfo&& info) override;
1023
#endif // if HAVE_SECURITY
1024
1025
        void on_reader_discovery(
1026
                fastdds::rtps::RTPSParticipant* participant,
1027
                fastdds::rtps::ReaderDiscoveryStatus reason,
1028
                const fastdds::rtps::SubscriptionBuiltinTopicData& info,
1029
                bool& should_be_ignored) override;
1030
1031
        void on_writer_discovery(
1032
                fastdds::rtps::RTPSParticipant* participant,
1033
                fastdds::rtps::WriterDiscoveryStatus reason,
1034
                const fastdds::rtps::PublicationBuiltinTopicData& info,
1035
                bool& should_be_ignored) override;
1036
1037
        bool should_endpoints_match(
1038
                const fastdds::rtps::RTPSParticipant* participant,
1039
                const fastdds::rtps::SubscriptionBuiltinTopicData& reader_info,
1040
                const fastdds::rtps::PublicationBuiltinTopicData& writer_info) override;
1041
1042
        DomainParticipantImpl* participant_;
1043
        int callback_counter_ = 0;
1044
1045
    }
1046
    rtps_listener_;
1047
1048
    void create_instance_handle(
1049
            InstanceHandle_t& handle);
1050
1051
    ReturnCode_t register_dynamic_type(
1052
            DynamicType::_ref_type dyn_type);
1053
1054
    virtual PublisherImpl* create_publisher_impl(
1055
            const PublisherQos& qos,
1056
            PublisherListener* listener);
1057
1058
    virtual SubscriberImpl* create_subscriber_impl(
1059
            const SubscriberQos& qos,
1060
            SubscriberListener* listener);
1061
1062
    IContentFilterFactory* find_content_filter_factory(
1063
            const char* filter_class_name);
1064
1065
    /**
1066
     * Set the DomainParticipantQos checking if the Qos can be updated or not
1067
     *
1068
     * @param to DomainParticipantQos to be updated
1069
     * @param from DomainParticipantQos desired
1070
     * @param first_time Whether the DomainParticipant has been already initialized or not
1071
     *
1072
     * @return true if there has been a changed in one of the attributes that can be updated.
1073
     * false otherwise.
1074
     */
1075
    static bool set_qos(
1076
            DomainParticipantQos& to,
1077
            const DomainParticipantQos& from,
1078
            bool first_time);
1079
1080
    static ReturnCode_t check_qos(
1081
            const DomainParticipantQos& qos);
1082
1083
    static bool can_qos_be_updated(
1084
            const DomainParticipantQos& to,
1085
            const DomainParticipantQos& from);
1086
};
1087
1088
} // namespace dds
1089
} // namespace fastdds
1090
} // namespace eprosima
1091
#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
1092
#endif // FASTDDS_DOMAIN__DOMAINPARTICIPANTIMPL_HPP