bool Cache::freeCachedImage(Image *image) { /* * if the supplied image is cached as a master image of a clone, it is freed and deregistered. * if not, no action is performed. * */ // WARNING : FIXME : DANGER !! if( !image )return false; // if( is_in_cache(image) && usageCounter[image->getKey()]==1 ) if( is_in_clone_cache(image) ) { usageCounter[image->getKey()]--; erase_clone(image); // we _always_ immediately delete clones setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return true; } else if( is_in_cache(image) ) { usageCounter[image->getKey()]--; if( (usageCounter[image->getKey()])==0 && image->getKey().second!=FIM_E_STDIN ) { #if 0 if( need_free() && image->getKey().second!=FIM_E_STDIN ) { cache_key_t key = image->getKey(); this->erase( image ); usageCounter.erase(key); } #else /* doing it here is dangerous : */ if( need_free() ) { Image * lrui = get_lru(true); if(lrui && ( lrui->getKey().second!=FIM_E_STDIN )) { cache_key_t key = lrui->getKey(); this->erase( lrui ); usageCounter.erase(key); } // missing usageCounter.erase().. } #endif } setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return true; } return false; }
Image * Cache::setAndCacheStdinCachedImage(Image * image) { /* FIXME : document me * */ if(!image) return NULL; cache_key_t key(FIM_STDIN_IMAGE_NAME,FIM_E_STDIN); try { #ifdef FIM_CACHE_DEBUG Image * oi=image; #endif image = new Image(*image); // cloning if(image) { cacheNewImage( image ); } } catch(FimException e) { /* we will survive :P */ image = NULL; /* we make sure no taint remains */ // if( e != FIM_E_NO_IMAGE )throw FIM_E_TRAGIC; /* hope this never occurs :P */ } if(!image)return NULL; //means that cloning failed. setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return image; //so, it could be a clone.. }
IOReturn com_milvich_driver_Thrustmaster::getReport(IOMemoryDescriptor *report, IOHIDReportType reportType, IOOptionBits options) { // I have no idea what the report types or option bits are... so I am just // ignoring them.. // use the data from the last interrupt... they shouldn't have changed... return getReport(report, fControlData, sizeof(fControlData)); }
std::string getDescription() const { std::stringstream desc; switch( getType( )) { case VolumeType::compartments: case VolumeType::somas: if( getFunctorType() == FunctorType::lfp ) desc << "local field potential in mV of "; else desc << "membrane voltage in mV of "; if( getType() == VolumeType::somas ) desc << "soma "; else desc << "compartment "; desc << "report '" << getReport() << "' for target '" << _get( "target" ) << "'"; break; case VolumeType::spikes: desc << "number of spikes in " << getDuration() << "ms for target '" << _get( "target" ) << "'"; break; case VolumeType::synapses: { desc << "number of synapses/voxel "; const std::string& preTarget = _get( "preTarget" ); if( preTarget.empty( )) desc << "for afferent synapses of target '" << _get( "target" ) << "'"; else desc << "for pathway from '" << preTarget << "' to '" << _get( "postTarget" ) << "'"; } break; case VolumeType::vsd: desc << "VSD (Voltage-Sensitive Dye) from " << getReport() << " for target '" << _get( "target" ) << "'"; break; case VolumeType::test: default: return ""; } return desc.str(); }
int Cache::prefetch(cache_key_t key) { // if(need_free()) // free_some_lru(); if(key.first == FIM_STDIN_IMAGE_NAME) return 0;// just a fix in the case the browser is still lame if(is_in_cache(key)) return 0; if(!loadNewImage(key)) return -1; setGlobalVariable(FIM_VID_CACHED_IMAGES,cached_elements()); setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return 0; // return getCachedImage(key)?0:-1; }
void com_milvich_driver_Thrustmaster::packet(UInt8 *data, IOByteCount length) { getReport(fReport, data, length); handleReport(fReport); }
int multitouch_setup(const uint8_t* ASpeedFirmware, int ASpeedFirmwareLen, const uint8_t* mainFirmware, int mainFirmwareLen) { bufferPrintf("multitouch: A-Speed firmware at 0x%08x - 0x%08x, Main firmware at 0x%08x - 0x%08x\r\n", (uint32_t) ASpeedFirmware, (uint32_t)(ASpeedFirmware + ASpeedFirmwareLen), (uint32_t) mainFirmware, (uint32_t)(mainFirmware + mainFirmwareLen)); OutputPacket = (uint8_t*) malloc(0x400); InputPacket = (uint8_t*) malloc(0x400); GetInfoPacket = (uint8_t*) malloc(0x400); GetResultPacket = (uint8_t*) malloc(0x400); memset(GetInfoPacket, 0x82, 0x400); memset(GetResultPacket, 0x68, 0x400); gpio_register_interrupt(MT_ATN_INTERRUPT, 0, 0, 0, multitouch_atn, 0); gpio_interrupt_enable(MT_ATN_INTERRUPT); multitouch_on(); bufferPrintf("multitouch: Sending A-Speed firmware...\r\n"); if(!loadASpeedFirmware(ASpeedFirmware, ASpeedFirmwareLen)) { free(InputPacket); free(OutputPacket); free(GetInfoPacket); free(GetResultPacket); return -1; } udelay(1000); bufferPrintf("multitouch: Sending main firmware...\r\n"); if(!loadMainFirmware(mainFirmware, mainFirmwareLen)) { free(InputPacket); free(OutputPacket); free(GetInfoPacket); free(GetResultPacket); return -1; } udelay(1000); bufferPrintf("multitouch: Determining interface version...\r\n"); if(!determineInterfaceVersion()) { free(InputPacket); free(OutputPacket); free(GetInfoPacket); free(GetResultPacket); return -1; } uint8_t reportBuffer[MaxPacketSize]; int reportLen; if(!getReport(MT_INFO_FAMILYID, reportBuffer, &reportLen)) { bufferPrintf("multitouch: failed getting family id!\r\n"); free(InputPacket); free(OutputPacket); free(GetInfoPacket); free(GetResultPacket); return -1; } FamilyID = reportBuffer[0]; if(!getReport(MT_INFO_SENSORINFO, reportBuffer, &reportLen)) { bufferPrintf("multitouch: failed getting sensor info!\r\n"); free(InputPacket); free(OutputPacket); free(GetInfoPacket); free(GetResultPacket); return -1; } SensorColumns = reportBuffer[2]; SensorRows = reportBuffer[1]; BCDVersion = ((reportBuffer[3] & 0xFF) << 8) | (reportBuffer[4] & 0xFF); Endianness = reportBuffer[0]; if(!getReport(MT_INFO_SENSORREGIONDESC, reportBuffer, &reportLen)) { bufferPrintf("multitouch: failed getting sensor region descriptor!\r\n"); free(InputPacket); free(OutputPacket); free(GetInfoPacket); free(GetResultPacket); return -1; } SensorRegionDescriptorLen = reportLen; SensorRegionDescriptor = (uint8_t*) malloc(reportLen); memcpy(SensorRegionDescriptor, reportBuffer, reportLen); if(!getReport(MT_INFO_SENSORREGIONPARAM, reportBuffer, &reportLen)) { bufferPrintf("multitouch: failed getting sensor region param!\r\n"); free(InputPacket); free(OutputPacket); free(GetInfoPacket); free(GetResultPacket); free(SensorRegionDescriptor); return -1; } SensorRegionParamLen = reportLen; SensorRegionParam = (uint8_t*) malloc(reportLen); memcpy(SensorRegionParam, reportBuffer, reportLen); if(!getReport(MT_INFO_SENSORDIM, reportBuffer, &reportLen)) { bufferPrintf("multitouch: failed getting sensor surface dimensions!\r\n"); free(InputPacket); free(OutputPacket); free(GetInfoPacket); free(GetResultPacket); free(SensorRegionDescriptor); free(SensorRegionParam); return -1; } SensorWidth = *((uint32_t*)&reportBuffer[0]); SensorHeight = *((uint32_t*)&reportBuffer[4]); int i; bufferPrintf("Family ID : 0x%x\r\n", FamilyID); bufferPrintf("Sensor rows : 0x%x\r\n", SensorRows); bufferPrintf("Sensor columns : 0x%x\r\n", SensorColumns); bufferPrintf("Sensor width : 0x%x\r\n", SensorWidth); bufferPrintf("Sensor height : 0x%x\r\n", SensorHeight); bufferPrintf("BCD Version : 0x%x\r\n", BCDVersion); bufferPrintf("Endianness : 0x%x\r\n", Endianness); bufferPrintf("Sensor region descriptor :"); for(i = 0; i < SensorRegionDescriptorLen; ++i) bufferPrintf(" %02x", SensorRegionDescriptor[i]); bufferPrintf("\r\n"); bufferPrintf("Sensor region param :"); for(i = 0; i < SensorRegionParamLen; ++i) bufferPrintf(" %02x", SensorRegionParam[i]); bufferPrintf("\r\n"); CurNOP = 0x64; GotATN = 0; while(TRUE) { EnterCriticalSection(); if(!GotATN) { LeaveCriticalSection(); continue; } --GotATN; LeaveCriticalSection(); while(readFrame() == 1); } return 0; }
QString KGpgVerify::getReport(const QStringList &log, const KGpgItemModel *model) { QString result; // newer versions of GnuPG emit both VALIDSIG and GOODSIG // for a good signature. Since VALIDSIG has more information // we use that. const QRegExp validsig(QLatin1String("^\\[GNUPG:\\] VALIDSIG([ ]+[^ ]+){10,}.*$")); const bool useGoodSig = (model == NULL) || (log.indexOf(validsig) == -1); QString sigtime; // timestamp of signature creation foreach (const QString &line, log) { if (!line.startsWith(QLatin1String("[GNUPG:] "))) continue; const QString msg = line.mid(9); if (!useGoodSig && msg.startsWith(QLatin1String("VALIDSIG "))) { // from GnuPG source, doc/DETAILS: // VALIDSIG <fingerprint in hex> <sig_creation_date> <sig-timestamp> // <expire-timestamp> <sig-version> <reserved> <pubkey-algo> // <hash-algo> <sig-class> <primary-key-fpr> const QStringList vsig = msg.mid(9).split(QLatin1Char(' '), QString::SkipEmptyParts); Q_ASSERT(vsig.count() >= 10); const KGpgKeyNode *node = model->findKeyNode(vsig[9]); if (node != NULL) { // ignore for now if this is signed with the primary id (vsig[0] == vsig[9]) or not if (node->getEmail().isEmpty()) result += i18n("<qt>Good signature from:<br /><b>%1</b><br />Key ID: %2<br /></qt>", node->getName(), vsig[9]); else result += i18nc("Good signature from: NAME <EMAIL>, Key ID: HEXID", "<qt>Good signature from:<br /><b>%1 <%2></b><br />Key ID: %3<br /></qt>", node->getName(), node->getEmail(), vsig[9]); result += sigTimeMessage(vsig[2]); } else { // this should normally never happen, but one could delete // the key just after the verification. Brute force solution: // do the whole report generation again, but this time make // sure GOODSIG is used. return getReport(log, NULL); } } else if (msg.startsWith(QLatin1String("UNEXPECTED")) || msg.startsWith(QLatin1String("NODATA"))) { result += i18n("No signature found.") + QLatin1Char('\n'); } else if (useGoodSig && msg.startsWith(QLatin1String("GOODSIG "))) { int sigpos = msg.indexOf( ' ' , 8); const QString keyid = msg.mid(8, sigpos - 8); // split the name/email pair to give translators more power to handle this QString email; QString name = msg.mid(sigpos + 1); int oPos = name.indexOf(QLatin1Char('<')); int cPos = name.indexOf(QLatin1Char('>')); if ((oPos >= 0) && (cPos >= 0)) { email = name.mid(oPos + 1, cPos - oPos - 1); name = name.left(oPos).simplified(); } if (email.isEmpty()) result += i18n("<qt>Good signature from:<br /><b>%1</b><br />Key ID: %2<br /></qt>", name, keyid); else result += i18nc("Good signature from: NAME <EMAIL>, Key ID: HEXID", "<qt>Good signature from:<br /><b>%1 <%2></b><br />Key ID: %3<br /></qt>", name, email, keyid); if (!sigtime.isEmpty()) { result += sigTimeMessage(sigtime); sigtime.clear(); } } else if (msg.startsWith(QLatin1String("SIG_ID "))) { const QStringList parts = msg.simplified().split(QLatin1Char(' ')); if (parts.count() > 2) sigtime = parts[2]; } else if (msg.startsWith(QLatin1String("BADSIG"))) { int sigpos = msg.indexOf( ' ', 7); result += i18n("<qt><b>BAD signature</b> from:<br /> %1<br />Key id: %2<br /><br /><b>The file is corrupted</b><br /></qt>", msg.mid(sigpos + 1).replace(QLatin1Char('<'), QLatin1String("<")), msg.mid(7, sigpos - 7)); } else if (msg.startsWith(QLatin1String("TRUST_UNDEFINED"))) { result += i18n("<qt>The signature is valid, but the key is untrusted<br /></qt>"); } else if (msg.startsWith(QLatin1String("TRUST_ULTIMATE"))) { result += i18n("<qt>The signature is valid, and the key is ultimately trusted<br /></qt>"); } } return result; }
Image * Cache::useCachedImage(cache_key_t key) { /* * the calling function needs an image, so calls this method. * if we already have the desired image and it is already used, * a clone is built and returned. * * if we have an unused master, we return it. * * then declare this image as used and increase a relative counter. * * a freeImage action will do the converse operation (and delete). * if the image is not already cached, it is loaded, if possible. * * so, if there is no such image, NULL is returned * */ #ifdef FIM_CACHE_DEBUG std::cout << " useCachedImage(\""<<key.first<<","<<key.second<<"\")\n"; #endif Image * image=NULL; if(!is_in_cache(key)) { /* * no Image cached at all for this filename * */ image = loadNewImage(key); if(!image)return NULL; // bad luck! usageCounter[key]=1; setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return image; // usageCounter[key]=0; } else { /* * at least one copy of this filename image is in cache * */ image=getCachedImage(key);// in this way we update the LRU cache :) if(!image) { // critical error #ifdef FIM_CACHE_DEBUG cout << "critical internal cache error!\n"; #endif setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return NULL; } if( used_image( key ) ) { // if the image was already used, cloning occurs // image = image->getClone(); // EVIL !! try { #ifdef FIM_CACHE_DEBUG Image * oi=image; #endif image = new Image(*image); // cloning #ifdef FIM_CACHE_DEBUG std::cout << " cloned image: \"" <<image->getName()<< "\" "<< image << " from \""<<oi->getName() <<"\" " << oi << "\n"; #endif } catch(FimException e) { /* we will survive :P */ image = NULL; /* we make sure no taint remains */ // if( e != FIM_E_NO_IMAGE )throw FIM_E_TRAGIC; /* hope this never occurs :P */ } if(!image)return NULL; //means that cloning failed. clone_pool.insert(image); // we have a clone cloneUsageCounter[image]=1; } lru_touch( key ); // if loading and eventual cloning succeeded, we count the image as used of course usageCounter[key]++; setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return image; //so, it could be a clone.. } }
void lionheart::Game::doTurn(std::shared_ptr<Display> display) { ++turns; //determine random turn order static std::random_device rd; static std::mt19937 engine(rd()); for(auto&& u:units) { std::shuffle(std::begin(u), std::end(u), engine); } auto u0 = std::begin(units[0]); auto u1 = std::begin(units[1]); while (u0 != std::end(units[0]) && u1 != std::end(units[1])) { auto doAction = [&](Unit &unit, std::shared_ptr<Player> p, std::vector<std::shared_ptr<Unit>> &allies, std::vector<std::shared_ptr<Unit>> &enemies)->bool { if (unit.isAlive()) { std::shared_ptr<const Paths> paths = nullptr; if(unit.getMoveSpeed() == 5) { paths = mountedPaths; } else { paths = infantryPaths; } // get recommendations auto action = p->recommendAction(unit, buildReport(map, turns, allies, enemies), Plan(unit, allies, enemies,paths)); // execute valid recommendations return action(map, unit, allies,enemies); } return false; }; // do player 0 unit if (u0 != std::end(units[0])) { auto unit = *u0; auto result = doAction(*unit,player[0],units[0],units[1]); ++u0; if(display&&result) { display->show(getReport(),player[0]->getBlazon(),player[1]->getBlazon()); } } // do player 1 unit if (u1 != std::end(units[1])) { auto unit = *u1; auto result = doAction(*unit,player[1],units[1],units[0]); ++u1; if(display&&result) { display->show(getReport(),player[0]->getBlazon(),player[1]->getBlazon()); } } } // remove the fallen for (auto &&u : units) { u.erase(std::remove_if(std::begin(u), std::end(u), [](std::shared_ptr<Unit> const &unit) { return !unit->isAlive(); }), std::end(u)); } if(!canContinue()) { state = FINISHED; } }