Click or drag to resize

GetterCacheManager Class

As the name implies, the GetterCacheManager is used to manage cached values for attributes in IVI-C drivers. It is important to note that the Nimbus caching engine for IVI-C drivers is used for two purposes -- 1) to support the IVI-defined state caching features which drivers may optionally implement, and 2) to support simulation which all IVI drivers are required to implement. Because the same cache is used for both state caching and simulation, the GetterCacheManager appears in most attribute implementation code. Understanding the tasks it performs is useful in understanding the overall flow of Nimbus-generated attribute implementation code.

The GetterCacheManager simplifies simulation and state caching code by performing the following tasks:

  • Checks to see if either state caching or simulation is enabled and does nothing if neither are enabled.

  • Automatically retrieves the cache entry for the specified attribute. If the attribute is associated with a repeated capability, then the GetterCacheManager retrieves the cache entry for the physical name supplied in the attribute getter's RepCapIdentifier parameter.

  • Automatically updates the cached value and sets its cached state to valid upon function exit. This is done in the class destructor so that the cache will be properly updated when the function has multiple return locations.

  • Provides a GetCachedValue function which allows implementation code to easily implement simulation.

Using the GetterCacheManager without Repeated Capabilities

The following code shows how the GetterCacheManager is declared in a an attribute getter implementation. In this example, the ACME4321_ATTR_BANDWIDTH attribute is not associated with a repeated capability.

C++
ViStatus _VI_FUNC acme4321_get_BANDWIDTH(ViSession Vi, ViConstString RepCapIdentifier, ViReal64* AttributeValue)
{
    // ...

    // At this point, when the cacheManager variable is declared, the GetterCacheManager checks to
    // see if either state caching or simulation are enabled.  If enabled, then the constructor
    // retrieves the cache entry.
    // 
    GetterCacheManager<ViReal64> cacheManager(Vi, ACME4321_ATTR_BANDWIDTH, *AttributeValue);

    if (SimulationEnabled(Vi))
    {
        if (!cacheManager.GetCachedValue(AttributeValue))
        {
            *AttributeValue = 3.14E6;
        }

        // Since the cacheManager destructor updates the cache, the AttributeValue will be stored
        // in the cache for simulation purposes at this point as well.
        // 
        return VI_SUCCESS;
    }

    // ...

}   // Upon function exit, the final value of AttributeValue will be stored in the cache
Using the GetterCacheManager with Repeated Capabilities

The following code shows how the GetterCacheManager is declared in a an attribute getter implementation. In this example, the ACME4321_ATTR_FREQUENCY attribute is associated with a channel repeated capability.

C++
ViStatus _VI_FUNC acme4321_get_FREQUENCY(ViSession Vi, ViConstString RepCapIdentifier, ViReal64* AttributeValue)
{
    // ...

    PhysicalNameList<Channel> physicalNames;
    ReturnOnError(Channel::ExpandSingleSelector(Vi, RepCapIdentifier, physicalNames));

    // At this point, when the cacheManager variable is declared, the GetterCacheManager checks to
    // see if either state caching or simulation are enabled.  If enabled, then the constructor
    // retrieves the cache entry for the specific physical name supplied.
    // 
    GetterCacheManager<ViReal64, Channel> cacheManager(Vi, physicalNames, ACME4321_ATTR_FREQUENCY, *AttributeValue);

    if (SimulationEnabled(Vi))
    {
        if (!cacheManager.GetCachedValue(AttributeValue))
        {
            *AttributeValue = 3.14E6;
        }

        // Since the cacheManager destructor updates the cache, the AttributeValue will be stored
        // in the cache for simulation purposes at this point as well.
        // 
        return VI_SUCCESS;
    }

    // ...

}   // Upon function exit, the final value of AttributeValue will be stored in the cache for all physical names supplied

Download a complete CHM version of this documentation here.