text: 
  //---------------------------------------------------------------------
  // This file is automatically generated. All manual edits will be lost.
  //---------------------------------------------------------------------
  // Service implementation for the NI-RFMXINSTR Metadata
  //---------------------------------------------------------------------
  #include "nirfmxinstr_service.h"
  
  #include <sstream>
  #include <fstream>
  #include <iostream>
  #include <atomic>
  #include <vector>
  #include <server/converters.h>
  
  namespace nirfmxinstr_grpc {
  
    using nidevice_grpc::converters::calculate_linked_array_size;
    using nidevice_grpc::converters::convert_from_grpc;
    using nidevice_grpc::converters::convert_to_grpc;
    using nidevice_grpc::converters::MatchState;
  
    const auto kErrorReadBufferTooSmall = -200229;
    const auto kWarningCAPIStringTruncatedToFitBuffer = 200026;
  
    NiRFmxInstrService::NiRFmxInstrService(
        NiRFmxInstrLibraryInterface* library,
        ResourceRepositorySharedPtr session_repository, 
        ViSessionResourceRepositorySharedPtr vi_session_resource_repository,
        const NiRFmxInstrFeatureToggles& feature_toggles)
        : library_(library),
        session_repository_(session_repository),
        vi_session_resource_repository_(vi_session_resource_repository),
        feature_toggles_(feature_toggles)
    {
    }
  
    NiRFmxInstrService::~NiRFmxInstrService()
    {
    }
  
    // Returns true if it's safe to use outputs of a method with the given status.
    inline bool status_ok(int32 status)
    {
      return status >= 0;
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::BuildCalibrationPlaneString(::grpc::ServerContext* context, const BuildCalibrationPlaneStringRequest* request, BuildCalibrationPlaneStringResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        char* calibration_plane_name = (char*)request->calibration_plane_name().c_str();
  
        while (true) {
          auto status = library_->BuildCalibrationPlaneString(calibration_plane_name, 0, nullptr);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          int32 selector_string_length = status;
        
          std::string selector_string;
          if (selector_string_length > 0) {
              selector_string.resize(selector_string_length - 1);
          }
          status = library_->BuildCalibrationPlaneString(calibration_plane_name, selector_string_length, (char*)selector_string.data());
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer || status > static_cast<decltype(status)>(selector_string_length)) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->set_selector_string(selector_string);
            nidevice_grpc::converters::trim_trailing_nulls(*(response->mutable_selector_string()));
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::BuildInstrumentString(::grpc::ServerContext* context, const BuildInstrumentStringRequest* request, BuildInstrumentStringResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        char* selector_string = (char*)request->selector_string().c_str();
        int32 instrument_number = request->instrument_number();
  
        while (true) {
          auto status = library_->BuildInstrumentString(selector_string, instrument_number, 0, nullptr);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          int32 selector_string_out_length = status;
        
          std::string selector_string_out;
          if (selector_string_out_length > 0) {
              selector_string_out.resize(selector_string_out_length - 1);
          }
          status = library_->BuildInstrumentString(selector_string, instrument_number, selector_string_out_length, (char*)selector_string_out.data());
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer || status > static_cast<decltype(status)>(selector_string_out_length)) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->set_selector_string_out(selector_string_out);
            nidevice_grpc::converters::trim_trailing_nulls(*(response->mutable_selector_string_out()));
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::BuildLOString(::grpc::ServerContext* context, const BuildLOStringRequest* request, BuildLOStringResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        char* selector_string = (char*)request->selector_string().c_str();
        int32 lo_index = request->lo_index();
  
        while (true) {
          auto status = library_->BuildLOString(selector_string, lo_index, 0, nullptr);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          int32 selector_string_out_length = status;
        
          std::string selector_string_out;
          if (selector_string_out_length > 0) {
              selector_string_out.resize(selector_string_out_length - 1);
          }
          status = library_->BuildLOString(selector_string, lo_index, selector_string_out_length, (char*)selector_string_out.data());
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer || status > static_cast<decltype(status)>(selector_string_out_length)) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->set_selector_string_out(selector_string_out);
            nidevice_grpc::converters::trim_trailing_nulls(*(response->mutable_selector_string_out()));
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::BuildModuleString(::grpc::ServerContext* context, const BuildModuleStringRequest* request, BuildModuleStringResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        char* selector_string = (char*)request->selector_string().c_str();
        char* module_name = (char*)request->module_name().c_str();
  
        while (true) {
          auto status = library_->BuildModuleString(selector_string, module_name, 0, nullptr);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          int32 selector_string_out_length = status;
        
          std::string selector_string_out;
          if (selector_string_out_length > 0) {
              selector_string_out.resize(selector_string_out_length - 1);
          }
          status = library_->BuildModuleString(selector_string, module_name, selector_string_out_length, (char*)selector_string_out.data());
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer || status > static_cast<decltype(status)>(selector_string_out_length)) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->set_selector_string_out(selector_string_out);
            nidevice_grpc::converters::trim_trailing_nulls(*(response->mutable_selector_string_out()));
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::BuildPortString(::grpc::ServerContext* context, const BuildPortStringRequest* request, BuildPortStringResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        char* selector_string = (char*)request->selector_string().c_str();
        char* port_name = (char*)request->port_name().c_str();
        char* device_name = (char*)request->device_name().c_str();
        int32 channel_number = request->channel_number();
  
        while (true) {
          auto status = library_->BuildPortString(selector_string, port_name, device_name, channel_number, 0, nullptr);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          int32 selector_string_out_length = status;
        
          std::string selector_string_out;
          if (selector_string_out_length > 0) {
              selector_string_out.resize(selector_string_out_length - 1);
          }
          status = library_->BuildPortString(selector_string, port_name, device_name, channel_number, selector_string_out_length, (char*)selector_string_out.data());
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer || status > static_cast<decltype(status)>(selector_string_out_length)) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->set_selector_string_out(selector_string_out);
            nidevice_grpc::converters::trim_trailing_nulls(*(response->mutable_selector_string_out()));
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::CfgExternalAttenuationInterpolationLinear(::grpc::ServerContext* context, const CfgExternalAttenuationInterpolationLinearRequest* request, CfgExternalAttenuationInterpolationLinearResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        char* table_name = (char*)request->table_name().c_str();
        int32 format;
        switch (request->format_enum_case()) {
          case nirfmxinstr_grpc::CfgExternalAttenuationInterpolationLinearRequest::FormatEnumCase::kFormat: {
            format = static_cast<int32>(request->format());
            break;
          }
          case nirfmxinstr_grpc::CfgExternalAttenuationInterpolationLinearRequest::FormatEnumCase::kFormatRaw: {
            format = static_cast<int32>(request->format_raw());
            break;
          }
          case nirfmxinstr_grpc::CfgExternalAttenuationInterpolationLinearRequest::FormatEnumCase::FORMAT_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for format was not specified or out of range");
            break;
          }
        }
  
        auto status = library_->CfgExternalAttenuationInterpolationLinear(instrument, selector_string, table_name, format);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::CfgExternalAttenuationInterpolationNearest(::grpc::ServerContext* context, const CfgExternalAttenuationInterpolationNearestRequest* request, CfgExternalAttenuationInterpolationNearestResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        char* table_name = (char*)request->table_name().c_str();
        auto status = library_->CfgExternalAttenuationInterpolationNearest(instrument, selector_string, table_name);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::CfgExternalAttenuationInterpolationSpline(::grpc::ServerContext* context, const CfgExternalAttenuationInterpolationSplineRequest* request, CfgExternalAttenuationInterpolationSplineResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        char* table_name = (char*)request->table_name().c_str();
        auto status = library_->CfgExternalAttenuationInterpolationSpline(instrument, selector_string, table_name);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::CfgExternalAttenuationTable(::grpc::ServerContext* context, const CfgExternalAttenuationTableRequest* request, CfgExternalAttenuationTableResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        char* table_name = (char*)request->table_name().c_str();
        auto frequency = const_cast<float64*>(request->frequency().data());
        auto external_attenuation = const_cast<float64*>(request->external_attenuation().data());
        auto array_size_determine_from_sizes = std::array<int, 2>
        {
          request->frequency_size(),
          request->external_attenuation_size()
        };
        const auto array_size_size_calculation = calculate_linked_array_size(array_size_determine_from_sizes, false);
  
        if (array_size_size_calculation.match_state == MatchState::MISMATCH) {
          return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The sizes of linked repeated fields [frequency, externalAttenuation] do not match");
        }
        auto array_size = array_size_size_calculation.size;
  
        auto status = library_->CfgExternalAttenuationTable(instrument, selector_string, table_name, frequency, external_attenuation, array_size);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::CfgFrequencyReference(::grpc::ServerContext* context, const CfgFrequencyReferenceRequest* request, CfgFrequencyReferenceResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        char* frequency_reference_source;
        switch (request->frequency_reference_source_enum_case()) {
          case nirfmxinstr_grpc::CfgFrequencyReferenceRequest::FrequencyReferenceSourceEnumCase::kFrequencyReferenceSourceMapped: {
            auto frequency_reference_source_imap_it = frequencyreferencesource_input_map_.find(request->frequency_reference_source_mapped());
            if (frequency_reference_source_imap_it == frequencyreferencesource_input_map_.end()) {
              return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for frequency_reference_source_mapped was not specified or out of range.");
            }
            frequency_reference_source = const_cast<char*>((frequency_reference_source_imap_it->second).c_str());
            break;
          }
          case nirfmxinstr_grpc::CfgFrequencyReferenceRequest::FrequencyReferenceSourceEnumCase::kFrequencyReferenceSourceRaw: {
            frequency_reference_source = const_cast<char*>(request->frequency_reference_source_raw().c_str());
            break;
          }
          case nirfmxinstr_grpc::CfgFrequencyReferenceRequest::FrequencyReferenceSourceEnumCase::FREQUENCY_REFERENCE_SOURCE_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for frequency_reference_source was not specified or out of range");
            break;
          }
        }
  
        float64 frequency_reference_frequency = request->frequency_reference_frequency();
        auto status = library_->CfgFrequencyReference(instrument, channel_name, frequency_reference_source, frequency_reference_frequency);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::CfgMechanicalAttenuation(::grpc::ServerContext* context, const CfgMechanicalAttenuationRequest* request, CfgMechanicalAttenuationResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 mechanical_attenuation_auto;
        switch (request->mechanical_attenuation_auto_enum_case()) {
          case nirfmxinstr_grpc::CfgMechanicalAttenuationRequest::MechanicalAttenuationAutoEnumCase::kMechanicalAttenuationAuto: {
            mechanical_attenuation_auto = static_cast<int32>(request->mechanical_attenuation_auto());
            break;
          }
          case nirfmxinstr_grpc::CfgMechanicalAttenuationRequest::MechanicalAttenuationAutoEnumCase::kMechanicalAttenuationAutoRaw: {
            mechanical_attenuation_auto = static_cast<int32>(request->mechanical_attenuation_auto_raw());
            break;
          }
          case nirfmxinstr_grpc::CfgMechanicalAttenuationRequest::MechanicalAttenuationAutoEnumCase::MECHANICAL_ATTENUATION_AUTO_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for mechanical_attenuation_auto was not specified or out of range");
            break;
          }
        }
  
        float64 mechanical_attenuation_value = request->mechanical_attenuation_value();
        auto status = library_->CfgMechanicalAttenuation(instrument, channel_name, mechanical_attenuation_auto, mechanical_attenuation_value);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::CfgRFAttenuation(::grpc::ServerContext* context, const CfgRFAttenuationRequest* request, CfgRFAttenuationResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 rf_attenuation_auto;
        switch (request->rf_attenuation_auto_enum_case()) {
          case nirfmxinstr_grpc::CfgRFAttenuationRequest::RfAttenuationAutoEnumCase::kRfAttenuationAuto: {
            rf_attenuation_auto = static_cast<int32>(request->rf_attenuation_auto());
            break;
          }
          case nirfmxinstr_grpc::CfgRFAttenuationRequest::RfAttenuationAutoEnumCase::kRfAttenuationAutoRaw: {
            rf_attenuation_auto = static_cast<int32>(request->rf_attenuation_auto_raw());
            break;
          }
          case nirfmxinstr_grpc::CfgRFAttenuationRequest::RfAttenuationAutoEnumCase::RF_ATTENUATION_AUTO_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for rf_attenuation_auto was not specified or out of range");
            break;
          }
        }
  
        float64 rf_attenuation_value = request->rf_attenuation_value();
        auto status = library_->CfgRFAttenuation(instrument, channel_name, rf_attenuation_auto, rf_attenuation_value);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::CfgSParameterExternalAttenuationTable(::grpc::ServerContext* context, const CfgSParameterExternalAttenuationTableRequest* request, CfgSParameterExternalAttenuationTableResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        char* table_name = (char*)request->table_name().c_str();
        auto frequency = const_cast<float64*>(request->frequency().data());
        int32 frequency_array_size = static_cast<int32>(request->frequency().size());
        auto s_parameters = convert_from_grpc<NIComplexDouble>(request->s_parameters());
        int32 s_parameter_table_size = static_cast<int32>(request->s_parameters().size());
        int32 number_of_ports = request->number_of_ports();
        int32 s_parameter_orientation;
        switch (request->s_parameter_orientation_enum_case()) {
          case nirfmxinstr_grpc::CfgSParameterExternalAttenuationTableRequest::SParameterOrientationEnumCase::kSParameterOrientation: {
            s_parameter_orientation = static_cast<int32>(request->s_parameter_orientation());
            break;
          }
          case nirfmxinstr_grpc::CfgSParameterExternalAttenuationTableRequest::SParameterOrientationEnumCase::kSParameterOrientationRaw: {
            s_parameter_orientation = static_cast<int32>(request->s_parameter_orientation_raw());
            break;
          }
          case nirfmxinstr_grpc::CfgSParameterExternalAttenuationTableRequest::SParameterOrientationEnumCase::S_PARAMETER_ORIENTATION_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for s_parameter_orientation was not specified or out of range");
            break;
          }
        }
  
        auto status = library_->CfgSParameterExternalAttenuationTable(instrument, selector_string, table_name, frequency, frequency_array_size, s_parameters.data(), s_parameter_table_size, number_of_ports, s_parameter_orientation);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::CfgSParameterExternalAttenuationType(::grpc::ServerContext* context, const CfgSParameterExternalAttenuationTypeRequest* request, CfgSParameterExternalAttenuationTypeResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        int32 s_parameter_type;
        switch (request->s_parameter_type_enum_case()) {
          case nirfmxinstr_grpc::CfgSParameterExternalAttenuationTypeRequest::SParameterTypeEnumCase::kSParameterType: {
            s_parameter_type = static_cast<int32>(request->s_parameter_type());
            break;
          }
          case nirfmxinstr_grpc::CfgSParameterExternalAttenuationTypeRequest::SParameterTypeEnumCase::kSParameterTypeRaw: {
            s_parameter_type = static_cast<int32>(request->s_parameter_type_raw());
            break;
          }
          case nirfmxinstr_grpc::CfgSParameterExternalAttenuationTypeRequest::SParameterTypeEnumCase::S_PARAMETER_TYPE_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for s_parameter_type was not specified or out of range");
            break;
          }
        }
  
        auto status = library_->CfgSParameterExternalAttenuationType(instrument, selector_string, s_parameter_type);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::CheckAcquisitionStatus(::grpc::ServerContext* context, const CheckAcquisitionStatusRequest* request, CheckAcquisitionStatusResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        int32 acquisition_done {};
        auto status = library_->CheckAcquisitionStatus(instrument, &acquisition_done);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_acquisition_done(static_cast<nirfmxinstr_grpc::Boolean>(acquisition_done));
          response->set_acquisition_done_raw(acquisition_done);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::CheckIfListExists(::grpc::ServerContext* context, const CheckIfListExistsRequest* request, CheckIfListExistsResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* list_name = (char*)request->list_name().c_str();
        int32 list_exists {};
        int32 personality {};
        auto status = library_->CheckIfListExists(instrument, list_name, &list_exists, &personality);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_list_exists(static_cast<nirfmxinstr_grpc::Boolean>(list_exists));
          response->set_list_exists_raw(list_exists);
          response->set_personality(static_cast<nirfmxinstr_grpc::Personality>(personality));
          response->set_personality_raw(personality);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::CheckIfSignalConfigurationExists(::grpc::ServerContext* context, const CheckIfSignalConfigurationExistsRequest* request, CheckIfSignalConfigurationExistsResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* signal_name = (char*)request->signal_name().c_str();
        int32 signal_configuration_exists {};
        int32 personality {};
        auto status = library_->CheckIfSignalConfigurationExists(instrument, signal_name, &signal_configuration_exists, &personality);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_signal_configuration_exists(static_cast<nirfmxinstr_grpc::Boolean>(signal_configuration_exists));
          response->set_signal_configuration_exists_raw(signal_configuration_exists);
          response->set_personality(static_cast<nirfmxinstr_grpc::Personality>(personality));
          response->set_personality_raw(personality);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::Close(::grpc::ServerContext* context, const CloseRequest* request, CloseResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        int32 force_destroy;
        switch (request->force_destroy_enum_case()) {
          case nirfmxinstr_grpc::CloseRequest::ForceDestroyEnumCase::kForceDestroy: {
            force_destroy = static_cast<int32>(request->force_destroy());
            break;
          }
          case nirfmxinstr_grpc::CloseRequest::ForceDestroyEnumCase::kForceDestroyRaw: {
            force_destroy = static_cast<int32>(request->force_destroy_raw());
            break;
          }
          case nirfmxinstr_grpc::CloseRequest::ForceDestroyEnumCase::FORCE_DESTROY_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for force_destroy was not specified or out of range");
            break;
          }
        }
  
        session_repository_->remove_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        auto status = library_->Close(instrument, force_destroy);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::DeleteAllExternalAttenuationTables(::grpc::ServerContext* context, const DeleteAllExternalAttenuationTablesRequest* request, DeleteAllExternalAttenuationTablesResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        auto status = library_->DeleteAllExternalAttenuationTables(instrument, selector_string);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::DeleteExternalAttenuationTable(::grpc::ServerContext* context, const DeleteExternalAttenuationTableRequest* request, DeleteExternalAttenuationTableResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        char* table_name = (char*)request->table_name().c_str();
        auto status = library_->DeleteExternalAttenuationTable(instrument, selector_string, table_name);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::DisableCalibrationPlane(::grpc::ServerContext* context, const DisableCalibrationPlaneRequest* request, DisableCalibrationPlaneResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        auto status = library_->DisableCalibrationPlane(instrument, selector_string);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::EnableCalibrationPlane(::grpc::ServerContext* context, const EnableCalibrationPlaneRequest* request, EnableCalibrationPlaneResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        auto status = library_->EnableCalibrationPlane(instrument, selector_string);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::ExportSignal(::grpc::ServerContext* context, const ExportSignalRequest* request, ExportSignalResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        int32 export_signal_source;
        switch (request->export_signal_source_enum_case()) {
          case nirfmxinstr_grpc::ExportSignalRequest::ExportSignalSourceEnumCase::kExportSignalSource: {
            export_signal_source = static_cast<int32>(request->export_signal_source());
            break;
          }
          case nirfmxinstr_grpc::ExportSignalRequest::ExportSignalSourceEnumCase::kExportSignalSourceRaw: {
            export_signal_source = static_cast<int32>(request->export_signal_source_raw());
            break;
          }
          case nirfmxinstr_grpc::ExportSignalRequest::ExportSignalSourceEnumCase::EXPORT_SIGNAL_SOURCE_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for export_signal_source was not specified or out of range");
            break;
          }
        }
  
        char* export_signal_output_terminal = (char*)request->export_signal_output_terminal().c_str();
        auto status = library_->ExportSignal(instrument, export_signal_source, export_signal_output_terminal);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeF32(::grpc::ServerContext* context, const GetAttributeF32Request* request, GetAttributeF32Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        float32 attr_val {};
        auto status = library_->GetAttributeF32(instrument, channel_name, attribute_id, &attr_val);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_attr_val(attr_val);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeF32Array(::grpc::ServerContext* context, const GetAttributeF32ArrayRequest* request, GetAttributeF32ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int32 actual_array_size {};
        while (true) {
          auto status = library_->GetAttributeF32Array(instrument, channel_name, attribute_id, nullptr, 0, &actual_array_size);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          response->mutable_attr_val()->Resize(actual_array_size, 0);
          float32* attr_val = response->mutable_attr_val()->mutable_data();
          auto array_size = actual_array_size;
          status = library_->GetAttributeF32Array(instrument, channel_name, attribute_id, attr_val, array_size, &actual_array_size);
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->mutable_attr_val()->Resize(actual_array_size, 0);
            response->set_actual_array_size(actual_array_size);
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeF64(::grpc::ServerContext* context, const GetAttributeF64Request* request, GetAttributeF64Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        float64 attr_val {};
        auto status = library_->GetAttributeF64(instrument, channel_name, attribute_id, &attr_val);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_attr_val(attr_val);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeF64Array(::grpc::ServerContext* context, const GetAttributeF64ArrayRequest* request, GetAttributeF64ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int32 actual_array_size {};
        while (true) {
          auto status = library_->GetAttributeF64Array(instrument, channel_name, attribute_id, nullptr, 0, &actual_array_size);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          response->mutable_attr_val()->Resize(actual_array_size, 0);
          float64* attr_val = response->mutable_attr_val()->mutable_data();
          auto array_size = actual_array_size;
          status = library_->GetAttributeF64Array(instrument, channel_name, attribute_id, attr_val, array_size, &actual_array_size);
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->mutable_attr_val()->Resize(actual_array_size, 0);
            response->set_actual_array_size(actual_array_size);
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeI16(::grpc::ServerContext* context, const GetAttributeI16Request* request, GetAttributeI16Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int16 attr_val {};
        auto status = library_->GetAttributeI16(instrument, channel_name, attribute_id, &attr_val);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_attr_val(attr_val);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeI32(::grpc::ServerContext* context, const GetAttributeI32Request* request, GetAttributeI32Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int32 attr_val {};
        auto status = library_->GetAttributeI32(instrument, channel_name, attribute_id, &attr_val);
        response->set_status(status);
        if (status_ok(status)) {
          auto checked_convert_attr_val = [](auto raw_value) {
            bool raw_value_is_valid = nirfmxinstr_grpc::NiRFmxInstrInt32AttributeValues_IsValid(raw_value);
            auto valid_enum_value = raw_value_is_valid ? raw_value : 0;
            return static_cast<nirfmxinstr_grpc::NiRFmxInstrInt32AttributeValues>(valid_enum_value);
          };
          response->set_attr_val(checked_convert_attr_val(attr_val));
          response->set_attr_val_raw(attr_val);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeI32Array(::grpc::ServerContext* context, const GetAttributeI32ArrayRequest* request, GetAttributeI32ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int32 actual_array_size {};
        while (true) {
          auto status = library_->GetAttributeI32Array(instrument, channel_name, attribute_id, nullptr, 0, &actual_array_size);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          response->mutable_attr_val_raw()->Resize(actual_array_size, 0);
          int32* attr_val = reinterpret_cast<int32*>(response->mutable_attr_val_raw()->mutable_data());
          auto array_size = actual_array_size;
          status = library_->GetAttributeI32Array(instrument, channel_name, attribute_id, attr_val, array_size, &actual_array_size);
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            auto checked_convert_attr_val = [](auto raw_value) {
              bool raw_value_is_valid = nirfmxinstr_grpc::NiRFmxInstrInt32AttributeValues_IsValid(raw_value);
              auto valid_enum_value = raw_value_is_valid ? raw_value : 0;
              return static_cast<nirfmxinstr_grpc::NiRFmxInstrInt32AttributeValues>(valid_enum_value);
            };
            response->mutable_attr_val()->Clear();
            response->mutable_attr_val()->Reserve(actual_array_size);
            std::transform(
              response->attr_val_raw().begin(),
              response->attr_val_raw().begin() + actual_array_size,
              google::protobuf::RepeatedFieldBackInserter(response->mutable_attr_val()),
              [&](auto x) { 
                  return checked_convert_attr_val(x);
              });
            response->mutable_attr_val()->Resize(actual_array_size, 0);
            response->set_actual_array_size(actual_array_size);
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeI64(::grpc::ServerContext* context, const GetAttributeI64Request* request, GetAttributeI64Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int64 attr_val {};
        auto status = library_->GetAttributeI64(instrument, channel_name, attribute_id, &attr_val);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_attr_val(attr_val);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeI64Array(::grpc::ServerContext* context, const GetAttributeI64ArrayRequest* request, GetAttributeI64ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int32 actual_array_size {};
        while (true) {
          auto status = library_->GetAttributeI64Array(instrument, channel_name, attribute_id, nullptr, 0, &actual_array_size);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          response->mutable_attr_val()->Resize(actual_array_size, 0);
          int64* attr_val = reinterpret_cast<int64*>(response->mutable_attr_val()->mutable_data());
          auto array_size = actual_array_size;
          status = library_->GetAttributeI64Array(instrument, channel_name, attribute_id, attr_val, array_size, &actual_array_size);
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->mutable_attr_val()->Resize(actual_array_size, 0);
            response->set_actual_array_size(actual_array_size);
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeI8(::grpc::ServerContext* context, const GetAttributeI8Request* request, GetAttributeI8Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int8 attr_val {};
        auto status = library_->GetAttributeI8(instrument, channel_name, attribute_id, &attr_val);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_attr_val(attr_val);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeI8Array(::grpc::ServerContext* context, const GetAttributeI8ArrayRequest* request, GetAttributeI8ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int32 actual_array_size {};
        while (true) {
          auto status = library_->GetAttributeI8Array(instrument, channel_name, attribute_id, nullptr, 0, &actual_array_size);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          std::vector<int8> attr_val(actual_array_size);
          auto array_size = actual_array_size;
          status = library_->GetAttributeI8Array(instrument, channel_name, attribute_id, attr_val.data(), array_size, &actual_array_size);
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->mutable_attr_val()->Clear();
            response->mutable_attr_val()->Reserve(actual_array_size);
            std::transform(
              attr_val.begin(),
              attr_val.begin() + actual_array_size,
              google::protobuf::RepeatedFieldBackInserter(response->mutable_attr_val()),
              [&](auto x) { 
                  return x;
              });
            response->mutable_attr_val()->Resize(actual_array_size, 0);
            response->set_actual_array_size(actual_array_size);
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeNIComplexDoubleArray(::grpc::ServerContext* context, const GetAttributeNIComplexDoubleArrayRequest* request, GetAttributeNIComplexDoubleArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int32 actual_array_size {};
        while (true) {
          auto status = library_->GetAttributeNIComplexDoubleArray(instrument, channel_name, attribute_id, nullptr, 0, &actual_array_size);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          std::vector<NIComplexDouble> attr_val(actual_array_size, NIComplexDouble());
          auto array_size = actual_array_size;
          status = library_->GetAttributeNIComplexDoubleArray(instrument, channel_name, attribute_id, attr_val.data(), array_size, &actual_array_size);
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            convert_to_grpc(attr_val, response->mutable_attr_val());
            {
              auto shrunk_size = actual_array_size;
              auto current_size = response->mutable_attr_val()->size();
              if (shrunk_size != current_size) {
                response->mutable_attr_val()->DeleteSubrange(shrunk_size, current_size - shrunk_size);
              }
            }        
            response->set_actual_array_size(actual_array_size);
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeNIComplexSingleArray(::grpc::ServerContext* context, const GetAttributeNIComplexSingleArrayRequest* request, GetAttributeNIComplexSingleArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int32 actual_array_size {};
        while (true) {
          auto status = library_->GetAttributeNIComplexSingleArray(instrument, channel_name, attribute_id, nullptr, 0, &actual_array_size);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          std::vector<NIComplexSingle> attr_val(actual_array_size, NIComplexSingle());
          auto array_size = actual_array_size;
          status = library_->GetAttributeNIComplexSingleArray(instrument, channel_name, attribute_id, attr_val.data(), array_size, &actual_array_size);
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            convert_to_grpc(attr_val, response->mutable_attr_val());
            {
              auto shrunk_size = actual_array_size;
              auto current_size = response->mutable_attr_val()->size();
              if (shrunk_size != current_size) {
                response->mutable_attr_val()->DeleteSubrange(shrunk_size, current_size - shrunk_size);
              }
            }        
            response->set_actual_array_size(actual_array_size);
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeString(::grpc::ServerContext* context, const GetAttributeStringRequest* request, GetAttributeStringResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
  
        while (true) {
          auto status = library_->GetAttributeString(instrument, channel_name, attribute_id, 0, nullptr);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          int32 array_size = status;
        
          std::string attr_val;
          if (array_size > 0) {
              attr_val.resize(array_size - 1);
          }
          status = library_->GetAttributeString(instrument, channel_name, attribute_id, array_size, (char*)attr_val.data());
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer || status > static_cast<decltype(status)>(array_size)) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->set_attr_val(attr_val);
            nidevice_grpc::converters::trim_trailing_nulls(*(response->mutable_attr_val()));
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeU16(::grpc::ServerContext* context, const GetAttributeU16Request* request, GetAttributeU16Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        uInt16 attr_val {};
        auto status = library_->GetAttributeU16(instrument, channel_name, attribute_id, &attr_val);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_attr_val(attr_val);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeU32(::grpc::ServerContext* context, const GetAttributeU32Request* request, GetAttributeU32Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        uInt32 attr_val {};
        auto status = library_->GetAttributeU32(instrument, channel_name, attribute_id, &attr_val);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_attr_val(attr_val);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeU32Array(::grpc::ServerContext* context, const GetAttributeU32ArrayRequest* request, GetAttributeU32ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int32 actual_array_size {};
        while (true) {
          auto status = library_->GetAttributeU32Array(instrument, channel_name, attribute_id, nullptr, 0, &actual_array_size);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          response->mutable_attr_val()->Resize(actual_array_size, 0);
          uInt32* attr_val = reinterpret_cast<uInt32*>(response->mutable_attr_val()->mutable_data());
          auto array_size = actual_array_size;
          status = library_->GetAttributeU32Array(instrument, channel_name, attribute_id, attr_val, array_size, &actual_array_size);
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->mutable_attr_val()->Resize(actual_array_size, 0);
            response->set_actual_array_size(actual_array_size);
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeU64Array(::grpc::ServerContext* context, const GetAttributeU64ArrayRequest* request, GetAttributeU64ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int32 actual_array_size {};
        while (true) {
          auto status = library_->GetAttributeU64Array(instrument, channel_name, attribute_id, nullptr, 0, &actual_array_size);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          response->mutable_attr_val()->Resize(actual_array_size, 0);
          uInt64* attr_val = reinterpret_cast<uInt64*>(response->mutable_attr_val()->mutable_data());
          auto array_size = actual_array_size;
          status = library_->GetAttributeU64Array(instrument, channel_name, attribute_id, attr_val, array_size, &actual_array_size);
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->mutable_attr_val()->Resize(actual_array_size, 0);
            response->set_actual_array_size(actual_array_size);
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeU8(::grpc::ServerContext* context, const GetAttributeU8Request* request, GetAttributeU8Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        uInt8 attr_val {};
        auto status = library_->GetAttributeU8(instrument, channel_name, attribute_id, &attr_val);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_attr_val(attr_val);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAttributeU8Array(::grpc::ServerContext* context, const GetAttributeU8ArrayRequest* request, GetAttributeU8ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int32 actual_array_size {};
        while (true) {
          auto status = library_->GetAttributeU8Array(instrument, channel_name, attribute_id, nullptr, 0, &actual_array_size);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          std::string attr_val(actual_array_size, '\0');
          auto array_size = actual_array_size;
          status = library_->GetAttributeU8Array(instrument, channel_name, attribute_id, (uInt8*)attr_val.data(), array_size, &actual_array_size);
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->set_attr_val(attr_val);
            response->mutable_attr_val()->resize(actual_array_size);
            response->set_actual_array_size(actual_array_size);
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetAvailablePorts(::grpc::ServerContext* context, const GetAvailablePortsRequest* request, GetAvailablePortsResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
  
        while (true) {
          auto status = library_->GetAvailablePorts(instrument, selector_string, 0, nullptr);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          int32 array_size = status;
        
          std::string available_ports;
          if (array_size > 0) {
              available_ports.resize(array_size - 1);
          }
          status = library_->GetAvailablePorts(instrument, selector_string, array_size, (char*)available_ports.data());
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer || status > static_cast<decltype(status)>(array_size)) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->set_available_ports(available_ports);
            nidevice_grpc::converters::trim_trailing_nulls(*(response->mutable_available_ports()));
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetError(::grpc::ServerContext* context, const GetErrorRequest* request, GetErrorResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
  
        while (true) {
          auto status = library_->GetError(instrument, nullptr, 0, nullptr);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          int32 error_description_buffer_size = status;
        
          int32 error_code {};
          std::string error_description;
          if (error_description_buffer_size > 0) {
              error_description.resize(error_description_buffer_size - 1);
          }
          status = library_->GetError(instrument, &error_code, error_description_buffer_size, (char*)error_description.data());
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer || status > static_cast<decltype(status)>(error_description_buffer_size)) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->set_error_code(error_code);
            response->set_error_description(error_description);
            nidevice_grpc::converters::trim_trailing_nulls(*(response->mutable_error_description()));
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetErrorString(::grpc::ServerContext* context, const GetErrorStringRequest* request, GetErrorStringResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        int32 error_code = request->error_code();
  
        while (true) {
          auto status = library_->GetErrorString(instrument, error_code, 0, nullptr);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          int32 error_description_buffer_size = status;
        
          std::string error_description;
          if (error_description_buffer_size > 0) {
              error_description.resize(error_description_buffer_size - 1);
          }
          status = library_->GetErrorString(instrument, error_code, error_description_buffer_size, (char*)error_description.data());
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer || status > static_cast<decltype(status)>(error_description_buffer_size)) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->set_error_description(error_description);
            nidevice_grpc::converters::trim_trailing_nulls(*(response->mutable_error_description()));
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetExternalAttenuationTableActualValue(::grpc::ServerContext* context, const GetExternalAttenuationTableActualValueRequest* request, GetExternalAttenuationTableActualValueResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        float64 external_attenuation {};
        auto status = library_->GetExternalAttenuationTableActualValue(instrument, selector_string, &external_attenuation);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_external_attenuation(external_attenuation);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetListNames(::grpc::ServerContext* context, const GetListNamesRequest* request, GetListNamesResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        int32 personality_filter;
        switch (request->personality_filter_enum_case()) {
          case nirfmxinstr_grpc::GetListNamesRequest::PersonalityFilterEnumCase::kPersonalityFilter: {
            personality_filter = static_cast<int32>(request->personality_filter());
            break;
          }
          case nirfmxinstr_grpc::GetListNamesRequest::PersonalityFilterEnumCase::kPersonalityFilterRaw: {
            personality_filter = static_cast<int32>(request->personality_filter_raw());
            break;
          }
          case nirfmxinstr_grpc::GetListNamesRequest::PersonalityFilterEnumCase::PERSONALITY_FILTER_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for personality_filter was not specified or out of range");
            break;
          }
        }
  
        int32 actual_list_names_size {};
        int32 actual_personality_array_size {};
        while (true) {
          auto status = library_->GetListNames(instrument, selector_string, personality_filter, nullptr, 0, &actual_list_names_size, nullptr, 0, &actual_personality_array_size);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          std::string list_names;
          if (actual_list_names_size > 0) {
              list_names.resize(actual_list_names_size - 1);
          }
          response->mutable_personality_raw()->Resize(actual_personality_array_size, 0);
          int32* personality = reinterpret_cast<int32*>(response->mutable_personality_raw()->mutable_data());
          auto list_names_size = actual_list_names_size;
          auto personality_array_size = actual_personality_array_size;
          status = library_->GetListNames(instrument, selector_string, personality_filter, (char*)list_names.data(), list_names_size, &actual_list_names_size, personality, personality_array_size, &actual_personality_array_size);
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->set_list_names(list_names);
            nidevice_grpc::converters::trim_trailing_nulls(*(response->mutable_list_names()));
            response->set_actual_list_names_size(actual_list_names_size);
            response->mutable_personality()->Clear();
            response->mutable_personality()->Reserve(actual_personality_array_size);
            std::transform(
              response->personality_raw().begin(),
              response->personality_raw().begin() + actual_personality_array_size,
              google::protobuf::RepeatedFieldBackInserter(response->mutable_personality()),
              [&](auto x) { 
                  return static_cast<nirfmxinstr_grpc::Personality>(x);
              });
            response->mutable_personality()->Resize(actual_personality_array_size, 0);
            response->set_actual_personality_array_size(actual_personality_array_size);
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetNIRFSASession(::grpc::ServerContext* context, const GetNIRFSASessionRequest* request, GetNIRFSASessionResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
  
        auto initiating_session_id = session_repository_->access_session_id(instrument_grpc_session.id(), instrument_grpc_session.name());
        auto init_lambda = [&] () {
          ViSession ni_rfsa_session;
          int status = library_->GetNIRFSASession(instrument, &ni_rfsa_session);
          return std::make_tuple(status, ni_rfsa_session);
        };
        uint32_t session_id = 0;
        const std::string& grpc_device_session_name = request->session_name();
        int status = vi_session_resource_repository_->add_dependent_session(grpc_device_session_name, init_lambda, initiating_session_id, session_id);
        response->set_status(status);
        if (status == 0) {
          response->mutable_ni_rfsa_session()->set_id(session_id);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetSelfCalibrateLastDateAndTime(::grpc::ServerContext* context, const GetSelfCalibrateLastDateAndTimeRequest* request, GetSelfCalibrateLastDateAndTimeResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        int64 self_calibrate_step;
        switch (request->self_calibrate_step_enum_case()) {
          case nirfmxinstr_grpc::GetSelfCalibrateLastDateAndTimeRequest::SelfCalibrateStepEnumCase::kSelfCalibrateStep: {
            self_calibrate_step = static_cast<int64>(request->self_calibrate_step());
            break;
          }
          case nirfmxinstr_grpc::GetSelfCalibrateLastDateAndTimeRequest::SelfCalibrateStepEnumCase::kSelfCalibrateStepRaw: {
            self_calibrate_step = static_cast<int64>(request->self_calibrate_step_raw());
            break;
          }
          case nirfmxinstr_grpc::GetSelfCalibrateLastDateAndTimeRequest::SelfCalibrateStepEnumCase::SELF_CALIBRATE_STEP_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for self_calibrate_step was not specified or out of range");
            break;
          }
        }
  
        CVIAbsoluteTime timestamp {};
        auto status = library_->GetSelfCalibrateLastDateAndTime(instrument, selector_string, self_calibrate_step, &timestamp);
        response->set_status(status);
        if (status_ok(status)) {
          convert_to_grpc(timestamp, response->mutable_timestamp());
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetSelfCalibrateLastTemperature(::grpc::ServerContext* context, const GetSelfCalibrateLastTemperatureRequest* request, GetSelfCalibrateLastTemperatureResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        int64 self_calibrate_step;
        switch (request->self_calibrate_step_enum_case()) {
          case nirfmxinstr_grpc::GetSelfCalibrateLastTemperatureRequest::SelfCalibrateStepEnumCase::kSelfCalibrateStep: {
            self_calibrate_step = static_cast<int64>(request->self_calibrate_step());
            break;
          }
          case nirfmxinstr_grpc::GetSelfCalibrateLastTemperatureRequest::SelfCalibrateStepEnumCase::kSelfCalibrateStepRaw: {
            self_calibrate_step = static_cast<int64>(request->self_calibrate_step_raw());
            break;
          }
          case nirfmxinstr_grpc::GetSelfCalibrateLastTemperatureRequest::SelfCalibrateStepEnumCase::SELF_CALIBRATE_STEP_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for self_calibrate_step was not specified or out of range");
            break;
          }
        }
  
        float64 temperature {};
        auto status = library_->GetSelfCalibrateLastTemperature(instrument, selector_string, self_calibrate_step, &temperature);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_temperature(temperature);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::GetSignalConfigurationNames(::grpc::ServerContext* context, const GetSignalConfigurationNamesRequest* request, GetSignalConfigurationNamesResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        int32 personality_filter;
        switch (request->personality_filter_enum_case()) {
          case nirfmxinstr_grpc::GetSignalConfigurationNamesRequest::PersonalityFilterEnumCase::kPersonalityFilter: {
            personality_filter = static_cast<int32>(request->personality_filter());
            break;
          }
          case nirfmxinstr_grpc::GetSignalConfigurationNamesRequest::PersonalityFilterEnumCase::kPersonalityFilterRaw: {
            personality_filter = static_cast<int32>(request->personality_filter_raw());
            break;
          }
          case nirfmxinstr_grpc::GetSignalConfigurationNamesRequest::PersonalityFilterEnumCase::PERSONALITY_FILTER_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for personality_filter was not specified or out of range");
            break;
          }
        }
  
        int32 actual_signal_names_size {};
        int32 actual_personality_array_size {};
        while (true) {
          auto status = library_->GetSignalConfigurationNames(instrument, selector_string, personality_filter, nullptr, 0, &actual_signal_names_size, nullptr, 0, &actual_personality_array_size);
          if (status < 0) {
            response->set_status(status);
            return ::grpc::Status::OK;
          }
          std::string signal_names;
          if (actual_signal_names_size > 0) {
              signal_names.resize(actual_signal_names_size - 1);
          }
          response->mutable_personality()->Resize(actual_personality_array_size, 0);
          int32* personality = reinterpret_cast<int32*>(response->mutable_personality()->mutable_data());
          auto personality_array_size = actual_personality_array_size;
          auto signal_names_size = actual_signal_names_size;
          status = library_->GetSignalConfigurationNames(instrument, selector_string, personality_filter, (char*)signal_names.data(), signal_names_size, &actual_signal_names_size, personality, personality_array_size, &actual_personality_array_size);
          if (status == kErrorReadBufferTooSmall || status == kWarningCAPIStringTruncatedToFitBuffer) {
            // buffer is now too small, try again
            continue;
          }
          response->set_status(status);
          if (status_ok(status)) {
            response->set_signal_names(signal_names);
            nidevice_grpc::converters::trim_trailing_nulls(*(response->mutable_signal_names()));
            response->set_actual_signal_names_size(actual_signal_names_size);
            response->mutable_personality()->Resize(actual_personality_array_size, 0);
            response->set_actual_personality_array_size(actual_personality_array_size);
          }
          return ::grpc::Status::OK;
        }
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::Initialize(::grpc::ServerContext* context, const InitializeRequest* request, InitializeResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        char* resource_name = (char*)request->resource_name().c_str();
        char* option_string = (char*)request->option_string().c_str();
  
        int32 is_new_session {};
        auto init_lambda = [&] () {
          niRFmxInstrHandle instrument;
          int status = library_->Initialize(resource_name, option_string, &instrument, &is_new_session);
          return std::make_tuple(status, instrument);
        };
        uint32_t session_id = 0;
        const std::string& grpc_device_session_name = request->session_name();
        auto cleanup_lambda = [&] (niRFmxInstrHandle id) { library_->Close(id, RFMXINSTR_VAL_FALSE); };
        int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda, session_id);
        response->set_status(status);
        if (status_ok(status)) {
          response->mutable_instrument()->set_id(session_id);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::InitializeFromNIRFSASession(::grpc::ServerContext* context, const InitializeFromNIRFSASessionRequest* request, InitializeFromNIRFSASessionResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto nirfsa_session_grpc_session = request->nirfsa_session();
        uInt32 nirfsa_session = vi_session_resource_repository_->access_session(nirfsa_session_grpc_session.id(), nirfsa_session_grpc_session.name());
  
        auto init_lambda = [&] () {
          niRFmxInstrHandle instrument;
          int status = library_->InitializeFromNIRFSASession(nirfsa_session, &instrument);
          return std::make_tuple(status, instrument);
        };
        uint32_t session_id = 0;
        const std::string& grpc_device_session_name = request->session_name();
        auto cleanup_lambda = [&] (niRFmxInstrHandle id) { library_->Close(id, RFMXINSTR_VAL_FALSE); };
        int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda, session_id);
        response->set_status(status);
        if (status_ok(status)) {
          response->mutable_instrument()->set_id(session_id);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::InitializeFromNIRFSASessionArray(::grpc::ServerContext* context, const InitializeFromNIRFSASessionArrayRequest* request, InitializeFromNIRFSASessionArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto nirfsa_sessions_request = request->nirfsa_sessions();
        std::vector<uInt32> nirfsa_sessions;
        std::transform(
          nirfsa_sessions_request.begin(),
          nirfsa_sessions_request.end(),
          std::back_inserter(nirfsa_sessions),
          [&](auto session) { return vi_session_resource_repository_->access_session(session.id(), session.name()); }); 
        int32 number_of_nirfsa_sessions = static_cast<int32>(request->nirfsa_sessions().size());
  
        auto init_lambda = [&] () {
          niRFmxInstrHandle instrument;
          int status = library_->InitializeFromNIRFSASessionArray(nirfsa_sessions.data(), number_of_nirfsa_sessions, &instrument);
          return std::make_tuple(status, instrument);
        };
        uint32_t session_id = 0;
        const std::string& grpc_device_session_name = request->session_name();
        auto cleanup_lambda = [&] (niRFmxInstrHandle id) { library_->Close(id, RFMXINSTR_VAL_FALSE); };
        int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda, session_id);
        response->set_status(status);
        if (status_ok(status)) {
          response->mutable_instrument()->set_id(session_id);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::IsSelfCalibrateValid(::grpc::ServerContext* context, const IsSelfCalibrateValidRequest* request, IsSelfCalibrateValidResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        int32 self_calibrate_valid {};
        int32 valid_steps {};
        auto status = library_->IsSelfCalibrateValid(instrument, selector_string, &self_calibrate_valid, &valid_steps);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_self_calibrate_valid(static_cast<nirfmxinstr_grpc::Boolean>(self_calibrate_valid));
          response->set_self_calibrate_valid_raw(self_calibrate_valid);
          if (valid_steps & 0x20)
            response->add_valid_steps_array(SelfCalStep::SELF_CAL_STEP_AMPLITUDE_ACCURACY);
          if (valid_steps & 0x200)
            response->add_valid_steps_array(SelfCalStep::SELF_CAL_STEP_DC_OFFSET);
          if (valid_steps & 0x8)
            response->add_valid_steps_array(SelfCalStep::SELF_CAL_STEP_DIGITIZER_SELF_CAL);
          if (valid_steps & 0x2)
            response->add_valid_steps_array(SelfCalStep::SELF_CAL_STEP_GAIN_REFERENCE);
          if (valid_steps & 0x4)
            response->add_valid_steps_array(SelfCalStep::SELF_CAL_STEP_IF_FLATNESS);
          if (valid_steps & 0x80)
            response->add_valid_steps_array(SelfCalStep::SELF_CAL_STEP_IMAGE_SUPPRESSION);
          if (valid_steps & 0x10)
            response->add_valid_steps_array(SelfCalStep::SELF_CAL_STEP_LO_SELF_CAL);
          if (valid_steps & 0x1)
            response->add_valid_steps_array(SelfCalStep::SELF_CAL_STEP_PRESELECTOR_ALIGNMENT);
          if (valid_steps & 0x40)
            response->add_valid_steps_array(SelfCalStep::SELF_CAL_STEP_RESIDUAL_LO_POWER);
          if (valid_steps & 0x100)
            response->add_valid_steps_array(SelfCalStep::SELF_CAL_STEP_SYNTHESIZER_ALIGNMENT);
          response->set_valid_steps_raw(valid_steps);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::LoadAllConfigurations(::grpc::ServerContext* context, const LoadAllConfigurationsRequest* request, LoadAllConfigurationsResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* file_path = (char*)request->file_path().c_str();
        int32 load_rf_instr_configuration = request->load_rf_instr_configuration();
        auto status = library_->LoadAllConfigurations(instrument, file_path, load_rf_instr_configuration);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::LoadSParameterExternalAttenuationTableFromS2PFile(::grpc::ServerContext* context, const LoadSParameterExternalAttenuationTableFromS2PFileRequest* request, LoadSParameterExternalAttenuationTableFromS2PFileResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        char* table_name = (char*)request->table_name().c_str();
        char* s2_p_file_path = (char*)request->s2_p_file_path().c_str();
        int32 s_parameter_orientation;
        switch (request->s_parameter_orientation_enum_case()) {
          case nirfmxinstr_grpc::LoadSParameterExternalAttenuationTableFromS2PFileRequest::SParameterOrientationEnumCase::kSParameterOrientation: {
            s_parameter_orientation = static_cast<int32>(request->s_parameter_orientation());
            break;
          }
          case nirfmxinstr_grpc::LoadSParameterExternalAttenuationTableFromS2PFileRequest::SParameterOrientationEnumCase::kSParameterOrientationRaw: {
            s_parameter_orientation = static_cast<int32>(request->s_parameter_orientation_raw());
            break;
          }
          case nirfmxinstr_grpc::LoadSParameterExternalAttenuationTableFromS2PFileRequest::SParameterOrientationEnumCase::S_PARAMETER_ORIENTATION_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for s_parameter_orientation was not specified or out of range");
            break;
          }
        }
  
        auto status = library_->LoadSParameterExternalAttenuationTableFromS2PFile(instrument, selector_string, table_name, s2_p_file_path, s_parameter_orientation);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::ResetAttribute(::grpc::ServerContext* context, const ResetAttributeRequest* request, ResetAttributeResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        auto status = library_->ResetAttribute(instrument, channel_name, attribute_id);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::ResetDriver(::grpc::ServerContext* context, const ResetDriverRequest* request, ResetDriverResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        auto status = library_->ResetDriver(instrument);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::ResetEntireSession(::grpc::ServerContext* context, const ResetEntireSessionRequest* request, ResetEntireSessionResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        auto status = library_->ResetEntireSession(instrument);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::ResetToDefault(::grpc::ServerContext* context, const ResetToDefaultRequest* request, ResetToDefaultResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        auto status = library_->ResetToDefault(instrument);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SaveAllConfigurations(::grpc::ServerContext* context, const SaveAllConfigurationsRequest* request, SaveAllConfigurationsResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* file_path = (char*)request->file_path().c_str();
        auto status = library_->SaveAllConfigurations(instrument, file_path);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SelectActiveExternalAttenuationTable(::grpc::ServerContext* context, const SelectActiveExternalAttenuationTableRequest* request, SelectActiveExternalAttenuationTableResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        char* table_name = (char*)request->table_name().c_str();
        auto status = library_->SelectActiveExternalAttenuationTable(instrument, selector_string, table_name);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SelfCalibrate(::grpc::ServerContext* context, const SelfCalibrateRequest* request, SelfCalibrateResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        int32 steps_to_omit;
        switch (request->steps_to_omit_enum_case()) {
          case nirfmxinstr_grpc::SelfCalibrateRequest::StepsToOmitEnumCase::kStepsToOmit: {
            steps_to_omit = static_cast<int32>(request->steps_to_omit());
            break;
          }
          case nirfmxinstr_grpc::SelfCalibrateRequest::StepsToOmitEnumCase::kStepsToOmitRaw: {
            steps_to_omit = static_cast<int32>(request->steps_to_omit_raw());
            break;
          }
          case nirfmxinstr_grpc::SelfCalibrateRequest::StepsToOmitEnumCase::STEPS_TO_OMIT_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for steps_to_omit was not specified or out of range");
            break;
          }
        }
  
        auto status = library_->SelfCalibrate(instrument, selector_string, steps_to_omit);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SelfCalibrateRange(::grpc::ServerContext* context, const SelfCalibrateRangeRequest* request, SelfCalibrateRangeResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* selector_string = (char*)request->selector_string().c_str();
        int32 steps_to_omit;
        switch (request->steps_to_omit_enum_case()) {
          case nirfmxinstr_grpc::SelfCalibrateRangeRequest::StepsToOmitEnumCase::kStepsToOmit: {
            steps_to_omit = static_cast<int32>(request->steps_to_omit());
            break;
          }
          case nirfmxinstr_grpc::SelfCalibrateRangeRequest::StepsToOmitEnumCase::kStepsToOmitRaw: {
            steps_to_omit = static_cast<int32>(request->steps_to_omit_raw());
            break;
          }
          case nirfmxinstr_grpc::SelfCalibrateRangeRequest::StepsToOmitEnumCase::STEPS_TO_OMIT_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for steps_to_omit was not specified or out of range");
            break;
          }
        }
  
        float64 minimum_frequency = request->minimum_frequency();
        float64 maximum_frequency = request->maximum_frequency();
        float64 minimum_reference_level = request->minimum_reference_level();
        float64 maximum_reference_level = request->maximum_reference_level();
        auto status = library_->SelfCalibrateRange(instrument, selector_string, steps_to_omit, minimum_frequency, maximum_frequency, minimum_reference_level, maximum_reference_level);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SendSoftwareEdgeAdvanceTrigger(::grpc::ServerContext* context, const SendSoftwareEdgeAdvanceTriggerRequest* request, SendSoftwareEdgeAdvanceTriggerResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        auto status = library_->SendSoftwareEdgeAdvanceTrigger(instrument);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SendSoftwareEdgeStartTrigger(::grpc::ServerContext* context, const SendSoftwareEdgeStartTriggerRequest* request, SendSoftwareEdgeStartTriggerResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        auto status = library_->SendSoftwareEdgeStartTrigger(instrument);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeF32(::grpc::ServerContext* context, const SetAttributeF32Request* request, SetAttributeF32Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        float32 attr_val = request->attr_val();
        auto status = library_->SetAttributeF32(instrument, channel_name, attribute_id, attr_val);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeF32Array(::grpc::ServerContext* context, const SetAttributeF32ArrayRequest* request, SetAttributeF32ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        auto attr_val = const_cast<float32*>(request->attr_val().data());
        int32 array_size = static_cast<int32>(request->attr_val().size());
        auto status = library_->SetAttributeF32Array(instrument, channel_name, attribute_id, attr_val, array_size);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeF64(::grpc::ServerContext* context, const SetAttributeF64Request* request, SetAttributeF64Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        float64 attr_val = request->attr_val();
        auto status = library_->SetAttributeF64(instrument, channel_name, attribute_id, attr_val);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeF64Array(::grpc::ServerContext* context, const SetAttributeF64ArrayRequest* request, SetAttributeF64ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        auto attr_val = const_cast<float64*>(request->attr_val().data());
        int32 array_size = static_cast<int32>(request->attr_val().size());
        auto status = library_->SetAttributeF64Array(instrument, channel_name, attribute_id, attr_val, array_size);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeI16(::grpc::ServerContext* context, const SetAttributeI16Request* request, SetAttributeI16Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        auto attr_val_raw = request->attr_val();
        if (attr_val_raw < std::numeric_limits<int16>::min() || attr_val_raw > std::numeric_limits<int16>::max()) {
            std::string message("value ");
            message.append(std::to_string(attr_val_raw));
            message.append(" doesn't fit in datatype ");
            message.append("int16");
            throw nidevice_grpc::ValueOutOfRangeException(message);
        }
        auto attr_val = static_cast<int16>(attr_val_raw);
  
        auto status = library_->SetAttributeI16(instrument, channel_name, attribute_id, attr_val);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
      catch (nidevice_grpc::ValueOutOfRangeException& ex) {
        return ::grpc::Status(::grpc::OUT_OF_RANGE, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeI32(::grpc::ServerContext* context, const SetAttributeI32Request* request, SetAttributeI32Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int32 attr_val;
        switch (request->attr_val_enum_case()) {
          case nirfmxinstr_grpc::SetAttributeI32Request::AttrValEnumCase::kAttrVal: {
            attr_val = static_cast<int32>(request->attr_val());
            break;
          }
          case nirfmxinstr_grpc::SetAttributeI32Request::AttrValEnumCase::kAttrValRaw: {
            attr_val = static_cast<int32>(request->attr_val_raw());
            break;
          }
          case nirfmxinstr_grpc::SetAttributeI32Request::AttrValEnumCase::ATTR_VAL_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for attr_val was not specified or out of range");
            break;
          }
        }
  
        auto status = library_->SetAttributeI32(instrument, channel_name, attribute_id, attr_val);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeI32Array(::grpc::ServerContext* context, const SetAttributeI32ArrayRequest* request, SetAttributeI32ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        auto attr_val_vector = std::vector<int32>();
        attr_val_vector.reserve(request->attr_val().size());
        std::transform(
          request->attr_val().begin(),
          request->attr_val().end(),
          std::back_inserter(attr_val_vector),
          [](auto x) { return x; });
        auto attr_val = attr_val_vector.data();
  
        int32 array_size = static_cast<int32>(request->attr_val().size());
        auto status = library_->SetAttributeI32Array(instrument, channel_name, attribute_id, attr_val, array_size);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeI64(::grpc::ServerContext* context, const SetAttributeI64Request* request, SetAttributeI64Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        int64 attr_val = request->attr_val();
        auto status = library_->SetAttributeI64(instrument, channel_name, attribute_id, attr_val);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeI64Array(::grpc::ServerContext* context, const SetAttributeI64ArrayRequest* request, SetAttributeI64ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        auto attr_val = const_cast<int64*>(reinterpret_cast<const int64*>(request->attr_val().data()));
        int32 array_size = static_cast<int32>(request->attr_val().size());
        auto status = library_->SetAttributeI64Array(instrument, channel_name, attribute_id, attr_val, array_size);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeI8(::grpc::ServerContext* context, const SetAttributeI8Request* request, SetAttributeI8Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        auto attr_val_raw = request->attr_val();
        if (attr_val_raw < std::numeric_limits<int8>::min() || attr_val_raw > std::numeric_limits<int8>::max()) {
            std::string message("value ");
            message.append(std::to_string(attr_val_raw));
            message.append(" doesn't fit in datatype ");
            message.append("int8");
            throw nidevice_grpc::ValueOutOfRangeException(message);
        }
        auto attr_val = static_cast<int8>(attr_val_raw);
  
        auto status = library_->SetAttributeI8(instrument, channel_name, attribute_id, attr_val);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
      catch (nidevice_grpc::ValueOutOfRangeException& ex) {
        return ::grpc::Status(::grpc::OUT_OF_RANGE, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeI8Array(::grpc::ServerContext* context, const SetAttributeI8ArrayRequest* request, SetAttributeI8ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        auto attr_val_raw = request->attr_val();
        auto attr_val = std::vector<int8>();
        attr_val.reserve(attr_val_raw.size());
        std::transform(
          attr_val_raw.begin(),
          attr_val_raw.end(),
          std::back_inserter(attr_val),
          [](auto x) { 
                if (x < std::numeric_limits<int8>::min() || x > std::numeric_limits<int8>::max()) {
                    std::string message("value ");
                    message.append(std::to_string(x));
                    message.append(" doesn't fit in datatype ");
                    message.append("int8");
                    throw nidevice_grpc::ValueOutOfRangeException(message);
                }
                return static_cast<int8>(x);
          });
  
        int32 array_size = static_cast<int32>(request->attr_val().size());
        auto status = library_->SetAttributeI8Array(instrument, channel_name, attribute_id, attr_val.data(), array_size);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
      catch (nidevice_grpc::ValueOutOfRangeException& ex) {
        return ::grpc::Status(::grpc::OUT_OF_RANGE, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeNIComplexDoubleArray(::grpc::ServerContext* context, const SetAttributeNIComplexDoubleArrayRequest* request, SetAttributeNIComplexDoubleArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        auto attr_val = convert_from_grpc<NIComplexDouble>(request->attr_val());
        int32 array_size = static_cast<int32>(request->attr_val().size());
        auto status = library_->SetAttributeNIComplexDoubleArray(instrument, channel_name, attribute_id, attr_val.data(), array_size);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeNIComplexSingleArray(::grpc::ServerContext* context, const SetAttributeNIComplexSingleArrayRequest* request, SetAttributeNIComplexSingleArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        auto attr_val = convert_from_grpc<NIComplexSingle>(request->attr_val());
        int32 array_size = static_cast<int32>(request->attr_val().size());
        auto status = library_->SetAttributeNIComplexSingleArray(instrument, channel_name, attribute_id, attr_val.data(), array_size);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeString(::grpc::ServerContext* context, const SetAttributeStringRequest* request, SetAttributeStringResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        char* attr_val;
        switch (request->attr_val_enum_case()) {
          case nirfmxinstr_grpc::SetAttributeStringRequest::AttrValEnumCase::kAttrValMapped: {
            auto attr_val_imap_it = nirfmxinstrstringattributevaluesmapped_input_map_.find(request->attr_val_mapped());
            if (attr_val_imap_it == nirfmxinstrstringattributevaluesmapped_input_map_.end()) {
              return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for attr_val_mapped was not specified or out of range.");
            }
            attr_val = const_cast<char*>((attr_val_imap_it->second).c_str());
            break;
          }
          case nirfmxinstr_grpc::SetAttributeStringRequest::AttrValEnumCase::kAttrValRaw: {
            attr_val = const_cast<char*>(request->attr_val_raw().c_str());
            break;
          }
          case nirfmxinstr_grpc::SetAttributeStringRequest::AttrValEnumCase::ATTR_VAL_ENUM_NOT_SET: {
            return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for attr_val was not specified or out of range");
            break;
          }
        }
  
        auto status = library_->SetAttributeString(instrument, channel_name, attribute_id, attr_val);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeU16(::grpc::ServerContext* context, const SetAttributeU16Request* request, SetAttributeU16Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        auto attr_val_raw = request->attr_val();
        if (attr_val_raw < std::numeric_limits<uInt16>::min() || attr_val_raw > std::numeric_limits<uInt16>::max()) {
            std::string message("value ");
            message.append(std::to_string(attr_val_raw));
            message.append(" doesn't fit in datatype ");
            message.append("uInt16");
            throw nidevice_grpc::ValueOutOfRangeException(message);
        }
        auto attr_val = static_cast<uInt16>(attr_val_raw);
  
        auto status = library_->SetAttributeU16(instrument, channel_name, attribute_id, attr_val);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
      catch (nidevice_grpc::ValueOutOfRangeException& ex) {
        return ::grpc::Status(::grpc::OUT_OF_RANGE, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeU32(::grpc::ServerContext* context, const SetAttributeU32Request* request, SetAttributeU32Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        uInt32 attr_val = request->attr_val();
        auto status = library_->SetAttributeU32(instrument, channel_name, attribute_id, attr_val);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeU32Array(::grpc::ServerContext* context, const SetAttributeU32ArrayRequest* request, SetAttributeU32ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        auto attr_val = const_cast<uInt32*>(reinterpret_cast<const uInt32*>(request->attr_val().data()));
        int32 array_size = static_cast<int32>(request->attr_val().size());
        auto status = library_->SetAttributeU32Array(instrument, channel_name, attribute_id, attr_val, array_size);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeU64Array(::grpc::ServerContext* context, const SetAttributeU64ArrayRequest* request, SetAttributeU64ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        auto attr_val = const_cast<uInt64*>(reinterpret_cast<const uInt64*>(request->attr_val().data()));
        int32 array_size = static_cast<int32>(request->attr_val().size());
        auto status = library_->SetAttributeU64Array(instrument, channel_name, attribute_id, attr_val, array_size);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeU8(::grpc::ServerContext* context, const SetAttributeU8Request* request, SetAttributeU8Response* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        uInt8 attr_val = request->attr_val();
        auto status = library_->SetAttributeU8(instrument, channel_name, attribute_id, attr_val);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::SetAttributeU8Array(::grpc::ServerContext* context, const SetAttributeU8ArrayRequest* request, SetAttributeU8ArrayResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        char* channel_name = (char*)request->channel_name().c_str();
        int32 attribute_id = request->attribute_id();
        uInt8* attr_val = (uInt8*)request->attr_val().c_str();
        int32 array_size = static_cast<int32>(request->attr_val().size());
        auto status = library_->SetAttributeU8Array(instrument, channel_name, attribute_id, attr_val, array_size);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::TimestampFromValues(::grpc::ServerContext* context, const TimestampFromValuesRequest* request, TimestampFromValuesResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        int64 seconds_since1970 = request->seconds_since1970();
        float64 fractional_seconds = request->fractional_seconds();
        CVIAbsoluteTime timestamp {};
        auto status = library_->TimestampFromValues(seconds_since1970, fractional_seconds, &timestamp);
        response->set_status(status);
        if (status_ok(status)) {
          convert_to_grpc(timestamp, response->mutable_timestamp());
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::ValuesFromTimestamp(::grpc::ServerContext* context, const ValuesFromTimestampRequest* request, ValuesFromTimestampResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto timestamp = convert_from_grpc<CVIAbsoluteTime>(request->timestamp());
        int64 seconds_since1970 {};
        float64 fractional_seconds {};
        auto status = library_->ValuesFromTimestamp(timestamp, &seconds_since1970, &fractional_seconds);
        response->set_status(status);
        if (status_ok(status)) {
          response->set_seconds_since1970(seconds_since1970);
          response->set_fractional_seconds(fractional_seconds);
        }
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
    //---------------------------------------------------------------------
    //---------------------------------------------------------------------
    ::grpc::Status NiRFmxInstrService::WaitForAcquisitionComplete(::grpc::ServerContext* context, const WaitForAcquisitionCompleteRequest* request, WaitForAcquisitionCompleteResponse* response)
    {
      if (context->IsCancelled()) {
        return ::grpc::Status::CANCELLED;
      }
      try {
        auto instrument_grpc_session = request->instrument();
        niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.id(), instrument_grpc_session.name());
        float64 timeout = request->timeout();
        auto status = library_->WaitForAcquisitionComplete(instrument, timeout);
        response->set_status(status);
        return ::grpc::Status::OK;
      }
      catch (nidevice_grpc::LibraryLoadException& ex) {
        return ::grpc::Status(::grpc::NOT_FOUND, ex.what());
      }
    }
  
  
    NiRFmxInstrFeatureToggles::NiRFmxInstrFeatureToggles(
      const nidevice_grpc::FeatureToggles& feature_toggles)
      : is_enabled(
          feature_toggles.is_feature_enabled("nirfmxinstr", CodeReadiness::kNextRelease))
    {
    }
  } // namespace nirfmxinstr_grpc
  
  