summaryrefslogtreecommitdiff
path: root/src/utilcode/configuration.cpp
diff options
context:
space:
mode:
authorAditya Mandaleeka <adityam@microsoft.com>2016-03-11 18:39:27 -0800
committerAditya Mandaleeka <adityam@microsoft.com>2016-03-25 17:54:53 -0700
commit1aa1b8ba64365f8b93a505d4f6165c6eaad84a7a (patch)
tree8959cf6022f00a12084aad1c4139d3ba3a5c9501 /src/utilcode/configuration.cpp
parent6cbd27ede090e1731b96d4d2b18813adb67e1487 (diff)
downloadcoreclr-1aa1b8ba64365f8b93a505d4f6165c6eaad84a7a.tar.gz
coreclr-1aa1b8ba64365f8b93a505d4f6165c6eaad84a7a.tar.bz2
coreclr-1aa1b8ba64365f8b93a505d4f6165c6eaad84a7a.zip
Add new configuration mechanism for CoreCLR.
Diffstat (limited to 'src/utilcode/configuration.cpp')
-rw-r--r--src/utilcode/configuration.cpp125
1 files changed, 125 insertions, 0 deletions
diff --git a/src/utilcode/configuration.cpp b/src/utilcode/configuration.cpp
new file mode 100644
index 0000000000..817bc06e90
--- /dev/null
+++ b/src/utilcode/configuration.cpp
@@ -0,0 +1,125 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// --------------------------------------------------------------------------------------------------
+// configuration.cpp
+//
+//
+// Access and update configuration values, falling back on legacy CLRConfig methods where necessary.
+//
+// --------------------------------------------------------------------------------------------------
+
+#include "stdafx.h"
+
+#include "clrconfig.h"
+#include "configuration.h"
+
+LPCWSTR *knobNames = nullptr;
+LPCWSTR *knobValues = nullptr;
+int numberOfKnobs = 0;
+
+void Configuration::InitializeConfigurationKnobs(int numberOfConfigs, LPCWSTR *names, LPCWSTR *values)
+{
+ numberOfKnobs = numberOfConfigs;
+
+ // Neither should be null, or both should be null
+ _ASSERT(!((names == nullptr) ^ (values == nullptr)));
+
+ knobNames = names;
+ knobValues = values;
+}
+
+static LPCWSTR GetConfigurationValue(LPCWSTR name)
+{
+ _ASSERT(name != nullptr);
+ if (name == nullptr || knobNames == nullptr || knobValues == nullptr)
+ {
+ return nullptr;
+ }
+
+ for (int i = 0; i < numberOfKnobs; ++i)
+ {
+ _ASSERT(knobNames[i] != nullptr);
+ if (wcscmp(name, knobNames[i]) == 0)
+ {
+ return knobValues[i];
+ }
+ }
+
+ return nullptr;
+}
+
+DWORD Configuration::GetKnobDWORDValue(LPCWSTR name, const CLRConfig::ConfigDWORDInfo& dwordInfo)
+{
+ bool returnedDefaultValue;
+ DWORD legacyValue = CLRConfig::GetConfigValue(dwordInfo, true /* acceptExplicitDefaultFromRegutil */, &returnedDefaultValue);
+ if (!returnedDefaultValue)
+ {
+ return legacyValue;
+ }
+
+ LPCWSTR knobValue = GetConfigurationValue(name);
+ if (knobValue != nullptr)
+ {
+ return wcstoul(knobValue, nullptr, 0);
+ }
+
+ return legacyValue;
+}
+
+DWORD Configuration::GetKnobDWORDValue(LPCWSTR name, DWORD defaultValue)
+{
+ LPCWSTR knobValue = GetConfigurationValue(name);
+ if (knobValue != nullptr)
+ {
+ return wcstoul(knobValue, nullptr, 0);
+ }
+
+ return defaultValue;
+}
+
+LPCWSTR Configuration::GetKnobStringValue(LPCWSTR name, const CLRConfig::ConfigStringInfo& stringInfo)
+{
+ LPCWSTR value = CLRConfig::GetConfigValue(stringInfo);
+ if (value == nullptr)
+ {
+ value = GetConfigurationValue(name);
+ }
+
+ return value;
+}
+
+LPCWSTR Configuration::GetKnobStringValue(LPCWSTR name)
+{
+ return GetConfigurationValue(name);
+}
+
+bool Configuration::GetKnobBooleanValue(LPCWSTR name, const CLRConfig::ConfigDWORDInfo& dwordInfo)
+{
+ bool returnedDefaultValue;
+ DWORD legacyValue = CLRConfig::GetConfigValue(dwordInfo, true /* acceptExplicitDefaultFromRegutil */, &returnedDefaultValue);
+ if (!returnedDefaultValue)
+ {
+ return (legacyValue != 0);
+ }
+
+ LPCWSTR knobValue = GetConfigurationValue(name);
+ if (knobValue != nullptr)
+ {
+ return (wcscmp(knobValue, W("true")) == 0);
+ }
+
+ return (legacyValue != 0);
+}
+
+bool Configuration::GetKnobBooleanValue(LPCWSTR name, bool defaultValue)
+{
+ LPCWSTR knobValue = GetConfigurationValue(name);
+ if (knobValue != nullptr)
+ {
+ return (wcscmp(knobValue, W("true")) == 0);
+ }
+
+ return defaultValue;
+} \ No newline at end of file