void init(bt_config_t *config) { int i; fillChunkList(&masterChunk, MASTER, config->chunk_file); fillChunkList(&hasChunk, HAS, config->has_chunk_file); fillPeerList(config); if((log_file = fopen("lab2-errors.txt", "w")) == NULL) { fprintf(stderr, "Failed to open logging file.\n"); }; maxConn = config->max_conn; nonCongestQueue = newqueue(); for(i = 0; i < peerInfo.numPeer; i++) { int peerID = peerInfo.peerList[i].peerID; uploadPool[peerID].dataQueue = newqueue(); uploadPool[peerID].ackWaitQueue = newqueue(); uploadPool[peerID].connID = 0; downloadPool[peerID].getQueue = newqueue(); downloadPool[peerID].timeoutQueue = newqueue(); downloadPool[peerID].ackSendQueue = newqueue(); downloadPool[peerID].connected = 0; downloadPool[peerID].cache = NULL; initWindows(&(downloadPool[peerID].rw), &(uploadPool[peerID].sw)); } printInit(); }
void gameManagement() { subWindowMap = glutCreateSubWindow(windowID, 0, 0, 600, winHeight); glutDisplayFunc(renderSubWindow); initWindows(); glutSetWindow(subWindowMap); glutPostRedisplay(); glLoadIdentity(); subWindowSprite = glutCreateSubWindow(windowID, 600, 0, 600, winHeight); glutDisplayFunc(renderSubWindowSprite); initWindows(); glutSetWindow(subWindowSprite); glutPostRedisplay(); }
bool DXGame::initialize(HINSTANCE hInstance, void *winProc, char *className){ dprintf(("entered initialize()\n")); if(!initWindows(hInstance, winProc, className)){ DestroyWindow(hwnd); return FALSE; } if(!initDirectX(hInstance)){ DestroyWindow(hwnd); return FALSE; } dprintf(("leaving initialize()\n")); return TRUE; }
GestureClassifierByHistogram::GestureClassifierByHistogram(const GestureClassifierByHistogram &rhs) : base_type(), params_(rhs.params_), refFullPhaseHistograms_(rhs.refFullPhaseHistograms_), refHistogramsForClass1Gesture_(rhs.refHistogramsForClass1Gesture_), refHistogramsForClass2Gesture_(rhs.refHistogramsForClass2Gesture_), refHistogramsForClass3Gesture_(rhs.refHistogramsForClass3Gesture_), gestureIdPatternHistogramsForClass1Gesture_(rhs.gestureIdPatternHistogramsForClass1Gesture_), histogramAccumulatorForClass1Gesture_(rhs.histogramAccumulatorForClass1Gesture_), histogramAccumulatorForClass2Gesture_(rhs.histogramAccumulatorForClass2Gesture_), histogramAccumulatorForClass3Gesture_(rhs.histogramAccumulatorForClass3Gesture_), matchedHistogramIndexes1ForClass1Gesture_(rhs.matchedHistogramIndexes1ForClass1Gesture_), matchedHistogramIndexes2ForClass1Gesture_(rhs.matchedHistogramIndexes2ForClass1Gesture_), matchedHistogramIndexesForClass2Gesture_(rhs.matchedHistogramIndexesForClass2Gesture_), matchedHistogramIndexesForClass3Gesture_(rhs.matchedHistogramIndexesForClass3Gesture_), gestureId_(rhs.gestureId_) { #if defined(__VISUALIZE_HISTOGRAMS_IN_GESTURE_CLASSIFIER_BY_HISTOGRAM_) initWindows(); #endif }
void Map::initCave (CaveMapTile* caveTile) { int start = -1; int end = -1; Platform *platform = getPlatform(caveTile, &start, &end, caveTile->getSize().y); if (platform == nullptr) { error(LOG_MAP, "failed to initialize the cave platform"); return; } platform->setCave(caveTile); initWindows(caveTile, start, end); caveTile->setRespawnPossible(true, EntityType::NONE); caveTile->setPlatformDimensions(start, end); }
int updateGetSingleChunk(Packet *pkt, int peerID) { recvWindow *rw = &(downloadPool[peerID].rw); int dataSize = getPacketSize(pkt) - 16; uint8_t *dataPtr = pkt->payload + 16; uint32_t seq = (uint32_t)getPacketSeq(pkt); downloadPool[peerID].timeoutCount = 0; fprintf(stderr,"Got pkt %d expecting %d\n", seq, rw->nextPacketExpected); if(seq >= rw->nextPacketExpected) { if((seq > rw->nextPacketExpected) && ((seq - rw->nextPacketExpected) <= INIT_THRESH)) { insertInOrder(&(downloadPool[peerID].cache), newFreePacketACK(seq), seq); newPacketACK(rw->nextPacketExpected - 1, downloadPool[peerID].ackSendQueue); } else if(seq - rw->nextPacketExpected <= INIT_THRESH) { newPacketACK(seq, downloadPool[peerID].ackSendQueue); rw->nextPacketExpected = flushCache(rw->nextPacketExpected, downloadPool[peerID].ackSendQueue, &(downloadPool[peerID].cache)); } rw->lastPacketRead = seq; rw->lastPacketRcvd = seq; int curChunk = downloadPool[peerID].curChunkID; long offset = (seq - 1) * PACKET_DATA_SIZE + BT_CHUNK_SIZE * curChunk; FILE *of = getChunk.filePtr; fprintf(stderr,"In: %d [%ld-%ld]\n", seq, offset, offset + dataSize); if(of != NULL) { fseek(of, offset, SEEK_SET); fwrite(dataPtr, sizeof(uint8_t), dataSize, of); } if(rw->nextPacketExpected > BT_CHUNK_SIZE / PACKET_DATA_SIZE + 1){ clearQueue(downloadPool[peerID].timeoutQueue); fprintf(stderr,"Chunk finished downloading! Next expected %d thresh %d\n", rw->nextPacketExpected, BT_CHUNK_SIZE / PACKET_DATA_SIZE + 1); getChunk.list[curChunk].fetchState = 1; downloadPool[peerID].state = 0; clearQueue(downloadPool[peerID].timeoutQueue); initWindows(&(downloadPool[peerID].rw), &(uploadPool[peerID].sw)); fprintf(stderr,"Chunk %d fetched!\n", curChunk); // fprintf(stderr,"%d More GETs in queue\n", downloadPool[peerID].getQueue->size); return 1; } else { return 0; } } else { fprintf(stderr,"Received an unexpected packet!" "Expecting %d but received %d!", rw->nextPacketExpected, seq); newPacketACK(seq, downloadPool[peerID].ackSendQueue); return 0; } }
int main(int argc, char* argv[]) { char *nDex = NULL; char *sharing_path = NULL; int port = 0; initWindows(); #ifndef DEBUG (void) argv; #else if ( argc > 3 ) { if ( !fileExist(nDex = argv[1]) || !verifPort(port = atoi(argv[2])) ) { QUIT_MSG("An error occur, please refere to previous error(s)\n"); } sharing_path = argv[3]; } else { printf("[INFO] Remember, you could use program argument in debug mode. \n"); printf("\t %s <path_to_ndex> <port> <share_directory>\n", argv[0]); printf("\t With <port> between 1024 and 65536.\n"); } if ( argc <= 3 ) { #endif nDex = askNDex(); port = askPort(); sharing_path = askShareRepo(); /* These ask, and move to the repository */ #ifdef DEBUG } #endif startCollector(nDex, port, sharing_path); if ( argc < 3 ) { free(nDex); free(sharing_path); } endWindows(); END(); exit(EXIT_SUCCESS); }
void updateACKQueue(Packet *pkt, int peerID) { sendWindow *sw = &(uploadPool[peerID].sw); uint32_t ack = getPacketAck(pkt); queue *ackWaitQueue = uploadPool[peerID].ackWaitQueue; queue *dataQueue = uploadPool[peerID].dataQueue; Packet *ackWait = peek(ackWaitQueue); struct timeval cur_time; gettimeofday(&cur_time, NULL); logger(peerID, uploadPool[peerID].connID, diffTimevalMilli(&cur_time, &(uploadPool[peerID].startTime)), sw->ctrl.windowSize); expandWindow(&(sw->ctrl)); uploadPool[peerID].timeoutCount = 0; fprintf(stderr,"Received ACK %d. Last ACK: %d. Next up: %d\n", ack, sw->lastPacketAcked, ackWait == NULL ? 65535 : getPacketSeq(ackWait)); if(ackWait != NULL) { if(ack >= getPacketSeq(ackWait)) { sw->dupCount = 0; while(ackWait != NULL && ack >= getPacketSeq(ackWait)) { dequeue(ackWaitQueue); freePacket(ackWait); ackWait = peek(ackWaitQueue); } sw->lastPacketAcked = ack; updateSendWindow(sw); if(ack == BT_CHUNK_SIZE / PACKET_DATA_SIZE + 1) { fprintf(stderr,"Finished sending current chunk!"); numConnUp--; initWindows(&(downloadPool[peerID].rw), &(uploadPool[peerID].sw)); assert(dequeue(ackWaitQueue) == NULL); } } else { // Unexpected ACK number if(ack == sw->lastPacketAcked) { // Dupliate ACK sw->dupCount++; fprintf(stderr,"Received duplicate packets %d\n", ack); if(sw->dupCount == MAX_DUPLICATE) { // Trigger a fast retransmit fprintf(stderr,"Received 3 duplicates acks %d retransmitting\n", ack); sw->dupCount = 0; mergeAtFront(ackWaitQueue, dataQueue); shrinkWindow(&(sw->ctrl)); } } } } }
void XBScene1::setup(XBBaseGUI *_gui) { XBBaseScene::setup(_gui); wavesMask.allocate(ofGetWidth(), ofGetHeight(), GL_RGB); wavesMask.begin(); ofSetBackgroundAuto(false); ofBackground(0, 0, 0); wavesMask.end(); initWindows(); initParticles(); initWaves(); initStones(); initLines(); blur.setup(getMainFBO().getWidth(), getMainFBO().getHeight(), 0); XBScene1GUI *myGUI = (XBScene1GUI *) gui; myGUI->flashDirector.getParameter().cast<bool>().addListener(this, &XBScene1::flashDirector); }
bool ofTrueTypeFont::initLibraries(){ if(!librariesInitialized){ FT_Error err; err = FT_Init_FreeType( &library ); if (err){ ofLogError("ofTrueTypeFont") << "loadFont(): couldn't initialize Freetype lib: FT_Error " << err; return false; } #ifdef TARGET_LINUX FcBool result = FcInit(); if(!result){ return false; } #endif #ifdef TARGET_WIN32 initWindows(); #endif librariesInitialized = true; } return true; }
bool MgrStereoHand::init(){ initWindows(); drawingModule = new DrawingModule; fs = new FrameStorage; fs->initFrames(); calibModule = new CalibrationModule; process = new ProcessingThread; process->init(fs, calibModule, calibDialog, statisticsDialog); calibDialog->init(calibModule); realProcessingThead = new QThread(); process->moveToThread(realProcessingThead); connect(realProcessingThead, SIGNAL(started()), process, SLOT(process())); connect(process, SIGNAL(finished()), realProcessingThead, SLOT(quit())); connect(process, SIGNAL(finished()), process, SLOT(deleteLater())); connect(realProcessingThead, SIGNAL(finished()), realProcessingThead, SLOT(deleteLater())); connect(realProcessingThead, SIGNAL(finished()), this, SLOT(realExit())); connect(process, SIGNAL(showImages()), this, SLOT(showImages())); connect(process, SIGNAL(messageError(QString, QString)), this, SLOT(errorMessage(QString, QString))); connect(process, SIGNAL(startedProcess()), this, SLOT(startedProcess())); connect(process, SIGNAL(finishedProcess()), this, SLOT(finishedProcess())); connect(process, SIGNAL(calibrationNotSet()), this, SLOT(calibrationNotSet())); connect(process, SIGNAL(showOverlay(QString,int)), this, SLOT(showOverlay(QString,int))); connect(process, SIGNAL(getFilmFileName()), this, SLOT(getFilmFileName())); //connect(this, SIGNAL(showOverlay(QString,int)), this, SLOT(showOverlay(QString,int))); realProcessingThead->start(); return true; }
int main(int argc, char** argv) { glutInit(&argc, argv); //glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(winWidth,winHeight); glutInitWindowPosition(100, 400); // 100, 100 //MAIN WINDOW windowID = glutCreateWindow("Hey World!"); //DISPLAY CALLBACK glutDisplayFunc(displayMain); init(); initWindows(); //KEYBOARD AND MOUSE CALLBACKS //cursor glutSetCursor(GLUT_CURSOR_INFO); //mouse glutTimerFunc(0,timer,0); glutMainLoop(); return 0; }
void Application::initPlayground(TPlatform* pPlatform) { setFactory( 0 ); initGameStates(); initWindows(pPlatform); }
int Kernel::start(char *argv[], Display *display, MSettings *themeSettings, MSettings *commonSettings, MSettings *actionSettings, MSettings *sessionSettings, bool isFirstRun) { runlevel_ = START; // init, order is very important display_ = display; monitors_ = new CMonitor(this); themeSettings_ = themeSettings; commonSettings_ = commonSettings; actionSettings_ = actionSettings; sessionSettings_ = sessionSettings; actionBindings_ = new MBindings(); isRecording_ = false; isMenuMode_ = false; isSloppyMode_ = true; isStackedTabbing_ = Util::get(commonSettings_, "cycle.mode") != "default"; borderWidth_ = Util::strToUInt(Util::get(commonSettings_, "border.width")); LOGDEBUG("--- begin of new NCWM session ---"); XSetErrorHandler(XCore::handleErrors); LOGDEBUG("error handler installed"); XCORE->setDisplay(display_); LOGDEBUG("xcore initialized"); Atoms::initAtoms(); LOGDEBUG("atoms initialized"); Cursors::initCursors(); LOGDEBUG("cursors initialized"); Actions::instance()->initInternActions(actionBindings_); LOGDEBUG("intern actions initialized"); initActionBindings(); LOGDEBUG("action bindings initialized"); initMonitors(); LOGDEBUG("monitors initialized"); initKeys(); LOGDEBUG("keys initialized"); Launcher::instance()->exec( Util::get(themeSettings_, "exec")); if (isFirstRun) { Actions::instance()->executeTerm(0, "man ncwm"); } // Sync all X buffers and wait until all events has been // processed XCORE->sync(); initWindows(); LOGDEBUG("windows initialized"); defaultPrompt_ = new Prompt(": ", &Binder::queryActionKeysForPattern); Action* startupAction = new Action("startup", &Actions::sequence, &Validators::isAlwaysPossible, Action::SEQUENCE, strdup(Util::get(commonSettings_, "startup.chain").c_str())); startupAction->perform(); delete startupAction; Expander::instance(); // rehash expander // Launch main event loop runlevel_ = RUN; int result = run(); serialize(); LOGDEBUG("current state serialized"); LOGDEBUG("--- end of NCWM session ---"); cleanup(); if (runlevel_ == RESTART) { saveSettings(); execvp(argv[0], argv); LOGERROR("restart failed", false); exit(1); } return result; }
int main(int argc, char *argv[]) { struct windows win = { NULL, NULL, NULL, NULL }; int curs_x = CURS_X_MIN, curs_y = CURS_Y_MIN, pad_minrow = 0, pad_textrows, ch, quit = 0; char *status = "", scratch[1000]; // Init curses initNCurses(); initWindows(&win); // Add text to main window loadAndAddText(&win.textpad, &pad_textrows, "story.txt"); while (!quit) { if ((ch = getch()) != ERR) { switch (tolower(ch)) { // UP case KEY_UP: if (curs_y > CURS_Y_MIN) { curs_y--; } else { if (pad_minrow > 0) { pad_minrow--; } } break; // DOWN case KEY_DOWN: if (curs_y < CURS_Y_MAX) { curs_y++; } else { if (pad_minrow < pad_textrows - PAD_HEIGHT) { pad_minrow++; } } break; // LEFT case KEY_LEFT: if (curs_x > CURS_X_MIN) { curs_x--; } break; // RIGHT case KEY_RIGHT: if (curs_x < CURS_X_MAX) { curs_x++; } break; // PAGE UP case KEY_PPAGE: curs_y = CURS_Y_MIN; pad_minrow = clip(pad_minrow - PAGE_SCROLL_SIZE, 0, pad_textrows - PAD_HEIGHT); break; // PAGE DOWN case KEY_NPAGE: curs_y = CURS_Y_MAX; pad_minrow = clip(pad_minrow + PAGE_SCROLL_SIZE, 0, pad_textrows - PAD_HEIGHT); break; // HOME case KEY_HOME: curs_x = CURS_X_MIN; break; // END case KEY_END: curs_x = CURS_X_MAX; break; case 'l': mvwinstr(win.textpad, pad_minrow + curs_y - 1, curs_x - 1, scratch); status = scratch; //status = "Lookup"; break; case 'u': status = "Use"; break; case 'g': status = "Goto"; break; case 't': status = "Talk"; break; case 'e': status = "Examine"; break; case 'q': quit = 1; break; default: break; } } updateTextPad(win.textpad, pad_minrow); updateStatusBar(win.status, status); updateCursor(win.main, curs_y, curs_x); } delWindows(&win); delNCurses(); return 0; }
void handlePacket(Packet *pkt) { if(verifyPacket(pkt)) { int type = getPacketType(pkt); switch(type) { case 0: { // WHOHAS fprintf(stderr,"->WHOHAS\n"); Packet *pktIHAVE = newPacketIHAVE(pkt); enqueue(nonCongestQueue, (void *)pktIHAVE); break; } case 1: { // IHAVE fprintf(stderr,"->IHAVE\n"); int peerIndex = searchPeer(&(pkt->src)); int peerID = peerInfo.peerList[peerIndex].peerID; newPacketGET(pkt, downloadPool[peerID].getQueue); idle = 0; break; } case 2: { // GET fprintf(stderr,"->GET\n"); if(numConnUp == maxConn){ fprintf(stderr,"->GET request denied.\n"); freePacket(pkt); break; } numConnUp++; int peerIndex = searchPeer(&(pkt->src)); int peerID = peerInfo.peerList[peerIndex].peerID; if(downloadPool[peerID].connected == 0){ clearQueue(uploadPool[peerID].ackWaitQueue); initWindows(&(downloadPool[peerID].rw), &(uploadPool[peerID].sw)); newPacketDATA(pkt, uploadPool[peerID].dataQueue); uploadPool[peerID].connID++; gettimeofday(&(uploadPool[peerID].startTime), NULL); } else { fprintf(stderr,"Only one-way connection is allowed.\n"); freePacket(pkt); } break; } case 3: { // DATA fprintf(stderr,"->DATA"); int peerIndex = searchPeer(&(pkt->src)); int peerID = peerInfo.peerList[peerIndex].peerID; if(1 == updateGetSingleChunk(pkt, peerID)) { downloadPool[peerID].connected = 0; numConnDown--; updateGetChunk(); } break; } case 4: { // ACK fprintf(stderr,"->ACK\n"); int peerIndex = searchPeer(&(pkt->src)); int peerID = peerInfo.peerList[peerIndex].peerID; updateACKQueue(pkt, peerID); break; } case 5: // DENIED default: fprintf(stderr,"DENIED\n"); } } else { fprintf(stderr,"Invalid packet!\n"); } freePacket(pkt); return; }