Boost logo

Boost Users :

Subject: [Boost-users] boost::signals2::signal - is a "decimated" version available?
From: Chris Stankevitz (chrisstankevitz_at_[hidden])
Date: 2012-05-21 20:01:01


Hi,

I'm using boost::signals2::signal to notify a dialog when the state of
an underlying object has changed.

The signal is sometimes is generated at 100Hz. Other times it is
generated at 1Hz. The dialog provides a "slot" for this signal that
updates the controls on the screen. I'd like to limit the "slot rate"
to 10Hz. By "slot rate" I mean the rate at which the slot receives
notification from the signal. This will prevent the screen updates
from happening faster than can be seen.

Has this been done already? If not, I'm going to implement something
like the pseudocode below. Currently I'm not sure how I to specify
"arguments" nor how I am going to specify the function "SlotCallback".

Thank you,

Chris

===

Pseudocode:

float MaxPeriod = 0.001; // 10Hz

class SignalDecimator
{

public:

  void Register(signal Signal, slot Slot)
  {
    Signal.connect(&SignalDecimator::SlotCallback, this, _1, _2, _3, _4...);

    mSlot = Slot;
  }

private:

  void SlotCallback(arguments Arguments)
  {
    if (TimeSinceLastCall() > MaxPeriod)
    {
      mSlot(Arguments);
    }
    else
    {
      mArguments = Arguments;

      if (!TimerIsRunning())
      {
        StartTimer(MaxPeriod - TimeSinceLastCall());
      }
    }
  }

  void TimerCallback()
  {
    mSlot(mArguments);
  }

  slot mSlot;

  timer mTimer;

  arguments mArguments;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net