| 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 | // AssemblyIdentityCache.cpp | 
| 7 | // | 
| 8 | |
| 9 | |
| 10 | // | 
| 11 | // Implements the AssemblyIdentityCache class | 
| 12 | // | 
| 13 | // ============================================================ | 
| 14 | |
| 15 | #define DISABLE_BINDER_DEBUG_LOGGING | 
| 16 | |
| 17 | #include "assemblyidentitycache.hpp" | 
| 18 | |
| 19 | namespace BINDER_SPACE | 
| 20 | { | 
| 21 | AssemblyIdentityCache::AssemblyIdentityCache() : SHash<AssemblyIdentityHashTraits>::SHash() | 
| 22 | { | 
| 23 | // Nothing to do here | 
| 24 | } | 
| 25 | |
| 26 | AssemblyIdentityCache::~AssemblyIdentityCache() | 
| 27 | { | 
| 28 | // Delete entries and contents array | 
| 29 | for (Hash::Iterator i = Hash::Begin(), end = Hash::End(); i != end; i++) | 
| 30 | { | 
| 31 | const AssemblyIdentityCacheEntry *pAssemblyIdentityCacheEntry = *i; | 
| 32 | delete pAssemblyIdentityCacheEntry; | 
| 33 | } | 
| 34 | RemoveAll(); | 
| 35 | } | 
| 36 | |
| 37 | HRESULT AssemblyIdentityCache::Add(LPCSTR szTextualIdentity, | 
| 38 | AssemblyIdentityUTF8 *pAssemblyIdentity) | 
| 39 | { | 
| 40 | HRESULT hr = S_OK; | 
| 41 | BINDER_LOG_ENTER(L "AssemblyIdentityCache::Add"); | 
| 42 | |
| 43 | NewHolder<AssemblyIdentityCacheEntry> pAssemblyIdentityCacheEntry; | 
| 44 | SAFE_NEW(pAssemblyIdentityCacheEntry, AssemblyIdentityCacheEntry); | 
| 45 | |
| 46 | pAssemblyIdentityCacheEntry->SetTextualIdentity(szTextualIdentity); | 
| 47 | pAssemblyIdentityCacheEntry->SetAssemblyIdentity(pAssemblyIdentity); | 
| 48 | |
| 49 | Hash::Add(pAssemblyIdentityCacheEntry); | 
| 50 | pAssemblyIdentityCacheEntry.SuppressRelease(); | 
| 51 | |
| 52 | Exit: | 
| 53 | BINDER_LOG_LEAVE_HR(L "AssemblyIdentityCache::Add", hr); | 
| 54 | return hr; | 
| 55 | } | 
| 56 | |
| 57 | AssemblyIdentityUTF8 *AssemblyIdentityCache::Lookup(LPCSTR szTextualIdentity) | 
| 58 | { | 
| 59 | BINDER_LOG_ENTER(L "AssemblyIdentityCache::Lookup"); | 
| 60 | AssemblyIdentityUTF8 *pAssemblyIdentity = NULL; | 
| 61 | AssemblyIdentityCacheEntry *pAssemblyIdentityCacheEntry = Hash::Lookup(szTextualIdentity); | 
| 62 | |
| 63 | if (pAssemblyIdentityCacheEntry != NULL) | 
| 64 | { | 
| 65 | BINDER_LOG(L "Found cached identity"); | 
| 66 | pAssemblyIdentity = pAssemblyIdentityCacheEntry->GetAssemblyIdentity(); | 
| 67 | } | 
| 68 | |
| 69 | BINDER_LOG_LEAVE(L "AssemblyIdentityCache::Lookup"); | 
| 70 | return pAssemblyIdentity; | 
| 71 | } | 
| 72 | }; | 
| 73 | 
