Provide the possibility to access the state machine of a device from the client side (C++ and Java API)
Closed this issue · 2 comments
Hello,
It would be very helpful if the client could have access to the state machine of a device.
For example : we need sometimes to know if a device command is authorized when the device is in a particular state.
The method can be boolean isAuthorized("Command Name", "State"). If the second argument is absent, it will check if the command is authorized in the current state.
This feature is needed in JTango (java API) and C++.
Regards,
Faranguiss Poncet
@faranguiss-poncet , thanks for the proposal.
A few questions/comments from my side:
-
From the signature it seems you want this method in the DeviceProxy. I would suggest to extract special interface aka
DeviceStateMachine
and add this method there e.g.DeviceStateMachine.isCommandAllowed(DeviceCommand|String)
and/or add it toDeviceCommand
e.g.DeviceCommand.isAllowed(DeviceState)
-
Since we are talking about state machine I wonder why exception is not enough? In Java, for instance, there is built-in IllegalStateException which is typical for such situations. Client API may convert DevFailed to ISE to be more specific
-
isAuthorized("Command Name", "State")
seems to me misleading. Typically Authorized means user has rights to do smth. In your case IMHOisAllowed
orisValid
will be better naming. -
I think even more useful will be to have something like
DeviceCommand.getValidStates() => DeviceState[]
Thank you for your answer.
I will first answer your question number 2. An exception is not enough. Because the exception is thrown when the command is executed by the client. But in GUIs sometimes we need to know in advance if a command is allowed (before executing the command) in the current state in order to disable / enable the related push buttons.
For the point 3 , I totally agree to change the isAuthorized and I have a little preference for isAllowed
Concerning points 1 and 4 which are the implementation choices : all I need is to be able at run time to find out if yes or no a command is allowed in the current state. The only issue I see is that I don't know if the class DeviceCommand exists in the Tango Client Java API (not the server side).
Any of your 3 proposals can be used as long as the corresponding class is available in Tango Client Java API.