2.4 Using GetSimulationFactories()

One way to establish a connection to a simulation target within CADI is to instantiate a CADI simulation and to connect to one of its targets.

To retrieve the list of available CADI simulation factories, the caller must execute the GetSimulationFactories() method in the CADI broker. The result of this call is an array of CADISimulationFactory pointers.
The list of simulation factories is static for a CADI broker, therefore it is only required to retrieve the list once at the beginning of a debug session.

Note

The caller is responsible for releasing, but not deleting, all obtained simulation factory objects. It is not sufficient to release only those objects that have been used to instantiate a simulation.
Figure 2-4 Getting the CADI simulation factories
To view this graphic, your browser must support the SVG format. Either install a browser with native support, or install an appropriate plugin such as Adobe SVG Viewer.

After retrieving the list of available simulation factories, the next step is to call the ObtainInterface() method of the CADI broker to check the compatibility of the requested factory. A static_cast() is required for the interface, to create the CADI broker.
After obtaining the appropriate CADI simulation factory, the caller must prepare the configuration of the targeted platform. This preparation includes retrieving the available parameters and their settings.
Call the GetParamterInfos() method of CADISimulationFactory to retrieve the parameter information. It returns a list with descriptions of the configurable parameters (that is of data type CADIParameterInfo_t). This list includes information such as the parameter ID for later reference, the parameter type, and the default value.
The caller can create a list of parameter values (of type CADIParameterValue_t) that are used for configuration of the platform. This list must end with an extra element that has the parameter ID 0xFFFFFFFF. It is required to add this element because not all parameters require setting and the order of the parameters within the list is undefined.

Note

Parameters that are not part of the value list that the caller sends are set to their default value.
The ID 0xFFFFFFFF is equal to static_cast<uint32_t>(-1).
Figure 2-5 Instantiating a CADI simulation
To view this graphic, your browser must support the SVG format. Either install a browser with native support, or install an appropriate plugin such as Adobe SVG Viewer.

The list of parameter values is forwarded to the Instantiate() method of the simulation factory. This call creates the actual CADI simulation. It might also receive a pointer to a CADIErrorCallback object and a pointer to a CADISimulationCallback object. These objects are automatically registered to the newly instantiated CADI simulation. The caller must provide them.
The result of the simulation instantiation is a pointer to a CADISimulation object. A compatibility check consisting of its ObtainInterface() method and calling static_cast() must be performed.
After the CADI simulation is created, the simulation factory is no longer required. The pointer to the corresponding CADISimulationFactory can therefore be released. This release can be safely done for these reasons:
  • The CADI broker manages the CADI simulation.
  • The simulation factory can be retrieved again from the broker if necessary.
Getting the simulation factory
// Having already obtained a pointer to the CADIBroker before
// which is called cadi_broker.
// Callback objects will be registered to CADISimulation.
MyCADIErrorCallback errorCallbackObject;
MyCADISimulationCallback simulationCallbackObject;
// Enable vector for MyCADISimulationCallback.
char simulationCallbacksEnable[eslapi::CADI_SIM_CB_Count];
// Enable all callbacks of MyCADISimulationCallback.
memset(simulationCallbacksEnable,
       1, eslapi::CADI_SIM_CB_Count * sizeof(char)); 
// Preparing parameters for GetSimulationFactories().
uint32_t desiredNumberOfFactories = 10; // Arbitrarily chosen, must be large
                                        // enough to get all factories.
uint32_t startFactoryIndex = 0;
uint32_t actualNumberOfFactories = 0;
// Array of CADISimulationFactory pointers to store the broker's factories.
eslapi::CADISimulationFactory** factoryList =
          new eslapi::CADISimulationFactory*[desiredNumberOfFactories]();
eslapi::CADIReturn_t status;
status = cadi_broker->GetSimulationFactories(startFactoryIndex,
                      desiredNumberOfFactories,
                      factoryList,
                      &actualNumberOfFactories);
if (status != eslapi::CADI_STATUS_OK)
{
   // GetSimulationFactories() failed.
}
// ...decide which entry in factory list to use,
// Let's assume we chose the second (index '1'!!)...
// Check compatibility of factory.
eslapi::if_name_t ifNameFactory = "eslapi.CADISimulationFactory2";
eslapi::if_rev_t  minRevFactory = 0;
eslapi::if_rev_t  actualRevFactory = 0;
if (factoryList[1]->ObtainInterface(ifNameFactory,
                                    minRevFactory,
                                    &actualRevFactory) == NULL)
{
     // Factory is incompatible.
}
// Continue with instantiation of a simulation...
uint32_t desiredNumberOfParameterInfos = 20; //Arbitrarily chosen, must
                          // be large enough to store all parameter infos.
uint32_t startParameterInfoIndex = 0;
uint32_t actualNumberOfParameterInfos = 0;
eslapi::CADIParameterInfo_t* parameterInfoList = new
eslapi::CADIParameterInfo_t[desiredNumberOfParameterInfos]();
status = factoryList[1]->GetParameterInfos(startParameterInfoIndex,
                                         desiredNumberOfParameterInfos,
                                         parameterInfoList,
                                         &actualNumberOfParameterInfos);
if (status != eslapi::CADI_STATUS_OK)
{
   // GetParameterInfos() failed.
}
eslapi::CADIParameterValue_t* parameterValues =
  new eslapi::CADIParameterValue_t[actualNumberOfParameterInfos + 1]();
                                   // + additional "terminating" element
// ...fill the parameter values accordingly...
// Set terminating element.
parameterValues[actualNumberOfParameterInfos].parameterID =
                                              static_cast<uint32_t>(-1);
cadi_simulation = factoryList[1]->Instantiate(parameterValues,
                       &errorCallbackObject,
                       &simulationCallbackObject,
                       simulationCallbacksEnable);
if (cadi_simulation == NULL)
{
       //instantiation failed
}
// Check compatibility of simulation.
eslapi::if_name_t ifNameSimulation = "eslapi.CADISimulation2";
eslapi::if_rev_t  minRevSimulation = 0;
eslapi::if_rev_t  actualRevSimulation = 0;
if (cadi_simulation->ObtainInterface(ifNameSimulation,
                                     minRevSimulation,
                                     &actualRevSimulation) == NULL)
{
       // Interface incompatible.
}
// No longer needed.
// Release CADISimulationFactories, no longer needed.
for (uint32_t i = 0; i < actualNumberOfFactories; i++)
     factoryList[1]->Release();
// No longer needed, destroy just the array.
delete[] factoryList;
// Continue with obtaining the CADI interface from simulation...          
Related reference
2.3.2 Creating the CADIBroker
Non-ConfidentialPDF file icon PDF versionARM DUI0842F
Copyright © 2014, 2015 ARM. All rights reserved.