inline void ApplicationUidClient::BuildSession(
     RefType<ServiceLocator::ApplicationServiceLocatorClient::Client>
     serviceLocatorClient, RefType<Network::SocketThreadPool> socketThreadPool,
     RefType<Threading::TimerThreadPool> timerThreadPool) {
   if(m_client.IsInitialized()) {
     m_client->Close();
     m_client.Reset();
   }
   auto serviceLocatorClientHandle = serviceLocatorClient.Get();
   auto socketThreadPoolHandle = socketThreadPool.Get();
   auto timerThreadPoolHandle = timerThreadPool.Get();
   auto addresses = ServiceLocator::LocateServiceAddresses(
     *serviceLocatorClientHandle, SERVICE_NAME);
   auto delay = false;
   Details::UidClientSessionBuilder sessionBuilder(Ref(serviceLocatorClient),
     [=] () mutable {
       if(delay) {
         Threading::LiveTimer delayTimer(boost::posix_time::seconds(3),
           Ref(*timerThreadPoolHandle));
         delayTimer.Start();
         delayTimer.Wait();
       }
       delay = true;
       return std::make_unique<Network::TcpSocketChannel>(addresses,
         Ref(*socketThreadPoolHandle));
     },
     [=] {
       return std::make_unique<Threading::LiveTimer>(
         boost::posix_time::seconds(10), Ref(*timerThreadPoolHandle));
     });
   m_client.Initialize(sessionBuilder);
 }
Esempio n. 2
0
void delayAndSchedule(unsigned int delayMillis)
{
  // create a one-shot timer on the fly
  Timer delayTimer(0, Timer::IS_NON_RECURRING, (delayMillis));

  // wait until the timer expires
  while (!delayTimer.isTimerExpired())
  {
    // schedule the timer above and all the other timers, so they will still run in 'parallel'
    scheduleTimers();
  }
}
Esempio n. 3
0
otError Dataset::AppendMleDatasetTlv(Message &aMessage) const
{
    otError        error = OT_ERROR_NONE;
    Mle::Tlv       tlv;
    Mle::Tlv::Type type;
    const Tlv *    cur = reinterpret_cast<const Tlv *>(mTlvs);
    const Tlv *    end = reinterpret_cast<const Tlv *>(mTlvs + mLength);

    VerifyOrExit(mLength > 0);

    type = (mType == Tlv::kActiveTimestamp ? Mle::Tlv::kActiveDataset : Mle::Tlv::kPendingDataset);

    tlv.SetType(type);
    tlv.SetLength(static_cast<uint8_t>(mLength) - sizeof(Tlv) - sizeof(Timestamp));
    SuccessOrExit(error = aMessage.Append(&tlv, sizeof(Tlv)));

    while (cur < end)
    {
        if (cur->GetType() == mType)
        {
            ; // skip Active or Pending Timestamp TLV
        }
        else if (cur->GetType() == Tlv::kDelayTimer)
        {
            uint32_t      elapsed = TimerMilli::GetNow() - mUpdateTime;
            DelayTimerTlv delayTimer(static_cast<const DelayTimerTlv &>(*cur));

            if (delayTimer.GetDelayTimer() > elapsed)
            {
                delayTimer.SetDelayTimer(delayTimer.GetDelayTimer() - elapsed);
            }
            else
            {
                delayTimer.SetDelayTimer(0);
            }

            SuccessOrExit(error = aMessage.Append(&delayTimer, sizeof(delayTimer)));
        }
        else
        {
            SuccessOrExit(error = aMessage.Append(cur, sizeof(Tlv) + cur->GetLength()));
        }

        cur = cur->GetNext();
    }

exit:
    return error;
}