* This file is part of the MindStudio project.
* Copyright (c) 2025 Huawei Technologies Co.,Ltd.
*
* MindStudio is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* ------------------------------------------------------------------------- */
#ifndef __MSOPPROF_PARSE_PLUGIN_INTERFACE_H__
#define __MSOPPROF_PARSE_PLUGIN_INTERFACE_H__
#include <vector>
#include "common/defs.h"
#include "parse/data_center/data_center.h"
#include "base_context.h"
namespace Profiling {
namespace Parse {
enum class PluginErrorCode : uint32_t {
SUCCESS = 0,
NONBLOCKING_ERROR,
FATAL_ERROR,
ERROR_CODE_END,
};
struct PluginInfo {
std::string pluginName;
std::vector<std::type_index> mandatoryDb;
std::vector<std::type_index> optionalDb;
std::set<ChipProductType> chipSupport;
bool isKeyPlugin = false;
};
class PluginInterface {
public:
explicit PluginInterface(DataCenter& dataCenter, ChipProductType chipType)
: dataCenter_(dataCenter), chipType_(chipType) {};
virtual ~PluginInterface() = default;
PluginErrorCode Run();
void SetEntry(bool comeIn)
{
isEntry_.store(comeIn);
}
bool GetEntry() const
{
return isEntry_.load();
}
protected:
virtual PluginErrorCode Entry() = 0;
virtual void DependencyRegister() = 0;
bool DependencyCheck(ChipProductType profChipType) const;
void RegisterPluginName(const std::string& pluginName)
{
pluginInfo_.pluginName = pluginName;
}
void RegisterMandatoryDb(std::initializer_list<std::type_index> requiredDb)
{
pluginInfo_.mandatoryDb = requiredDb;
}
void RegisterOptionalDb(std::initializer_list<std::type_index> requiredDb)
{
pluginInfo_.optionalDb = requiredDb;
}
void RegisterChip(std::initializer_list<ChipProductType> supportChipType)
{
pluginInfo_.chipSupport = std::set<ChipProductType>(supportChipType);
}
void RegisterKeyPlugin(bool isKeyPlugin)
{
pluginInfo_.isKeyPlugin = isKeyPlugin;
}
PluginInfo pluginInfo_;
DataCenter& dataCenter_;
ChipProductType chipType_;
private:
bool IsBaseProductTypeRegistered(const ChipProductType &profChipType) const;
std::atomic<bool> isEntry_ {false};
};
}
}
#endif