6.15. Advanced Features - Approval for Joining a Session

You can determine whether to allow a station to join a session at the time of joining.

Registering an Approval Determination Callback

Only the session host has the authority to determine whether a request to join a session is either approved or denied. When performing a determination, prepare the determination callback function and register it to the session. When a join request arrives while the determination callback function is not registered, it is usually approved.

Code 6-36. Registering and Unregistering a Determination Callback Function
// Executable if an instance of the Session class exists.
// Register a determination callback function to the Session class.
nn::pia::session::Session::GetInstance()->RegisterJoiningApprovalCallback(sampleJoinApprovalCallback);
 
// This callback function is called when the station acting as the session host receives a join request
// while the callback is registered until it is unregistered.
 
// Unregisters the Session class determination callback function.
nn::pia::session::Session::GetInstance()->UnregisterJoiningApprovalCallback();

Determining Approval

The code for the determination callback is implemented in the application.

Warning:

Do not include any processes that would block for a long time within the callback function. This can negatively affect system processes.

The only times outside of the determination callback that a join request can be denied is either when a session is full or during host migration.

Code 6-37. Sample Callback Function for Determining Whether to Approve a Join Request.
// Example of a join-in request approval determination callback function
bool sampleJoinApprovalCallback(const nn::pia::transport::Station::IdentificationToken* pRequesterToken)
{
    bool judgment;
    // Write the code for determining approval of a join request. The pRequesterToken parameter
    // is the pointer to the identification token for the station requesting approval to join.
    // Do not include code that blocks for a long period of time because that might impact the system.
    if (judgment)
    {
        // Approve if 'true' is returned.
        return true;
    }
    else
    {
        // Deny if 'false' is returned.
        return false;
    }
}