Skip to content

Commit

Permalink
Bug fix for timeout event with 0ms doesn't work with webvi. (#698)
Browse files Browse the repository at this point in the history
WebVI does not execute when an event structure is used with a timeout event of 0 ms.
BUG [link](https://ni.visualstudio.com/DevCentral/_workitems/edit/1474951)
Whenever event structure timeout was 0ms it goes to InitObservableTimerState with tickCount as 0x7FFFFFFFFFFFFFFF setting it to infinite wait instead of executing event structure immediately.
![1](https://user-images.githubusercontent.com/97939637/152923175-6637ef0a-9691-46e1-b215-3470675e1b2c.PNG)
At first, I tried adding a condition in ReserveObservationStatesWithTimeout to check if tickCount>= 0 , pass tickCount in InitObservableTimerState so that we immediately trigger the observer whenever the timeout is 0. But during testing we found that it affected the behavior of other nodes as well such as the OneButtonDialog.
So, didn't move forward with this approach.
Now, I have added a condition if the timeout given is 0ms we execute the event structure immediately by going to the desired branch target. I have tested it with different configurations and the behavior was the same as the current vireo version.

Have added test cases and have also tested with other test cases.
  • Loading branch information
amehra-ni authored Feb 11, 2022
1 parent 2939ca2 commit f3deab4
Show file tree
Hide file tree
Showing 6 changed files with 422 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/core/Events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ VIREO_FUNCTION_SIGNATUREV(WaitForEventsAndDispatch, WaitForEventsParamBlock)
if (!occ.HasOccurred(staticCount, false)) {
Observer* pObserver = clump->GetObservationStates(2);
if (!pObserver) {
PlatformTickType future = msTimeout > 0 ? gPlatform.Timer.MillisecondsFromNowToTickCount(msTimeout) : 0;
PlatformTickType future = msTimeout >= 0 ? gPlatform.Timer.MillisecondsFromNowToTickCount(msTimeout) : 0;
pObserver = clump->ReserveObservationStatesWithTimeout(2, future);
occ.InsertObserver(pObserver+1, occ.Count()+1);
return clump->WaitOnObservableObject(_this);
Expand Down
3 changes: 3 additions & 0 deletions test-it/ExpectedResults/EventStructureWith0msTimeout.vtr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
User event generated
User event executed
Timeout event executed
3 changes: 3 additions & 0 deletions test-it/ExpectedResults/EventStructureWithPositiveTimeout.vtr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
User event generated
User event executed
Timeout event executed
207 changes: 207 additions & 0 deletions test-it/ViaTests/EventStructureWith0msTimeout.via
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
// Autogenerated Vireo assembly file
// Generated on 02/10/2022 10:20:07
//---------------------------------------------------
//VI Definition: ::VireoDevSystem::Interactive::WebApp::index.gviweb
define (WebApp%3A%3Aindex%2Egviweb dv(.VirtualInstrument (
Events: c(
e(c( // Event Struct 0
e(dv(c(
e(.UInt32 eventSource)
e(.UInt32 eventType)
e(.UInt32 controlUID)
e(.UInt32 dynamicIndex)
) (25 1000 0 1 ))local4)
e(dv(c(
e(.UInt32 eventSource)
e(.UInt32 eventType)
e(.UInt32 controlUID)
e(.UInt32 dynamicIndex)
) (0 1 0 0 ))local9)
))
)
Locals: c( // Data Space
e(dv(.String 'WebApp::index.gviweb')local10)
de(dv(.String '')dataItem_String)
e(.String local12)
ce(dv(.String '')c13)
e(.UserEventRefNum<.String> local14)
e(.ErrorCluster local15)
e(.ErrorCluster local16)
e(.Boolean local17)
e(.EventRegRefNum<c(
e(c(
e(.Int32 eventType)
e(.UserEventRefNum<.String> eventRefnum)
) )
)> local20)
e(.ErrorCluster local21)
e(.UserEventRefNum<.String> local22)
e(.ErrorCluster local23)
ce(dv(.Boolean false)c24)
ce(dv(.Boolean true)c25)
e(.ErrorCluster local26)
e(.Boolean local27)
e(.Int32 local28)
e(.String local29)
e(.ErrorCluster local30)
ce(dv(.Int32 0)c31)
ce(dv(.Int32 2)c32)
ce(dv(.Int32 0)c33)
e(.Int32 local34)
e(.Int32 local35)
de(dv(.Boolean false)dataItem_Stop)
e(.Boolean local37)
e(.Int32 local38)
e(.Int32 local39)
e(c(
e(.UInt32 Source)
e(.UInt32 Type)
e(.UInt32 Time)
e(.UInt32 Index)
e(.UserEventRefNum<.String> UsrEvtRef)
e(.String event%20data)
) local46)
e(c(
e(.UInt32 Source)
e(.UInt32 Type)
e(.UInt32 Time)
e(.UInt32 Index)
) local51)
e(c(
e(.UInt32 Source)
e(.UInt32 Type)
e(.UInt32 Time)
e(.UInt32 Index)
e(.UserEventRefNum<.String> UsrEvtRef)
e(.String event%20data)
) local58)
e(.String local59)
e(.String local60)
de(dv(.String '')dataItem_String_2)
e(.String local62)
e(c(
e(.UInt32 Source)
e(.UInt32 Type)
e(.UInt32 Time)
e(.UInt32 Index)
) local67)
e(.UInt32 local68)
ce(dv(.String 'timeouts')c69)
de(dv(.String '')dataItem_String_3)
e(.String local71)
e(.EventRegRefNum<c(
e(c(
e(.Int32 eventType)
e(.UserEventRefNum<.String> eventRefnum)
) )
)> local74)
e(.EventRegRefNum<c(
e(c(
e(.Int32 eventType)
e(.UserEventRefNum<.String> eventRefnum)
) )
)> local77)
e(.EventRegRefNum<c(
e(c(
e(.Int32 eventType)
e(.UserEventRefNum<.String> eventRefnum)
) )
)> local80)
e(.ErrorCluster local81)
e(.ErrorCluster local82)
de(dv(.ErrorCluster (false 0 '' ))dataItem_ErrorOut)
e(.ErrorCluster local84)
e(.ErrorCluster local85)
e(.ErrorCluster local86)
ce(dv(.Int32 1000)c87)
ce(dv(.Boolean false)c88)
e(.Boolean local89)
e(.Boolean local90)
e(.ErrorCluster local91)
e(.Occurrence local92)
e(.Boolean local93)
ce(dv(.Int32 0)c94)
e(.EventRegRefNum<c(
e(c(
e(.Int32 eventType)
e(.UserEventRefNum<.String> eventRefnum)
) )
)> local97)
ce(dv(.Boolean false)c98)
ce(dv(.Int32 0)c99)
ce(dv(.Int32 0)c100)
ce(dv(.Int32 1)c101)
)
clump(1
Perch(3)
Copy(dataItem_String local12)
Copy(local85 local15)
CreateUserEvent(local14 local15)
Copy(local15 local16)
Copy(local16.status local17)
Copy(local86 local21)
RegisterForEvents(local20 local21 c87 local14)
Copy(local14 local22)
GenerateUserEvent(local22 local12 c88 local21)
Printf("User event generated\n")
Xor(c24 local17 local89)
BranchIfFalse(1 local89)
Xor(c25 local17 local90)
BranchIfFalse(2 local90)
Branch(3)
Perch(1)
Branch(0)
Perch(2)
Copy(local16 local26)
Copy(local26.status local27)
Copy(local26.code local28)
Copy(local26.source local29)
Copy(local91 local30)
JavaScriptInvoke(local92 true * 'LogLabVIEWError' * local27 local28 local29)
Branch(0)
Perch(0)
IsGE(c33 c32 local93)
BranchIfTrue(5 local93)
Branch(6)
Perch(6)
Copy(c94 local34)
Copy(c32 local35)
Copy(local20 local97)
Perch(7)
CopyAndReset(dataItem_Stop local37 c98)
WaitForEventsAndDispatch(c31 local20 c99 c100 local46 9 c101 local51 10)
Branch(8)
Perch(9)
Copy(local46 local58)
Copy(local58.event%20data local59)
Printf("User event executed\n")
StringToUpper(local59 local60 )
Copy(local60 dataItem_String_2)
Copy(local20 local74)
Branch(8)
Perch(10)
Copy(local51 local67)
Copy(local67.Time local68)
Copy(c69 dataItem_String_3)
Copy(local20 local74)
Printf("Timeout event executed\n")
Branch(8)
Perch(8)
Increment(local34 local34 )
BranchIfGE(11 local34 local35)
BranchIfTrue(11 local37)
Branch(7)
Perch(11)
Copy(local74 local80)
Branch(4)
Perch(5)
Copy(local77 local80)
Branch(4)
Perch(4)
UnregisterForEvents(local80 local21)
DestroyUserEvent(local22 local21)
Copy(local21 dataItem_ErrorOut)
/* Clump Ended. */ )
)))
enqueue (WebApp%3A%3Aindex%2Egviweb)
//Finished!! :D
Loading

0 comments on commit f3deab4

Please sign in to comment.