call a class method inside callback for CBState
Hi all, I wish to call a class method inside the callback method for CBState. However, the callback method does not have a self parameter. When I call a class method from inside the callback I get the exception "User data key 'classmethodname' not available. Available keys :[]". Is there any specific way to do this ?
Any hint or help would be a great help !!
Asked by amarbanerjee23 on 2017-09-06 00:51:02 UTC
Answers
Hi all, I found the answer.
We need to pass the methods in the cb_args[]
. E.g.
smach.StateMachine.add('STATE1',CBState(
self.my_call_back,cn_args=[self.class_method_tobe_called_inside_call_back]))
Then in the part of @smach.cb_interface()
, we need to pass a function name in the input_keys[]
E.g.
@smach.cb_interface(input_keys['class_method_to_call_inside_callback'])
Then inside the callback simply call the method with the same name as passed in the input keys e.g
@smach.cb_interface(input_keys['**method_to_call'**])
def my_call_back(self,method_to_call):
method_to_call()
Asked by amarbanerjee23 on 2017-09-07 02:05:15 UTC
Comments