-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCSystemCreateEvents.cpp
66 lines (49 loc) · 1.33 KB
/
CSystemCreateEvents.cpp
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
// CSystemCreateEvents.cpp
//
// CSystemCreateEvents class
#include "PreComp.h"
void CSystemCreateEvents::AddDeferredEvent (CSpaceObject *pObj, CExtension *pExtension, CXMLElement *pEventCode)
// AddDeferredEvent
//
// Adds a deferred event. The caller must guarantee the lifetime of pObj and pEventCode
{
SEventDesc *pEvent = m_Events.Insert();
pEvent->pObj = pObj;
pEvent->pExtension = pExtension;
pEvent->pEventCode = pEventCode;
}
ALERROR CSystemCreateEvents::FireDeferredEvent (const CString &sEvent, CString *retsError)
// FireDeferredEvent
//
// Fires the given event for all objects in the deferred list
{
int i;
CCodeChainCtx Ctx;
for (i = 0; i < m_Events.GetCount(); i++)
{
if (strEquals(sEvent, m_Events[i].pEventCode->GetTag()))
{
// Link the code
ICCItemPtr pCode = Ctx.LinkCode(m_Events[i].pEventCode->GetContentText(0));
if (pCode->IsError())
{
if (retsError)
*retsError = pCode->GetStringValue();
return ERR_FAIL;
}
// Execute
Ctx.SetExtension(m_Events[i].pExtension);
Ctx.DefineContainingType(m_Events[i].pObj);
Ctx.SaveAndDefineSourceVar(m_Events[i].pObj);
ICCItemPtr pResult = Ctx.RunCode(pCode);
// Check error
if (pResult->IsError())
{
if (retsError)
*retsError = pResult->GetStringValue();
return ERR_FAIL;
}
}
}
return NOERROR;
}