f315b32c0d07854e6422dffc3e27870858c5c674
[platform/upstream/coreclr.git] / src / binder / inc / applicationcontext.hpp
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 // ============================================================
5 //
6 // ApplicationContext.hpp
7 //
8
9
10 //
11 // Defines the ApplicationContext class
12 //
13 // ============================================================
14
15 #ifndef __BINDER__APPLICATION_CONTEXT_HPP__
16 #define __BINDER__APPLICATION_CONTEXT_HPP__
17
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"
25
26 namespace BINDER_SPACE
27 {
28     //=============================================================================================
29     // Data structures for Simple Name -> File Name hash
30     struct FileNameMapEntry
31     {
32         LPWSTR m_wszFileName;
33     };
34     
35     class FileNameHashTraits : public NoRemoveSHashTraits< DefaultSHashTraits< FileNameMapEntry > >
36     {
37      public:
38         typedef PCWSTR key_t;
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)
42         {
43             key_t key;
44             key = e.m_wszFileName;
45             return key;
46         }
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); }
49     };
50
51     typedef SHash<FileNameHashTraits> TpaFileNameHash;
52     
53     // Entry in SHash table that maps namespace to list of files
54     struct SimpleNameToFileNameMapEntry
55     {
56         LPWSTR m_wszSimpleName;
57         LPWSTR m_wszILFileName;
58         LPWSTR m_wszNIFileName;
59     };
60     
61     // SHash traits for Namespace -> FileNameList hash
62     class SimpleNameToFileNameMapTraits : public NoRemoveSHashTraits< DefaultSHashTraits< SimpleNameToFileNameMapEntry > >
63     {
64      public:
65         typedef PCWSTR key_t;
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)
69         {
70             key_t key;
71             key = e.m_wszSimpleName;
72             return key;
73         }
74         static count_t Hash(const key_t &str)
75         {
76             SString ssKey(SString::Literal, str);
77             return ssKey.HashCaseInsensitive();
78         }
79         static BOOL Equals(const key_t &lhs, const key_t &rhs) { LIMITED_METHOD_CONTRACT; return (SString::_wcsicmp(lhs, rhs) == 0); }
80         
81         void OnDestructPerEntryCleanupAction(const SimpleNameToFileNameMapEntry & e)
82         {
83             if (e.m_wszILFileName == nullptr && e.m_wszNIFileName == nullptr)
84             {
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.
87                 return;
88             }
89             
90             if (e.m_wszSimpleName != nullptr)
91             {
92                 delete [] e.m_wszSimpleName;
93             }
94             if (e.m_wszILFileName != nullptr)
95             {
96                 delete [] e.m_wszILFileName;
97             }
98             if (e.m_wszNIFileName != nullptr)
99             {
100                 delete [] e.m_wszNIFileName;
101             }
102         }
103         static const bool s_DestructPerEntryCleanupAction = true;
104     };
105
106     typedef SHash<SimpleNameToFileNameMapTraits> SimpleNameToFileNameMap;
107     
108     class ApplicationContext
109         : public IUnknown
110     {
111     public:
112         // IUnknown methods
113         STDMETHOD(QueryInterface)(REFIID   riid,
114                                   void   **ppv);
115         STDMETHOD_(ULONG, AddRef)();
116         STDMETHOD_(ULONG, Release)();
117
118         // ApplicationContext methods
119         ApplicationContext();
120         virtual ~ApplicationContext();
121         HRESULT Init();
122
123         inline SString &GetApplicationName();
124         inline DWORD GetAppDomainId();
125         inline void SetAppDomainId(DWORD dwAppDomainId);
126
127         HRESULT SetupBindingPaths(/* in */ SString &sTrustedPlatformAssemblies,
128                                   /* in */ SString &sPlatformResourceRoots,
129                                   /* in */ SString &sAppPaths,
130                                   /* in */ SString &sAppNiPaths,
131                                   /* in */ BOOL     fAcquireLock);
132
133         HRESULT GetAssemblyIdentity(/* in */ LPCSTR                szTextualIdentity,
134                                     /* in */ AssemblyIdentityUTF8 **ppAssemblyIdentity);
135
136         // Getters/Setter
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();
147         
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();
153
154 #ifdef FEATURE_VERSIONING_LOG
155         inline BindingLog *GetBindingLog();
156         inline void ClearBindingLog();
157 #endif // FEATURE_VERSIONING_LOG
158
159     protected:
160         LONG               m_cRef;
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
171
172         AssemblyIdentityCache m_assemblyIdentityCache;
173
174         StringArrayList    m_platformResourceRoots;
175         StringArrayList    m_appPaths;
176         StringArrayList    m_appNiPaths;
177
178         SimpleNameToFileNameMap * m_pTrustedPlatformAssemblyMap;
179         TpaFileNameHash    * m_pFileNameHash;
180     };
181
182 #include "applicationcontext.inl"
183
184 };
185
186 #endif