diff options
Diffstat (limited to 'src/binder/failurecache.cpp')
-rw-r--r-- | src/binder/failurecache.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/binder/failurecache.cpp b/src/binder/failurecache.cpp new file mode 100644 index 0000000000..931a56ec1a --- /dev/null +++ b/src/binder/failurecache.cpp @@ -0,0 +1,86 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// +// ============================================================ +// +// FailureCache.cpp +// + + +// +// Implements the FailureCache class +// +// ============================================================ + +#include "failurecache.hpp" + +namespace BINDER_SPACE +{ + FailureCache::FailureCache() : SHash<FailureCacheHashTraits>::SHash() + { + // Nothing to do here + } + + FailureCache::~FailureCache() + { + // Delete entries and contents array + for (Hash::Iterator i = Hash::Begin(), end = Hash::End(); i != end; i++) + { + const FailureCacheEntry *pFailureCacheEntry = *i; + delete pFailureCacheEntry; + } + RemoveAll(); + } + + HRESULT FailureCache::Add(SString &assemblyNameorPath, + HRESULT hrBindingResult) + { + HRESULT hr = S_OK; + BINDER_LOG_ENTER(L"FailureCache::Add"); + + NewHolder<FailureCacheEntry> pFailureCacheEntry; + SAFE_NEW(pFailureCacheEntry, FailureCacheEntry); + + // No error occured; report the original error + hr = hrBindingResult; + + pFailureCacheEntry->GetAssemblyNameOrPath().Set(assemblyNameorPath); + pFailureCacheEntry->SetBindingResult(hrBindingResult); + + Hash::Add(pFailureCacheEntry); + pFailureCacheEntry.SuppressRelease(); + + Exit: + BINDER_LOG_LEAVE_HR(L"FailureCache::Add", hr); + return hr; + } + + HRESULT FailureCache::Lookup(SString &assemblyNameorPath) + { + HRESULT hr = S_OK; + BINDER_LOG_ENTER(L"FailureCache::Lookup"); + FailureCacheEntry *pFailureCachEntry = Hash::Lookup(assemblyNameorPath); + + if (pFailureCachEntry != NULL) + { + hr = pFailureCachEntry->GetBindingResult(); + } + + BINDER_LOG_LEAVE_HR(L"FailureCache::Lookup", hr); + return hr; + } + + void FailureCache::Remove(SString &assemblyName) + { + BINDER_LOG_ENTER(L"FailureCache::Remove"); + + FailureCacheEntry *pFailureCachEntry = Hash::Lookup(assemblyName); + + // Hash::Remove does not clean up entries + Hash::Remove(assemblyName); + SAFE_DELETE(pFailureCachEntry); + + BINDER_LOG_LEAVE(L"FailureCache::Remove"); + } +}; |