ActivationFactoryBase.h
2.02 KB
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
#pragma once
#include "os/WindowsRuntime.h"
#include "vm/Atomic.h"
#include "vm/ComObjectBase.h"
#include "vm/Exception.h"
#include "utils/Memory.h"
#include "utils/TemplateUtils.h"
#include <new>
namespace il2cpp
{
namespace vm
{
template<typename TDerived>
struct NOVTABLE ActivationFactoryBase : public ComObjectBase, Il2CppIActivationFactory
{
private:
volatile uint32_t m_RefCount;
public:
ActivationFactoryBase() :
m_RefCount(1) // We start with a ref count of 1
{
Il2CppStaticAssert(utils::TemplateUtils::IsBaseOf<ActivationFactoryBase<TDerived>, TDerived>::value);
}
virtual il2cpp_hresult_t STDCALL ActivateInstance(Il2CppIInspectable** instance) IL2CPP_OVERRIDE
{
return IL2CPP_E_NOTIMPL;
}
IL2CPP_FORCE_INLINE uint32_t AddRefImpl()
{
return Atomic::Increment(&m_RefCount);
}
IL2CPP_FORCE_INLINE uint32_t ReleaseImpl()
{
const uint32_t count = Atomic::Decrement(&m_RefCount);
if (count == 0)
Destroy();
return count;
}
IL2CPP_FORCE_INLINE il2cpp_hresult_t GetRuntimeClassNameImpl(Il2CppHString* className)
{
utils::StringView<Il2CppNativeChar> classNameView(IL2CPP_NATIVE_STRING("System.Runtime.InteropServices.WindowsRuntime.IActivationFactory"));
return os::WindowsRuntime::CreateHString(classNameView, className);
}
IL2CPP_FORCE_INLINE static TDerived* __CreateInstance()
{
void* memory = utils::Memory::Malloc(sizeof(TDerived));
if (memory == NULL)
Exception::RaiseOutOfMemoryException();
return new(memory) TDerived;
}
private:
IL2CPP_FORCE_INLINE void Destroy()
{
IL2CPP_ASSERT(m_RefCount == 0);
TDerived* instance = static_cast<TDerived*>(this);
instance->~TDerived();
utils::Memory::Free(instance);
}
};
}
}