Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call a VI in the do method depending on the subclass of the called actor automatically

Solved!
Go to solution

Dear community,

I have an actor class "Base" which inherits from the AF actor and several specialized classes (for Example "MainReactor") which inherit from "Base" class. The base actor has a method "handleCoolantLeak.vi" and there are overrides for all specialized actors. I want to send a "reportCoolantLossMsg" message to the "MainReactor" actor itself (which has detected the coolant loss) and there I want the handle coolant leak method (which overiddes some parent method that should be executed as well) executed. Due to this, the do method converts the class on which the handleCoolantLeak method is applied into the Class of MainReactor. After this the caller should be also informed and there the overriden handleCoolantLeak Method should be also executed.

But the caller has a different class, and therefore the conversion to more specialized class fails, since the object constant provided in Do.vi is from another fork of the inheritance tree.

How can I achieve, that the actor which receives a message calls the overriden sub vi of its own class?

Probably I can loop over all subclasses until the conversion routine does not fail.

Do I violate some AF law or is there a best practice?

Thanks in advance.

Edit: Preserve Runtime Class might do this. Unfortunatly I am new to Labview...

Now I wonder why I need a object constant and two conversions to more specific class. If I just preserved the runtime class everything would be fine.

0 Kudos
Message 1 of 4
(3,850 Views)
Solution
Accepted by topic author mthimm1

You mention that your "do method converts the class on which the handleCoolantLeak method is applied into the Class of MainReactor" using an object constant for 'MainReactor'.  This then causes a class conflict when you receive a message for a different subclass of "Base" class.

One solution is to use "Base" class as your object constant, and have "MainReactor" and the other specialized actors override the "Base" class method in the 'Do.vi' to implement their specialized versions of the base method.

In other words, your 'Do.vi' is downcasting from Actor.lvclass to a class that is too far down in your inheritance tree, making it too specialized.  To make it more general, downcast only as far as your common ("Base") class.

0 Kudos
Message 2 of 4
(3,411 Views)

Sorry, for my bad problem description.

I already have the "Base" class as object constant in the do VI. My plan was exactly to use the mechanism you describe. Probably I did an mistake somewhere else.

I have put a breakpoint in the method which ovverrides the handleCoolantLeak.vi from the Base actor. My application did not reach it.

Does it make sense to use "preserve runtime class" in this context?

0 Kudos
Message 3 of 4
(3,411 Views)

The downcasting VI should be sufficient in your case.

If your execution never gets into the override, you don't have enough information to determine why it doesn't.

I would set a breakpoint in the Do.vi and verify that it's being reached, that your actor is what it should be, that it's being downcast correctly, and that it reaches the method VI that it's supposed to override.

Message 4 of 4
(3,411 Views)