DataReceivedHandler

The DataReceivedHandler handles configuration-related logical operations.

This handler receives messages of type DataToBackend. These messages include:

  • changing metadata (DPEs)
  • changing archive groups
  • operations with segments
  • changing the settings to the database
  • changing the state of the redundancy
  • turn off the backend.

To process these messages, set a handler on your СonfigChannelHandler object using the setOnDataReceivedHandler method.

Example:

configChannelHandler.setOnDataReceivedHandler([&](DataToBackend& dataFromFrontend)
{
    DataReceivedHandler::processFrontendRequest(dataFromFrontend, configChannelHandler, redundancyState, doExit, logDebugFunc);
});

DataReceivedHandler can handle the following messages:

  • archivegroupdeltaresponse - Contains a message of type ArchiveGroupDeltaRespone for changing archive groups (create, modify, delete).

    DataToBackend dataFromFrontend;
    
    // handle changing archive groups
    if (dataFromFrontend.has_archivegroupdeltaresponse())
    {
        // process archivegroupdeltaresponse
        ArchiveGroupDeltaRespone archiveGroupDeltaResponse = dataFromFrontend.archivegroupdeltaresponse();
        logDebugFunc("The backend processes changing archive groups request: \n" + dataFromFrontend.archivegroupdeltaresponse().DebugString());
    
        MetadataHandler::processArchiveGroups(archiveGroupDeltaResponse);
    
        return;
    }
  • metadataruntimeupdate - Contains a message of type MetadataDeltaResponse for modifying DPEs (create, modify, delete).

    DataToBackend dataFromFrontend;
    // handle changing metadata (DPEs)
    if (dataFromFrontend.has_metadataruntimeupdate())
    {
        // process metadataruntimeupdate
        MetadataDeltaResponse metadataUpdate = dataFromFrontend.metadataruntimeupdate();
        logDebugFunc("The backend processes changing metadata (DPEs) request: \n" + metadataUpdate.DebugString());
        MetadataHandler::processMetadata(metadataUpdate);
    }
  • archiveddpidsrequest - Requests a list of DPEs that are archived with the archive group which data point ID is given in the ArchivedDpIdsRequest message.

    DataToBackend dataFromFrontend;
    
    // updates the DPE list for WinCC OA for the requested archive group
    if (dataFromFrontend.has_archiveddpidsrequest())
    {
        ArchivedDpIdsRequest archivedDpIdsRequest = dataFromFrontend.archiveddpidsrequest();
        logDebugFunc("The backend updates the DPE list for WinCC OA for the requested archive group: \n" + archivedDpIdsRequest.DebugString());
    
        ArchivedDpIdsList archivedDpIdsList;
        // get archive group info 
        const auto& protobufDpIdentifier = archivedDpIdsRequest.groupid();
    
        // prepare dpids
    
        // send dpids of archive group
        configChannelHandler.sendArchivedDpIdsList(archivedDpIdsList);
    }
  • redundancyinfo - The message contains information about the redundant state of the system to which the backend is connected. It is usually shown when the state of the system changes.

    DataToBackend dataFromFrontend;
    // handle changing redundancy state
    if (dataFromFrontend.has_redundancyinfo())
    {
        logDebugFunc("The backend processes changing redundancy state request: \n" + dataFromFrontend.redundancyinfo().DebugString());
        // change redundancy state
        RedundancyInfo redundancyInfo = dataFromFrontend.redundancyinfo();
        logDebugFunc("New redundancy state: " + (redundancyInfo.state() == RedundancyInfo_State_Active ? "Active" : "Passive"));
    
        return;
    }
  • dbparams - Contains modified database settings that should be used (connection string, database name, specific database settings, etc.). In Out-Of-Proc mode , a command to stop the backend is also received through this type of message.

    DataToBackend dataFromFrontend;
    if (dataFromFrontend.has_dbparams())
    {
        DatabaseParameters dbParams = dataFromFrontend.dbparams();
        logDebugFunc("The backend processes changing database parameters request: \n" + dbParams.DebugString());
    
        // stop the backend if the do_shutdown command is received
        // otherwise update configuration 
        if (dbParams.do_shutdown())
        {
            logDebugFunc("The backend receives shutdown command.");
            doExit = true;
        }
        else
        {
            // process updated parameters
            // processDbParameters(dbParams);
        }
    
        return;
    }
  • segmentcommand - Contains a request to perform an operation on segments. The following commands can be received:

    • back up the segment
    • delete a segment
    • restore the segment
    • send a list of segments of the archive group
    • execute a specific command.
    DataToBackend dataFromFrontend;
    
    // handle operations with segments
    if (dataFromFrontend.has_segmentcommand())
    {
        const auto& segmentCommand = dataFromFrontend.segmentcommand();
        const auto commandCase = segmentCommand.command_case();
        bool segmentCommandResult = false;
    
        switch (commandCase)
        {
        case SegmentCommand::kBackupSegmentById:
        {
            logDebugFunc("The backend backups the segment with id: " + segmentCommand.deletesegmentbyid());
    
            // backup segment
            segmentCommandResult = true;
    
            processResultSegmentCommand(configChannelHandler, segmentCommand.groupid(), segmentCommandResult, commandCase);
            break;
        }
        case SegmentCommand::kDeleteSegmentById:
        {
            logDebugFunc("The backend deletes the segment with id: " + segmentCommand.deletesegmentbyid());
    
            // delete segment
            segmentCommandResult = true;
    
            processResultSegmentCommand(configChannelHandler, segmentCommand.groupid(), segmentCommandResult, commandCase);
            break;
        }
        case SegmentCommand::kRestoreSegmentById:
            logDebugFunc("The backend restores the segment with id: " + segmentCommand.restoresegmentbyid());
    
            // restore segment
            segmentCommandResult = true;
            processResultSegmentCommand(configChannelHandler, segmentCommand.groupid(), segmentCommandResult, commandCase);
            break;
        case SegmentCommand::kSpecificCommand:
            logDebugFunc("The backend processes specific command: " + segmentCommand.specificcommand());
            break;
        case SegmentCommand::kUpdateSegmentList:
        {
            logDebugFunc("The backend updates the list of segments with group id: \n" + segmentCommand.groupid().DebugString());
    
            SegmentMetadataList segmentMetadataList;
    
            // prepare segment list
            // get archive group info 
            const auto groupId = segmentCommand.groupid();
    
            // send segment list
            configChannelHandler.sendSegmentMetadataList(segmentMetadataList);
            break;
        }
        }
    }
    //...
    
    void processResultSegmentCommand(ConfigChannelHandler& handler, const ProtobufDpIdentifier& groupId, bool operationResult, SegmentCommand::CommandCase command)
    {
        SegmentCommandResponse response;
        *response.mutable_groupid() = groupId;
    
        const auto responseCode = operationResult ? 0 : -1;
        switch (command)
        {
        case SegmentCommand::kBackupSegmentById:
            response.set_backupresponsecode(responseCode);
            break;
        case SegmentCommand::kDeleteSegmentById:
            response.set_deleteresponsecode(responseCode);
            break;
        case SegmentCommand::kRestoreSegmentById:
            response.set_restoreresponsecode(responseCode);
            break;
        default:
            break;
        }
    
        handler.sendSegmentCommandResponse(response);
    }