LCOV - code coverage report
Current view: top level - base_comm/resources/endpoint_pairs/sockets - socket_mgr.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 2 2
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 2 2

            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 SOCKET_MGR_H
      12              : #define SOCKET_MGR_H
      13              : 
      14              : #include <atomic>
      15              : #include <mutex>
      16              : #include <condition_variable>
      17              : 
      18              : #include "../../../../../legacy/ascend950/unified_platform/resource/socket/socket.h"
      19              : 
      20              : namespace hcomm {
      21              : 
      22              : class SocketMgr {
      23              : public:
      24          148 :     SocketMgr() {};
      25          148 :     ~SocketMgr() {};
      26              :     HcclResult GetNewSocket(const Hccl::SocketConfig& socketConfig, Hccl::Socket*& socket);
      27              :     HcclResult GetSocket(const Hccl::SocketConfig& socketConfig, Hccl::Socket*& socket);
      28              :     HcclResult GetHostSocket(const Hccl::SocketConfig& socketConfig, Hccl::Socket*& socket);
      29              :     HcclResult CreateSocketWithSocketHandle(const Hccl::SocketConfig& socketConfig);
      30              :     HcclResult MakeSocketInUse(Hccl::Socket*& socket);
      31              :     HcclResult PutSocket(const Hccl::SocketConfig*& socketConfig, Hccl::Socket*& socket);
      32              :     HcclResult UpdateSocketConfig(const Hccl::SocketConfig*& socketConfig, Hccl::Socket*& socket);
      33              :     HcclResult DeleteWhiteList(Hccl::Socket* socket);
      34              :     HcclResult DestroySocket(Hccl::Socket* socket);
      35              :     static void DeInit(u32 devPhyId);
      36              :     static SocketMgr& GetInstance(s32 phyId);
      37              : 
      38              : private:
      39              :     HcclResult Init();
      40              :     HcclResult GetSocketHandle(const Hccl::SocketConfig& socketConfig, Hccl::SocketHandle& socketHandle);
      41              :     HcclResult AddWhiteList(const Hccl::SocketConfig& socketConfig, const Hccl::SocketHandle& socketHandle);
      42              :     HcclResult CreateSocket(const Hccl::SocketConfig& socketConfig, const Hccl::SocketHandle& socketHandle);
      43              : 
      44              : private:
      45              :     SocketMgr(const SocketMgr&) = delete;
      46              :     SocketMgr& operator=(const SocketMgr&) = delete;
      47              : 
      48              :     bool isLoaded_{false};
      49              :     bool isHostOnlyInit_{false};
      50              :     uint32_t devicePhyId_{};
      51              :     uint32_t serverListenPort_{};
      52              :     std::unordered_map<Hccl::SocketConfig, std::unique_ptr<Hccl::Socket>> socketMap_{};
      53              :     std::unordered_map<Hccl::SocketHandle, std::vector<Hccl::RaSocketWhitelist>> handle2WhiteListMap_{};
      54              :     std::unordered_map<Hccl::Socket*, std::atomic<bool>> socketInUseMap_{};
      55              :     std::mutex mutex_{};
      56              :     std::condition_variable socketAvailableCv_;
      57              : };
      58              : 
      59              : } // namespace hcomm
      60              : 
      61              : #endif // SOCKET_MGR_H
        

Generated by: LCOV version 2.0-1