SetReadCallback
Top  Previous  Next

Description

Sets up a callback function which will be called when a client application issues a feature read request.

[C++]
int
 SetReadCallback(void* context, FeatureCallback callback);

  
 where FeatureCallback type is defined as

    typedef bool (*FeatureCallback)(void* context, const char* feature);


Parameters
[C/C++]
 
[in] void* context  
Address of the context in which the callback function will be called.  
 
[in] FeatureCallback callback  
Address of the callback function  
 
[in] const char* feature  
String containing the name of the feature whose value is about to be read by a client application.  
 

Return Values


S_OK  
Success  
E_FAIL  
Failure  


Example


This fragment of an MFC code uses a feature-read callback to obtain the current temperature value from a thermal sensor and modify the value of the Temperature feature before it gets transmitted to the client application.

   
int
 onFeatureRead(void
* context, const
 char
* feature)
      {
         CGigemuDlg* dlg = (CGigemuDlg*) context;
         return
 dlg->onFeatureRead(feature);
      }

int CGigemuDlg::onFeatureRead(const char* feature)  
{  
  if(CString(feature)=="Temperature")  
  {  
    float temp;  
    GetTemperatureFromSensor(&temp);  
      m_pCamera->SetFeatureFloatValue(feature, temp);  
  }  
    return 0;  
}  

      BOOL CGigemuDlg::OnInitDialog()
      {
  ....        
  m_pCamera->SetReadCallback(this, &::onFeatureRead);  
  ....  
}  
 

Remarks


The read callback function is called before the value of the feature is transmitted to the client application. Therefore, the callback can be used to update the value of the feature at the time of the read request. This is especially useful when the feature represents a real-world measurement such as the temperature, as shown in the example above.

If you are using a callback function in the main thread of the simulation application, make sure that no lengthy processing is done in the body of the function as otherwise the connection to the remote client may become broken.