diff --git a/include/user/stimulusBuffer.h b/include/user/stimulusBuffer.h index 1f56d36..286a381 100644 --- a/include/user/stimulusBuffer.h +++ b/include/user/stimulusBuffer.h @@ -54,7 +54,7 @@ public: shouldContinue(false), timer(ioService) {} - ~StimulusBuffer() = default; + virtual ~StimulusBuffer() = default; // Non-copyable, movable StimulusBuffer(const StimulusBuffer&) = delete; @@ -71,6 +71,15 @@ public: void stop(); +protected: + // Virtual functions for derived classes to override + virtual int getStopDelayMs() const + { + return CONFIG_STIMBUFF_FRAME_PERIOD_MS; + } + + virtual void stimFrameProductionTimesliceInd() = 0; + private: void onTimeout(const boost::system::error_code& error); @@ -112,10 +121,9 @@ inline void StimulusBuffer::stop() boost::asio::deadline_timer delayTimer(ioService); AsynchronousBridge bridge(ioService); - // Set up the delay for CONFIG_STIMBUFF_FRAME_PERIOD_MS to let in-flight - // operation finish + // Set up the delay to let in-flight operation finish delayTimer.expires_from_now( - boost::posix_time::milliseconds(CONFIG_STIMBUFF_FRAME_PERIOD_MS)); + boost::posix_time::milliseconds(getStopDelayMs())); delayTimer.async_wait( [&bridge](const boost::system::error_code& error) @@ -166,7 +174,8 @@ inline void StimulusBuffer::onTimeout(const boost::system::error_code& error) else { nextWakeupDelayMs = CONFIG_STIMBUFF_FRAME_RETRY_DELAY_MS; } - // Placeholder handler (empty for now) + // Call the derived class's frame production handler + stimFrameProductionTimesliceInd(); // Note: The lock should be released when frame production completes // Schedule next timeout with the pre-determined duration diff --git a/stimBuffApis/livoxGen1/pcloudStimulusBuffer.cpp b/stimBuffApis/livoxGen1/pcloudStimulusBuffer.cpp index 620f148..2a16e17 100644 --- a/stimBuffApis/livoxGen1/pcloudStimulusBuffer.cpp +++ b/stimBuffApis/livoxGen1/pcloudStimulusBuffer.cpp @@ -19,5 +19,11 @@ formatDesc(formatDesc), stagingBuffer( { } +void PcloudStimulusBuffer::stimFrameProductionTimesliceInd() +{ + // Release the spinlock for now + frameAssemblyRateLimiter.release(); +} + } // namespace stim_buff } // namespace smo diff --git a/stimBuffApis/livoxGen1/pcloudStimulusBuffer.h b/stimBuffApis/livoxGen1/pcloudStimulusBuffer.h index 371c98a..2963143 100644 --- a/stimBuffApis/livoxGen1/pcloudStimulusBuffer.h +++ b/stimBuffApis/livoxGen1/pcloudStimulusBuffer.h @@ -36,6 +36,9 @@ public: PcloudStimulusBuffer(PcloudStimulusBuffer&&) = default; PcloudStimulusBuffer& operator=(PcloudStimulusBuffer&&) = default; +protected: + void stimFrameProductionTimesliceInd() override; + public: device::DeviceAttachmentSpec deviceAttachmentSpec; std::shared_ptr device;