Program Listing for File control.hpp

Return to documentation for file (morpheus/_lib/include/morpheus/messages/control.hpp)

Copy
Copied!
            

/* * SPDX-FileCopyrightText: Copyright (c) 2021-2023, 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. */ #pragma once #include <nlohmann/json.hpp> #include <pybind11/pytypes.h> #include <map> #include <memory> #include <string> namespace morpheus { class MessageMeta; #pragma GCC visibility push(default) enum class ControlMessageType { NONE, INFERENCE, TRAINING }; class ControlMessage { public: ControlMessage(); ControlMessage(const nlohmann::json& config); ControlMessage(const ControlMessage& other); // Copies config and metadata, but not payload void config(const nlohmann::json& config); const nlohmann::json& config() const; void add_task(const std::string& task_type, const nlohmann::json& task); bool has_task(const std::string& task_type) const; const nlohmann::json remove_task(const std::string& task_type); void set_metadata(const std::string& key, const nlohmann::json& value); bool has_metadata(const std::string& key) const; const nlohmann::json get_metadata(const std::string& key) const; std::shared_ptr<MessageMeta> payload(); void payload(const std::shared_ptr<MessageMeta>& payload); ControlMessageType task_type(); void task_type(ControlMessageType task_type); private: static const std::string s_config_schema; // NOLINT static std::map<std::string, ControlMessageType> s_task_type_map; // NOLINT ControlMessageType m_cm_type{ControlMessageType::NONE}; std::shared_ptr<MessageMeta> m_payload{nullptr}; nlohmann::json m_tasks{}; nlohmann::json m_config{}; }; struct ControlMessageProxy { static std::shared_ptr<ControlMessage> create(pybind11::dict& config); static std::shared_ptr<ControlMessage> create(std::shared_ptr<ControlMessage> other); static std::shared_ptr<ControlMessage> copy(ControlMessage& self); static pybind11::dict config(ControlMessage& self); // Required for proxy conversion of json -> dict in python static void config(ControlMessage& self, pybind11::dict& config); static void add_task(ControlMessage& self, const std::string& type, pybind11::dict& task); static pybind11::dict remove_task(ControlMessage& self, const std::string& type); static void set_metadata(ControlMessage& self, const std::string& key, pybind11::object& value); static pybind11::object get_metadata(ControlMessage& self, const std::string& key); }; #pragma GCC visibility pop } // namespace morpheus

© Copyright 2023, NVIDIA. Last updated on Apr 11, 2023.