int resolveBinding(EShLanguage /*stage*/, const char* /*name*/, const glslang::TType& type, bool is_live) override { int set; if (type.getQualifier().hasSet()) set = type.getQualifier().layoutSet; else set = 0; if (type.getQualifier().hasBinding()) { if (type.getBasicType() == glslang::EbtSampler) { const glslang::TSampler& sampler = type.getSampler(); if (sampler.isImage()) return reserveSlot(set, baseImageBinding + type.getQualifier().layoutBinding); if (sampler.isPureSampler()) return reserveSlot(set, baseSamplerBinding + type.getQualifier().layoutBinding); if (sampler.isTexture()) return reserveSlot(set, baseTextureBinding + type.getQualifier().layoutBinding); } if (type.getQualifier().storage == EvqUniform) return reserveSlot(set, baseUboBinding + type.getQualifier().layoutBinding); if (type.getQualifier().storage == EvqBuffer) return reserveSlot(set, baseSsboBinding + type.getQualifier().layoutBinding); } else if (is_live && doAutoMapping) { // find free slot, the caller did make sure it passes all vars with binding // first and now all are passed that do not have a binding and needs one if (type.getBasicType() == glslang::EbtSampler) { const glslang::TSampler& sampler = type.getSampler(); if (sampler.isImage()) return getFreeSlot(set, baseImageBinding); if (sampler.isPureSampler()) return getFreeSlot(set, baseSamplerBinding); if (sampler.isTexture()) return getFreeSlot(set, baseTextureBinding); } if (type.getQualifier().storage == EvqUniform) return getFreeSlot(set, baseUboBinding); if (type.getQualifier().storage == EvqBuffer) return getFreeSlot(set, baseSsboBinding); } return -1; }
int Inventory::addItem(const int id, const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment, const Equipped equipped) { const int slot = getFreeSlot(); setItem(slot, id, type, quantity, refine, color, identified, damaged, favorite, equipment, equipped); return slot; }
int asyncclass::setSlot(void* context, handler f, ulong us, int slot, bool repValue) { if(slot==-1) slot = getFreeSlot(); if(slot==-1) return slot; fnContext[slot] = context; fn[slot] = f; fnPeriod[slot] = us; fnStamp[slot] = 0; fnRepeat[slot] = repValue; return slot; }
void cOrderProcesser::addOrder(cBuildingListItem *item) { assert(item); int freeSlot = getFreeSlot(); if (freeSlot > -1) { orderedItems[freeSlot] = item; // store the original paid price, so in case the player decides // to undo an order, he gets the same amount of money back that he paid for // (since the prices can still fluctuate during the order process) pricePaidForItem[freeSlot] = item->getBuildCost(); } }
/* Crea un proceso */ int procCreate(char *name, process_t p, void *stack, void *heap, int fds[],int files, int argc, char **argv, int tty, int orphan, int priority){ int slot = getFreeSlot(); /* Obtengo un semaforo para controlar la salida de los hijos */ proc[slot].semChild = semGetID(0); proc[slot].semFather = semGetID(0); /* Obtengo un pid para el cual pid%MAX_PROCESS de el slot obtenido */ proc[slot].pid = proc[slot].pid + MAX_PROCESS; /* Si el proceso es huerfano, es hijo de INIT */ proc[slot].ppid = (orphan)? INIT_PROCESS : schedCurrentProcess(); /* Aumento en 1 la cantidad de hijos del padre */ proc[proc[slot].ppid%MAX_PROCESS].childCount++; strcpy(proc[slot].name, name); proc[slot].status = READY; /* No está implementado el uso del heap, pero se podría agregar muy * sencillamente asignando el heap, y luego a travez de un syscall * se pueda retornar, además un malloc podría administrar esta memoria * y en caso de que necesite más memoria podría pedir más páginas */ proc[slot].heapPages[0] = heap; proc[slot].usedheapPages = 0; /* Este proceso no tiene hijos */ proc[slot].childCount = 0; proc[slot].stackPages[0] = stack; proc[slot].usedstackPages = 1; proc[slot].attachedTTY = tty; proc[slot].retval = 0; memcpy(proc[slot].fds, fds, files*sizeof(int)); proc[slot].ESP = (byte*) buildStack(stack, p, argc, argv); /* Agregarlo al scheduler para que lo empiece a correr */ schedAdd(proc[slot].pid, name, priority); schedContinue(proc[slot].pid); return proc[slot].pid; }
int lfmpscq_enqueue(lfmpscq_d_t *qd, void *data) { int node_idx, t, t_next; lfmpscq_slot_head_t *node_ptr, *t_ptr; int *shared_idx; /* try to get a free slot for the new node */ if ((node_idx = getFreeSlot(qd)) == -1) return -1; /* set up new node */ node_ptr = (void *)((unsigned long)(qd->slots) + node_idx * (sizeof(lfmpscq_slot_head_t) + qd->nodeDataSize)); hwfunctions_memcpy((void *)((unsigned long)node_ptr + sizeof(lfmpscq_slot_head_t)), data, qd->nodeDataSize); node_ptr->next = UNDEFINED_NODE; /* set pointer to shared node index */ shared_idx = (int *)(qd->sharedIdxs + qd->userID); /* now enqueue */ while(1) { /* read tail */ t = qd->q->tail; /* set shared index to protect the node from reuse until this was allowed explicitely */ *(shared_idx) = t; /* make sure the index saved in shared_idx was a valid index of tail at some time beween the previous line and now */ if(qd->q->tail != t) continue; /* read the next-index of the node we assume as tail */ t_ptr = (lfmpscq_slot_head_t *)((unsigned long)(qd->slots) + t * (sizeof(lfmpscq_slot_head_t) + qd->nodeDataSize)); t_next = t_ptr->next; /* if tail (or what we assume to be tail) is not pointing to last node in list, * try to update tail and start over */ if(t_next != UNDEFINED_NODE) { atomic_cas32(&(qd->q->tail), t, t_next); continue; } /* try to append the new node */ if(atomic_cas32(&(t_ptr->next), UNDEFINED_NODE, node_idx)) break; } /* try to update tail; if not successfull, the next enqueue will do this for us */ atomic_cas32(&(qd->q->tail), t, node_idx); return 0; }
SlotID CCreatureSet::getSlotFor(const CCreature *c, ui32 slotsAmount/*=ARMY_SIZE*/) const { assert(c->valid()); for(TSlots::const_iterator i=stacks.begin(); i!=stacks.end(); ++i) { assert(i->second->type->valid()); if(i->second->type == c) { return i->first; //if there is already such creature we return its slot id } } return getFreeSlot(slotsAmount); }
bool Inventory::addItem(Item* item) { if (item->isWeapon() && getWeapon() == NULL) { weapon = (Weapon*)item; weapon->setWielder(ch); return true; } int slot = getFreeSlot(); if (slot == -1) return false; items[slot] = item; return true; }
int Inventory::AddItem(Item* item, int amount) { int left = amount; for (int i = 0; i < slots; i++) { if(storedItems[i] != nullptr && *storedItems[i]->first == *item) { if(storedItems[i]->second + amount <= getSlotCapacity()) { storedItems[i]->second += amount; return 0; } else { int toAdd = getSlotCapacity() - storedItems[i]->second; storedItems[i]->second += toAdd; left -= toAdd; } } } while(left != 0) { int freeSlot = getFreeSlot(); if(left != 0 && freeSlot != -1) { if(left <= getSlotCapacity()) { storedItems[freeSlot] = new std::pair<Item*, int>(item, left); return 0; } else { storedItems[freeSlot] = new std::pair<Item*, int>(item, getSlotCapacity()); left -= getSlotCapacity(); } } else if(freeSlot == -1) break; } return left; }
bool ScanAsyncFile::add_read(TimeScope time_scope) { if( file_pos>=file_len ) return false; Slot *slot=getFreeSlot(); if( !slot ) return false; Packet<uint8> packet=pset.try_get(); bool ret=true; if( !packet ) { packet=pset.get(time_scope); if( !packet ) { backFreeSlot(); return false; } ret=false; } ulen len=(ulen)Min<FilePosType>(file_len-file_pos,max_read_len); FilePosType off=file_pos; file_pos+=len; Packet<uint8,Slot *,Sys::AsyncFile::ReadBufExt> packet2=packet.pushExt<Slot *>(slot).pushExt<Sys::AsyncFile::ReadBufExt>(off,len); packet2.pushCompleteFunction(function_complete_read()); file.read(packet2.forgetExt<1>()); return ret; }
void cBuildingList::addItemToList(cBuildingListItem * item) { assert(item); if (isItemInList(item)) { logbook("Failed to add icon to cBuildingList, item is already in list."); // item is already in list, do not add return; } int slot = getFreeSlot(); if (slot < 0) { logbook("Failed to add icon to cBuildingList, no free slot left in list"); assert(false); return; } // add items[slot] = item; item->setSlotId(slot); maxItems = slot; // char msg[355]; // sprintf(msg, "Icon added with id [%d] added to cBuilding list, put in slot[%d], set maxItems to [%d]", item->getBuildId(), slot, maxItems); // logbook(msg); }
void Inventory::addItem(int id, int quantity) { setItem(getFreeSlot(), id, quantity); }
int parseTrackerResponse( struct torrentInfo * torrent, char * response, int responseLen ) { int i,j; // Find the number of bytes designated to peers char * peerListPtr = strstr( response, "5:peers" ); if ( ! peerListPtr ) { return 0; } peerListPtr += strlen( "5:peers" ); char * numEnd = peerListPtr; while ( (*numEnd) && (*(numEnd) != ':') ) { numEnd ++ ; } *numEnd = '\0'; int numBytes = atoi( peerListPtr ); logToFile( torrent, "TRACKER RESPONSE Number of Peers: %d\n", numBytes / 6 ); *numEnd = ':'; if ( response + responseLen < numEnd+1+numBytes ) { // We still need more data ... return 0; } char * intervalPtr = strstr( response, "8:intervali" ); if ( ! intervalPtr ) { return 0; } char * intervalPtrStart = intervalPtr + strlen( "8:intervali" ); char * intervalPtrEnd = strchr( intervalPtrStart, 'e' ); if ( ! intervalPtrEnd ) { return 0; } *intervalPtrEnd = '\0'; int interval = atoi( intervalPtrStart ); *intervalPtrEnd = 'e'; unsigned char ip[4]; uint16_t portBytes; peerListPtr = numEnd + 1; char handshake[68]; char tmp = 19; memcpy( &handshake[0], &tmp, 1 ); char protocol[20]; strncpy( protocol, "BitTorrent protocol", 19 ); memcpy( &handshake[1], protocol, 19 ); int flags = 0; memcpy( &handshake[20], &flags, 4 ); memcpy( &handshake[24], &flags, 4 ); memcpy( &handshake[28], torrent->infoHash, 20 ); memcpy( &handshake[48], torrent->peerID, 20 ); #ifdef TRACKER_RESP_HACK // Overwrite the first peer with a particular IP and port if ( numBytes / 6 > 0 ) { char fake[6]; char * ptr = fake; char fake1 = IP0; memcpy( ptr, &fake1, 1 ); fake1 = IP1; memcpy( ptr+1, &fake1, 1 ); fake1 = IP2; memcpy( ptr+2, &fake1, 1 ); fake1 = IP3; memcpy( ptr+3, &fake1, 1 ); short fakePort = htons( PORT ); memcpy( ptr+4, &fakePort, 2 ); memcpy( peerListPtr, ptr, 6 ); } #endif for ( i = 0; i < numBytes/6; i ++ ) { int newSlot = getFreeSlot( torrent ); struct peerInfo * this = &torrent->peerList[ newSlot ]; // Get IP and port data in the right place memcpy( ip, peerListPtr, 4 ); memcpy( &portBytes, peerListPtr + 4, 2 ); snprintf( this->ipString, 16, "%u.%u.%u.%u", (int)ip[0], (int)ip[1], (int)ip[2], (int)ip[3] ); this->portNum = ntohs( portBytes ); // Before continuing, see if we already have an existing // connection with this host int exists = 0; for( j = 0; j < torrent->peerListLen; j ++ ) { if ( j == newSlot || torrent->peerList[j].defined == 0 ) { continue; } if ( !strcmp( torrent->peerList[j].ipString, this->ipString ) ) { exists = 1; break; } } if ( exists ) { this->defined = 0; break; } if ( connectToPeer( this, torrent, handshake ) ) { logToFile( torrent, "STATUS Initializing %s:%u - FAILED\n", this->ipString, (int)this->portNum ); } else { logToFile( torrent, "STATUS Initializing %s:%u - SUCCESS\n", this->ipString, (int)this->portNum ); } peerListPtr += 6; } return interval; }
void fillDesk(void) { struct udev *udev; udev_device *thedev; udev_device *usbdev; char buffer[BUFFERSIZE]; char path[BUFFERSIZE]; char *uuid=NULL; int iconhint=0; bool iscd=false; bool isdvd=false; bool isusb=false; FILE *fp; const char *ptr; char *holdfilename=NULL; /* Create the udev object */ udev = udev_new(); if (!udev) { printf("Can't create udev\n"); exit(1); } deskIconsCnt=RESERVED; fp=popen("ls -1 /dev/disk/by-uuid","r"); if(fp!=NULL) { buffer[0]=0; while(fgets(buffer,BUFFERSIZE,fp)) { addExtraIconSpace(); clearDeskEntry(deskIconsCnt,false); buffer[strlen(buffer)-1]=0; asprintf(&uuid,"%s",buffer); sprintf(path,"/dev/disk/by-uuid/%s",buffer); buffer[readlink(path,buffer,BUFFERSIZE)]=0; ptr=strrchr(buffer,'/'); ptr++; sprintf(path,"/dev/%s",ptr); if(strcmp(path,rootDev)==0) continue; deskIconsArray[deskIconsCnt].partname=strdup(ptr); thedev=udev_device_new_from_subsystem_sysname(udev,"block",ptr); if(thedev==NULL) { printf("no dev for %s from %s\n",ptr,buffer); exit(1); } else { if(strcmp(udev_device_get_property_value(thedev,"ID_FS_USAGE"),"filesystem")==0) { ptr=udev_device_get_property_value(thedev,"ID_FS_LABEL"); if(ptr==NULL) ptr=udev_device_get_property_value(thedev,"ID_SERIAL"); if(ptr==NULL) continue; iconhint=0; deskIconsArray[deskIconsCnt].label=strdup(ptr); deskIconsArray[deskIconsCnt].uuid=uuid; isdvd=false; iscd=false; isusb=false; if(udev_device_get_property_value(thedev,"ID_CDROM_MEDIA_DVD")!=NULL) { iconhint=DVD; isdvd=true; } if(udev_device_get_property_value(thedev,"ID_CDROM_MEDIA_CD")!=NULL) { iconhint=CDROM; iscd=true; } usbdev=udev_device_get_parent_with_subsystem_devtype(thedev,"usb","usb_device"); if(usbdev!=NULL) { isusb=true; if(udev_device_get_property_value(thedev,"ID_DRIVE_THUMB")!=NULL) iconhint=STICK; else iconhint=getUSBData(udev_device_get_property_value(thedev,"ID_VENDOR")); } asprintf(&deskIconsArray[deskIconsCnt].dev,"/dev/%s",deskIconsArray[deskIconsCnt].partname); deskIconsArray[deskIconsCnt].dvd=isdvd; deskIconsArray[deskIconsCnt].cdrom=iscd; deskIconsArray[deskIconsCnt].usb=isusb; deskIconsArray[deskIconsCnt].file=false; deskIconsArray[deskIconsCnt].iconhint=iconhint; if(ignores!=NULL) { if(strstr(ignores,deskIconsArray[deskIconsCnt].label)!=NULL) deskIconsArray[deskIconsCnt].ignore=true; } sprintf(buffer,"%s/%s",diskInfoPath,deskIconsArray[deskIconsCnt].uuid); if(loadVarsFromFile(buffer,globalFileData)) { deskIconsArray[deskIconsCnt].x=fileDiskXPos; deskIconsArray[deskIconsCnt].y=fileDiskYPos; if(fileGotCustomIcon==true) { deskIconsArray[deskIconsCnt].icon=fileCustomIcon; deskIconsArray[deskIconsCnt].customicon=true; fileCustomIcon=NULL; fileGotCustomIcon=false; } else deskIconsArray[deskIconsCnt].icon=NULL; } else { getFreeSlot(&deskIconsArray[deskIconsCnt].x,&deskIconsArray[deskIconsCnt].y); saveInfofile(DISKFOLDER,deskIconsArray[deskIconsCnt].label,NULL,NULL,deskIconsArray[deskIconsCnt].uuid,(char*)iconDiskType[deskIconsArray[deskIconsCnt].iconhint],deskIconsArray[deskIconsCnt].x,deskIconsArray[deskIconsCnt].y,deskIconsCnt); } deskIconsArray[deskIconsCnt].installed=true; xySlot[deskIconsArray[deskIconsCnt].x][deskIconsArray[deskIconsCnt].y]=1; deskIconsCnt++; } } } } pclose(fp); holdfilename=NULL; //desktop files sprintf(buffer,"find %s -mindepth 1 -maxdepth 1",desktopPath); char buffer2[4096]; char *tptr; fp=popen(buffer,"r"); while(fgets(buffer,BUFFERSIZE,fp)) { char *ptr; buffer[strlen(buffer)-1]=0; ptr=strrchr(buffer,'/'); ptr++; sprintf(buffer2,"%s/%s",cachePath,ptr); addExtraIconSpace(); if(strcmp(&buffer[strlen(buffer)-8],".desktop")==0) { holdfilename=strdup(buffer); } if(fileExists(buffer2)==-1) { clearDeskEntry(deskIconsCnt,false); deskIconsArray[deskIconsCnt].mountpoint=strdup(buffer); ptr=strrchr(buffer,'/'); ptr++; deskIconsArray[deskIconsCnt].label=strdup(ptr); tptr=getMimeType(buffer); ptr=strchr(tptr,'/'); while(ptr!=NULL) { *ptr='-'; ptr=strchr(tptr,'/'); } ptr=strstr(tptr,"text-x-shellscript"); if(ptr==NULL) deskIconsArray[deskIconsCnt].mime=strdup(tptr); else deskIconsArray[deskIconsCnt].mime=strdup("application-x-shellscript"); free(tptr); getFreeSlot(&deskIconsArray[deskIconsCnt].x,&deskIconsArray[deskIconsCnt].y); xySlot[deskIconsArray[deskIconsCnt].x][deskIconsArray[deskIconsCnt].y]=1; saveInfofile(CACHEFOLDER,deskIconsArray[deskIconsCnt].label,deskIconsArray[deskIconsCnt].mime,deskIconsArray[deskIconsCnt].mountpoint,NULL,NULL,deskIconsArray[deskIconsCnt].x,deskIconsArray[deskIconsCnt].y,deskIconsCnt); deskIconsArray[deskIconsCnt].installed=true; deskIconsArray[deskIconsCnt].file=true; deskIconsCnt++; } else { readDesktopFile(ptr); } if((holdfilename!=NULL) && (deskIconsArray[deskIconsCnt-1].customicon==false)) { char commandbuffer[MAXBUFFER]; char *icon; char *pth; sprintf(commandbuffer,"awk -F= '/Icon=/{print $2}' \"%s\"",holdfilename); icon=oneLiner("%s",commandbuffer); pth=strrchr(icon,'.'); if(pth!=NULL) *pth=0; if(icon!=NULL) { pth=pathToIcon(icon,""); deskIconsArray[deskIconsCnt-1].icon=strdup(pth); } free(holdfilename); holdfilename=NULL; fileCustomIcon=NULL; } } pclose(fp); }
void Inventory::addItem(int id, int quantity, int refine, unsigned char color, bool equipment) { setItem(getFreeSlot(), id, quantity, refine, color, equipment); }
bool cOrderProcesser::hasOrderedAnything() { // the id is either > 0 (meaning slot 0 is taken, or more) // or the id is lower than 0, (meaning, all slots are taken) return getFreeSlot() > 0 || getFreeSlot() < 0; }
bool cOrderProcesser::acceptsOrders() { int freeSlot = getFreeSlot(); bool result = frigateSent == false && orderPlaced == false && freeSlot > -1; return result; }
void FrameBuffer::appendData(const unsigned char* data, const unsigned int size) { lock_guard<recursive_mutex> scopedLock(syncMutex_); //fwrite(frame.getFrameData(),1,frame.getDataBlockSize(),fp); ptr_lib::shared_ptr<DataBlock> dataBlockSlot; int segNum = ceil( (double)size / (double)maxNdnPktSize_ ); unsigned int lastSegSize = size % maxNdnPktSize_; if( 0 == lastSegSize ) lastSegSize = maxNdnPktSize_; uint8_t nalHead = data[4]; if( nalHead == 0x67) lastSeqNo_ = lastPkgNo_+1; int currentBlockSize; for( int i = 0; i < segNum; ++i ) { currentBlockSize = (i==segNum-1) ? lastSegSize : maxNdnPktSize_; dataBlockSlot = getFreeSlot(); if( !dataBlockSlot.get() ) LOG(ERROR) << "[FrameBuffer] RecvFrame: getFreeSlot error" << endl; // cout <<"Segme: " << i // << " size=" << currentBlockSize // << " data: " << (void*)frame.getBuf()+(i*maxSegBlockSize_) // << " ~ " << (void*)(frame.getBuf()+currentBlockSize) // << endl << endl; dataBlockSlot->fillData(data+(i*maxNdnPktSize_),currentBlockSize); // cout << "Block" << i // << " size=" << dataBlock->size() // << " data: " << (void*)dataBlock->dataPtr() // << " ~ " << (void*)(dataBlock->dataPtr()+dataBlock->size()) // << endl << endl; // cout << "Rcev frame size = " << dataBlock->size() // << " data: " << (void*)dataBlock->dataPtr() // << " ~ " << (void*)(dataBlock->dataPtr()+dataBlock->size()) // << endl << endl << endl; // for( int i = 0; i< dataBlock->size(); ++i ) // cout << hex << dataBlock->dataPtr()[i] << " " ; ndn::Name dataPrefix(basePrefix_); dataPrefix.append(NdnUtils::componentFromInt(++lastPkgNo_)); dataPrefix.append(NameComponents::NameComponentNalMetainfo); std::vector<uint8_t> value; value.push_back(nalHead); dataPrefix.append(value); activeSlots_[dataPrefix] = dataBlockSlot; LOG_IF(ERROR, dataBlockSlot->size()<=0) << "[FrameBuffer] Cached ERROR " << dataPrefix.toUri() << " seg:"<< i << " Num:" << segNum << " ( Size = " << dec << currentBlockSize<<" of " << size << " )" << endl; LOG(INFO) << "[FrameBuffer] Cached " << dataPrefix.toUri() << " (" << i << "-" << segNum << ") [" << dec << dataBlockSlot->size()<<"-" << size << "]" << endl; //NdnUtils::printMem("cache",dataBlock->dataPtr(),20); } }
void Inventory::addItem(int id, int quantity, bool equipment) { setItem(getFreeSlot(), id, quantity, equipment); }