File xml_config.hpp

File List > astutedds > dcps > xml_config.hpp

Go to the documentation of this file

//
// Copyright (c) 2026, Astute Systems PTY LTD
//
// This file is part of the Astute DDS developed by Astute Systems.
//
// See the commercial LICENSE file in the project root for full license details.
//
// @file xml_config.hpp
// @brief DDS XML QoS profile loader (OMG DDS ยง8.5 / RTF-DDS-XML profile format)
//
// Loads QoS profiles from an XML file following the OMG DDS XML profile
// syntax.  Profiles are identified by "LibraryName::ProfileName" and may
// inherit from a base profile via the base_name attribute.
//
// Example XML:
//
//   <dds>
//     <qos_library name="MyLibrary">
//       <qos_profile name="ReliableProfile">
//         <datawriter_qos>
//           <reliability><kind>RELIABLE</kind></reliability>
//           <durability><kind>TRANSIENT_LOCAL</kind></durability>
//           <history><kind>KEEP_LAST</kind><depth>10</depth></history>
//         </datawriter_qos>
//         <datareader_qos>
//           <reliability><kind>RELIABLE</kind></reliability>
//           <durability><kind>TRANSIENT_LOCAL</kind></durability>
//         </datareader_qos>
//       </qos_profile>
//     </qos_library>
//   </dds>
//
// Usage:
//
//   XmlQosLoader loader;
//   loader.load_file("profiles.xml");
//
//   DataWriterQos wqos;
//   loader.get_datawriter_qos("MyLibrary::ReliableProfile", wqos);
//

#ifndef ASTUTEDDS_DCPS_XML_CONFIG_HPP
#define ASTUTEDDS_DCPS_XML_CONFIG_HPP

#include <astutedds/dcps/qos.hpp>

#include <map>
#include <mutex>
#include <string>
#include <vector>

namespace astutedds::dcps
{

struct XmlQosProfile
{
    std::string library_name;
    std::string profile_name;
    std::string base_name; 

    DataWriterQos writer_qos;
    DataReaderQos reader_qos;
    TopicQos topic_qos;
    DomainParticipantQos participant_qos;

    bool has_writer_qos{false};
    bool has_reader_qos{false};
    bool has_topic_qos{false};
    bool has_participant_qos{false};
};

class XmlQosLoader
{
public:
    XmlQosLoader() = default;
    ~XmlQosLoader() = default;

    // Non-copyable, movable
    XmlQosLoader(const XmlQosLoader&) = delete;
    XmlQosLoader& operator=(const XmlQosLoader&) = delete;
    XmlQosLoader(XmlQosLoader&&) noexcept = default;
    XmlQosLoader& operator=(XmlQosLoader&&) noexcept = default;

    bool load_file(const std::string& path);

    bool load_string(const std::string& xml);

    bool get_datawriter_qos(const std::string& profile_key, DataWriterQos& qos) const;

    bool get_datareader_qos(const std::string& profile_key, DataReaderQos& qos) const;

    bool get_topic_qos(const std::string& profile_key, TopicQos& qos) const;

    bool get_participant_qos(const std::string& profile_key, DomainParticipantQos& qos) const;

    std::vector<std::string> profile_keys() const;

    void clear();

private:
    mutable std::mutex mutex_;
    std::map<std::string, XmlQosProfile> profiles_; 

    // Parsing helpers
    bool parse_xml(const std::string& xml);
    const XmlQosProfile* resolve(const std::string& key) const; 
};

} // namespace astutedds::dcps

#endif // ASTUTEDDS_DCPS_XML_CONFIG_HPP