|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Manually cancelling a Command
Hello,
I am trying to create a Command subclass which listens for an interrupt to cancel the command. When cancelling the command, I have tried using the Cancel() method, but it fails when the command is part of a CommandGroup. Is there a universal way to forcibly end a command from within the command itself? EDIT: Also, can the Cancel() method be used on a CommandGroup object? If so, I could work around this issue. Last edited by axiomofdarkness : 23-03-2016 at 14:52. |
|
#2
|
||||
|
||||
|
Re: Manually cancelling a Command
Within your command:
Code:
if(getGroup() != null) getGroup().cancel(); else cancel(); |
|
#3
|
|||||
|
|||||
|
Re: Manually cancelling a Command
Quote:
|
|
#4
|
||||
|
||||
|
Re: Manually cancelling a Command
Will this cause issues if multiple commands are trying to end their parent CommandGroup?
|
|
#5
|
||||
|
||||
|
Re: Manually cancelling a Command
Hmm. What does it mean to "listen" for an interrupt?
|
|
#6
|
||||
|
||||
|
Re: Manually cancelling a Command
I have a background thread that checks for a certain button combination on the joystick being pressed. The Cancel() method will be called when that condition is true.
Last edited by axiomofdarkness : 23-03-2016 at 15:50. Reason: Made wording clearer |
|
#7
|
||||
|
||||
|
Re: Manually cancelling a Command
Quote:
|
|
#8
|
||||
|
||||
|
Re: Manually cancelling a Command
My mistake - I apologize for the error. What would an interrupt be then?
|
|
#9
|
||||
|
||||
|
Re: Manually cancelling a Command
The hardware generates an electrical signal (called an interrupt) that causes the CPU to stop what it's doing, save its "context", jump to a new location in program memory, and start executing there. That location is called an ISR -- interrupt service routine. When the ISR is done executing, it tells the CPU to go back to where it was when the interrupt occurred. The CPU uses the saved "context" to go back to where it was, as it was.
You can see there is no polling involved. That's the advantage of interrupts. The disadvantage is that interrupts can occur at any time -- asynchronously -- so you have to be careful when using them. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|