-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDependentHandle.cpp
50 lines (43 loc) · 1.18 KB
/
DependentHandle.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
#include <ConfigurableFirmata.h>
#include "FirmataIlExecutor.h"
#include "DependentHandle.h"
#include "SelfTest.h"
void DependentHandle::Init()
{
}
DependentHandle::DependentHandle()
{
}
bool DependentHandle::ExecuteHardwareAccess(FirmataIlExecutor* executor, ExecutionState* currentFrame, NativeMethod method, const VariableVector& args, Variable& result)
{
switch(method)
{
case NativeMethod::DependentHandle_InternalInitialize:
{
ASSERT(args.size() == 2);
// We're currently not reusing existing entries. But these handles are rarely used, so this should not normally cause a memory leak
pair<void*, void*> newElem(args[0].Object, args[1].Object);
int offset = executor->_weakDependencies.push_back(newElem);
result.Type = VariableKind::Int32;
result.setSize(4),
result.Int32 = offset + 1; // because 0 is an invalid handle
}
break;
case NativeMethod::DependentHandle_InternalFree:
{
ASSERT(args.size() == 1);
size_t handle = args[0].Uint32;
if (handle >= executor->_weakDependencies.size())
{
break;
}
auto& elem = executor->_weakDependencies.at(handle);
elem.first = nullptr;
elem.second = nullptr;
break;
}
default:
return false;
}
return true;
}