1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 // ============================================================
6 // ApplicationContext.hpp
11 // Defines the ApplicationContext class
13 // ============================================================
15 #ifndef __BINDER__APPLICATION_CONTEXT_HPP__
16 #define __BINDER__APPLICATION_CONTEXT_HPP__
18 #include "bindertypes.hpp"
19 #include "failurecache.hpp"
20 #include "assemblyidentitycache.hpp"
21 #ifdef FEATURE_VERSIONING_LOG
22 #include "bindinglog.hpp"
23 #endif // FEATURE_VERSIONING_LOG
24 #include "stringarraylist.h"
26 namespace BINDER_SPACE
28 //=============================================================================================
29 // Data structures for Simple Name -> File Name hash
30 struct FileNameMapEntry
35 class FileNameHashTraits : public NoRemoveSHashTraits< DefaultSHashTraits< FileNameMapEntry > >
39 static const FileNameMapEntry Null() { FileNameMapEntry e; e.m_wszFileName = nullptr; return e; }
40 static bool IsNull(const FileNameMapEntry & e) { return e.m_wszFileName == nullptr; }
41 static key_t GetKey(const FileNameMapEntry & e)
44 key = e.m_wszFileName;
47 static count_t Hash(const key_t &str) { return HashiString(str); }
48 static BOOL Equals(const key_t &lhs, const key_t &rhs) { LIMITED_METHOD_CONTRACT; return (_wcsicmp(lhs, rhs) == 0); }
51 typedef SHash<FileNameHashTraits> TpaFileNameHash;
53 // Entry in SHash table that maps namespace to list of files
54 struct SimpleNameToFileNameMapEntry
56 LPWSTR m_wszSimpleName;
57 LPWSTR m_wszILFileName;
58 LPWSTR m_wszNIFileName;
61 // SHash traits for Namespace -> FileNameList hash
62 class SimpleNameToFileNameMapTraits : public NoRemoveSHashTraits< DefaultSHashTraits< SimpleNameToFileNameMapEntry > >
66 static const SimpleNameToFileNameMapEntry Null() { SimpleNameToFileNameMapEntry e; e.m_wszSimpleName = nullptr; return e; }
67 static bool IsNull(const SimpleNameToFileNameMapEntry & e) { return e.m_wszSimpleName == nullptr; }
68 static key_t GetKey(const SimpleNameToFileNameMapEntry & e)
71 key = e.m_wszSimpleName;
74 static count_t Hash(const key_t &str)
76 SString ssKey(SString::Literal, str);
77 return ssKey.HashCaseInsensitive();
79 static BOOL Equals(const key_t &lhs, const key_t &rhs) { LIMITED_METHOD_CONTRACT; return (SString::_wcsicmp(lhs, rhs) == 0); }
81 void OnDestructPerEntryCleanupAction(const SimpleNameToFileNameMapEntry & e)
83 if (e.m_wszILFileName == nullptr && e.m_wszNIFileName == nullptr)
85 // Don't delete simple name here since it's a filename only entry and will be cleaned up
86 // by the SimpleName -> FileName entry which reuses the same filename pointer.
90 if (e.m_wszSimpleName != nullptr)
92 delete [] e.m_wszSimpleName;
94 if (e.m_wszILFileName != nullptr)
96 delete [] e.m_wszILFileName;
98 if (e.m_wszNIFileName != nullptr)
100 delete [] e.m_wszNIFileName;
103 static const bool s_DestructPerEntryCleanupAction = true;
106 typedef SHash<SimpleNameToFileNameMapTraits> SimpleNameToFileNameMap;
108 class ApplicationContext
113 STDMETHOD(QueryInterface)(REFIID riid,
115 STDMETHOD_(ULONG, AddRef)();
116 STDMETHOD_(ULONG, Release)();
118 // ApplicationContext methods
119 ApplicationContext();
120 virtual ~ApplicationContext();
123 inline SString &GetApplicationName();
124 inline DWORD GetAppDomainId();
125 inline void SetAppDomainId(DWORD dwAppDomainId);
127 HRESULT SetupBindingPaths(/* in */ SString &sTrustedPlatformAssemblies,
128 /* in */ SString &sPlatformResourceRoots,
129 /* in */ SString &sAppPaths,
130 /* in */ SString &sAppNiPaths,
131 /* in */ BOOL fAcquireLock);
133 HRESULT GetAssemblyIdentity(/* in */ LPCSTR szTextualIdentity,
134 /* in */ AssemblyIdentityUTF8 **ppAssemblyIdentity);
137 inline ExecutionContext *GetExecutionContext();
138 inline InspectionContext *GetInspectionContext();
139 inline FailureCache *GetFailureCache();
140 inline HRESULT AddToFailureCache(SString &assemblyNameOrPath,
141 HRESULT hrBindResult);
142 inline StringArrayList *GetAppPaths();
143 inline SimpleNameToFileNameMap *GetTpaList();
144 inline TpaFileNameHash *GetTpaFileNameList();
145 inline StringArrayList *GetPlatformResourceRoots();
146 inline StringArrayList *GetAppNiPaths();
148 // Using a host-configured Trusted Platform Assembly list
149 bool IsTpaListProvided();
150 inline CRITSEC_COOKIE GetCriticalSectionCookie();
151 inline LONG GetVersion();
152 inline void IncrementVersion();
154 #ifdef FEATURE_VERSIONING_LOG
155 inline BindingLog *GetBindingLog();
156 inline void ClearBindingLog();
157 #endif // FEATURE_VERSIONING_LOG
161 Volatile<LONG> m_cVersion;
162 SString m_applicationName;
163 DWORD m_dwAppDomainId;
164 ExecutionContext *m_pExecutionContext;
165 InspectionContext *m_pInspectionContext;
166 FailureCache *m_pFailureCache;
167 CRITSEC_COOKIE m_contextCS;
168 #ifdef FEATURE_VERSIONING_LOG
169 BindingLog m_bindingLog;
170 #endif // FEATURE_VERSIONING_LOG
172 AssemblyIdentityCache m_assemblyIdentityCache;
174 StringArrayList m_platformResourceRoots;
175 StringArrayList m_appPaths;
176 StringArrayList m_appNiPaths;
178 SimpleNameToFileNameMap * m_pTrustedPlatformAssemblyMap;
179 TpaFileNameHash * m_pFileNameHash;
182 #include "applicationcontext.inl"