iceoryx QOS 策略

一、PublisherOptions & SubscriberOptions

1、PublisherOptions

/// @brief This struct is used to configure the publisher
struct PublisherOptions
{
    /// @brief The size of the history chunk queue
    uint64_t historyCapacity{0U};

    /// @brief The name of the node where the publisher should belong to
    iox::NodeName_t nodeName{""};

    /// @brief The option whether the publisher should already be offered when creating it
    bool offerOnCreate{true};

    /// @brief The option whether the publisher should block when the subscriber queue is full
    ConsumerTooSlowPolicy subscriberTooSlowPolicy{ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA};

    /// @brief serialization of the PublisherOptions
    cxx::Serialization serialize() const noexcept;
    /// @brief deserialization of the PublisherOptions
    static cxx::expected<PublisherOptions, cxx::Serialization::Error>
    deserialize(const cxx::Serialization& serialized) noexcept;
};

详细解释

  1. historyCapacity:历史数据块队列的大小。这决定了发布者在发布数据时保留的历史数据块数量。

  2. nodeName:发布者所属节点的名称。

  3. offerOnCreate:一个布尔选项,用于指示发布者在创建时是否已经提供数据。

  4. subscriberTooSlowPolicy:当订阅者队列已满时,发布者是否应该阻塞的选项。默认行为是丢弃最旧的数据。

  5. serialize():发布者选项的序列化方法,用于将 PublisherOptions 转换为可存储或传输的格式。

  6. deserialize():发布者选项的反序列化方法,用于将序列化的数据转换回 PublisherOptions 对象。

这些注释和变量用于配置一个发布者的行为和属性,确保在创建和使用发布者时能够正确处理数据发布和队列管理。

PublisherOptions 示例

#include "iceoryx_posh/popo/publisher.hpp"
#include "iceoryx_posh/runtime/posh_runtime.hpp"
#include "iceoryx_utils/cxx/optional.hpp"
#include <iostream>

struct MyData
{
    int value;
};

int main()
{
    iox::runtime::PoshRuntime::initRuntime("publisher");

    // 配置 PublisherOptions
    iox::popo::PublisherOptions publisherOptions;
    publisherOptions.historyCapacity = 10; // 设置历史缓冲区容量
    publisherOptions.nodeName = "MyNode";  // 设置节点名称    // 创建 Publisher
    iox::popo::Publisher<MyData> publisher({"Example", "Publisher", "MyData"}, publisherOptions);

    // 发布数据
    for (int i = 0; i < 10; ++i)
    {
        publisher.loan()
            .and_then([&](auto& sample) {
                sample->value = i;
                sample.publish();
            })
            .or_else([](auto& error) {
                std::cerr << "Could not loan sample! Error: " << error << std::endl;
            });
    }    return 0;
}

2、SubscriberOptions

/// @brief This struct is used to configu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值