4.3. Obtaining a custom interface

Implementation example for extending the target-side described how to implement a custom extension for the CADI interface on target-side. This interface must now be obtained by the caller. Follow the procedure described in this section to ensure the correct functionality of the acquired interface and to avoid, for example, the utilization of an outdated interface revision.

The procedure of obtaining a custom interface is the same as the one described in Obtaining an interface pointer to the target for the standard interfaces:

  1. A CAInterface pointer to the target interface class is required. This is typically returned by the CADI simulation.

  2. The ObtainInterface() method must be called to check if the desired interface is provided.

  3. The returned pointer to CAInterface, which might differ from the originally obtained one, must be converted to a pointer to the requested interface class by using a static_cast().

    Example 4.6 shows how this might be done for the MyExtensions and MyCADI classes as implemented in Implementation example for extending the target-side.

    Example 4.6. Using CADISimulation to return a pointer to the interface

    CADISimulation* cadiSimulation;
    uint32_t targetID;
    CAInterface* ca_interface;
    MyExtensions* my_extensions_if;
       //get the CADISimulation pointer
    // here, gets a pointer of type CAInterface. this pointer can be used to obtain
    // any interface provided by the target using ObtainInterface()
    ca_interface = cadiSimulation->GetTarget(targetID);
    //obtain the desired interface
    if_name_t ifName = “MyExtensions”;
    if_rev_t  minRev = 0;
    if_rev_t  actualRev = 0;
    // ObtainInterface() asks for "MyExtensions" interface
    // it returns the corresponding base class pointer
    ca_interface = ca_interface->ObtainInterface(ifName, minRev, &actualRev);
    if (ca_interface == NULL)
       //something went wrong, handle it...
    else //MyExtensions interface supported
       my_extensions_if =
          .   //go on using the obtained interface extensions

Copyright © 2008-2010 ARM Limited. All rights reserved.ARM DUI 0444F