std::vector<std::string> Arduino::genericIOReportTask(const std::string &stringToSend, const std::string &header, const std::string &endHeader, double delay) { std::lock_guard<std::mutex> ioLock{this->m_ioMutex}; if (!this->m_ioStream->isOpen()) { this->m_ioStream->openPort(); GeneralUtilities::delayMilliseconds(BOOTLOADER_BOOT_TIME); } this->m_ioStream->writeString(stringToSend); GeneralUtilities::delayMilliseconds(delay); std::unique_ptr<std::string> returnString{std::make_unique<std::string>("")}; EventTimer eventTimer; eventTimer.start(); do { std::string str{this->m_ioStream->readStringUntil("}")}; if (str != "") { *returnString = str; break; } eventTimer.update(); } while (eventTimer.totalMilliseconds() < this->m_ioStream->timeout()); if (GeneralUtilities::startsWith(*returnString, header) && GeneralUtilities::endsWith(*returnString, endHeader)) { *returnString = returnString->substr(static_cast<std::string>(header).length() + 1); *returnString = returnString->substr(0, returnString->length()-1); } else { return std::vector<std::string>{}; } return GeneralUtilities::parseToVector(*returnString, ';'); }
void timerStop(IntervalTimer * itimer) { if (itimer == NULL) return; EventTimer *timer = (EventTimer *)(itimer->data); timer->stop(timer); }
void Session::addToPendingAcks(qint64 msgId) { EventTimer *t = new EventTimer(msgId, ACK_TIMEOUT, this); connect(t, &EventTimer::timerTimeout, this, &Session::ack); t->start(); //timeout of 60 secs m_pendingAcks[msgId] = t; if (m_pendingAcks.size() > MAX_PENDING_ACKS) { ackAll(); } }
void freeEventTimer (EventTimer **timer) { if(timer == NULL) { return; } EventTimer *ptimer = *timer; if(ptimer == NULL) { return; } ptimer->shutdown(ptimer); /* maintain the linked list */ if(ptimer->_prev != NULL) { if(ptimer == _last) { _last = ptimer->_prev; } if(ptimer->_next != NULL) { ptimer->_prev->_next = ptimer->_next; } else { ptimer->_prev->_next = NULL; } /* last one */ } else if (ptimer->_next == NULL) { _first = NULL; } if(ptimer->_next != NULL) { if(ptimer == _first) { _first = ptimer->_next; } if(ptimer->_prev != NULL) { ptimer->_next->_prev = ptimer->_prev; } else { ptimer->_next->_prev = NULL; } } if(*timer != NULL) { free(*timer); } *timer = NULL; }
Boolean timerRunning(IntervalTimer * itimer) { if (itimer==NULL) return FALSE; EventTimer *timer = (EventTimer *)(itimer->data); return timer->isRunning(timer); }
Boolean timerExpired(IntervalTimer * itimer) { if (itimer == NULL) return FALSE; EventTimer *timer = (EventTimer *)(itimer->data); return timer->isExpired(timer); }
void timerStart(IntervalTimer * itimer, double interval) { if (itimer == NULL) return; if(interval > PTPTIMER_MAX_INTERVAL) { interval = PTPTIMER_MAX_INTERVAL; } itimer->interval = interval; EventTimer* timer = (EventTimer *)(itimer->data); timer->start(timer, interval); }
void Session::sendAcks(const QList<qint64> &msgIds) { // verify that socket is connected. Don't send acks if state is other than connected. // In case the socket is not connected, pending acks will be sent when socket is // connected back again. if (state() != QAbstractSocket::ConnectedState) { return; } OutboundPkt p(mSettings); p.appendInt(TL_MsgsAck); p.appendInt(CoreTypes::typeVector); int n = msgIds.length(); p.appendInt(n); Q_FOREACH (qint64 msgId, msgIds) { p.appendLong(msgId); qCDebug(TG_CORE_SESSION) << "Ack for msgId" << msgId; EventTimer* t = m_pendingAcks.take(msgId); if (t) { t->stop(); delete t; } }
void VOD_SessionControl::ProcessTimeoutCallBack(int32_t fd, short event, void *arg) { (void) fd; (void) event; pthread_mutex_lock(&mVodSessionListMutex); EventTimer* pEvt = (EventTimer*) arg; if (NULL != pEvt) { SendMsgInfo *msgInfo = (SendMsgInfo *) pEvt->getUserData(); if (NULL != msgInfo) { unsigned int sessId = msgInfo->sessionId; LOG(DLOGL_REALLY_NOISY, " MessageTimeoutCallBack : %d ", msgInfo->transId); // TODO: this is dangerous because VOD_SessionControl object may be gone // Is there way for onDemand controller to handle this? ActiveVodSessionMap::iterator it; bool found = false; for (it = mActiveVodSessionMap.begin(); it != mActiveVodSessionMap.end(); ++it) { if (it->first == sessId) { found = true; break; } } LOG(DLOGL_MINOR_EVENT, "sessId: %d found: %d", sessId, found); if (found) { //if message exist in queue then resend list<SendMsgInfo *>::iterator itr; VOD_SessionControl *objPtr = msgInfo->objPtr; for (itr = objPtr->sendMsgInfoList.begin(); itr != objPtr->sendMsgInfoList.end(); ++itr) { if (msgInfo->transId == (*itr)->transId) { LOG(DLOGL_REALLY_NOISY, "SendPendingMessage: evtTimer: %p transId: %d", pEvt, msgInfo->transId); if (((*itr)->msgRetryCount <= 1)) { objPtr->sendMsgInfoList.remove(*itr); delete *itr; *itr = NULL; if (msgInfo->ptrOnDemand) { LOG(DLOGL_ERROR, " NOT RECEIVED SERVER RESPONSE - sending error to service layer !!"); msgInfo->ptrOnDemand->queueEvent(kOnDemandSessionErrorEvent); } } else { //resend the message objPtr->SendPendingMessage(*itr); (*itr)->msgRetryCount--; LOG(DLOGL_NORMAL, "Add message timer event for retry msgRetryCount::%d", (*itr)->msgRetryCount); EventLoop* evtLoop = (*itr)->ptrOnDemand->GetEventLoop(); if (evtLoop != NULL) { uint32_t tMsg = 0; OnDemandSystemClient::getInstance()->GetmessageTimer(&tMsg); EventTimer* evtTimer = evtLoop->addTimer(EVENTTIMER_TIMEOUT, tMsg, 0, VOD_SessionControl::ProcessTimeoutCallBack, (void *)(*itr)); (*itr)->evtTimer = evtTimer; } } break; } } } else { LOG(DLOGL_MINOR_EVENT, "Warning: no action - sessId: %d no longer active", sessId); } } delete pEvt; pEvt = NULL; } pthread_mutex_unlock(&mVodSessionListMutex); }