Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement static event registration for controls in Vireo. #455

Merged
merged 31 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3e46bc0
JS C API for registering control events
segaljared Jun 14, 2018
35911d7
Update Xcode project
spathiwa Jun 19, 2018
f897fc2
Refactor RefNumVal type to not carry its type with its data.
spathiwa Jun 19, 2018
09cefde
Add controlEvents module to vireo loader.
spathiwa Jun 19, 2018
b5e3c8d
First pass at Vireo-side of static control event registration.
spathiwa Jun 19, 2018
8dd0a36
Fix lint issues.
spathiwa Jun 19, 2018
cba8029
Add example static control reg test file (not in testList yet, subjec…
spathiwa Jun 19, 2018
8dadea5
Fix ESLint errors
spathiwa Jun 19, 2018
8ca79a8
Ignore non-numeric controlIDs
spathiwa Jun 20, 2018
b13ac87
Add VI UnregisterForStaticEvents, called when top-level VI finishes.
spathiwa Jun 20, 2018
1dc847b
Store controlRef value in EventOracleObj indexed by eventOracleIndex
spathiwa Jun 21, 2018
0a8004e
Make ControlReferences to the same item in the same VI always be the …
spathiwa Jun 21, 2018
a41a3d2
Update test to ensure ControlRefs are unique for a given controlID
spathiwa Jun 21, 2018
fffa31d
Fix construction of previous refnum from index (and previous refnum h…
spathiwa Jun 21, 2018
9142267
Add error checking in JS OccurEvent to make sure eventOracleIndex mat…
spathiwa Jun 21, 2018
798d069
JS wrapper for the OccurEvent C API
siddhukrs Jun 21, 2018
910829e
Add first set of tests
siddhukrs Jun 21, 2018
895a5e0
Tests for multiple registrations and valuechange on unregistered control
siddhukrs Jun 21, 2018
fc94e86
Fix linting errors
siddhukrs Jun 21, 2018
bad5298
Merge pull request #1 from siddhukrs/valueChangedEvents
spathiwa Jun 21, 2018
d239dfc
Add simple Vireo unit test for Value Changed event.
spathiwa Jun 21, 2018
2c72c1a
Bug fix: Different events on same control should use same eventOracle…
spathiwa Jun 22, 2018
a739686
Address Carlos' feedback.
spathiwa Jun 22, 2018
7c3bad6
Address review feedback: Remove exception handling code around js reg…
spathiwa Jun 23, 2018
4fa6c64
Address review feedback from Sankara.
spathiwa Jun 25, 2018
f70b2ad
Address rajsite feedback; make default registerForControlEvents callb…
spathiwa Jun 25, 2018
650ae4f
Address Sankara feedbak: use const & instead of * in refnum method.
spathiwa Jun 25, 2018
5a7372f
Fix eslint error
spathiwa Jun 25, 2018
d5aa407
Lint is well-named, because it also describes the intelligence of the…
spathiwa Jun 25, 2018
4588fc2
Back out of throw in reg/unreg because it fails control event karma t…
spathiwa Jun 26, 2018
c6b3d9f
Update .eslintignore, exclude Documents folder and temp folder in tes…
spathiwa Jun 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions source/core/Events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,13 @@ VIREO_FUNCTION_SIGNATURE2(UserEventRef_Create, RefNumVal, ErrorCluster)
}

// GenerateUserEvent(userEventRef<typed_data> data errorIO) -- fire event, copying data into event queues of all registered observers
VIREO_FUNCTION_SIGNATURE4(UserEventRef_Generate, RefNumVal, void, Boolean, ErrorCluster)
VIREO_FUNCTION_SIGNATURE5(UserEventRef_Generate, TypeCommon, RefNumVal, void, Boolean, ErrorCluster)
{
RefNumVal* refnumPtr = _ParamPointer(0);
void *pSourceData = _ParamPointer(1);
// Boolean highPro = _ParamPointer(2) ? _Param(2) : false;
ErrorCluster *errPtr = _ParamPointer(3);
TypeRef type = refnumPtr ? refnumPtr->Type()->GetSubElement(0) : nullptr;
RefNumVal* refnumPtr = _ParamPointer(1);
void *pSourceData = _ParamPointer(2);
// Boolean highPro = _ParamPointer(3) ? _Param(3) : false;
ErrorCluster *errPtr = _ParamPointer(4);
TypeRef type = refnumPtr ? _ParamPointer(0)->GetSubElement(0) : nullptr;
void *userEventRef = nullptr;

// TODO(spathiwa) implement high-priority User Events
Expand Down Expand Up @@ -618,6 +618,7 @@ struct RegistertForEventArgs {

struct RegisterForEventsParamBlock : public VarArgInstruction
{
_ParamDef(TypeCommon, regType);
_ParamDef(RefNumVal, regRef);
_ParamDef(ErrorCluster, errorClust);
_ParamImmediateDef(RegistertForEventArgs, argument1[1]);
Expand Down Expand Up @@ -720,7 +721,7 @@ VIREO_FUNCTION_SIGNATUREV(RegisterForEvents, RegisterForEventsParamBlock)
RefNumVal* eventRegRefnumPtr = _ParamPointer(regRef);
DynamicEventRegInfo *regInfo = nullptr;

const Int32 numberOfFixedArgs = 2; // eventRegRef, errorIO
const Int32 numberOfFixedArgs = 3; // eventRegRef (type,data), errorIO
const Int32 numArgsPerTuple = 3; // <eventType, user/control ref (STAD)> pairs
Int32 numVarArgs = (_ParamVarArgCount() - numberOfFixedArgs);
Int32 numTuples = numVarArgs / numArgsPerTuple;
Expand All @@ -729,10 +730,10 @@ VIREO_FUNCTION_SIGNATUREV(RegisterForEvents, RegisterForEventsParamBlock)
if (errPtr && errPtr->status)
return _NextInstruction();

if (eventRegRefnumPtr->Type()->SubElementCount() != 1 || !eventRegRefnumPtr->Type()->GetSubElement(0)->IsCluster()) {
if (_ParamPointer(regType)->SubElementCount() != 1 || !_ParamPointer(regType)->GetSubElement(0)->IsCluster()) {
return ReturnRegForEventsFatalError("RegisterForEvents: malformed ref ref type, doesn't contain cluster", 0);
}
Int32 regCount = eventRegRefnumPtr->Type()->GetSubElement(0)->SubElementCount();
Int32 regCount = _ParamPointer(regType)->GetSubElement(0)->SubElementCount();
if (numVarArgs % numArgsPerTuple != 0 || regCount != numTuples) {
return ReturnRegForEventsFatalError("RegisterForEvents: Wrong number of arguments. Should be one <event code, ref> input pair"
" per item in the event reg refnum output type", 0);
Expand Down Expand Up @@ -765,7 +766,7 @@ VIREO_FUNCTION_SIGNATUREV(RegisterForEvents, RegisterForEventsParamBlock)
EventRegistrationRefNumManager::AddCleanupProc(vi, CleanUpEventRegRefNum, erRefNum);

// Loop through input types and register for events
TypeRef regRefClusterType = eventRegRefnumPtr->Type()->GetSubElement(0);
TypeRef regRefClusterType = _ParamPointer(regType)->GetSubElement(0);
RegistertForEventArgs *arguments = _ParamImmediate(argument1);
for (Int32 refInput = 0; refInput < numTuples; ++refInput) {
if (!arguments[refInput].ref._pData) { // wildcard argument, for re-registration, skip argument and leave previous registration
Expand Down Expand Up @@ -949,9 +950,12 @@ VIREO_FUNCTION_SIGNATUREV(WaitForEventsAndDispatch, WaitForEventsParamBlock)
// should go back to sleep w/o running timeout case)
const EventData &eventData = EventOracle::TheEventOracle().GetEventData(eventQID);

dynIndex += regInfo ? regInfo->DynamicEventMatch(eventData.common, eventRegRefnumPtr ?
eventRegRefnumPtr[regRefIndex-1].Type()->GetSubElement(0) : nullptr) : 0;

if (regInfo) {
TypeRef eventRegRefType = regRefArg[0]._paramType;
if (eventRegRefType->IsCluster())
eventRegRefType = eventRegRefType->GetSubElement(regRefIndex-1);
dynIndex += regInfo->DynamicEventMatch(eventData.common, eventRegRefType->GetSubElement(0));
}
for (Int32 inputTuple = 0; inputTuple < numTuples; ++inputTuple) {
UInt32 eventSpecIndex = *arguments[inputTuple].eventSpecIndex;
if (eventSpecIndex >= esCount) {
Expand All @@ -963,12 +967,15 @@ VIREO_FUNCTION_SIGNATUREV(WaitForEventsAndDispatch, WaitForEventsParamBlock)
InstructionCore *esBranchTarget = arguments[inputTuple].branchTarget;
if (EventMatch(eventData, eventSpecRef[eventSpecIndex], dynIndex)) {
// gPlatform.IO.Printf("Event match %d -> %x\n", eventSpecRef[eventSpecIndex].eventType, esBranchTarget);
const Int32 commonDataSize = sizeof(EventCommonData);
Int32 commonDataSize = sizeof(EventCommonData);
Int32 dataNodeSize = esEventDataNodeType->TopAQSize();
// TODO(spathiwa) Compute eventIndex when we support multiple events sharing event cases
UInt32 eventIndex = 0;
if (dataNodeSize >= commonDataSize) {
memcpy(esEventDataNode, &eventData, commonDataSize);
Int32 alignment = eventData.eventDataType->AQAlignment();
if (commonDataSize % alignment != 0)
commonDataSize = (commonDataSize + alignment-1) & ~(alignment-1);
*EventIndexFieldPtr(esEventDataNode) = eventIndex;

if (eventData.eventDataType->TopAQSize() == dataNodeSize - commonDataSize) {
Expand Down Expand Up @@ -1027,12 +1034,12 @@ DEFINE_VIREO_BEGIN(Events)
// User Events
DEFINE_VIREO_TYPE(UserEventRefNum, "refnum($0)")
DEFINE_VIREO_FUNCTION_CUSTOM(CreateUserEvent, UserEventRef_Create, "p(o(UserEventRefNum ue) io(ErrorCluster err))")
DEFINE_VIREO_FUNCTION_CUSTOM(GenerateUserEvent, UserEventRef_Generate, "p(i(UserEventRefNum ue) i(* element) i(Boolean highprio) io(ErrorCluster err))")
DEFINE_VIREO_FUNCTION_CUSTOM(GenerateUserEvent, UserEventRef_Generate, "p(i(StaticTypeExplicitData) i(UserEventRefNum ue) i(* element) i(Boolean highprio) io(ErrorCluster err))")
DEFINE_VIREO_FUNCTION_CUSTOM(DestroyUserEvent, UserEventRef_Destroy, "p(i(UserEventRefNum ue) io(ErrorCluster err))")

// Event registration
DEFINE_VIREO_TYPE(EventRegRefNum, "refnum($0)")
DEFINE_VIREO_FUNCTION(RegisterForEvents, "p(i(VarArgCount) io(EventRegRefNum ref) io(ErrorCluster err)"
DEFINE_VIREO_FUNCTION(RegisterForEvents, "p(i(VarArgCount) i(StaticTypeExplicitData) io(EventRegRefNum ref) io(ErrorCluster err)"
"i(VarArgRepeat) i(Int32 eventType)i(StaticTypeAndData))")
DEFINE_VIREO_FUNCTION(UnregisterForEvents, "p(i(EventRegRefNum ref) io(ErrorCluster err))")

Expand Down
Loading