238 views
in System Integration by

Hi Everyone. 

While developing with Embedded Wizard, I noticed that for each method, the generated code includes two functions:

  • One named UnitNameClassName_MethodName(...)

  • Another named UnitNameClassName__MethodName(...) (with a double underscore)

The difference between the two seems to be as follows:

  • The first function contains the logic defined in Embedded Wizard and wants as first input a reference to the instance of the class we want to operate on.

  • The second function, called a wrapper, takes a void* pointer as its first input. Its only operation is to cast that pointer to the appropriate type and then call the first function (the one with the single underscore).

Example :
/* This is the method called by the device to trigger a page change in the GUI*/
void AppMainVMClass_UpdateCurrentPage( AppMainVMClass _this, XInt32 aNewValue )
{
  EwTrace( "%s%i", EwLoadString( &_Const0000 ), aNewValue );

  if ((XEnum)aNewValue != _this->CurrentPage )
  {
    _this->previousPage = _this->CurrentPage;
    _this->CurrentPage = (XEnum)aNewValue;
    EwNotifyRefObservers( EwNewRef( _this, AppMainVMClass_OnGetCurrentPage, AppMainVMClass_OnSetCurrentPage ), 
      0 );
  }
}

/* Wrapper function for the non virtual method : 'AppMainVM::Class.UpdateCurrentPage()' */
void AppMainVMClass__UpdateCurrentPage( void* _this, XInt32 aNewValue )
{
  AppMainVMClass_UpdateCurrentPage((AppMainVMClass)_this, aNewValue );
}

I would like to understand the purpose of this design pattern and whether it can be avoided.
In my source code, whenever I invoke a method generated by Embedded Wizard, I already know the exact class type the method belongs to. Therefore, I don't see the need to perform the aforementioned cast.

Thanks in Advance.
Dario.

1 Answer

0 votes
by
Hello dB,

the functions with single underscore are internal and not intended to be invoked directly from your own code. In turn, the functions with two underscore are the right way to invoke the code.

Depending on the inheritance of the class, the double-underscore functions take care of runtime relevant evaluation of which version of the single-underscore function is called. Your example above is an a simple case without any inheritance relevant aspects to take in account so that the double-underscore function directly invokes the single-underscore. In other cases the double-underscore function contains more code to estimate the right code execution.

Please note, in our documentation we only show the usage of double-underscore version of functions. Consider the single-underscore functions as internal functions.

I hope it helps you further.

Best regards

Paul Banach
by
Hello Paul,
Now I can see the point of it.

 

Thanks for your answer.
Dario

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...