| |||
| Home > The Target Connection Mechanism > Getting existing CADI simulations |
If the caller connects to a running CADI simulation, it must
retrieve information on already existing simulations by calling
the GetSimulationInfos() method of the CADI broker
as shown in Figure 2.6.
This call returns an internal list of available simulations that
is maintained by the broker. The number of elements retrieved depends
on:
the size of the buffer used to fetch the list
the number of simulations that are available
the specified start index into the internal buffer in the broker.
The list of existent simulations held by the broker can change dynamically, so it might be necesary to update this list regularly to detect the creation or destruction of CADI simulations.
Based on the acquired information, the caller uses SelectSimulation() to
select a simulation to attach to. To specify a simulation, its ID
(as part of the simulation info) must be used.
SelectSimulation() might receive pointers
to a CADIErrorCallback object and a CADISimulationCallback object.
These objects are automatically registered to the requested simulation
and must be provided by the caller.
It is not required that a specific simulation ID matches the corresponding index for the simulation within the internal list held by the broker.
The result of SelectSimulation() is a CADISimulation pointer
to the requested simulation. The ObtainInterface() method
and the static_cast scheme must be applied to
check validity.
Example 2.4 shows a typical implementation:
Example 2.4. Getting an existing CADI simulation
//having already obtained a pointer to the CADIBroker before
//which is called cadi_broker
MyCADIErrorCallback errorCallbackObject;
MyCADISimulationCallback simulationCallbackObject;
char simulationCallbacksEnable[eslapi::CADI_SIM_CB_Count];
memset(simulationCallbacksEnable,
1, eslapi::CADI_SIM_CB_Count * sizeof(char)); //enable all callbacks
uint32_t desiredNumberOfSimulations = 10;
uint32_t startSimulationInfoIndex = 0;
uint32_t actualNumberOfSimulations = 0;
eslapi::CADISimulationInfo_t* simulationList = new
eslapi::CADISimulationInfo_t[desiredNumberOfSimulations]();
eslapi::CADIReturn_t status;
status = cadi_broker->GetSimulationInfos(startSimulationInfoIndex,
desiredNumberOfSimulations,
simulationList,
&actualNumberOfSimulations);
if (status != eslapi::CADI_STATUS_OK)
{
//GetSimulationInfos() failed
}
//... decide which simulation to connect to, for this example using the
//second one (index '\1'!!)...
CADISimulation* cadi_simulation
= cadi_broker->SelectSimulation(simulationList[1].id,
&errorCallbackObject,
&simulationCallbackObject,
simulationCallbacksEnable);
if (cadi_simulation == NULL)
{
//connection to simulation failed
}
//check compatibility
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)