Click or drag to resize

GetDriverSession

Retrieves a pointer to the DriverSession-derived class maintained in the driver project's DriverSession.h file.

template <typename TSession = DriverSession>
TSession* GetDriverSession(ViSession Vi);
Parameters
Vi

[in] ViSession handle for the driver session. This handle is initially created using the IVI Shared Components IviSession_New function. See the discussion of the Handle function for more information on the association of this ViSession handle with the DriverSession object.

Return Value

Returns a pointer to the DriverSession-derived class associated with the IVI session specified in the Vi parameter.

Remarks

Much of the functionality in the Nimbus Runtime Library is implemented on the DriverSession class, which serves as a base class for the driver-specific session class maintained in the driver project's DriverSession.h file. For convenience, the DriverSession functions most commonly used are exposed as global functions that internally access the DriverSession instance created at initialization.

In some cases it may be necessary to directly access the DriverSession class from within a function or attribute implementation. This would occur if the desired functionality was not exposed via a global function. This would also typically occur if the driver developed defined custom helper functions or driver-specific member variables on the specific DriverSession class defined in the DriverSession.h file. The GetDriverSession function provides access to the DriverSession class for directly accessing such member functions and member variables.

Example

The following example demonstrates use of the GetDriverSession function.

C++
ViStatus _VI_FUNC acme4321_Configure(ViSession Vi, ViReal64 Frequency, ViReal64 Bandwidth)
{
    // ...

    // Not specifying a template parameter yields a pointer of type DriverSesion, so only public functions 
    // defined in the Nimbus Runtime Library can be accessed.
    // 
    auto pBase = GetDriverSession(Vi);
    pBase->SomeNimbusHelper();       // OK -- can access any public function on DriverSession
    pBase->MyHelper();               // ERROR -- MyHelper function is defined on Acme4321DriverSession, not DriverSession

    // Specifying a template parameter yields a pointer of type Acme4321DriverSession
    // 
    auto pDerived = GetDriverSession<Acme4321DriverSession>(Vi);
    pDerived->SomeNimbusHelper();    // Still OK -- can access any public function on DriverSession
    pDerived->MyHelper();            // OK -- can access any public function defined on Acme4321DriverSession

    // ...
}

Download a complete CHM version of this documentation here.