Knowledge Base

Back

How to fix warning RC156 'Getinstance returns a Component'

How to handle warning RC156 "The code generator setting "GetInstance returns a Component" is deprecated and will be removed in ASD:Suite version 9.0.0.".

  • Step 1: Use the wizard by applying the solution and ensure that the GetInstance returns an Interface. In order to change this setting for all interface models in your project in one go, you can download an Extended version of the SetModelProperties tool.
  • Step 2: Re-generate all the code for that respective component by selecting the design model and pressing ctrl-F7.
  • Step 3: Apply the following changes in your hand-written (client) code to avoid compiler errors (explained below per language). Note that this only applies to C++, C#, and Java.
  • Step 4: Re-build the code.
Please note that this is a warning and it is not mandatory to remove this warning immediately. However, we do recommend not to postpone this too long as from R4 v9.0.0 onwards it is required that GetInstance functions return an interface.




C++:

The xxxComponent.h header file initially contains the following code:


class AlarmSystemComponent: public AlarmSystemInterface

{

public:

  static boost::shared_ptr<AlarmSystemComponent> GetInstance();

};

 

Which is changed after re-generating the code into (changes marked in bold):

      class AlarmSystemComponent: public AlarmSystemInterface

{

public:

  static boost::shared_ptr<AlarmSystemInterface> GetInstance();

};

 

The corresponding hand-written code needs to be changed from:

      boost::shared_ptr<AlarmSystemComponent> alarm;

 

into (changes marked in bold):

      boost::shared_ptr<AlarmSystemInterface> alarm;

 

C#

The xxxPartialComponent.cs file initially contains the following code:

      public partial class AlarmSystemComponent: AlarmSystemInterface

{

  public static AlarmSystemComponent GetInstance()

  {

    return GetInstanceImpl();

  }

}

 

Which is changed after re-generating the code into (changes marked in bold):

      public partial class AlarmSystemComponent: AlarmSystemInterface

{

  public static AlarmSystemInterface GetInstance()

  {

    return GetInstanceImpl();

  }

}

 

The corresponding hand-written code needs to be changed from:

      private AlarmSystemComponent alarm = null;

 

into (changes marked in bold):

      private AlarmSystemInterface alarm = null;

  

Java

The xxxComponent.java file initially contains the following code:

public final static AlarmSystemComponent getInstance() {

  AlarmSystemComponent c = new AlarmSystemComponent();

  return c;

}

 

Which is changed after re-generating the code into (changes marked in bold):

      public final static AlarmSystemInterface getInstance() {

  AlarmSystemComponent c = new AlarmSystemComponent();

  return c;

}

 

The corresponding hand-written code needs to be changed from:

      private AlarmSystemComponent alarm;

 

into (changes marked in bold):

      private AlarmSystemInterface alarm;