Program Listing for File DomainParticipantFactory.hpp

Return to documentation for file (include/fastdds/dds/domain/DomainParticipantFactory.hpp)

// Copyright 2019 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.

#ifndef FASTDDS_DDS_DOMAIN__DOMAINPARTICIPANTFACTORY_HPP
#define FASTDDS_DDS_DOMAIN__DOMAINPARTICIPANTFACTORY_HPP

#include <map>
#include <memory>
#include <mutex>

#include <fastdds/dds/core/ReturnCode.hpp>
#include <fastdds/dds/core/status/StatusMask.hpp>
#include <fastdds/dds/domain/qos/DomainParticipantExtendedQos.hpp>
#include <fastdds/dds/domain/qos/DomainParticipantFactoryQos.hpp>
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicType.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilder.hpp>
#include <fastdds/dds/xtypes/type_representation/ITypeObjectRegistry.hpp>
#include <fastdds/LibrarySettings.hpp>

namespace eprosima {

namespace fastdds {
namespace rtps {

class RTPSDomainImpl;

namespace detail {
class TopicPayloadPoolRegistry;
}  // namespace detail
}  // namespace rtps

namespace dds {

class DomainParticipantListener;
class DomainParticipant;
class DomainParticipantImpl;

namespace detail {
struct LogResources;
}  // namespace detail

class DomainParticipantFactory
{

public:

    FASTDDS_EXPORTED_API static DomainParticipantFactory* get_instance();

    FASTDDS_EXPORTED_API static std::shared_ptr<DomainParticipantFactory> get_shared_instance();

    FASTDDS_EXPORTED_API DomainParticipant* create_participant(
            DomainId_t domain_id,
            const DomainParticipantQos& qos,
            DomainParticipantListener* listener = nullptr,
            const StatusMask& mask = StatusMask::all());

    FASTDDS_EXPORTED_API DomainParticipant* create_participant(
            const DomainParticipantExtendedQos& extended_qos,
            DomainParticipantListener* listener = nullptr,
            const StatusMask& mask = StatusMask::all());

    FASTDDS_EXPORTED_API DomainParticipant* create_participant_with_default_profile();


    FASTDDS_EXPORTED_API DomainParticipant* create_participant_with_default_profile(
            DomainParticipantListener* listener,
            const StatusMask& mask);

    FASTDDS_EXPORTED_API DomainParticipant* create_participant_with_profile(
            DomainId_t domain_id,
            const std::string& profile_name,
            DomainParticipantListener* listener = nullptr,
            const StatusMask& mask = StatusMask::all());

    FASTDDS_EXPORTED_API DomainParticipant* create_participant_with_profile(
            const std::string& profile_name,
            DomainParticipantListener* listener = nullptr,
            const StatusMask& mask = StatusMask::all());

    FASTDDS_EXPORTED_API DomainParticipant* lookup_participant(
            DomainId_t domain_id) const;

    FASTDDS_EXPORTED_API std::vector<DomainParticipant*> lookup_participants(
            DomainId_t domain_id) const;

    FASTDDS_EXPORTED_API ReturnCode_t get_default_participant_qos(
            DomainParticipantQos& qos) const;

    FASTDDS_EXPORTED_API const DomainParticipantQos& get_default_participant_qos() const;

    FASTDDS_EXPORTED_API ReturnCode_t set_default_participant_qos(
            const DomainParticipantQos& qos);

    FASTDDS_EXPORTED_API ReturnCode_t get_participant_qos_from_profile(
            const std::string& profile_name,
            DomainParticipantQos& qos) const;

    FASTDDS_EXPORTED_API ReturnCode_t get_participant_qos_from_xml(
            const std::string& xml,
            DomainParticipantQos& qos) const;

    FASTDDS_EXPORTED_API ReturnCode_t get_participant_qos_from_xml(
            const std::string& xml,
            DomainParticipantQos& qos,
            const std::string& profile_name) const;

    FASTDDS_EXPORTED_API ReturnCode_t get_default_participant_qos_from_xml(
            const std::string& xml,
            DomainParticipantQos& qos) const;

