Branch data Line data Source code
1 : : /* 2 : : * Copyright (C) 2026 by Thun Lu. All rights reserved. 3 : : * Author: Thun Lu <thun.lu@zohomail.cn> 4 : : * Repo: https://github.com/thun-res/vlink 5 : : * _ __ __ _ __ 6 : : * | | / / / / (_) ____ / /__ 7 : : * | | / / / / / / / __ \ / //_/ 8 : : * | |/ / / /___ / / / / / / / ,< 9 : : * |___/ /_____/ /_/ /_/ /_/ /_/|_| 10 : : * 11 : : * Licensed under the Apache License, Version 2.0 (the "License"); 12 : : * you may not use this file except in compliance with the License. 13 : : * You may obtain a copy of the License at 14 : : * 15 : : * http://www.apache.org/licenses/LICENSE-2.0 16 : : * 17 : : * Unless required by applicable law or agreed to in writing, software 18 : : * distributed under the License is distributed on an "AS IS" BASIS, 19 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 : : * See the License for the specific language governing permissions and 21 : : * limitations under the License. 22 : : */ 23 : : 24 : : #pragma once 25 : : 26 : : #include <atomic> 27 : : #include <memory> 28 : : #include <mutex> 29 : : #include <string> 30 : : #include <thread> 31 : : #include <tuple> 32 : : #include <unordered_map> 33 : : #include <utility> 34 : : #include <vector> 35 : : 36 : : #include "./base/message_loop.h" 37 : : #include "./impl/abstract_factory.h" 38 : : #include "./modules/intra_conf.h" 39 : : 40 : : namespace vlink { 41 : : 42 : : enum class IntraType : uint8_t { 43 : : kQueue = 0, 44 : : kDirect = 1, 45 : : }; 46 : : 47 : : using IntraID = std::tuple<uint8_t, std::string, int32_t, IntraType>; 48 : : 49 : : // IntraPipeline 50 : : class IntraPipeline final : public MessageLoop { 51 : : public: 52 : : using MessageLoop::MessageLoop; 53 : : 54 : : protected: 55 : : size_t get_max_task_count() const override; 56 : : }; 57 : : 58 : : // IntraFactory 59 : : class IntraFactory final : public AbstractFactory<IntraID> { 60 : : public: 61 : : IntraPipeline& get_pipeline(int32_t pipeline); 62 : : 63 : : private: 64 : : IntraFactory(); 65 : : 66 : : ~IntraFactory() override; 67 : : 68 : : std::mutex pipeline_mtx_; 69 : : std::unordered_map<int32_t, IntraPipeline> pipeline_map_; 70 : : 71 [ + + + - : 71 : VLINK_SINGLETON_DECLARE(IntraFactory) + - - - ] 72 : : }; 73 : : 74 : : // IntraNode 75 : : class IntraNode final : public AbstractObject<IntraID>, public std::enable_shared_from_this<IntraNode> { 76 : : public: 77 : : explicit IntraNode(const IntraID&); 78 : : 79 : : ~IntraNode() override; 80 : : 81 : : std::any get_native_handle() const override; 82 : : 83 : : bool publish(IntraType type, uint32_t channel, const Bytes& msg_data); 84 : : 85 : : bool publish(IntraType type, uint32_t channel, const IntraData& intra_data); 86 : : 87 : : bool call(IntraType type, uint32_t channel, const Bytes& req_data, NodeImpl::MsgCallback&& callback = nullptr); 88 : : 89 : : private: 90 : : IntraPipeline* pipeline_{nullptr}; 91 : : }; 92 : : 93 : : } // namespace vlink