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

Vireo EggShell Refactor for Supporting More Types #471

Merged
merged 70 commits into from
Jul 13, 2018

Conversation

rajsite
Copy link
Member

@rajsite rajsite commented Jun 28, 2018

Implementation of "Vireo API Changes for Supporting More Types Design Doc" - NITalk - PDF

This change encapsulates the breaking API changes associated with the Vireo API refactor. There is still additional work to be done out of master after the change is merged consisting of:

  1. Making error checks and error handling consistent across all of the new api functions: JS API Refactor Acceptance Conditions #466

  2. Migrating the following JavaScript users of the now deprecated API functions to the new API functions: HttpClient, JavaScriptInvoke, Core (FPSync, LV Error Handling), Events.

  3. Removing the deprecated API functionality

LVjs Build: Still in-progress testing changes in Bajor/Main

var i = 0,
typeHandler;

for (i = 0; typeHandlers.length; i += 1) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Should be i < typeHandlers.length

Copy link
Contributor

@gleono gleono Jul 2, 2018

Choose a reason for hiding this comment

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

😮 you are right. dunno how that slipped through. I'll fix it later today.

Copy link
Contributor

Choose a reason for hiding this comment

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

Was this code exercised by one of the tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like it couldn't have, it would be an infinite loop.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, we are missing a test for a type that we cannot handle. I'll add that as well as fixing this.


var dispatchVisitCluster = function (typeVisitor, valueRef, data) {
validateVisitMethod(typeVisitor.visitCluster, 'visitCluster');
return typeVisitor.visitCluster(typeVisitor, valueRef, data);
Copy link
Member Author

Choose a reason for hiding this comment

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

Should be typeVisitor.visitCluster(valueRef, data);

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I'lll fix it

Copy link
Contributor

@sanmut sanmut left a comment

Choose a reason for hiding this comment

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

Still reviewing

}
//------------------------------------------------------------
//! Read a symbol's value as a string. Value will be formatted according to the format designated.
VIREO_EXPORT const char* EggShell_ReadValueString(TypeManagerRef tm,
const char* viName, const char* eltName, const char* format)
VIREO_EXPORT EggShellResult EggShell_ReadValueString(TypeManagerRef tm, const TypeRef typeRef, void* data, const char* format, UInt8** valueString)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not keep valueString char **?

Copy link
Contributor

Choose a reason for hiding this comment

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

Begin() returns a UInt8*. Might as well avoid the cast.

//! Returns -1 if the symbols is not found, -2 if was not possible to resize the array and 0 if resizing was successful.
VIREO_EXPORT Int32 EggShell_ResizeArray(TypeManagerRef tm, const char* viName, const char* eltName, Int32 rank, Int32* newLengths)
VIREO_EXPORT EggShellResult EggShell_ResizeArray(TypeManagerRef tm, const TypeRef typeRef, const void* pData,
Int32 newDimensionsLength, Int32 newDimensions[])
Copy link
Contributor

Choose a reason for hiding this comment

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

newDimensionsLength is quite a misleading name for rank. We should stick to using rank. If newLengths is not clear enough, that can be renamed as newDimensionLengths.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree.

Copy link
Member Author

@rajsite rajsite Jul 3, 2018

Choose a reason for hiding this comment

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

I'm down for renaming the newDimensions[] input to dimensionLengths[] as that is the name used in the rest of vireo.

How do y'all feel about me removing the newDimensionsLength/Rank input?

All it does is take the passed value and check that it is equal to the Rank Vireo already knows.

I would rather add a comment that says dimensionLengths[] should have a number of items equal to the Rank of the array being manipulated. It seems like an unnecessary input since this api is not allowing changing the rank of a Vireo array.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, renaming newDimensions -> dimensionLengths

and

newDimensionsLength -> rank

is fine. @gleonoliva might be tackling this in a bit

