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 | // FailureCache.cpp |
7 | // |
8 | |
9 | |
10 | // |
11 | // Implements the FailureCache class |
12 | // |
13 | // ============================================================ |
14 | |
15 | #include "failurecache.hpp" |
16 | |
17 | namespace BINDER_SPACE |
18 | { |
19 | FailureCache::FailureCache() : SHash<FailureCacheHashTraits>::SHash() |
20 | { |
21 | // Nothing to do here |
22 | } |
23 | |
24 | FailureCache::~FailureCache() |
25 | { |
26 | // Delete entries and contents array |
27 | for (Hash::Iterator i = Hash::Begin(), end = Hash::End(); i != end; i++) |
28 | { |
29 | const FailureCacheEntry *pFailureCacheEntry = *i; |
30 | delete pFailureCacheEntry; |
31 | } |
32 | RemoveAll(); |
33 | } |
34 | |
35 | HRESULT FailureCache::Add(SString &assemblyNameorPath, |
36 | HRESULT hrBindingResult) |
37 | { |
38 | HRESULT hr = S_OK; |
39 | BINDER_LOG_ENTER(L"FailureCache::Add"); |
40 | |
41 | NewHolder<FailureCacheEntry> pFailureCacheEntry; |
42 | SAFE_NEW(pFailureCacheEntry, FailureCacheEntry); |
43 | |
44 | // No error occurred; report the original error |
45 | hr = hrBindingResult; |
46 | |
47 | pFailureCacheEntry->GetAssemblyNameOrPath().Set(assemblyNameorPath); |
48 | pFailureCacheEntry->SetBindingResult(hrBindingResult); |
49 | |
50 | Hash::Add(pFailureCacheEntry); |
51 | pFailureCacheEntry.SuppressRelease(); |
52 | |
53 | Exit: |
54 | BINDER_LOG_LEAVE_HR(L"FailureCache::Add", hr); |
55 | return hr; |
56 | } |
57 | |
58 | HRESULT FailureCache::Lookup(SString &assemblyNameorPath) |
59 | { |
60 | HRESULT hr = S_OK; |
61 | BINDER_LOG_ENTER(L"FailureCache::Lookup"); |
62 | FailureCacheEntry *pFailureCachEntry = Hash::Lookup(assemblyNameorPath); |
63 | |
64 | if (pFailureCachEntry != NULL) |
65 | { |
66 | hr = pFailureCachEntry->GetBindingResult(); |
67 | } |
68 | |
69 | BINDER_LOG_LEAVE_HR(L"FailureCache::Lookup", hr); |
70 | return hr; |
71 | } |
72 | |
73 | void FailureCache::Remove(SString &assemblyName) |
74 | { |
75 | BINDER_LOG_ENTER(L"FailureCache::Remove"); |
76 | |
77 | FailureCacheEntry *pFailureCachEntry = Hash::Lookup(assemblyName); |
78 | |
79 | // Hash::Remove does not clean up entries |
80 | Hash::Remove(assemblyName); |
81 | SAFE_DELETE(pFailureCachEntry); |
82 | |
83 | BINDER_LOG_LEAVE(L"FailureCache::Remove"); |
84 | } |
85 | }; |
86 |