forked from vpinball/vpinball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventproxy.h
98 lines (78 loc) · 2.67 KB
/
eventproxy.h
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
92
93
94
95
96
97
98
#pragma once
class Ball;
class EventProxyBase
{
public:
virtual HRESULT FireDispID(const DISPID dispid, DISPPARAMS * const pdispparams) = 0;
void FireVoidEvent(const int dispid)
{
DISPPARAMS dispparams = { nullptr, nullptr, 0, 0 };
FireDispID(dispid, &dispparams);
}
void FireVoidEventParm(const int dispid, const float parm)
{
CComVariant rgvar[1] = { CComVariant(parm) };
DISPPARAMS dispparams = { rgvar, nullptr, 1, 0 };
FireDispID(dispid, &dispparams);
}
void FireVoidEventParm(const int dispid, const int parm)
{
CComVariant rgvar[1] = { CComVariant(parm) };
DISPPARAMS dispparams = { rgvar, nullptr, 1, 0 };
FireDispID(dispid, &dispparams);
}
/*void FireVoidEventParm(const int dispid, const unsigned int parm)
{
CComVariant rgvar[1] = { CComVariant(parm) };
DISPPARAMS dispparams = { rgvar, nullptr, 1, 0 };
FireDispID(dispid, &dispparams);
}*/
/*void FireVoidEventParm(const int dispid, const char* parm)
{
CComVariant rgvar[1] = { CComVariant(parm) };
DISPPARAMS dispparams = { rgvar, nullptr, 1, 0 };
FireDispID(dispid, &dispparams);
}*/
};
template <class T, const IID* psrcid>
class EventProxy : public EventProxyBase, public IConnectionPointImpl<T, psrcid, CComDynamicUnkArray>
{
public:
EventProxy() {}
virtual ~EventProxy() {}
void FireVoidGroupEvent(const int dispid)
{
T* const pT = (T*)this;
for (size_t i = 0; i < pT->m_vEventCollection.size(); ++i)
{
Collection * const pcollection = pT->m_vEventCollection[i];
if (pcollection!=nullptr)
{
CComVariant rgvar[1] = { CComVariant((long)pT->m_viEventCollection[i]) };
DISPPARAMS dispparams = { rgvar, nullptr, 1, 0 };
pcollection->FireDispID(dispid, &dispparams);
}
}
if (pT->m_singleEvents)
FireVoidEvent(dispid);
}
HRESULT FireDispID(const DISPID dispid, DISPPARAMS * const pdispparams) override
{
T* const pT = (T*)this;
pT->Lock();
IUnknown** pp = IConnectionPointImpl<T, psrcid, CComDynamicUnkArray>::m_vec.begin();
while (pp < IConnectionPointImpl<T, psrcid, CComDynamicUnkArray>::m_vec.end())
{
if (*pp != nullptr)
{
g_frameProfiler.EnterProfileSection(FrameProfiler::PROFILE_SCRIPT);
IDispatch* const pDispatch = reinterpret_cast<IDispatch*>(*pp);
pDispatch->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, pdispparams, nullptr, nullptr, nullptr);
g_frameProfiler.ExitProfileSection();
}
++pp;
}
pT->Unlock();
return S_OK;
}
};