Improve naming in GRPC streaming code

This commit is contained in:
Gaute Lindkvist 2020-02-21 08:57:01 +01:00
parent a3a7b6029e
commit 6a4d90ad02
4 changed files with 31 additions and 27 deletions

View File

@ -189,10 +189,13 @@ const std::vector<RigCell>& RiaActiveCellInfoStateHandler::reservoirCells() cons
//--------------------------------------------------------------------------------------------------
grpc::Status RiaActiveCellInfoStateHandler::assignReply( rips::CellInfoArray* reply )
{
const size_t packageSize = RiaGrpcServiceInterface::numberOfMessagesForByteCount( sizeof( rips::CellInfoArray ) );
size_t packageIndex = 0u;
const size_t packageSize = RiaGrpcServiceInterface::numberOfDataUnitsInPackage( sizeof( rips::CellInfo ) );
size_t indexInPackage = 0u;
reply->mutable_data()->Reserve( (int)packageSize );
for ( ; packageIndex < packageSize && m_currentCellIdx < m_activeCellInfo->reservoirCellCount(); ++packageIndex )
// Stream until you've reached the package size or total cell count. Whatever comes first.
// If you've reached the package size you'll come back for another round.
for ( ; indexInPackage < packageSize && m_currentCellIdx < m_activeCellInfo->reservoirCellCount(); ++indexInPackage )
{
rips::CellInfo singleCellInfo;
grpc::Status singleCellInfoStatus = assignNextActiveCellInfoData( &singleCellInfo );
@ -206,7 +209,7 @@ grpc::Status RiaActiveCellInfoStateHandler::assignReply( rips::CellInfoArray* re
break;
}
}
if ( packageIndex > 0u )
if ( indexInPackage > 0u )
{
return Status::OK;
}

View File

@ -142,14 +142,18 @@ public:
//--------------------------------------------------------------------------------------------------
Status assignStreamReply( PropertyChunk* reply )
{
const size_t packageSize = RiaGrpcServiceInterface::numberOfMessagesForByteCount( sizeof( rips::PropertyChunk ) );
size_t packageIndex = 0u;
// How many data units will fit into one stream package?
const size_t packageSize = RiaGrpcServiceInterface::numberOfDataUnitsInPackage( sizeof( double ) );
size_t indexInPackage = 0u;
reply->mutable_values()->Reserve( (int)packageSize );
for ( ; packageIndex < packageSize && m_streamedValueCount < m_cellCount; ++packageIndex, ++m_streamedValueCount )
// Stream until you've reached the package size or total cell count. Whatever comes first.
// If you've reached the package size you'll come back for another round.
for ( ; indexInPackage < packageSize && m_streamedValueCount < m_cellCount; ++indexInPackage, ++m_streamedValueCount )
{
reply->add_values( cellResult( m_streamedValueCount ) );
}
if ( packageIndex > 0u )
if ( indexInPackage > 0u )
{
return grpc::Status::OK;
}
@ -274,12 +278,6 @@ protected:
size_t timeStepIndex,
RigEclipseResultAddress resVarAddr ) override
{
auto resultValues = caseData->results( porosityModel )->modifiableCellScalarResult( resVarAddr, timeStepIndex );
if ( resultValues->empty() )
{
resultValues->resize( caseData->grid( gridIndex )->cellCount() );
}
m_resultAccessor =
RigResultAccessorFactory::createFromResultAddress( caseData, gridIndex, porosityModel, timeStepIndex, resVarAddr );
m_resultModifier =

View File

@ -53,14 +53,13 @@ RimCase* RiaGrpcServiceInterface::findCase( int caseId )
}
//--------------------------------------------------------------------------------------------------
/// Find the number of messages that will fit in the given bytes.
/// The default argument is meant to be a sensible size for GRPC.
/// Find the number of data items that will fit in the given bytes.
/// The default argument for numBytesWantedInPackage is meant to be a sensible size for GRPC.
//--------------------------------------------------------------------------------------------------
size_t RiaGrpcServiceInterface::numberOfMessagesForByteCount( size_t messageSize,
size_t numBytesWantedInPackage /*= 64 * 1024u*/ )
size_t RiaGrpcServiceInterface::numberOfDataUnitsInPackage( size_t dataUnitSize, size_t packageByteCount /*= 64 * 1024u*/ )
{
size_t messageCount = numBytesWantedInPackage / messageSize;
return messageCount;
size_t dataUnitCount = packageByteCount / dataUnitSize;
return dataUnitCount;
}
//--------------------------------------------------------------------------------------------------
@ -137,13 +136,17 @@ void RiaGrpcServiceInterface::copyPdmObjectFromRipsToCaf( const rips::PdmObject*
auto pdmValueField = dynamic_cast<caf::PdmValueField*>( field );
if ( pdmValueField )
{
QString keyword = pdmValueField->keyword();
QString value = QString::fromStdString( parametersMap[keyword.toStdString()] );
QVariant oldValue, newValue;
if ( assignFieldValue( value, pdmValueField, &oldValue, &newValue ) )
auto ricfHandle = pdmValueField->template capability<RicfFieldHandle>();
if ( ricfHandle )
{
destination->uiCapability()->fieldChangedByUi( field, oldValue, newValue );
QString keyword = pdmValueField->keyword();
QString value = QString::fromStdString( parametersMap[keyword.toStdString()] );
QVariant oldValue, newValue;
if ( assignFieldValue( value, pdmValueField, &oldValue, &newValue ) )
{
destination->uiCapability()->fieldChangedByUi( field, oldValue, newValue );
}
}
}
}

View File

@ -52,7 +52,7 @@ public:
virtual std::vector<RiaGrpcCallbackInterface*> createCallbacks() = 0;
virtual ~RiaGrpcServiceInterface() = default;
static RimCase* findCase( int caseId );
static size_t numberOfMessagesForByteCount( size_t messageSize, size_t byteCount = 64 * 1024u );
static size_t numberOfDataUnitsInPackage( size_t dataUnitSize, size_t packageByteCount = 64 * 1024u );
static void copyPdmObjectFromCafToRips( const caf::PdmObjectHandle* source, rips::PdmObject* destination );
static void copyPdmObjectFromRipsToCaf( const rips::PdmObject* source, caf::PdmObjectHandle* destination );