Overriding TargetRTS functions in a model

May 4, 2020

Did you know that it's possible to override a certain function from the TargetRTS in a model? This may be useful in some cases where you want to customize the behavior of the TargetRTS for only one specific model. In that case it may be easier to just override one or a few functions from the TargetRTS instead of creating your own specific copy of the TargetRTS.

As an example, assume you have a model that uses the Log service from the TargetRTS, but now you want to turn off all logging. Rather than finding all the many places where the Log service is used in the model and change them, we can simply just override a few of the Log functions to disable all logging.

  1. First we create an Artifact in the model. Name it as you like, for example "Log_Override".
  2. Make sure the created artifact is included as a source element of the TC. Either directly, or indirectly as contained in a source element (such as the top package).
  3. Double-click the artifact to open the Code Editor. Write empty implementations for the four functions from the Log service that are involved when printing log messages to stderr:
void Log::Base::show( const void * value, const RTObject_class * type )
{
}

void Log::Base::show( const char * str )
{
}

void Log::Base::commit( void )
{
}

void Log::Base::crtab( int i )
{
}
  1. Build your application TC.

If you now get link errors ("multiple defined symbols"), it means the linker was unabled to replace the functions from the TargetRTS with your new empty functions. There can be a few different reasons for this: