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 all commits
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
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ emsdk/*
coverage/*
objs/*
gh-pages/*
Documents/*
test-it/temp
12 changes: 4 additions & 8 deletions Vireo_Xcode/VireoEggShell.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
446506DC206ACCCA00B0CD8E /* ControlRef.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 446506DB206ACCCA00B0CD8E /* ControlRef.cpp */; };
4466C7991E4F08EE004B5E31 /* MatchPat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4466C7971E4F08EE004B5E31 /* MatchPat.cpp */; };
4466C79A1E4F08EE004B5E31 /* Waveform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4466C7981E4F08EE004B5E31 /* Waveform.cpp */; };
44B71BD31EC65368008683F6 /* WebSocketClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 44B71BD21EC65368008683F6 /* WebSocketClient.cpp */; };
44C2350E20428CD50064583B /* Events.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 44C2350D20428CD50064583B /* Events.cpp */; };
4700BD741948FBF400794482 /* ExecutionContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 47D84DDB17C2A271009053DB /* ExecutionContext.cpp */; };
4700BD751948FC0400794482 /* Math.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 47D84DDF17C2A271009053DB /* Math.cpp */; };
Expand Down Expand Up @@ -122,6 +121,8 @@
/* Begin PBXFileReference section */
352F24BA209A3D51007D9799 /* DataReflectionVisitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DataReflectionVisitor.h; path = include/DataReflectionVisitor.h; sourceTree = "<group>"; };
44026BAA1EFAEFC600DB51B4 /* Array.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Array.h; path = include/Array.h; sourceTree = "<group>"; };
441F02CB20D9959B008910D2 /* library_controlEvents.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = library_controlEvents.js; path = ../source/core/library_controlEvents.js; sourceTree = "<group>"; };
441F02CC20D9959B008910D2 /* module_controlEvents.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = module_controlEvents.js; path = ../source/core/module_controlEvents.js; sourceTree = "<group>"; };
443536321CFF4979002BA5DB /* 2HelloWorlds.via */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = 2HelloWorlds.via; path = "../test-it/2HelloWorlds.via"; sourceTree = "<group>"; };
443536331CFF4979002BA5DB /* AllocatedDataValues.via */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = AllocatedDataValues.via; path = "../test-it/AllocatedDataValues.via"; sourceTree = "<group>"; };
443536341CFF4979002BA5DB /* ArrayComparison.via */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ArrayComparison.via; path = "../test-it/ArrayComparison.via"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -276,13 +277,10 @@
44ABE7DC1D3D6A20008EB066 /* Round.via */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Round.via; path = "../test-it/Round.via"; sourceTree = "<group>"; };
44ABE7DD1D3D6A20008EB066 /* ArrayInterpolate.via */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ArrayInterpolate.via; path = "../test-it/ArrayInterpolate.via"; sourceTree = "<group>"; };
44ABE7DE1D3D6A20008EB066 /* ComplexMathFunctions.via */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ComplexMathFunctions.via; path = "../test-it/ComplexMathFunctions.via"; sourceTree = "<group>"; };
44B71BD21EC65368008683F6 /* WebSocketClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebSocketClient.cpp; path = ../source/io/WebSocketClient.cpp; sourceTree = "<group>"; };
44C2350D20428CD50064583B /* Events.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Events.cpp; path = core/Events.cpp; sourceTree = "<group>"; };
44C2350F2045FAD70064583B /* Events.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Events.h; path = include/Events.h; sourceTree = "<group>"; };
44C295D51F8C037A001877B4 /* library_webSocketClient.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = library_webSocketClient.js; path = ../source/io/library_webSocketClient.js; sourceTree = "<group>"; };
44C295D61F8C037A001877B4 /* module_httpClient.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = module_httpClient.js; path = ../source/io/module_httpClient.js; sourceTree = "<group>"; };
44C295D71F8C037A001877B4 /* module_other.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = module_other.js; path = ../source/io/module_other.js; sourceTree = "<group>"; };
44C295D81F8C037A001877B4 /* module_webSocketClient.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = module_webSocketClient.js; path = ../source/io/module_webSocketClient.js; sourceTree = "<group>"; };
44C295D91F8C037A001877B4 /* module_eggShell.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = module_eggShell.js; path = ../source/io/module_eggShell.js; sourceTree = "<group>"; };
44C295DA1F8C03B7001877B4 /* library_coreHelpers.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = library_coreHelpers.js; path = core/library_coreHelpers.js; sourceTree = "<group>"; };
44C295DB1F8C03B7001877B4 /* vireo.loader.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = vireo.loader.js; path = core/vireo.loader.js; sourceTree = "<group>"; };
Expand Down Expand Up @@ -780,14 +778,13 @@
472A078F1AA67EF8008109FA /* DebugGPIO.cpp */,
472B7BE717D0E1FC00201196 /* FileIO.cpp */,
47A877741AE6925800EC5D77 /* HttpClient.cpp */,
44B71BD21EC65368008683F6 /* WebSocketClient.cpp */,
47A877751AE6925800EC5D77 /* library_httpClient.js */,
4750F16F19C378D600FA80B8 /* library_canvas2d.js */,
44C295D51F8C037A001877B4 /* library_webSocketClient.js */,
441F02CB20D9959B008910D2 /* library_controlEvents.js */,
441F02CC20D9959B008910D2 /* module_controlEvents.js */,
44C295D91F8C037A001877B4 /* module_eggShell.js */,
44C295D61F8C037A001877B4 /* module_httpClient.js */,
44C295D71F8C037A001877B4 /* module_other.js */,
44C295D81F8C037A001877B4 /* module_webSocketClient.js */,
446506D2206AC83600B0CD8E /* library_javaScriptInvoke.js */,
446506D6206AC83600B0CD8E /* library_propertyNode.js */,
446506D5206AC83600B0CD8E /* module_javaScriptInvoke.js */,
Expand Down Expand Up @@ -1158,7 +1155,6 @@
472B7BE517D0E1E800201196 /* TDCodecVia.cpp in Sources */,
472B7BE817D0E1FC00201196 /* FileIO.cpp in Sources */,
444C46841E1C5A540037FA98 /* Date.cpp in Sources */,
44B71BD31EC65368008683F6 /* WebSocketClient.cpp in Sources */,
472A078A1AA6204A008109FA /* NumericString.cpp in Sources */,
4466C79A1E4F08EE004B5E31 /* Waveform.cpp in Sources */,
47B76CD91B28DB090083AEEB /* Platform.cpp in Sources */,
Expand Down
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'test-it/karma/http/*.Test.js',
'test-it/karma/javascriptinvoke/*.Test.js',
'test-it/karma/propertynode/*.Test.js',
'test-it/karma/events/*.Test.js',
'test-it/karma/static/*.Test.js'
]);

