This is a follow-up to a comment in my previous post. I am trying to listen to a shared resource's Entry and Exit from within a custom Acquire object I have.
https://answers.flexsim.com/questions/135257/custom-acquire-resource-activity-processflow-modul.html
I slightly modified the ReinforcementLearning::addDecisionListener() method. I made the following changes:
- Replaced DecisionEvent() with FlexSimEvent()
- Replaced this->holder with a parameter listenerObj (I am currently passing in my custom acquire object's holder)
- void addEventListener(FlexSim::TreeNode* eventObject, const char* eventName, FlexSim::TreeNode* listenerObj)
- {
- if (objectexists(eventObject))
- {
- // Find and select event
- EventBinding eventBinding;
- eventObject->objectAs(SimpleDataType)->enumerateEvents(&eventBinding);
- eventBinding.select(eventName);
- TreeNode* theNode = eventObject->objectAs(SimpleDataType)->assertEvent(&eventBinding);
- if (theNode)
- {
- switch_activelisteners(theNode, 1);
- TreeNode* newListenerNode = nodeinsertinto(theNode);
- switch_activelisteners(newListenerNode, 1);
- switch_destroyonreset(newListenerNode, 1);
- nodeaddcouplingdata(newListenerNode, new FlexSim::FlexSimEvent(), 1);
- nodepoint(newListenerNode, listenerObj);
- }
- }
- }
I am using this method as follows:
- addEventListener(treenodeReferenceToResourceBlock, "OnExit", customAcquireObject->holder)
In the tree, I can see this successfully add a listener to OnExit. However, it looks different compared to, for example, the listener added by an Event Triggered Source block.
Using my code:
Using Event Triggered Source:
Am I doing this correctly?
Also, how can I hook into this listener and execute a function within my custom acquire block when this event fires?