In the browser, you can specify the name and location of the final component. You can also specify which elements to map to a component, the locations of any include files, and which libraries, additional sources, and standard headers to link in during compilation.
If the component is an executable file, Rational Rhapsody generates a specification file and an implementation file for it called Main<component>.h and Main<component>.c. These files are named for the active component. For example, if the active component is called DefaultComponent and it is an executable file, the names for its source files are MainDefaultComponent.h and MainDefaultComponent.c. If the component is a library, the files are named simply <component>.h and <component>.c (without the "Main" prefix).
The component specification (.h) file declares the component and its initializer and cleanup methods. For example:
/************************************************ . . . #ifndef MainDefaultComponent_H #define MainDefaultComponent_H /*---------------------------------------------*/ /* MainDefaultComponent.h */ /*---------------------------------------------*/ /* Constructors and destructors:*/ void DefaultComponent_Init(); void DefaultComponent_Cleanup(); #endif /************************************************ File Path : DefaultComponent\DefaultConfig\ MainDefaultComponent.h ************************************************/
The component implementation (.c) file contains the main program loop. For example:
.
.
.
#include "MainDefaultComponent.h"
#include <oxf/Ric.h>
#include "Default.h"
/*---------------------------------------------*/
/* MainDefaultComponent.c */
/*---------------------------------------------*/
void DefaultComponent_Init() {
Default_OMInitializer_Init();
}
void DefaultComponent_Cleanup() {
Default_OMInitializer_Cleanup();
}
int main(int argc, char* argv[]) {
if(RiCOXFInit(argc, argv, 6423, "", 0, 0)) {
DefaultComponent_Init();
{
/*#[ configuration
DefaultComponent\DefaultConfig */
/* your code goes here */;
/*#]*/
}
RiCOXFStart(FALSE);
DefaultComponent_Cleanup();
return 0;
}
else
return 1;
}
/************************************************
File Path : DefaultComponent\DefaultConfig\
MainDefaultComponent.c
************************************************/
The component specification file includes the Ric.h file, in which the real‑time framework for IBM Rational Rhapsody Developer for C is defined.
The main program loop calls RiCOXFInit(), one of the functions provided by the framework. This framework initialization function performs the following operations:
If RiCOXFInit() returns successfully, the main() function then executes any initialization code entered in the Initialization tab for the configuration. The main() function then calls the function to initialize the component (for example, DefaultComponent_Init()). This function in turn calls the functions to initialize any packages contained in the component.
Once the component is initialized, the main() function calls the RiCOXFStart() function, which starts the main task. By default, the generated code passes a parameter value of FALSE to the OXFStart() function. This means that the system does not fork a new task and the model runs on the main system thread.
If you are creating a GUI application and the compiled component is a library that must not interfere with the main program thread, you want to pass a value of TRUE to RiCOXFStart(), thus preventing the library from taking control of the system.
Together, the RiCOXFInit() and RiCOXFStart() functions start the Rational Rhapsody model running. They must be called before your model can start receiving events. If the component is a library that will be linked into another application (for example, a GUI application), Rational Rhapsody does not generate a main() function for it. You must write the code to call these two functions, first RiCOXFInit() and then RiCOXFStart(), somewhere in the main program loop for the application to start the event processing.
If your animation port number is set to any number other than the default of 6423 in your rhapsody.ini file, you must pass the correct port number as the third parameter to RiCOXFInit().
For example, in the home heating system sample, the program entry point for the GUI application (hhsproto component) is defined in the hhsprdlg.cpp file with the following call:
RiCOXFInit(NULL, NULL, 6423, "", 0, 0);
The third argument to RiCOXFInit(), 6423, is the default animation port number. If your animation port is set to a different number, you can edit this argument to match the one in use (for example, 6424). Otherwise, animation does not work.
When the last event has been processed and the model has reached a termination point, the main() function calls the function to clean up the component (for example, DefaultComponent_Cleanup()).
Component source files are generated to the configuration directory, which is under the component directory by default. For example:
<project_dir>\<component_dir>\<config_dir>