const uint8_t* QsfpModule::getQsfpValuePtr(int dataAddress, int offset, int length) const { /* if the cached values are not correct */ if (!cacheIsValid()) { throw FbossError("Qsfp is either not present or the data is not read"); } if (dataAddress == QsfpPages::LOWER) { CHECK_LE(offset + length, sizeof(qsfpIdprom_)); /* Copy data from the cache */ return(qsfpIdprom_ + offset); } else { offset -= MAX_QSFP_PAGE_SIZE; CHECK_GE(offset, 0); CHECK_LE(offset, MAX_QSFP_PAGE_SIZE); if (dataAddress == QsfpPages::PAGE0) { CHECK_LE(offset + length, sizeof(qsfpPage0_)); /* Copy data from the cache */ return(qsfpPage0_ + offset); } else if (dataAddress == QsfpPages::PAGE3 && !flatMem_) { CHECK_LE(offset + length, sizeof(qsfpPage3_)); /* Copy data from the cache */ return(qsfpPage3_ + offset); } else { throw FbossError("Invalid Data Address 0x%d", dataAddress); } } }
void QsfpModule::getTransceiverInfo(TransceiverInfo &info) { lock_guard<std::mutex> g(qsfpModuleMutex_); info.present = present_; info.transceiver = type(); info.port = qsfpImpl_->getNum(); if (!cacheIsValid()) { return; } if (getSensorInfo(info.sensor)) { info.__isset.sensor = true; } if (getVendorInfo(info.vendor)) { info.__isset.vendor = true; } if (getCableInfo(info.cable)) { info.__isset.cable = true; } if (getThresholdInfo(info.thresholds)) { info.__isset.thresholds = true; } for (int i = 0; i < CHANNEL_COUNT; i++) { Channel chan; chan.channel = i; info.channels.push_back(chan); } if (getSensorsPerChanInfo(info.channels)) { info.__isset.channels = true; } else { info.channels.clear(); } }
// Must be called with lock held on qsfpModuleMutex_ void QsfpModule::refreshCacheIfPossibleLocked() { // Check whether we should refresh data if (std::time(nullptr) - lastReadTime_.load() > kQsfpMinReadIntervalSecs) { dirty_ = true; } if (!cacheIsValid()) { detectTransceiverLocked(); } }
void ScopedStyleTree::popStyleCache(const ContainerNode* scopingNode) { if (!cacheIsValid(scopingNode)) return; if (m_cache.scopedResolver && m_cache.scopedResolver->scopingNode() == scopingNode) m_cache.scopedResolver = m_cache.scopedResolver->parent(); m_cache.nodeForScopedStyles = scopingNode->parentOrShadowHostNode(); }
void ScopedStyleTree::pushStyleCache(const ContainerNode* scopingNode, const ContainerNode* parent) { if (m_authorStyles.isEmpty()) return; if (!cacheIsValid(parent)) { resolveStyleCache(scopingNode); return; } ScopedStyleResolver* scopedResolver = scopedStyleResolverFor(scopingNode); if (scopedResolver) m_cache.scopedResolver = scopedResolver; m_cache.nodeForScopedStyles = scopingNode; }
int QsfpModule::getFieldValue(SffField fieldName, uint8_t* fieldValue) { lock_guard<std::mutex> g(qsfpModuleMutex_); int offset; int length; int dataAddress; /* Determine if QSFP is present */ if (cacheIsValid()) { try { getQsfpFieldAddress(fieldName, dataAddress, offset, length); getQsfpValue(dataAddress, offset, length, fieldValue); } catch (const std::exception& ex) { LOG(ERROR) << "Error reading field value for transceiver:" << folly::to<std::string>(qsfpImpl_->getName()) << " " << ex.what(); } } return -1; }