char * coreOperationOpenFile(char * path , char * openingMode, RuntimeErrorValidator * validator){ Iterator * tokens = buildIterator(tokenize(path , '/')); char * vdaName = hasMoreElements(tokens) ? next(tokens) : NULL; char * fileName = hasMoreElements(tokens) ? next(tokens) : NULL; if( !isOpeningModeDelete(openingMode) && !isOpeningModeRead(openingMode) && !isOpeningModeWrite(openingMode)){ setError(validator , "El parametro de modo de apertura de archivo no es valido"); return NULL; } if(fileName == NULL || vdaName == NULL){ setError(validator , "La ruta al archivo no tiene el formato valido"); return NULL; } int hdId = openFileInTdd(vdaName , fileName , openingMode , validator); if(hasError(validator) || hdId < 0){ return NULL; }else{ return itoa(hdId); } }
void executeKssCommandList(char * arg , ListenSocket ls){ RuntimeErrorValidator * validator = buildErrorSuccessValidator(); //List params = getFirstParameter("Dispositivo o directorio a Listar"); List params = buildStringsListWithValues(1 , arg); MpsRequest * req = buildMpsRequest( generateRandomKey(16) , SHELL_LS , params); MpsResponse * resp = sendAndReceiveMpsMessages(ls , req ,validator); if(isDebugEnabled()) debug(concatAll(2, "Codigo de resultado: " , resp->statusCode)); Iterator * ite = buildIterator(resp->returnValues); if( equalsStrings(resp->statusCode , MPS_RESPONSE_STATUS_CODE_SUCCESS)){ char * serializedFiles = next(ite); List files = deserializeList(serializedFiles); ite = buildIterator(files); printf("Contenido del directorio:\n"); printf("--------------------------------------------------------------------------------------\n"); while(hasMoreElements(ite)){ char * elem = next(ite); printf("%s\n " , trim(elem)); } }else{ printf("%s" , ( hasMoreElements(ite) ? (char *) next(ite) : "Ha ocurrido un error")); } }
void executeOperationRead(ListenSocket ls , MpsMessage * aReq , RuntimeErrorValidator * validator) { Iterator * ite = buildIterator(aReq->commands); char * fileId = hasMoreElements(ite) ? next(ite) : NULL; /* Se recibe como parametro. * Es una buena practica obtenerlo de esta forma y no mantener un estado aunq * el enunciado no dice nada. * En ultima instancia hay q mantener el estado de las peticiones para este cliente y * de esta manera el ultimo sector consumido. */ char * lastSectorSended = hasMoreElements(ite) ? next(ite) : NULL; FileBlock * block = coreOperationReadFile(fileId , lastSectorSended , validator); if(hasError(validator)) { replyValidationError(ls , aReq , validator); return; } List blockList = NULL; if(hasTwoSectors(block)) { blockList = buildStringsListWithValues(4 , itoa(block->sector1.sector) , block->sector1.data , itoa(block->sector2.sector) , block->sector2.data ); } else { blockList = buildStringsListWithValues(2 , itoa(block->sector1.sector) , block->sector1.data); } MpsMessage * response = buildMpsMessage(aReq->descriptorId , MPS_RESPONSE_STATUS_CODE_SUCCESS , aReq->operationName , blockList); sendMpsMessage(response , ls , validator); }
void m_read() { m_ok = (m_enumeration && m_enumeration->hasMoreElements()) ? true : false; if (m_ok) { m_enumeration->nextElement(m_value); } }
FileBlock * coreOperationReadFile(char * fileId , char * lastSectorSended , RuntimeErrorValidator * validator){ TddRecord * record = getTddRecordByFileHandleId(atoi(fileId)); if(record == NULL){ setError(validator , "El archivo no se encuentra abierto o cargado en la TDD"); return NULL; } if(record->openingMode != OPENING_MODE_READ){ setError(validator , "El archivo no esta abierto en modo solo lectura"); return NULL; } Iterator * iteSectors = buildIterator(record->fileSectors); /* * Si se ha hecho un envio antes y existe un indice a partir del cual buscar * entonces se recorre hasta dicho indice. * De lo contrario se utiliza el primer numero de sector como indice ya q no * ha habido ninguno anterior. */ if(!equalsStrings(lastSectorSended , KSS_FTP_ENTRYPOINT_READ_FILE_NO_PREVIOUS_SEARCH_INDEX) ){ while( hasMoreElements(iteSectors) && !equalsStrings(lastSectorSended , next(iteSectors)) ); } int sector1ToSend = hasMoreElements(iteSectors) ? atoi(next(iteSectors)) : -1; int sector2ToSend = hasMoreElements(iteSectors) ? atoi(next(iteSectors)) : -1; if(sector1ToSend < 0 || sector2ToSend < 0){ setError(validator , "Los numeros de sectores encontrados son invalidos"); return NULL; } VdaComponent * comp = getMountedVda(record->vdaName); if(comp == NULL){ setError(validator , "El VDA no se encuentra montado"); return NULL; } return callVdaOperationGetSectores(comp , sector1ToSend , sector2ToSend , validator); }
void * getNode(List list , Bool (*selectionCriteria)(void *)){ Iterator * ite = buildIterator(list); while(hasMoreElements(ite)){ void * elem = next(ite); if(selectionCriteria(elem)){ return elem; } } return NULL; }
Bool containsNode(List list, void * element ){ Iterator * ite = buildIterator(list); while(hasMoreElements(ite)){ void * elem = next(ite); if(list->equalityCriteria(elem , element)){ return TRUE; } } return FALSE; }
void PartialOsmMapReader::readPartial(shared_ptr<OsmMap> map) { _partialMap = map; while (hasMoreElements() && (_elementsRead < _maxElementsPerMap)) { shared_ptr<Element> element = readNextElement(); _partialMap->addElement(element); } _elementsRead = 0; }
BillboardSprite::~BillboardSprite(void) { if (mNode) { auto objIter = mNode->getAttachedObjectIterator(); SceneManager* mgr = SceneManagerContainer::getSceneManager(); while (objIter.hasMoreElements()) mgr->destroyMovableObject(objIter.getNext()); mgr->destroySceneNode(mNode); } }
void executeOperationWrite(ListenSocket ls , MpsMessage * aReq, RuntimeErrorValidator * validator) { Iterator * ite = buildIterator(aReq->commands); char * fileId = hasMoreElements(ite) ? next(ite) : NULL; char * contentBlock = hasMoreElements(ite) ? next(ite) : NULL; coreOperationWriteFile(fileId , contentBlock , validator); if(hasError(validator)) { replyValidationError(ls , aReq , validator); return; } MpsMessage * response = buildMpsMessage(aReq->descriptorId , MPS_RESPONSE_STATUS_CODE_SUCCESS , aReq->operationName , NULL); sendMpsMessage(response , ls , validator); }
/* * Devuelve una lista de nombres de archivos con sus tamaños * Ambos datos estan separados por una coma y en formato de un * string. */ List getVdaFiles(char * vda , RuntimeErrorValidator * validator){ List fileNames = buildSringsList(); List fileInformations = callFssOperationGetDirectoryInformation(vda , validator); Iterator * fileInfosIterator = buildIterator(fileInformations); while(hasMoreElements(fileInfosIterator)){ FileInformation * infor = next(fileInfosIterator); char * element = concatAll(3, ltoa(infor->size) ,",", infor->name); addNode(fileNames , element ); } return (fileNames->size > 0) ? fileNames : NULL; }
/* * Apertura del archivo * 70 lineas la puta madre!!!! */ void executeOperationOpen(ListenSocket ls , MpsMessage * aReq, RuntimeErrorValidator * validator) { Iterator * ite = buildIterator(aReq->commands); char * openingMode = hasMoreElements(ite) ? next(ite) : NULL; char * path = hasMoreElements(ite) ? next(ite) : NULL; char * handleId = coreOperationOpenFile(path , openingMode , validator); if(hasError(validator)) { replyValidationError(ls , aReq , validator); return; } MpsMessage * response = buildMpsMessage(aReq->descriptorId , MPS_RESPONSE_STATUS_CODE_SUCCESS , aReq->operationName , buildStringsListWithValues(1, handleId)); sendMpsMessage(response , ls , validator); }
void flush(TddRecord * record , RuntimeErrorValidator * validator){ if(!hasTwoSectors(record->fileBlock)){ error(concatAll(4, "Ojo! Se estan asignando dos sectores para un bloque que solo necesita uno: /" , record->vdaName , "/" , record->fileName)); } if(record->openingMode != OPENING_MODE_WRITE){ setError(validator , "El archivo no fue abierto para escritura"); return; } List sectors = callFssOperationAssignAndGetSectors(record->vdaName , record->fileName , validator); if(hasError(validator)){ return; } Iterator * ite = buildIterator(sectors); int sector1 = atoi( hasMoreElements(ite) ? next(ite) : "-1" ); int sector2 = atoi( hasMoreElements(ite) ? next(ite) : "-1" ); if(sector1 < 0 || sector2 < 0 || sector1 == sector2 ){ setError(validator , "Los numeros de sectores deben ser mayores o iguales a cero y deben ser distintos"); return; } setFileBlockSectors( record->fileBlock , sector1 , sector2); VdaComponent * comp = getMountedVda(record->vdaName); if(comp == NULL){ setError(validator , "El vda necesario para realizar el flush no se encuentra montado"); return; } callVdaOperationPutSectores(comp , record->fileBlock , validator); }
void doOnlineListFiles(ClientThreadResource * res , ListenSocket clientSocket , RuntimeErrorValidator * validator){ char * pathToList = res->relativeWorkingDir; List contents = callKssOperationList(res->heapHandler , pathToList , validator); Iterator * ite = buildIterator(contents , res->heapHandler); while(hasMoreElements(ite)){ if( equalsStrings(res->relativeWorkingDir , "/")){ char * vdaName = next(ite); char * msg = concat(res->heapHandler, 3, "drwxrwxrwx 1 ftp ftp 4096 Jul 11 2011 ", vdaName , CHARACTER_CRLF); sendBytes(clientSocket , msg , (int) strlen(msg)); }else{ char * serializedContent = next(ite); List files = deserializeList(serializedContent ,res->heapHandler); Iterator * ite = buildIterator(files , res->heapHandler); char * size = hasMoreElements(ite) ? next(ite) : NULL; char * fileName = hasMoreElements(ite) ? next(ite) : NULL; char * msg = concat(res->heapHandler, 5 , "-rwxrwxrwx 1 ftp ftp " , size , "Jul 11 2011 " , fileName , CHARACTER_CRLF); sendBytes(clientSocket , msg , (int) strlen(msg)); } } if(hasError(validator)){ res->resultMessage = buildResponseMessageType426(res->heapHandler); }else{ res->resultMessage = buildResponseMessageType226(res->heapHandler); } }
void testFilesTransferMps2(){ RuntimeErrorValidator * validator = buildErrorSuccessValidator(); MpsMessage * request = receiveMpsMessage(getFileSystemConnection() , validator); Iterator * ite = buildIterator(request->commands); char * path = hasMoreElements(ite) ? next(ite) : NULL; if(path == NULL){ setError(validator , "El puto archivo vino en null"); return ; } info(concatAll(3 , "DescriptorId = '" , strndup(request->descriptorId , 16) , "'")); info(concatAll(2, "Archivo solicitado: " , path)); File * file1 = fopen(path , "r"); char buffer1[512]; char buffer2[512]; while(! feof(file1) ){ bzero(buffer1 , 512); bzero(buffer2 , 512); int readedS1 = fread(buffer1, sizeof(char) , 512 , file1); int readedS2 = fread(buffer2, sizeof(char) , 512 , file1); info(concatAll(5 , "Enviando contenido: { Sector1 = " , itoa(readedS1) , " , Sector2 = " , itoa(readedS2) , "}")); FileBlock * block = buildEmptyFileBlock(); setFileBlockContents(block , buffer1 , buffer2 , readedS1 , readedS2); MpsMessage * response = buildMpsMessage(request->descriptorId, MPS_RESPONSE_STATUS_CODE_SUCCESS , request->operationName , NULL); response->block = block; sendMpsBlockMessage(getFileSystemConnection() , response , validator); } MpsMessage * response = buildMpsMessage(request->descriptorId, MPS_RESPONSE_STATUS_CODE_SUCCESS , request->operationName , NULL); sendMpsMessage(response , getFileSystemConnection() , validator); fclose(file1); }
/* * Genera una serializacion de la lista */ char * serializeValueList(List values , HeapHandler hh){ char arguments[2048]; Iterator * iteArgs = buildIterator(values , hh); int position = 0; ZeroMemory(arguments , 2048); while(hasMoreElements(iteArgs)){ char * argument = next(iteArgs); argument = encode(argument); strcpy(arguments + position, argument); position += (int)strlen(argument); if(hasMoreElements(iteArgs)){ strcpy(arguments + position , MPS_FIELD_OPERATION_SEPARATOR); position++; } } return strdup(arguments); }
char * serializeList(List list , char * separator , HeapHandler hh){ Iterator * ite = buildIterator(list , hh); char * serialization = NULL; while(hasMoreElements(ite)){ char * element = next(ite); if(serialization == NULL){ serialization = strdup(element); }else{ serialization = concat( hh , 3 , serialization , separator , strdup(element)); } } return serialization; }
VdaInformation * callVdaOperationGetChs(VdaComponent * vdaComp , RuntimeErrorValidator * validator){ MpsMessage * req = buildMpsMessage(generateRandomKey(16) , MPS_RESPONSE_STATUS_CODE_SUCCESS, VDA_CHS_GETTING , NULL); MpsMessage * response = sendAndReceiveMpsMessages(vdaComp->listenSocket , req , validator); if( response->statusCode != MPS_RESPONSE_STATUS_CODE_SUCCESS ){ Iterator * ite = buildIterator(response->commands); char * errorMessage = hasMoreElements(ite)?next(ite):NULL; setError(validator , errorMessage); return NULL; }else{ return buildVdaInformation(vdaComp->vdaName , response->commands); } }
std::vector<std::string> OgreEntityRenderer::getEntityAnimationNames() const { std::vector<std::string> names; if (mEntity && mEntity->getAllAnimationStates()) { auto I = mEntity->getAllAnimationStates()->getAnimationStateIterator(); while (I.hasMoreElements()) { auto state = I.getNext(); names.push_back(state->getAnimationName()); } } return names; }
void COgreManager::updateFrameStats() { RenderTarget::FrameStats& stats = const_cast<RenderTarget::FrameStats&>(mWindow->getStatistics()); stats.batchCount = 0; stats.triangleCount = 0; auto iter = mRoot->getRenderSystem()->getRenderTargetIterator(); while(iter.hasMoreElements()) { RenderTarget* rt = iter.getNext(); stats.batchCount += rt->getBatchCount(); stats.triangleCount += rt->getTriangleCount(); } }
void printScene(Ogre::SceneNode* node, int indent) { for (int i = 0; i < indent; i++) { std::cout << " "; } indent++; std::cout << node->getName() << " " << node->getPosition() << " " << node->getOrientation() * Ogre::Vector3(0, 0, -1) << std::endl; auto objects = node->getAttachedObjectIterator(); while (objects.hasMoreElements()) { for (int i = 0; i < indent; i++) { std::cout << " "; } auto object = objects.getNext(); std::cout << object->getName(); if (auto light = dynamic_cast<Ogre::Light*>(object)) { std::cout << " " << light->getDirection() * Ogre::Vector3(0, 0, -1); } else if (auto cam = dynamic_cast<Ogre::Camera*>(object)) { std::cout << " " << cam->getOrientation() * Ogre::Vector3(0, 0, -1); } std::cout << std::endl; } auto n = node->getChildIterator(); while (n.hasMoreElements()) { printScene(dynamic_cast<Ogre::SceneNode*>(n.getNext()), indent + 1); } }
template <class TVal> TVal& ValueHashTableOfEnumerator<TVal>::nextElement() { // Make sure we have an element to return if (!hasMoreElements()) ThrowXML(NoSuchElementException, XMLExcepts::Enum_NoMoreElements); // // Save the current element, then move up to the next one for the // next time around. // ValueHashTableBucketElem<TVal>* saveElem = fCurElem; findNext(); return saveElem->fData; }
void* RefHashTableOfEnumerator<TVal, THasher>::nextElementKey() { // Make sure we have an element to return if (!hasMoreElements()) ThrowXMLwithMemMgr(NoSuchElementException, XMLExcepts::Enum_NoMoreElements, fMemoryManager); // // Save the current element, then move up to the next one for the // next time around. // RefHashTableBucketElem<TVal>* saveElem = fCurElem; findNext(); return saveElem->fKey; }
void OgreEntityRenderer::enableAnimation(const std::string& animationName) { if (mEntity && mEntity->getAllAnimationStates()) { auto I = mEntity->getAllAnimationStates()->getAnimationStateIterator(); while (I.hasMoreElements()) { auto state = I.getNext(); if (state->getAnimationName() == animationName) { mActiveAnimation = state; state->setEnabled(true); } else { state->setEnabled(false); } } } }
void application::setup_resources() { Ogre::ConfigFile conf; conf.load(resource_cfg); auto it = conf.getSectionIterator(); while (it.hasMoreElements()) { auto sect = it.peekNextKey(); auto settings = it.getNext(); for (auto i: *settings) Ogre::ResourceGroupManager::getSingleton() .addResourceLocation (i.second, i.first, sect); } }
void testListingFiles(){ RuntimeErrorValidator * validator = buildErrorSuccessValidator(); List l = getAllFiles("VDA1", validator); if(hasError(validator)){ error(validator->errorDescription); return ; } Iterator * ite = buildIterator(l); char * element = NULL; while( hasMoreElements(ite)){ element = next(ite); info( concatAll(4, "Archivo: " , element , " con tamaño: " , ltoa(getCurrentFileSize("VDA1" , element , validator)))); } }
void executeKssCommandTddDump(ListenSocket ls){ RuntimeErrorValidator * validator = buildErrorSuccessValidator(); MpsRequest * req = buildMpsRequest( generateRandomKey(16) , SHELL_TDD_DUMP , NULL); MpsResponse * resp = sendAndReceiveMpsMessages(ls , req ,validator); Iterator * ite = buildIterator(resp->returnValues); if(isDebugEnabled()) debug(concatAll(2, "Codigo de resultado: " , resp->statusCode)); if( equalsStrings(resp->statusCode , MPS_RESPONSE_STATUS_CODE_SUCCESS)){ info("Resultado satisfactorio "); }else{ printf("%s\n" , ( hasMoreElements(ite) ? (char *) next(ite) : "Ha ocurrido un error")); } }
void Hash2KeysSetOfEnumerator<THasher>::nextElementKey(const void*& retKey1, int& retKey2) { // Make sure we have an element to return if (!hasMoreElements()) ThrowXMLwithMemMgr(NoSuchElementException, XMLExcepts::Enum_NoMoreElements, fMemoryManager); // // Save the current element, then move up to the next one for the // next time around. // Hash2KeysSetBucketElem* saveElem = fCurElem; findNext(); retKey1 = saveElem->fKey1; retKey2 = saveElem->fKey2; return; }
template <class TVal> void RefHash2KeysTableOfEnumerator<TVal>::nextElementKey(void*& retKey1, int& retKey2) { // Make sure we have an element to return if (!hasMoreElements()) ThrowXMLwithMemMgr(NoSuchElementException, XMLExcepts::Enum_NoMoreElements, fMemoryManager); // // Save the current element, then move up to the next one for the // next time around. // RefHash2KeysTableBucketElem<TVal>* saveElem = fCurElem; findNext(); retKey1 = saveElem->fKey1; retKey2 = saveElem->fKey2; return; }
void SceneNodeWrapper::destroyAllAttachedMovableObjects( Ogre::SceneNode* node ) { if(!node) return; // Destroy all the attached objects Ogre::SceneNode::ObjectIterator itObject = node->getAttachedObjectIterator(); while ( itObject.hasMoreElements() ) node->getCreator()->destroyMovableObject(itObject.getNext()); // Recurse to child SceneNode auto itChild = node->getChildIterator(); while ( itChild.hasMoreElements() ) { Ogre::SceneNode* pChildNode = static_cast<Ogre::SceneNode*>(itChild.getNext()); destroyAllAttachedMovableObjects(pChildNode); } }