LCOV - code coverage report
Current view: top level - base_comm/resources/endpoints/server_socket - server_socket_manager.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 9 9
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #ifndef SERVER_SOCKET_MANAGER_H
      12              : #define SERVER_SOCKET_MANAGER_H
      13              : #include <mutex>
      14              : #include <unordered_map>
      15              : #include "hccl/hccl_res.h"
      16              : // Orion
      17              : #include "socket/socket.h"
      18              : #include "virtual_topo.h"
      19              : #include "socket_config.h"
      20              : #include "socket_manager.h"
      21              : #include "orion_adapter_rts.h"
      22              : #include "socket_handle_manager.h"
      23              : #include "host_socket_handle_manager.h"
      24              : 
      25              : namespace hcomm {
      26              : 
      27              : class ServerSocketManager {
      28              : public:
      29           89 :     static ServerSocketManager& GetInstance() {
      30           89 :         static ServerSocketManager instance;
      31           89 :         return instance;
      32              :     }
      33              :     ServerSocketManager(const ServerSocketManager&) = delete;
      34              :     ServerSocketManager& operator=(const ServerSocketManager&) = delete;
      35              :     ServerSocketManager(ServerSocketManager&&) = delete;
      36              :     ServerSocketManager& operator=(ServerSocketManager&&) = delete;
      37              :     
      38            1 :     ~ServerSocketManager() {};
      39              : 
      40              :     HcclResult ServerSocketStartListen(const Hccl::PortData& localPort, const Hccl::NicType nicType, const uint32_t devPhyId, uint32_t *port);
      41              :     HcclResult ServerSocketStopListen(const Hccl::PortData& localPort, const Hccl::NicType nicType, const uint32_t port);
      42              :     void DeInit(u32 devPhyId);
      43              : 
      44              : private:
      45            1 :     ServerSocketManager()
      46            1 :     {
      47              :         // Ensure that (Host)SocketHandleManager destruct after the destructionon of device/host ServerSocketMap_.
      48            1 :         (void)Hccl::SocketHandleManager::GetInstance();
      49            1 :         (void)Hccl::HostSocketHandleManager::GetInstance();
      50            1 :     };
      51              :     HcclResult DeviceSocketListen(const Hccl::PortData& localPort, const uint32_t devPhyId, uint32_t *port);
      52              :     HcclResult HostSocketListen(const Hccl::PortData& localPort, const uint32_t devPhyId, uint32_t *port);
      53              :     HcclResult DeviceSocketStopListen(const Hccl::PortData& localPort, const uint32_t port);
      54              :     HcclResult HostSocketStopListen(const Hccl::PortData& localPort, const uint32_t port);
      55              :     void DeInitDeviceSockets(u32 devPhyId);
      56              :     void DeInitHostSockets(u32 devPhyId);
      57              : 
      58              :     // PortData : {ListenPort : {Socket, Count}}
      59              :     std::unordered_map<Hccl::PortData, std::unordered_map<uint32_t, std::pair<std::unique_ptr<Hccl::Socket>, uint32_t>>> deviceServerSocketMap_{};
      60              :     std::unordered_map<Hccl::PortData, std::unordered_map<uint32_t, std::pair<std::unique_ptr<Hccl::Socket>, uint32_t>>> hostServerSocketMap_{};
      61              :     std::unique_ptr<Hccl::SocketManager> socketMgrCompat_;
      62              :     std::mutex hostMutex_{};
      63              :     std::mutex deviceMutex_{};
      64              : };
      65              : 
      66              : } // namespace hcomm
      67              : 
      68              : #endif // SERVER_SOCKET_MGR_H
        

Generated by: LCOV version 2.0-1