summaryrefslogtreecommitdiff
path: root/src/binder/inc/loadcontext.inl
blob: b8002e03cc6ab96154e66785fbd4f1fd74c213da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
// ============================================================
//
// LoadContext.inl
//


//
// Implements the inlined methods of LoadContext template class
//
// ============================================================

#ifndef __BINDER__LOAD_CONTEXT_INL__
#define __BINDER__LOAD_CONTEXT_INL__

template <DWORD dwIncludeFlags>
LoadContext<dwIncludeFlags>::LoadContext() :
    SHash<AssemblyHashTraits<ContextEntry *, dwIncludeFlags> >::SHash()
{
    m_cRef = 1;
}

template <DWORD dwIncludeFlags>
LoadContext<dwIncludeFlags>::~LoadContext()
{
    // Delete context entries and contents array
    for (typename Hash::Iterator i = Hash::Begin(), end = Hash::End(); i != end; i++)
    {
        const ContextEntry *pContextEntry = *i;
        delete pContextEntry;
    }
    this->RemoveAll();
}

template <DWORD dwIncludeFlags>
ULONG LoadContext<dwIncludeFlags>::AddRef()
{
    return InterlockedIncrement(&m_cRef);
}

template <DWORD dwIncludeFlags>
ULONG LoadContext<dwIncludeFlags>::Release()
{
    ULONG ulRef = InterlockedDecrement(&m_cRef);

    if (ulRef == 0) 
    {
        delete this;
    }

    return ulRef;
}

template <DWORD dwIncludeFlags>
ContextEntry *LoadContext<dwIncludeFlags>::Lookup(AssemblyName *pAssemblyName)
{
    ContextEntry *pContextEntry =
        SHash<AssemblyHashTraits<ContextEntry *, dwIncludeFlags> >::Lookup(pAssemblyName);

    return pContextEntry;
}

template <DWORD dwIncludeFlags>
HRESULT LoadContext<dwIncludeFlags>::Register(BindResult *pBindResult)
{
    HRESULT hr = S_OK;
    ContextEntry *pContextEntry = NULL;

    SAFE_NEW(pContextEntry, ContextEntry);

    pContextEntry->SetIsDynamicBind(pBindResult->GetIsDynamicBind());
    pContextEntry->SetIsInGAC(pBindResult->GetIsInGAC());
    pContextEntry->SetIsSharable(pBindResult->GetIsSharable());
    pContextEntry->SetAssemblyName(pBindResult->GetAssemblyName(), TRUE /* fAddRef */);
    pContextEntry->SetAssembly(pBindResult->GetAssembly());

    if (pBindResult->GetIsFirstRequest())
    {
        pContextEntry->SetIsFirstRequest(TRUE);
    }

    SHash<AssemblyHashTraits<ContextEntry *, dwIncludeFlags> >::Add(pContextEntry);

 Exit:
    return hr;
}

#endif