2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2025-02-07 13:56:19 +00:00
|
|
|
* Copyright (C) 2020-2025 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-06-08 16:19:52 +02:00
|
|
|
#include "shared/source/os_interface/debug_env_reader.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2023-08-20 04:31:48 +00:00
|
|
|
#include "shared/source/helpers/api_specific_config.h"
|
2020-06-08 16:19:52 +02:00
|
|
|
#include "shared/source/utilities/io_functions.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2023-08-20 04:31:48 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2020-06-08 16:19:52 +02:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-10-10 16:02:19 +02:00
|
|
|
const char *EnvironmentVariableReader::appSpecificLocation(const std::string &name) {
|
|
|
|
|
return name.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-20 04:31:48 +00:00
|
|
|
bool EnvironmentVariableReader::getSetting(const char *settingName, bool defaultValue, DebugVarPrefix &type) {
|
|
|
|
|
return getSetting(settingName, static_cast<int64_t>(defaultValue), type) ? true : false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
bool EnvironmentVariableReader::getSetting(const char *settingName, bool defaultValue) {
|
2020-03-27 07:47:16 +01:00
|
|
|
return getSetting(settingName, static_cast<int64_t>(defaultValue)) ? true : false;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-20 04:31:48 +00:00
|
|
|
int32_t EnvironmentVariableReader::getSetting(const char *settingName, int32_t defaultValue, DebugVarPrefix &type) {
|
|
|
|
|
return static_cast<int32_t>(getSetting(settingName, static_cast<int64_t>(defaultValue), type));
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
int32_t EnvironmentVariableReader::getSetting(const char *settingName, int32_t defaultValue) {
|
2020-03-27 07:47:16 +01:00
|
|
|
return static_cast<int32_t>(getSetting(settingName, static_cast<int64_t>(defaultValue)));
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-20 04:31:48 +00:00
|
|
|
int64_t EnvironmentVariableReader::getSetting(const char *settingName, int64_t defaultValue, DebugVarPrefix &type) {
|
|
|
|
|
int64_t value = defaultValue;
|
|
|
|
|
char *envValue;
|
|
|
|
|
|
2023-09-21 14:02:00 +00:00
|
|
|
auto prefixString = ApiSpecificConfig::getPrefixStrings();
|
|
|
|
|
auto prefixType = ApiSpecificConfig::getPrefixTypes();
|
2023-08-20 04:31:48 +00:00
|
|
|
uint32_t i = 0;
|
|
|
|
|
|
|
|
|
|
for (const auto &prefix : prefixString) {
|
2023-09-07 12:44:36 +00:00
|
|
|
std::string neoKey = prefix;
|
|
|
|
|
neoKey += settingName;
|
|
|
|
|
envValue = IoFunctions::getenvPtr(neoKey.c_str());
|
2023-08-20 04:31:48 +00:00
|
|
|
if (envValue) {
|
|
|
|
|
value = atoll(envValue);
|
|
|
|
|
type = prefixType[i];
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2023-12-05 12:06:54 +00:00
|
|
|
type = DebugVarPrefix::none;
|
2023-08-20 04:31:48 +00:00
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-27 07:47:16 +01:00
|
|
|
int64_t EnvironmentVariableReader::getSetting(const char *settingName, int64_t defaultValue) {
|
|
|
|
|
int64_t value = defaultValue;
|
2017-12-21 00:45:38 +01:00
|
|
|
char *envValue;
|
|
|
|
|
|
2020-06-08 16:19:52 +02:00
|
|
|
envValue = IoFunctions::getenvPtr(settingName);
|
2017-12-21 00:45:38 +01:00
|
|
|
if (envValue) {
|
2022-09-09 13:19:21 +00:00
|
|
|
value = atoll(envValue);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-20 04:31:48 +00:00
|
|
|
std::string EnvironmentVariableReader::getSetting(const char *settingName, const std::string &value, DebugVarPrefix &type) {
|
2025-02-07 13:56:19 +00:00
|
|
|
std::string keyValue = value;
|
2023-08-20 04:31:48 +00:00
|
|
|
|
2023-09-21 14:02:00 +00:00
|
|
|
auto prefixString = ApiSpecificConfig::getPrefixStrings();
|
|
|
|
|
auto prefixType = ApiSpecificConfig::getPrefixTypes();
|
2023-08-20 04:31:48 +00:00
|
|
|
|
|
|
|
|
uint32_t i = 0;
|
|
|
|
|
for (const auto &prefix : prefixString) {
|
2023-09-07 12:44:36 +00:00
|
|
|
std::string neoKey = prefix;
|
|
|
|
|
neoKey += settingName;
|
2025-02-07 13:56:19 +00:00
|
|
|
auto envValue = IoFunctions::getEnvironmentVariable(neoKey.c_str());
|
|
|
|
|
|
2023-08-20 04:31:48 +00:00
|
|
|
if (envValue) {
|
|
|
|
|
keyValue.assign(envValue);
|
|
|
|
|
type = prefixType[i];
|
|
|
|
|
return keyValue;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2023-12-05 12:06:54 +00:00
|
|
|
type = DebugVarPrefix::none;
|
2023-08-20 04:31:48 +00:00
|
|
|
return keyValue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
std::string EnvironmentVariableReader::getSetting(const char *settingName, const std::string &value) {
|
2025-02-07 13:56:19 +00:00
|
|
|
std::string keyValue = value;
|
|
|
|
|
char *envValue = IoFunctions::getEnvironmentVariable(settingName);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
if (envValue) {
|
|
|
|
|
keyValue.assign(envValue);
|
|
|
|
|
}
|
2025-02-07 13:56:19 +00:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
return keyValue;
|
|
|
|
|
}
|
2025-02-07 13:56:19 +00:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|