PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1

20.3. Callback function

The callback function that is used in the BREW Interface Wrapper need to be declared, implemented, and registered originally.

As in the following sample code, the actual callback function is called via the dummy callback function.

[Note] Prototype of function that registers the callback function

The prototype of function that registers the callback function depends on the BREW Interface Wrapper.

Detailed information: "BREW API Reference"

Example 20.6. Declare, implement, and register the callback function of SFBCamera class.

SFMTYPEDEFCLASS(Camera)
class Camera {
SFMSEALCOPY(Camera)

private:
    SFBCameraSmp _camera;      // ICamera Interface Wrapper class 

public:
    SFCError Resume(Void);                      // resume processing
    friend Void OnCameraSHP(VoidPtr reference, AEECameraNotify* notify);    // dummy callback function 
    Void OnCamera(AEECameraNotify* notify);     // actual callback function
};

#endif

// resume processing: basic initialization for camera
SFCError Camera::Resume(Void)
{
    SFCError error(SFERR_NO_ERROR);
 
    // get camera interface
    if ((_camera = SFBCamera::NewInstance()) != null) {     
    
        // register dummy callback function
        error = _camera->RegisterNotify(OnCameraSHP, this); 
        
        if (error == SFERR_NO_ERROR) {

            ...

        }
        
    // when camera interface cannot be obtained
    } else {
    
        error = SFERR_NO_MEMORY;   
    }
    
    if (error != SFERR_NO_ERROR) {
       // error processing
    }
    return error;
}

// dummy callback function 
Void OnCameraSHP(VoidPtr reference, AEECameraNotify *notify)
{
    // call actual callback function
    static_case<CameraPtr>(reference)->OnCamera(notify); 
    return;
}

// actual callback function
Void Camera::OnCamera(AEECameraNotify* notify)
{
    switch (notify->nStatus) {
        case CAM_STATUS_START:  // when camera is started
            ...
            break;
        case CAM_STATUS_FRAME:  // when new frame is obtained
            ...
            break;
        case CAM_STATUS_DONE:   // when processing is finished
            ...
            break;
        case CAM_STATUS_FAIL:   // when processing is failed
            ...
            break;
        case CAM_STATUS_ABORT:  // when processing is stopped
            ...
            break;
    }
    return;
}