summaryrefslogtreecommitdiff
path: root/src/inc/shim
diff options
context:
space:
mode:
Diffstat (limited to 'src/inc/shim')
-rw-r--r--src/inc/shim/locationinfo.h42
-rw-r--r--src/inc/shim/runtimeselector.h55
-rw-r--r--src/inc/shim/runtimeselector.inl105
-rw-r--r--src/inc/shim/shimselector.h55
-rw-r--r--src/inc/shim/shimselector.inl104
-rw-r--r--src/inc/shim/versionandlocationinfo.h36
-rw-r--r--src/inc/shim/versionandlocationinfo.inl35
-rw-r--r--src/inc/shim/versioninfo.h46
-rw-r--r--src/inc/shim/versioninfo.inl170
9 files changed, 648 insertions, 0 deletions
diff --git a/src/inc/shim/locationinfo.h b/src/inc/shim/locationinfo.h
new file mode 100644
index 0000000000..d6a1b6d0b4
--- /dev/null
+++ b/src/inc/shim/locationinfo.h
@@ -0,0 +1,42 @@
+// 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.
+//
+// locationinfo.h
+//
+// Enum describing different types of locations for coreCLR
+//
+// Note: must be platform independent
+//
+// ======================================================================================
+
+
+#ifndef LOCATIONINFO_H
+#define LOCATIONINFO_H
+
+
+// in order of preference, smaller is better
+enum LocationInfo
+{
+ Loc_System=1,
+ Loc_Machine=2,
+ Loc_User=3,
+ Loc_Network=4,
+ Loc_Undefined =0xffff
+};
+
+// Returns the more preferred of two locations
+//
+// Assumptions: LocationInfo is defined in a manner that a smaller value is better
+//
+// Input:
+// locations to compare
+//
+// Output:
+// the preferred location
+inline LocationInfo BetterLocation(LocationInfo l1, LocationInfo l2)
+{
+ return l1<l2?l1:l2;
+};
+
+#endif // LOCATIONINFO_H
diff --git a/src/inc/shim/runtimeselector.h b/src/inc/shim/runtimeselector.h
new file mode 100644
index 0000000000..168aee9aa8
--- /dev/null
+++ b/src/inc/shim/runtimeselector.h
@@ -0,0 +1,55 @@
+// 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.
+//
+// runtimeselector.h
+//
+// Class that select the best runtime
+//
+// Note: very similar to ShimSelector but is so simple that adding a common template parent class is not worth it
+//
+// Note: must be platform independent
+//
+// ======================================================================================
+
+
+#ifndef RUNTIMESELECTOR_H
+#define RUNTIMESELECTOR_H
+
+// does not currently need to add anything to VersionAndLocationInfo
+#include "versionandlocationinfo.h"
+typedef VersionAndLocationInfo RuntimeInfo;
+
+class RuntimeSelector
+{
+protected:
+ VersionInfo m_RequestedVersion; // requested version
+ RuntimeInfo m_Best; // the best option so far
+ bool m_bHasSomething; // has any data
+public:
+ //constructor
+ RuntimeSelector();
+
+ // whether the given info compatible with the request
+ bool IsAcceptable(const RuntimeInfo& runtimeInfo) const;
+
+ // add runtime info
+ HRESULT Add(const RuntimeInfo& runtimeInfo);
+
+ // set the version requested
+ void SetRequestedVersion(const VersionInfo& version);
+
+ // get the best found
+ RuntimeInfo GetBest();
+
+ // has any useful data
+ bool HasUsefulRuntimeInfo();
+
+ // is 1st better than 2nd
+ static bool IsBetter(const RuntimeInfo& ri1, const RuntimeInfo& ri2);
+};
+
+#include "runtimeselector.inl"
+
+#endif // RUNTIMESELECTOR_H
+
diff --git a/src/inc/shim/runtimeselector.inl b/src/inc/shim/runtimeselector.inl
new file mode 100644
index 0000000000..5b73a69d94
--- /dev/null
+++ b/src/inc/shim/runtimeselector.inl
@@ -0,0 +1,105 @@
+// 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.
+//
+// runtimeselector.inl
+//
+// implementation that select the best runtime
+//
+// Note: must be platform independent
+//
+// ======================================================================================
+
+// Constructor
+//
+// Simply marks the fact that no data is set
+inline RuntimeSelector::RuntimeSelector()
+{
+ m_bHasSomething=false;
+}
+
+// Sets the runtime version requested
+//
+// Input:
+// version - version to set
+inline void RuntimeSelector::SetRequestedVersion(const VersionInfo& version)
+{
+ m_RequestedVersion=version;
+};
+
+
+// Returns whether the given runtime can be used
+//
+// Input:
+// runtimeInfo - the runtime info
+//
+// Output:
+// return value - true: can be used, false: cannot be used
+inline bool RuntimeSelector::IsAcceptable(const RuntimeInfo& runtimeInfo) const
+{
+ return ( m_RequestedVersion.Major() == runtimeInfo.Version().Major() &&
+ m_RequestedVersion.Minor() == runtimeInfo.Version().Minor());
+}
+
+
+// Returns add the given runtime to the potentially used runtimes list
+//
+// Input:
+// runtimeInfo - the runtime info
+//
+// Output:
+// return value - S_OK added, S_FALSE not added (not a failure) or a failure code
+inline HRESULT RuntimeSelector::Add(const RuntimeInfo& runtimeInfo)
+{
+ HRESULT hr = S_FALSE;
+ if(!IsAcceptable(runtimeInfo))
+ return S_FALSE;
+
+ if(!m_bHasSomething || IsBetter(runtimeInfo,m_Best))
+ {
+ m_Best=runtimeInfo;
+ hr=S_OK;
+ }
+
+ m_bHasSomething=true;
+ return hr;
+};
+
+// Returns add the best runtime of the options given (see Add)
+//
+// Output:
+// return value - the best option
+inline RuntimeInfo RuntimeSelector::GetBest()
+{
+ return m_Best;
+};
+
+// Returns whether we have any usable choices
+//
+// Output:
+// return value - true if the has something usable
+inline bool RuntimeSelector::HasUsefulRuntimeInfo()
+{
+ return m_bHasSomething;
+};
+
+// Compares two given options
+//
+// Input:
+// ri1, ri2 - runtimes to compare
+//
+// Output:
+// return value - true if ri1 is better than ri2
+inline bool RuntimeSelector::IsBetter(const RuntimeInfo& ri1, const RuntimeInfo& ri2)
+{
+ switch(ri1.Version().Compare(ri2.Version()))
+ {
+ case -1: return false;
+ case 1: return true;
+ default:
+ return (BetterLocation(ri1.Location(),ri2.Location())==ri1.Location());
+ }
+};
+
+
+
diff --git a/src/inc/shim/shimselector.h b/src/inc/shim/shimselector.h
new file mode 100644
index 0000000000..0eaafd64dd
--- /dev/null
+++ b/src/inc/shim/shimselector.h
@@ -0,0 +1,55 @@
+// 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.
+//
+// shimselector.h
+//
+// Class that select the best runtime
+//
+// Note: very similar to RuntimeSelector but is so simple that adding a common template parent class is not worth it
+//
+// Note: must be platform independent
+//
+// ======================================================================================
+
+#ifndef SHIMSELECTOR_H
+#define SHIMSELECTOR_H
+
+// does not currently need to add anything to VersionAndLocationInfo
+#include "versionandlocationinfo.h"
+typedef VersionAndLocationInfo ShimInfo;
+
+class ShimSelector
+{
+protected:
+ VersionInfo m_Baseline; // base line to compare against
+ ShimInfo m_Best; // best found so far
+ bool m_bHasSomething; // has any data
+public:
+
+ //constructor
+ ShimSelector();
+
+ // whether the given info is better than the base line
+ bool IsAcceptable(const ShimInfo& shimInfo) const;
+
+ // add shim info
+ HRESULT Add(const ShimInfo& shimInfo);
+
+ //set the base line
+ void SetBaseline(const VersionInfo& version);
+
+ // get the best found
+ ShimInfo GetBest();
+
+ // has any useful data
+ bool HasUsefulShimInfo();
+
+ // is 1st better than 2nd
+ static bool IsBetter(const ShimInfo& ri1, const ShimInfo& ri2);
+};
+
+
+#include "shimselector.inl"
+
+#endif // SHIMSELECTOR_H
diff --git a/src/inc/shim/shimselector.inl b/src/inc/shim/shimselector.inl
new file mode 100644
index 0000000000..2fd3b14d3e
--- /dev/null
+++ b/src/inc/shim/shimselector.inl
@@ -0,0 +1,104 @@
+// 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.
+//
+// shimselector.inl
+//
+// implementation that select the best shim
+//
+// Note: must be platform independent
+//
+// ======================================================================================
+
+
+
+// Constructor
+//
+// Simply marks the fact that no data is set
+inline ShimSelector::ShimSelector()
+{
+ m_bHasSomething=false;
+}
+
+// Sets the base line to compare against
+//
+// Input:
+// version - the version info
+inline void ShimSelector::SetBaseline(const VersionInfo& version)
+{
+ m_Baseline=version;
+}
+
+// Checks whether the shim is better that the base (the current one)
+//
+// Input:
+// shimInfo - the shim info
+//
+// Output:
+// return value - true: better, false: worse or the same
+inline bool ShimSelector::IsAcceptable(const ShimInfo& shimInfo) const
+{
+ return ( m_Baseline.Compare(shimInfo.Version()) < 0 );
+}
+
+// Returns add the given shim to the potentially used shim list
+//
+// Input:
+// shimInfo - the shim info
+//
+// Output:
+// return value - S_OK added, S_FALSE not added (not a failure) or a failure code
+inline HRESULT ShimSelector::Add(const ShimInfo& shimInfo)
+{
+ HRESULT hr = S_FALSE;
+ if(!IsAcceptable(shimInfo))
+ return S_FALSE;
+
+ if(!m_bHasSomething || IsBetter(shimInfo,m_Best))
+ {
+ m_Best=shimInfo;
+ hr=S_OK;
+ }
+
+ m_bHasSomething=true;
+ return hr;
+};
+
+// Returns add the best shim of the options given (see Add)
+//
+// Output:
+// return value - the best option
+inline ShimInfo ShimSelector::GetBest()
+{
+ return m_Best;
+};
+
+// Returns whether we have any usable choices
+//
+// Output:
+// return value - true if the has something usable
+inline bool ShimSelector::HasUsefulShimInfo()
+{
+ return m_bHasSomething;
+};
+
+// Compares two given options
+//
+// Input:
+// si1, si2 - shims to compare
+//
+// Output:
+// return value - true if si1 is better than si2
+inline bool ShimSelector::IsBetter(const ShimInfo& si1, const ShimInfo& si2)
+{
+ switch(si1.Version().Compare(si2.Version()))
+ {
+ case -1: return false;
+ case 1: return true;
+ default:
+ return (BetterLocation(si1.Location(),si2.Location())==si1.Location());
+ }
+};
+
+
+
diff --git a/src/inc/shim/versionandlocationinfo.h b/src/inc/shim/versionandlocationinfo.h
new file mode 100644
index 0000000000..38be7f2c98
--- /dev/null
+++ b/src/inc/shim/versionandlocationinfo.h
@@ -0,0 +1,36 @@
+// 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.
+//
+// versionandlocationinfo.h
+//
+// a simple struct encapsulating version# and location code
+//
+// Note: must be platform independent
+//
+// ======================================================================================
+
+
+#ifndef VERSIONANDLOCATIONINFO_H
+#define VERSIONANDLOCATIONINFO_H
+
+#include "versioninfo.h"
+#include "locationinfo.h"
+
+struct VersionAndLocationInfo
+{
+protected:
+ VersionInfo m_Version;
+ LocationInfo m_Location;
+public:
+ VersionAndLocationInfo();
+ VersionAndLocationInfo(const VersionInfo& version, const LocationInfo location);
+ VersionInfo Version() const;
+ LocationInfo Location() const ;
+};
+
+
+#include "versionandlocationinfo.inl"
+
+#endif // VERSIONANDLOCATIONINFO_H
+
diff --git a/src/inc/shim/versionandlocationinfo.inl b/src/inc/shim/versionandlocationinfo.inl
new file mode 100644
index 0000000000..37c0d98c92
--- /dev/null
+++ b/src/inc/shim/versionandlocationinfo.inl
@@ -0,0 +1,35 @@
+// 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.
+//
+// versionandlocationinfo.inl
+//
+// simple accessors for the struct encapsulating version# and location code
+//
+// Note: must be platform independent
+//
+// ======================================================================================
+
+
+inline VersionAndLocationInfo::VersionAndLocationInfo():
+ m_Version(0,0,0,0),
+ m_Location(Loc_Undefined)
+{
+};
+
+inline VersionAndLocationInfo::VersionAndLocationInfo(const VersionInfo& version, const LocationInfo location):
+ m_Version(version),
+ m_Location(location)
+{
+};
+
+inline VersionInfo VersionAndLocationInfo::Version() const
+{
+ return m_Version;
+};
+
+inline LocationInfo VersionAndLocationInfo::Location() const
+{
+ return m_Location;
+};
+
diff --git a/src/inc/shim/versioninfo.h b/src/inc/shim/versioninfo.h
new file mode 100644
index 0000000000..f3f3b8a719
--- /dev/null
+++ b/src/inc/shim/versioninfo.h
@@ -0,0 +1,46 @@
+// 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.
+//
+// versioninfo.h
+//
+// representation of version#
+//
+// Note: must be platform independent
+//
+// ======================================================================================
+
+#ifndef VERSIONINFO_H
+#define VERSIONINFO_H
+
+
+struct VersionInfo
+{
+protected:
+ unsigned short m_wMajor;
+ unsigned short m_wMinor;
+ unsigned short m_wBuild;
+ unsigned short m_wRevision;
+public:
+ VersionInfo();
+ VersionInfo( const unsigned short major,
+ const unsigned short minor,
+ const unsigned short build,
+ const unsigned short revision
+ );
+ unsigned short Major() const;
+ unsigned short Minor() const;
+ unsigned short Build() const;
+ unsigned short Revision() const;
+
+ // 1 if "this" is bigger, -1 if "this' is smaller
+ int Compare(const VersionInfo& version) const;
+
+ // on success returns count of numbers read (<=4), otherwise -1
+ static int Parse( LPCTSTR szString,
+ VersionInfo* result);
+};
+
+#include "versioninfo.inl"
+
+#endif
diff --git a/src/inc/shim/versioninfo.inl b/src/inc/shim/versioninfo.inl
new file mode 100644
index 0000000000..f2f6b110c0
--- /dev/null
+++ b/src/inc/shim/versioninfo.inl
@@ -0,0 +1,170 @@
+// 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.
+//
+// versioninfo.inl
+//
+// representation of version#
+//
+// Note: must be platform independent
+//
+// ======================================================================================
+
+
+// default cctor
+inline VersionInfo::VersionInfo()
+{
+ m_wMajor=0;
+ m_wMinor=0;
+ m_wBuild=0;
+ m_wRevision=0;
+}
+
+// constructor
+inline VersionInfo::VersionInfo( unsigned short major,
+ unsigned short minor,
+ unsigned short build,
+ unsigned short revision
+ )
+{
+ m_wMajor=major;
+ m_wMinor=minor;
+ m_wBuild=build;
+ m_wRevision=revision;
+}
+
+// field accessor
+inline unsigned short VersionInfo::Major() const
+{
+ return m_wMajor;
+};
+
+// field accessor
+inline unsigned short VersionInfo::Minor() const
+{
+ return m_wMinor;
+};
+
+// field accessor
+inline unsigned short VersionInfo::Build() const
+{
+ return m_wBuild;
+};
+
+// field accessor
+inline unsigned short VersionInfo::Revision() const
+{
+ return m_wRevision;
+};
+
+// Compares against the given version
+//
+// Input:
+// version - the version info
+//
+// Output:
+// return value:
+// -1 given version is newer
+// 1 given version is older
+// 0 given version is the same
+inline int VersionInfo::Compare(const VersionInfo& version) const
+{
+ if (Major() > version.Major())
+ return 1;
+ if (Major() < version.Major())
+ return -1;
+ if (Minor() > version.Minor())
+ return 1;
+ if (Minor() < version.Minor())
+ return -1;
+ if (Build() > version.Build())
+ return 1;
+ if (Build() < version.Build())
+ return -1;
+ if (Revision() > version.Revision())
+ return 1;
+ if (Revision() < version.Revision())
+ return -1;
+ return 0;
+}
+
+
+// Parses the given string into VersionInfo
+//
+// Input:
+// szString - the string to parse, "x.x.x.x"
+//
+// Output:
+// return value: count of fields parsed (<=4) or -1 if an error
+inline int VersionInfo::Parse(LPCTSTR szString, VersionInfo* result)
+{
+ // sscanf is nice but we need an exact format match and no 0s
+ size_t iLen = _tcslen(szString);
+
+ unsigned short wVersion[4] = {0};
+ int iVerIdx = 0;
+ unsigned int dwCurrentValue = 0;
+ bool bFirstChar = true;
+
+ for (size_t i=0; i<= iLen; i++)
+ {
+ if(szString[i] == _T('\0'))
+ {
+ if(!bFirstChar)
+ wVersion[iVerIdx++] = (unsigned short)(dwCurrentValue & 0xffff);
+ break;
+ }
+ else
+ if (szString[i] == _T('.') )
+ {
+ if(bFirstChar)
+ return -1;
+
+ // fill in
+ wVersion[iVerIdx++] = (unsigned short)(dwCurrentValue & 0xffff);
+
+ //check for extra characters
+ if (iVerIdx > sizeof(wVersion)/sizeof(wVersion[0]))
+ {
+ if (szString[i+1] == _T('\0'))
+ break;
+ else
+ return -1;
+ }
+
+ //reset
+ dwCurrentValue=0;
+ bFirstChar=true;
+ continue;
+ }
+ else
+ if (szString[i] < _T('0'))
+ {
+ return -1;
+ }
+ else
+ if (szString[i] > _T('9'))
+ {
+ return -1;
+ }
+ else
+ if (szString[i] == _T('0') && bFirstChar && szString[i+1]!= _T('.') && szString[i+1]!= _T('\0') )
+ {
+ return -1;
+ }
+
+ // the character is a digit
+ dwCurrentValue=dwCurrentValue*10+szString[i]-_T('0');
+ if(dwCurrentValue > 0xffff)
+ return -1;
+
+ bFirstChar=false;
+
+ }
+
+ //successfully parsed
+ *result = VersionInfo(wVersion[0], wVersion[1], wVersion[2], wVersion[3]);
+ return iVerIdx;
+
+}
+