Write Handler

Setup the onWriteRequest handler of the CommonBackend class to handle write events.

This handler takes a protobuf message of type DpeList and returns the write result. The NGA Manager has a write timeout if it is exceeded, the write request will be sent again.

Example

commonBackend.onWriteRequest([&](const DpeList& values)
{
  logDebug("Backend processes onWriteRequest request: \n" + values.DebugString());

    if (doExit)
    {
      return false;
    }

    // writing only non direct read mode
    if (directReadMode)
    {
      return true;
    }

    bool writeResult = true;

    writeResult = WriteHandler::writeData(values); // return true if writing successfully otherwise return false

    return writeResult;
});

The data for recording is divided into several types:

  • event recording
  • alarm recording
  • updating the alarm
bool writeData(const DpeList& values)
{
  for (const auto& dp : values.dpelist())
  {
    // get group info
    const auto groupTableIndex = dp.grouptableindex();
    const auto& group = values.groups(groupTableIndex);

    // insert alarm to group
    if (dp.has_dpealarm())
    {
      auto alarm = dp.dpealarm();
    }
    // update alarm in group
    else if (dp.has_dpealarmupdate())
    {
      auto alarmUpdate = dp.dpealarmupdate();
    }
    // insert event to group
    else if (dp.has_dpevalue())
    {
      auto dpeValue = dp.dpevalue();
    }
  }
  return true;
}