LCOV - code coverage report
Current view: top level - basic_component/package_manager/inc - package_worker_factory.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 2 2
Test Date: 2026-07-28 10:52:48 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 TSD_PACKAGE_WORKER_FACTORY_H
      12              : #define TSD_PACKAGE_WORKER_FACTORY_H
      13              : 
      14              : #include <map>
      15              : #include <string>
      16              : #include <mutex>
      17              : #include <memory>
      18              : #include <functional>
      19              : #include "base_package_worker.h"
      20              : #include "basic_define.h"
      21              : 
      22              : namespace tsd {
      23              : using PackageWorkerCreateFunc = std::function<std::shared_ptr<BasePackageWorker>(const PackageWorkerParas&)>;
      24              : 
      25              : class PackageWorkerFactory {
      26              : public:
      27              :     static PackageWorkerFactory& GetInstance();
      28              :     static bool RegisterPackageWorker(const PackageWorkerType type, const PackageWorkerCreateFunc& func);
      29              :     std::shared_ptr<BasePackageWorker> CreatePackageWorker(
      30              :         const PackageWorkerType type, const PackageWorkerParas paras) const;
      31              : 
      32              : private:
      33            2 :     PackageWorkerFactory() : creatorMapMtx_(), creatorMap_(){};
      34            2 :     ~PackageWorkerFactory() = default;
      35              : 
      36              :     PackageWorkerFactory(PackageWorkerFactory const&) = delete;
      37              :     PackageWorkerFactory& operator=(PackageWorkerFactory const&) = delete;
      38              :     PackageWorkerFactory(PackageWorkerFactory&&) = delete;
      39              :     PackageWorkerFactory& operator=(PackageWorkerFactory&&) = delete;
      40              : 
      41              :     bool RegisterPackageWorkerCreator(const PackageWorkerType type, const PackageWorkerCreateFunc& func);
      42              : 
      43              :     std::mutex creatorMapMtx_;
      44              :     std::map<PackageWorkerType, PackageWorkerCreateFunc> creatorMap_;
      45              : };
      46              : } // namespace tsd
      47              : 
      48              : #define REGISTER_PACKAGE_WORKER(type, clazz)                                                                      \
      49              :     namespace {                                                                                                   \
      50              :     static bool __attribute__((unused)) g_Creator_##clazz = PackageWorkerFactory::RegisterPackageWorker(          \
      51              :         (type),                                                                                                   \
      52              :         [](const PackageWorkerParas paras) -> std::shared_ptr<clazz> { return std::make_shared<clazz>(paras); }); \
      53              :     }
      54              : 
      55              : #endif // TSD_PACKAGE_WORKER_FACTORY_H
        

Generated by: LCOV version 2.0-1