int KeyboardProxy::handleRawData(char *data, int bytes) { int error = validateData(data, bytes); if (error != SUCCESS) return error; UCHAR inputData[KEYBOARD_PACKET_SIZE] = { 0 }; set<UCHAR> currentKeysDown; copySet(¤tKeysDown, &lastKeysDown); // start with the keys that had no state change for (int i = 0; i < bytes; i += 2) if (lastKeysDown.find(data[i]) != lastKeysDown.end()) currentKeysDown.erase(data[i]); // Do the rest of the data; there is a 6 key cap for (int i = 0; i < bytes && currentKeysDown.size() < 6; i += 2) if (data[i + 1]) currentKeysDown.insert(data[i]); // create the data to send int index = 2; set<UCHAR>::iterator it; for (it = currentKeysDown.begin(); it != currentKeysDown.end(); ++it) { if (*it == 226) // left alt inputData[0] |= 0b00000100; if (*it == 224) // left control inputData[0] |= 0b00000001; if (*it == 225) // left shift inputData[0] |= 0b00000010; if (*it == 231) // left GUI inputData[0] |= 0b00001000; inputData[index] = *it; index++; } sendDataToDriver(inputData, KEYBOARD_PACKET_SIZE); copySet(&lastKeysDown, ¤tKeysDown); return SUCCESS; }
void SkGroup::reset() { if (fOriginal) // has been copied return; int index = 0; int max = fCopies.count() << 5; for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { if (index >= max || copySet(index) == false) continue; SkApply* apply = (SkApply*) *ptr; SkASSERT(apply->isApply()); SkASSERT(apply->getScope()); *ptr = apply->getScope(); markCopyClear(index); index++; } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AggregateCopyPropagation::LocalCopyPropagation(Block* block, TOperandToIdDict& availableCopies) { BitVector killSet(infoList_.Count()); BitVector copySet(infoList_.Count()); // Unused here. // Try to use the original operand instead of the copy. // We need to recompute the 'kill' set, because copies available // at the block entry might be invalidated by 'store' and 'call'. for(auto instr = block->FirstInstruction(); instr; instr = instr->NextInstruction()) { if(auto callInstr = instr->As<CallInstr>()) { // This might be a call that kills copies. AddToKillSet(callInstr, killSet, copySet); ReplaceWithOriginal(callInstr, availableCopies, killSet); } else if(auto storeInstr = instr->As<StoreInstr>()) { AddToKillSet(storeInstr, killSet, copySet); } else if(auto loadInstr = instr->As<LoadInstr>()) { // Try to replace the operands with the original ones. ReplaceWithOriginal(loadInstr, availableCopies, killSet); } } }
int main(int argc, char const *argv[]) { //inicializacao if(initializeCommunication(argc, argv) != 0) exit(-1); //inicailizacao falhou putdebug("inicialização completa\n"); //inicializar conjunto de ligacoes initializeConnectionSet(); int maxFd = curNode.fd; //descritor com valor mais elevado char buffer[BUFSIZE]; //buffer utilizado para fazer a leitura dos descritores int inputReady = 0; //indica se existe input disponivel para ler int quit = FALSE; while(!quit) { //reinicializar conjunto de fds de leitura FD_ZERO(&readFds); //adicionar ligacoes no conjunto de fds copySet(&readFds); //adicionar listen fd ao conjunto de fds FD_SET(curNode.fd, &readFds); //adicionar stdin ao conjunto de fds FD_SET(STDIN_FILENO, &readFds); putdebug("CurNode - ring: %d id: %d ip: %s port: %s fd: %d", curRing, curNode.id, curNode.ip, curNode.port, curNode.fd); putdebug("SucciNode - id: %d ip: %s port: %s fd: %d", succiNode.id, succiNode.ip, succiNode.port, succiNode.fd); putdebug("PrediNode - id: %d ip: %s port: %s fd: %d", prediNode.id, prediNode.ip, prediNode.port, prediNode.fd); if(maxFd < getMaxConnection()) { maxFd = getMaxConnection(); } //esperar por descritor pronto para ler putmessage("\r> "); inputReady = select(maxFd + 1, &readFds, NULL, NULL, NULL); if(inputReady <= 0) { putdebugError("main", "select falhou"); continue; } if(FD_ISSET(curNode.fd, &readFds)) { //testar se o listen fd esta pronto para leitura struct sockaddr_in addr; socklen_t addrlen = sizeof(addr); bzero(&addr, addrlen); //aceitar ligacao int connectionFd; if( (connectionFd = accept(curNode.fd, (struct sockaddr*)&addr, &addrlen)) == -1) { putdebugError("main", "ligação não foi aceite"); } else { putdebug("nova ligação %d com endereço: %s", connectionFd, inet_ntoa(addr.sin_addr)); //adicionar descritor ao conjunto de descritores de ligacao addConnection(connectionFd); //definir um timeout para as comunicações struct timeval tv; tv.tv_sec = 5; setsockopt(connectionFd, SOL_SOCKET, SO_SNDTIMEO,(struct timeval *)&tv,sizeof(struct timeval)); setsockopt(connectionFd, SOL_SOCKET, SO_RCVTIMEO,(struct timeval *)&tv,sizeof(struct timeval)); } } if(FD_ISSET(STDIN_FILENO, &readFds)) { //testar se o utilizador executou um comando //ler comando do utilizador bzero(buffer, sizeof(buffer)); if(fgets(buffer, BUFSIZE, stdin) != NULL) { //executar comando do utilizador putdebug("processar comando do utilizador"); int errorCode = executeUserCommand(buffer); switch(errorCode) { case 0: putdebug("comando de utilizador processado com sucesso"); break; case -1: putdebugError("main", "falha no processamento do comando de utilizador"); break; case 1: { putmessage("programa vai sair\n"); //fechar todos os sockets int fd = getFirstConnection(); while(fd >= 0) { close(fd); rmConnection(fd); //proxima ligacao fd = getNextConnection(fd); } //fechar socket de escuta e socket do servidor de arranque closeSockets(); quit = TRUE; continue; } } } } //ler fds de ligacoes actuais com o nó int connectionFd = getFirstConnection(); while(connectionFd >= 0) { if(FD_ISSET(connectionFd, &readFds)) { //limpar buffer de rececao bzero(buffer, sizeof(buffer)); //ler mensagem if(readMessage(connectionFd, buffer, sizeof(buffer)) <= 0) { close(connectionFd); //fechar ligacao rmConnection(connectionFd); //remover no do conjunto de ligacoes putdebug("ligacao %d terminada", connectionFd); if(connectionFd == prediNode.fd) { prediNode.fd = -1; prediNode.id = -1; putdebug("ligação terminada com predi"); if(succiNode.fd == -1 && !iAmStartNode) { //estou sozinha mas não sou o nó de arranque //isto significa que houve uma saida abrupta //registar num novo anel if(registerNewRing() == -1) { putdebugError("handleEND", "não foi possível registar novo anel"); return -1; } } } if(connectionFd == succiNode.fd) { succiNode.fd = -1; succiNode.id = -1; putdebug("ligação terminada com succi"); //colocar um alarme de 2 segundos para garnatir que todas as ligações //que são par ser terminadas têm efeito no estado do nó signal(SIGALRM, rebuildSignal); alarm(REBUILD_INTERVAL); } } else { //tratar mensagem recebida putdebug("mensagem recebida pela ligacao %d: %s", connectionFd, buffer); //remover \n int length = strlen(buffer); if(buffer[length - 1] == '\n') buffer[length - 1] = '\0'; if(strcmp(buffer, "ERROR") == 0) { //houve um erro na comunicação TCP puterror("ocorreu um erro na comunicação entre nós\n"); closeConnection(&connectionFd); continue; } if(handleMessage(buffer, connectionFd) == -1) { //notificar quem enviou o pedido que ocorreu um erro char answer[] = "ERROR\n"; sendMessage(connectionFd, answer); if(connectionFd == prediNode.fd) { prediNode.fd = -1; prediNode.id = -1; putdebug("ligação terminada com predi por causa de erro"); } if(connectionFd == succiNode.fd) { succiNode.fd = -1; succiNode.id = -1; putdebug("ligação terminada com succi por causa de erro"); } //terminar ligacao closeConnection(&connectionFd); } } } //proxima ligacao connectionFd = getNextConnection(connectionFd); } } return 0; }
Polynomial::Polynomial(const Polynomial & x) : d_terms(x.d_terms), d_set(AdmissibleOrder::s_getCurrent()),d_numberOfTerms(x.d_numberOfTerms) { copySet(x.d_set); };