//------------------------------------------------------------
//! Get the values for dimensions of the array. Assumes dimensions target is of length equal to rank
//! Caller is expected to allocate an array dimensions of size array rank for the duration of function invocation.
VIREO_EXPORT void Data_GetArrayDimensions(const void* pData, IntIndex dimensions[])
Copy link
Contributor

Choose a reason for hiding this comment

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

"Dimensions" as a name by itself is ambiguous. What about Dimensions? Number of Dimensions or Length of each dimension? I would be consistent with Vireo's terminology: Use Rank for number of Dimensions which is an integer; use DimensionLengths for lengths of each dimension which is an integer array.
e.g.:
Data_GetArrayDimensionLengths(...., Int dimensionLengthts[])

Copy link
Member Author

Choose a reason for hiding this comment

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

Will change to the dimensionLengths name used in the rest of Vireo

}
//------------------------------------------------------------
//! Get the total length for an array
VIREO_EXPORT Int32 Data_GetArrayLength(const void* pData)
Copy link
Contributor

Choose a reason for hiding this comment

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

This name ArrayLength is good 👍

STACK_VAR(String, tempReturn);
returnBuffer = tempReturn.DetachValue();
} else {
returnBuffer->Resize1D(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Resize1D(0);

Instead of resizing it to a size of 0 and then appending immediately, Resize1D can be called with name.Length()+1 and then name can be copied to instead of getting appended and will be more efficient.

Also, in other places in this PR.


if (returnBuffer) {
returnBuffer->AppendSubString(&name);
// Add an explicit nullptr terminator so it looks like a C string.
Copy link
Contributor

Choose a reason for hiding this comment

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

nullptr terminator --> null terminator

Copy link
Contributor

Choose a reason for hiding this comment

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

When applying this change, don't forget to update other functions with the same comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I took care of that

TypeRef t = this;
while (t) {
SubString typeName = t->Name();
SubString analogTypess(TypeAnalogWaveform);
Copy link
Contributor

Choose a reason for hiding this comment

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

SubString analogTypess(TypeAnalogWaveform);

this temporary is misspelled but not likely even needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll change the name

@@ -546,6 +651,66 @@ VIREO_EXPORT TypeRef TypeRef_GetSubElementByIndex(TypeRef typeRef, Int32 index)
return typeRef->GetSubElement(index);
}
//------------------------------------------------------------
VIREO_EXPORT Boolean TypeRef_IsCluster(TypeRef typeRef)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have the prefix of EggShell for all the new APIs that start with TypeRef as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are not exposing these functions to eggShell, I don't think they should be prefixed as eggshell. That's why we added the typeHelpers module.

return valueRef;
};

Module.eggShell.findSubValueRef = publicAPI.eggShell.findSubValueRef = function (valueRef, path) {
Copy link
Contributor

Choose a reason for hiding this comment

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

path should be renamed to subPath to reflect it is not the full path.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll change it.

Copy link
Contributor

@spathiwa spathiwa left a comment

Choose a reason for hiding this comment

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

Excellent work. This was an ambitious refactor.

@@ -10,6 +10,7 @@ define(ArrayDemo dv(.VirtualInstrument (

e(a(.Int32 * *) variableArray2d)
e(a(.Int32 2 3) fixedArray2d)
e(a(.Int32 0 0) fixedArray2dEmpty)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add comments to via tests with items that appear to be unused like this one to note that they are read programmatically by a karma test.

@@ -21,6 +21,9 @@ typedef enum {
kEggShellResult_UnexpectedObjectType = 2,
kEggShellResult_InvalidResultPointer = 3,
kEggShellResult_UnableToCreateReturnBuffer = 4,
kEggShellResult_InvalidTypeRef = 5,
kEggShellResult_MismatchedArrayRank = 6,
kEggSehllResult_UnableToParseData = 7,
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo here

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching this one. I'll fix it 👍


Module.typeHelpers.findTypeDispatcher = function (typeRef) {
var i = 0,
typeHandler;
Copy link
Contributor

Choose a reason for hiding this comment

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

spacing issue

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the spacing issue? Linter did not complain with this.

Copy link
Contributor

@cglzaguilar cglzaguilar left a comment

Choose a reason for hiding this comment

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

I have some comments so far.

{
void *pData = nullptr;

SubString objectName(viName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Add TypeManagerScope (tm), before this line.

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right, I'll change it.

}
//------------------------------------------------------------
// Write a string value to a symbol. Value will be parsed according to format designated.
VIREO_EXPORT EggShellResult EggShell_WriteValueString(TypeManagerRef tm, const TypeRef typeRef, void* data, const char* format, const char* value)
Copy link
Contributor

Choose a reason for hiding this comment

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

In this and other functions use pData instead of data to keep the naming consistent.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll fix it.

return kEggShellResult_Success;
}
//------------------------------------------------------------
// Write a string value to a symbol. Value will be parsed according to format designated.
Copy link
Contributor

Choose a reason for hiding this comment

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

"to designated format" instead of "to format designated"?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll change it


if (returnBuffer) {
returnBuffer->AppendSubString(&name);
// Add an explicit nullptr terminator so it looks like a C string.
Copy link
Contributor

Choose a reason for hiding this comment

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

When applying this change, don't forget to update other functions with the same comment.

rajsite and others added 19 commits July 9, 2018 19:05
Also added a test for unssported Enums of 64 bits.
Standardized on call for dispatchers and fixed loop condition.
Timestamps are 2 UInt64 therefore their JSON representation are strings.
Updating expected values to match this.
Also added tests that verify this behavior.
fix for findSubValueRef.
I added tests that effectively fail before the fix and pass after making it.
Included is the renaming of TypeWaveform.test.js to TypeWaveform.Test.js which were not being executed because of the regex used in karma.conf to include tests. I also fixed those.
* Adressed feedback from PR

* Renamed subpathstackPointer

* Fixing typo, variable names and TypeManagerScope for FindValue.

* Renamed pData in header
@rajsite
Copy link
Member Author

rajsite commented Jul 10, 2018

@gleonoliva rebased on top of master at 581798e

Copy link
Contributor

@cglzaguilar cglzaguilar left a comment

Choose a reason for hiding this comment

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

Please address minor feedback, other than that, good to go from my part.

{
TypeRef t = this;
while (t) {
if (t->Name().Compare(&TypeInt8) || t->Name().Compare(&TypeInt16) || t->Name().Compare(&TypeInt32)
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor comment for readability, keep all signed checks on one line and the unsigned checks in another line.

)))

enqueue (MyVI)
// Finished!
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a new line at the end of the file to remove the "red marker"

expect(readDouble('enum64releases')).toBe(5);
});

it('to read different boolean types from memory', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Change "boolean types" to "boolean values"

Copy link
Contributor

Choose a reason for hiding this comment

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

All other tests use the word 'types' in them do you want me to change those too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see the inconsistency, I'll change all of them to be values.

testWriteDouble('enum64releases', 5, 4);
});

it('to write different boolean types to memory', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here, "boolean types" to "boolean values".

expect(readDouble('dataItem_ArrayOfTimestamp', '0')).toMatchIEEE754Number(3564057536.423476);
});

it('to read different double values from N-dimensional arrays', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a 3D case on this list.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a 3D case on line 41

Copy link
Contributor

Choose a reason for hiding this comment

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

Great!

Guillermo Leon and others added 3 commits July 10, 2018 15:24
* Changed test names to from types to values to keep them consistent

* Added an extra line at the end to remove red marker

* Improving readibility by having signed type checks in same line
Use decoded field names in readValueRefObject
@rajsite rajsite merged commit 8bdcb79 into ni:master Jul 13, 2018
gleono pushed a commit to gleono/VireoSDK that referenced this pull request Jul 13, 2018
gleono pushed a commit to gleono/VireoSDK that referenced this pull request Jul 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants