Program Listing for File sidecar_dispatch_queue.hpp
↰ Return to documentation for file (include/holoscan/pubsub/common/sidecar_dispatch_queue.hpp)
/*
* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* 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 PUBSUB_COMMON_INCLUDE_PUBSUB_SIDECAR_DISPATCH_QUEUE_HPP
#define PUBSUB_COMMON_INCLUDE_PUBSUB_SIDECAR_DISPATCH_QUEUE_HPP
#include <condition_variable>
#include <deque>
#include <functional>
#include <mutex>
#include <thread>
#include <vector>
#include <gxf/pubsub/gid.hpp>
#include <gxf/pubsub/pubsub_transport.hpp>
namespace holoscan {
class SidecarDispatchQueue {
public:
using ReceiveCallback = nvidia::gxf::PubSubTransport::ReceiveCallback;
using CallbackProvider = std::function<ReceiveCallback()>;
explicit SidecarDispatchQueue(CallbackProvider get_callback);
~SidecarDispatchQueue();
SidecarDispatchQueue(const SidecarDispatchQueue&) = delete;
SidecarDispatchQueue& operator=(const SidecarDispatchQueue&) = delete;
void start();
void stop();
void enqueue(nvidia::gxf::Gid publisher_gid, std::vector<uint8_t>&& payload,
nvidia::gxf::MessageMetadata metadata);
private:
void dispatch_loop();
struct Item {
nvidia::gxf::Gid publisher_gid;
std::vector<uint8_t> payload;
nvidia::gxf::MessageMetadata metadata;
};
CallbackProvider get_callback_;
std::mutex mutex_;
std::condition_variable cv_;
std::deque<Item> queue_;
bool running_ = false;
std::thread thread_;
};
} // namespace holoscan
#endif/* PUBSUB_COMMON_INCLUDE_PUBSUB_SIDECAR_DISPATCH_QUEUE_HPP */