diff --git a/include/user/stimulusProducer.h b/include/user/stimulusProducer.h index b503d84..7f7e57e 100644 --- a/include/user/stimulusProducer.h +++ b/include/user/stimulusProducer.h @@ -73,8 +73,8 @@ public: const std::shared_ptr& spec) const; virtual std::shared_ptr getOrCreateAttachedStimulusBuffer( - const std::shared_ptr& deviceAttachmentSpec, - int histbuffMs) = 0; + const std::shared_ptr + &deviceAttachmentSpec) = 0; // Check if any attached buffer has the specified qualeIfaceApi bool hasBufferWithQualeIfaceApi(const std::string& qualeIfaceApi) const; diff --git a/stimBuffApis/livoxGen1/livoxGen1.cpp b/stimBuffApis/livoxGen1/livoxGen1.cpp index 8e4d86d..a8f9c14 100644 --- a/stimBuffApis/livoxGen1/livoxGen1.cpp +++ b/stimBuffApis/livoxGen1/livoxGen1.cpp @@ -80,37 +80,6 @@ getStimulusProducer( return nullptr; } -// Helper function to parse histbuffMs from device attachment spec -static int parseHistbuffMs( - const std::shared_ptr& spec) -{ - int histbuffMs = 30000; // Default: 30000ms (30 seconds) - const std::vector histbuffParamNames = { - "history-buffer-duration-ms", - "hist-buff-duration-ms", - "histbuff-duration-ms", - "histbuff-ms" - }; - - // Loop through synonyms in reverse order; lattermost synonym wins. - for (auto synIt = histbuffParamNames.rbegin(); - synIt != histbuffParamNames.rend(); ++synIt) - { - const auto& paramName = *synIt; - try { - histbuffMs = smo::device::DeviceAttachmentSpec - ::parseRequiredParamAsInt( - spec->qualeIfaceApiParams, paramName); - break; // Found and parsed successfully - } catch (const std::exception&) { - // Parameter not found or parse error, continue to next synonym - continue; - } - } - - return histbuffMs; -} - // Helper function to parse n-dgrams-per-frame from stim-buff-api params static size_t parseNDgramsPerFrame( const std::shared_ptr& spec) @@ -205,13 +174,10 @@ private: return false; } - // Parse histbuffMs - int histbuffMs = parseHistbuffMs(context->spec); - // Call getOrCreateAttachedStimulusBuffer (may throw, catch and return failure) try { context->stimProducer->getOrCreateAttachedStimulusBuffer( - context->spec, histbuffMs); + context->spec); } catch (const std::exception& e) { std::cerr << __func__ << ": Failed to create StimBuffer: " << e.what() << ". Producer is committed, DeviceReattacher will retry." diff --git a/stimBuffApis/livoxGen1/pcloudStimulusProducer.cpp b/stimBuffApis/livoxGen1/pcloudStimulusProducer.cpp index e09baa5..9adb6a5 100644 --- a/stimBuffApis/livoxGen1/pcloudStimulusProducer.cpp +++ b/stimBuffApis/livoxGen1/pcloudStimulusProducer.cpp @@ -106,6 +106,37 @@ void produceStimFrameAck(void) { } +// Helper function to parse histbuffMs from device attachment spec +static int parseHistbuffMs( + const std::shared_ptr& spec) +{ + int histbuffMs = 30000; // Default: 30000ms (30 seconds) + const std::vector histbuffParamNames = { + "history-buffer-duration-ms", + "hist-buff-duration-ms", + "histbuff-duration-ms", + "histbuff-ms" + }; + + // Loop through synonyms in reverse order; lattermost synonym wins. + for (auto synIt = histbuffParamNames.rbegin(); + synIt != histbuffParamNames.rend(); ++synIt) + { + const auto& paramName = *synIt; + try { + histbuffMs = device::DeviceAttachmentSpec + ::parseRequiredParamAsInt( + spec->qualeIfaceApiParams, paramName); + break; // Found and parsed successfully + } catch (const std::exception&) { + // Parameter not found or parse error, continue to next synonym + continue; + } + } + + return histbuffMs; +} + std::shared_ptr PcloudStimulusProducer::getAttachedStimulusBuffer( const std::shared_ptr& spec) const @@ -142,8 +173,7 @@ PcloudStimulusProducer::getAttachedStimulusBuffer( std::shared_ptr PcloudStimulusProducer::getOrCreateAttachedStimulusBuffer( - const std::shared_ptr& deviceAttachmentSpec, - int histbuffMs + const std::shared_ptr& deviceAttachmentSpec ) { // Check if buffer already exists (idempotent) @@ -151,6 +181,9 @@ PcloudStimulusProducer::getOrCreateAttachedStimulusBuffer( if (existingBuffer) { return existingBuffer; } + // Parse histbuffMs from device attachment spec + int histbuffMs = parseHistbuffMs(deviceAttachmentSpec); + // Parse qualeIfaceApi to determine buffer type const std::string& qualeIfaceApi = deviceAttachmentSpec->qualeIfaceApi; diff --git a/stimBuffApis/livoxGen1/pcloudStimulusProducer.h b/stimBuffApis/livoxGen1/pcloudStimulusProducer.h index 161432b..57a6fff 100644 --- a/stimBuffApis/livoxGen1/pcloudStimulusProducer.h +++ b/stimBuffApis/livoxGen1/pcloudStimulusProducer.h @@ -64,8 +64,7 @@ public: std::shared_ptr getOrCreateAttachedStimulusBuffer( const std::shared_ptr - &deviceAttachmentSpec, - int histbuffMs) override; + &deviceAttachmentSpec) override; std::shared_ptr getAttachedStimulusBuffer( const std::shared_ptr& spec)