Expand Down
2 changes: 2 additions & 0 deletions make-it/EmMakefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ endif
EM_OPT = $(EM_OPTFLAGS) $(WASM_FLAG) -s NO_EXIT_RUNTIME=1 -std=c++14 -fno-exceptions --memory-init-file 0 -s NO_DYNAMIC_EXECUTION=1
EMFLAGS = -I$(INCDIR) -DkVireoOS_emscripten $(EM_OPT)
EMLIBRARY = --js-library $(CORESOURCEDIR)/library_coreHelpers.js \
--js-library $(CORESOURCEDIR)/library_controlEvents.js \
--js-library $(IOSOURCEDIR)/library_canvas2d.js \
--js-library $(IOSOURCEDIR)/library_httpClient.js \
--js-library $(IOSOURCEDIR)/library_javaScriptInvoke.js \
Expand All @@ -113,6 +114,7 @@ EM_EXPORTS = -s EXPORTED_FUNCTIONS="[\
'_EggShell_GetPointer',\
'_EggShell_GetArrayDimLength',\
'_Occurrence_Set',\
'_OccurEvent',\
'_Data_ValidateArrayType',\
'_Data_GetStringBegin',\
'_Data_GetStringLength',\
Expand Down
1 change: 1 addition & 0 deletions make-it/EmMakefile-AAL
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ EM_EXPORTS = -s EXPORTED_FUNCTIONS='[\
"_EggShell_ReadValueString",\
"_EggShell_WriteValueString",\
"_Occurrence_Set",\
"_OccurEvent",\
"_Data_WriteString",\
"_Data_WriteInt32",\
"_Data_WriteUInt32"\
Expand Down
26 changes: 21 additions & 5 deletions source/core/ControlRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ class ControlRefNumManager : public RefNumManager {
public:
static ControlRefNumManager &ControlRefManager() { return _s_singleton; }
static ControlRefNumType &RefNumStorage() { return _s_singleton.RefNumManager(); }
RefNum FindOrCreateRefNum(ControlRefInfo *info) {
ControlRefNumType::RefNumIterator ctlRefIter = _refStorage.Begin(), ctlRefEnd = _refStorage.End();
while (ctlRefIter != ctlRefEnd) {
if (ctlRefIter->second._refData.vi == info->vi && ctlRefIter->second._refData.controlTag->IsEqual(info->controlTag)) {
// Found an existing ref with the same data; return it, and dispose the new StringRef, because we now own it.
info->controlTag->Delete(info->controlTag);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"info->controlTag->Delete()" is confusing. I would use the class name directly as this is a static method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I disagree -- controlTag is a StringRef but the static method is in the TypedArray base class; I think accessing the method via the variable type is more robust to changes in the class hierarchy. What's confusing about it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way TypedArrayCore and String are implemented now, I don't understand how accessing a static method using an object gives any robustness to changes in the class hierarchy.

If the intent is to keep Delete() as static in TypedArrayCore and have another static/non-static method by the same name "Delete()" in the derived class, that would be a strong code smell.

OTOH, derived class itself can be passed as a template argument to base class and the base class method can in turn call the derived class static implementation. Though it would work, unless there is a strong reason not to make the method in base class virtual, it is not likely a good idea to do (and nothing of that sort is done here anyway currently).

In C# (not sure but likely Java too), it is a compiler error to access a static method using object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more robust because it uses the (declared, not virtual) type of the class to locate the static method to call. If String was refactored to have a more efficient implementation which did not depend on TypedArrayCore but still conformed to the same API, this call would not need to change.
This is not C#.

return ControlRefNumType::RefNumFromIndexAndExistingHeader(ctlRefIter->first, ctlRefIter->second._refHeader);
}
++ctlRefIter;
}
return _refStorage.NewRefNum(info);
}

ControlRefNumType &RefNumManager() { return _refStorage; }
};
Expand All @@ -65,7 +77,7 @@ static void CleanUpControlReference(intptr_t arg) {
// ControlReferenceCreate -- create a control ref linked to control associated with controlTag on given VI.
ControlRefNum ControlReferenceCreate(VirtualInstrument *vi, const StringRef &controlTag) {
ControlRefInfo controlRefInfo(vi, controlTag);
ControlRefNum refnum = ControlRefNumManager::RefNumStorage().NewRefNum(&controlRefInfo);
ControlRefNum refnum = ControlRefNumManager::ControlRefManager().FindOrCreateRefNum(&controlRefInfo);
ControlRefNumManager::AddCleanupProc(nullptr, CleanUpControlReference, refnum);
return refnum;
}
Expand All @@ -85,11 +97,15 @@ NIError ControlReferenceLookup(ControlRefNum refnum, VirtualInstrument **pVI, St
ControlRefInfo controlRefInfo;
NIError err = ControlRefNumManager::RefNumStorage().GetRefNumData(refnum, &controlRefInfo);
if (err == kNIError_Success) {
*pVI = controlRefInfo.vi;
*pControlTag = controlRefInfo.controlTag;
if (pVI)
*pVI = controlRefInfo.vi;
if (pControlTag)
*pControlTag = controlRefInfo.controlTag;
} else {
*pVI = nullptr;
*pControlTag = nullptr;
if (pVI)
*pVI = nullptr;
if (pControlTag)
*pControlTag = nullptr;
}
return err;
}
Expand Down
Loading