bool
    RateLimiters::filter(const IMC::Message* msg)
    {
      uint32_t mid = msg->getId();
      RateMap::iterator rmitr = m_rates.find(mid);

      if (rmitr != m_rates.end())
      {
        double now = Time::Clock::get();
        double& stime = m_stimes[MsgKey(mid, msg->getSourceEntity())];

        if (stime + rmitr->second > now)
          return true;

        stime = now;
      }

      return false;
    }
Exemple #2
0
    //! Filter message
    //! @param[in] msg IMC Message.
    //! @return true if message filtered, false otherwise.
    bool
    MessageFilter::filter(const IMC::Message* msg)
    {
      uint32_t mid = msg->getId();

      // Filter message by entity.
      if (m_filtered[mid].size() > 0)
      {
        bool matched = false;
        std::vector<uint32_t>::iterator itr = m_filtered[mid].begin();
        for (; itr != m_filtered[mid].end(); ++itr)
        {
          if (*itr == msg->getSourceEntity())
          {
            matched = true;
            break;
          }
        }

        // This entity is not listed to be passed.
        if (!matched)
          return true;
      }

      // Filter message by rate.
      RateMap::iterator rmitr = m_rates.find(mid);

      if (rmitr != m_rates.end())
      {
        double now = Time::Clock::get();
        double& stime = m_stimes[MsgKey(mid, msg->getSourceEntity())];

        if (stime + rmitr->second > now)
          return true;

        stime = now;
      }

      return false;
    }
Exemple #3
0
int MAS::Widget::SendMessage(int msg, intptr_t c) {
   int ret = D_O_K;

   // convert the Allegro message constant to a MASkinG message handler
   switch (msg) {
      case (MSG_START):   MsgStart();   Animate();   break;
      case (MSG_END):      MsgEnd();      break;
      case (MSG_DRAW):   MsgDraw();      break;
      case (MSG_CLICK):   MsgClick();      break;
      case (MSG_DCLICK):   MsgDClick();   break;
      case (MSG_KEY):      MsgKey();      break;
      case (MSG_CHAR):   if (MsgChar(c))      ret |= D_USED_CHAR;      break;
      case (MSG_UCHAR):   if (MsgUChar(c))   ret |= D_USED_CHAR;      break;
      case (MSG_XCHAR):   if (MsgXChar(c))   ret |= D_USED_CHAR;      break;
      case (MSG_WANTFOCUS):   if (MsgWantfocus())   ret |= D_WANTFOCUS;   break;
      case (MSG_GOTFOCUS):   MsgGotfocus();      break;
      case (MSG_LOSTFOCUS):   MsgLostfocus();      break;
      case (MSG_GOTMOUSE):   MsgGotmouse();      break;
      case (MSG_LOSTMOUSE):   MsgLostmouse();      break;
      case (MSG_RADIO):      MsgRadio(c);      break;
      case (MSG_WHEEL):      MsgWheel(c);      break;
      case (MSG_LPRESS):      MsgLPress();      break;
      case (MSG_MPRESS):      MsgMPress();      break;
      case (MSG_RPRESS):      MsgRPress();      break;
      case (MSG_LRELEASE):   MsgLRelease();      break;
      case (MSG_MRELEASE):   MsgMRelease();      break;
      case (MSG_RRELEASE):   MsgRRelease();      break;
      case (MSG_MOVE):      MsgMove();         break;
      case (MSG_RESIZE):      MsgResize();      break;
      case (MSG_SHAPE):      MsgShape();         break;
      case (MSG_TIMER):      MsgTimer((ALLEGRO_TIMER_EVENT *)c); break;
      case (MSG_TICK):      MsgTick();         break;
      case (MSG_INITSKIN):   MsgInitSkin();      break;
      case (MSG_CLOSE):      if (MsgClose()) ret |= D_CLOSE;      break;
      case (MSG_WANTMOUSE):   if (MsgWantmouse())   ret |= D_WANTFOCUS;   break;
      case (MSG_WANTTAB):      if (MsgWantTab())   ret |= D_WANTFOCUS;   break;
   };

   return ret;
}