    FASTDDS_EXPORTED_API ReturnCode_t get_participant_extended_qos_from_profile(
            const std::string& profile_name,
            DomainParticipantExtendedQos& extended_qos) const;

    FASTDDS_EXPORTED_API ReturnCode_t get_participant_extended_qos_from_xml(
            const std::string& xml,
            DomainParticipantExtendedQos& extended_qos) const;

    FASTDDS_EXPORTED_API ReturnCode_t get_participant_extended_qos_from_xml(
            const std::string& xml,
            DomainParticipantExtendedQos& extended_qos,
            const std::string& profile_name) const;

    FASTDDS_EXPORTED_API ReturnCode_t get_default_participant_extended_qos_from_xml(
            const std::string& xml,
            DomainParticipantExtendedQos& extended_qos) const;

    FASTDDS_EXPORTED_API ReturnCode_t get_participant_extended_qos_from_default_profile(
            DomainParticipantExtendedQos& extended_qos) const;

    FASTDDS_EXPORTED_API ReturnCode_t delete_participant(
            DomainParticipant* part);

    FASTDDS_EXPORTED_API ReturnCode_t load_profiles();

    FASTDDS_EXPORTED_API ReturnCode_t load_XML_profiles_file(
            const std::string& xml_profile_file);

    FASTDDS_EXPORTED_API ReturnCode_t load_XML_profiles_string(
            const char* data,
            size_t length);

    FASTDDS_EXPORTED_API ReturnCode_t check_xml_static_discovery(
            std::string& xml_file);

    FASTDDS_EXPORTED_API ReturnCode_t get_qos(
            DomainParticipantFactoryQos& qos) const;

    FASTDDS_EXPORTED_API ReturnCode_t set_qos(
            const DomainParticipantFactoryQos& qos);

    FASTDDS_EXPORTED_API ReturnCode_t get_library_settings(
            LibrarySettings& library_settings) const;

    FASTDDS_EXPORTED_API ReturnCode_t set_library_settings(
            const LibrarySettings& library_settings);

    FASTDDS_EXPORTED_API ReturnCode_t get_dynamic_type_builder_from_xml_by_name(
            const std::string& type_name,
            DynamicTypeBuilder::_ref_type& type);

    FASTDDS_EXPORTED_API xtypes::ITypeObjectRegistry& type_object_registry();

protected:

    friend class DomainParticipant;

    std::map<DomainId_t, std::vector<DomainParticipantImpl*>> participants_;

    DomainParticipantFactory();

    virtual ~DomainParticipantFactory();

    DomainParticipantFactory (
            const DomainParticipantFactory&) = delete;

    void operator = (
            const DomainParticipantFactory&) = delete;

    void reset_default_participant_qos();

    static void set_qos(
            DomainParticipantFactoryQos& to,
            const DomainParticipantFactoryQos& from,
            bool first_time);

    static ReturnCode_t check_qos(
            const DomainParticipantFactoryQos& qos);

    static bool can_qos_be_updated(
            const DomainParticipantFactoryQos& to,
            const DomainParticipantFactoryQos& from);

    void participant_has_been_deleted(
            DomainParticipantImpl* part);

    mutable std::mutex mtx_participants_;

    mutable bool default_xml_profiles_loaded;

    DomainId_t default_domain_id_;

    DomainParticipantFactoryQos factory_qos_;

    DomainParticipantQos default_participant_qos_;

    std::shared_ptr<fastdds::rtps::detail::TopicPayloadPoolRegistry> topic_pool_;

    std::shared_ptr<fastdds::rtps::RTPSDomainImpl> rtps_domain_;

    std::shared_ptr<detail::LogResources> log_resources_;

    mutable std::mutex default_xml_profiles_loaded_mtx_;
};

}  // namespace dds
}  // namespace fastdds
}  // namespace eprosima

#endif // FASTDDS_DDS_DOMAIN__DOMAINPARTICIPANTFACTORY_HPP