void RenderContext::create() { if(s_primedContext || s_creationLock) { logThrowGL("[RenderContext] You cannot create a RenderContext while " "another is primed or being created!"); } s_creationLock = true; // context needs to be current to call glewInit makeCurrent(); // glewExperimental to use context versions above 3.2 // TODO: call glewInit just once (???) glewExperimental = GL_TRUE; GLenum status = glewInit(); // check for errors if(status != GLEW_OK) { logThrowGL("[RenderContext] glewInit() failed with status <", status, ">!"); } // check for GL error (glew often causes one when using new context versions) auto err = glGetError(); if(err != GL_NO_ERROR) { logNotice("[RenderContext] glewInit() caused an openGL error <", translateGLError(err), ">."); } // configure context configure(); // reset state resetCurrent(); s_creationLock = false; m_wasCreated = true; }
void RenderContext::prime(std::function<void(HotRenderContext&)> func) { // check if another target is already current if(s_primedContext) { logThrowGL("[RenderContext] You cannot prime more than one RenderContext " "at a time!"); } if(s_creationLock) { logThrowGL("[RenderContext] You cannot prime a RenderContext while another " "is being create!"); } if(!m_wasCreated) { logThrowGL("[RenderContext] You cannot prime a RenderContext that was not " "created yet!"); } // make context current and create HotContext makeCurrent(); HotRenderContext hot(*this); s_primedContext = &hot; // call function func(hot); // reset state resetCurrent(); s_primedContext = nullptr; }
/** \param[in] newDoc XML document to define as the XML tree of this FevenData. \retval RET_OK No problemo. \retval RET_CANNOTACCESS Error accessing the XML tree, or parameter is void. \retval RET_NONODESELECTED Nothing found, content free. \retval RET_NONAME No name field in the first node. \retval RET_NOTEXIST First node not exist. */ long FevenData::setDatasFromXml( xmlDocPtr newDoc) { long ret = RET_OK; if( newDoc) { // Erase all existing datas endXml(); doc = newDoc; ret = startXml( doc->children); // init the datas node pointer resetCurrent(); gotoChildren(); Find( XML_DATAS, false); datas = current; // Get MetaDatas getMetaEvenDatasFromXml(); updateHashValue(); return ret; } else return RET_CANNOTACCESS; }
void MultiTaskScheduler::start() { thread = std::thread([this] () { makeCurrent(); unowned = stashGet(); boost::context::jump_fcontext(&initialContext, unowned->context, 0); if (unowned != nullptr) { stashPut(unowned); unowned = nullptr; } resetCurrent(); }); }
int timeout( int timerID, void *flowdata ) { accData_t *data = (accData_t *)flowdata; #ifdef DEBUG fprintf( stderr, "bandwidth: timeout(n = %d)\n", timerID ); #endif appendCounters(data); resetCurrent(data); return 0; }
void MyTrie::loadDictionary() { //load the given dictionary std::ifstream myDictionary; myDictionary.open(dictionary); //open the dictionary if(myDictionary.is_open()) //if it is onep { std::cout << "Loading Dictionary"; int k = 0; std::string line; while(getline(myDictionary, line)) //read it line by line { if(k % 72 == 0 || k % 72 == 12 || k % 72 == 24) //some poor attempt on to graphically show that loading is in progress std::cout << "."; if(k % 72 == 36 || k % 72 == 48 || k % 72 == 60) std::cout << "\b \b"; k++; isValidWord = true; //set it to be a valid word for(int i = 0; i < line.length(); i++) //read the line letter by letter { if(line[i] >= 'a' && line[i] <= 'z') //if it's a lower case character { goDown(line[i]); //go down the tree with that character } else { if(line[i] >= 'A' && line[i] <= 'Z') //if it's a capital letter { char c = line[i] + 32; //set it as lowercase goDown(c); //go down with that letter } else { isValidWord = false; //if not, set the word to be not valid } } } if(isValidWord) //once you finish reading the line confirmWordInLoad(); //confirm the word in load else //if not resetCurrent(); //reset the current pointer } std::cout << std::endl; myDictionary.close(); //close the dictionary } else //if you can't open it, let the user know std::cout << "Could not find the dictionary!" << std::endl; }
//-------------------------------------------------------------- void testApp::keyPressed(int key){ // if(key <= 49+N_LAYER) { // Top row num key 1 = 49 // editLayer = key-49; // ofLog() << "Set Layer to " << editLayer; // } switch(key) { case '`': setEditMode(!getEditMode()); break; case 'x': resetCurrent(); break; case 'd': debug = !debug; cam->toggleGui(debug); break; case 'z': saveEditted(); break; case 'q': if(debug) editPoly = 0; else editCanvas = 0; break; case 'w': if(debug) editPoly = 1; else editCanvas = 1; break; case 'e': if(debug) editPoly = 2; else editCanvas = 2; break; case 'r': if(debug) editPoly = 3; else editCanvas = 3; break; // case '[': //exportSettings(); break; case ']': reloadSettings(); ofClear(0); break; case 'c': cam->closePoints(editPoly); break; case 'C': cam->resetCircle(); break; case 'f': fullscreen = !fullscreen; ofSetFullscreen(fullscreen); break; case 'v': part->increaseUpper(); break; case 'b': part->decreaseUpper(); break; case 'n': part->increaseLower(); break; case 'm': part->decreaseLower(); break; } }
void TGroup::shutDown() { /* looks like this is a fix from someone! No such string both in TV 1.0 & 2.0. Let it stay here for a while */ resetCurrent(); TView *p = last; if (p != 0) { do { p->hide(); p = p->prev(); } while (p != last); do { TView *T = p->prev(); destroy(p); p = T; } while (last != 0); } freeBuffer(); current = 0; TView::shutDown(); }
int initFlowRec( configParam_t *params, void **flowdata ) { accData_t *data; data = malloc( sizeof(accData_t) ); if (data == NULL ) { return -1; } data->numSets = 0; data->maxSets = 0; data->dataSets = NULL; data->export_ts = time(NULL); /* init current block of counters */ resetCurrent( data ); /* copy default timers to current timers array for a specific task */ memcpy(data->currTimers, timers, sizeof(timers)); while (params[0].name != NULL) { if (!strcmp(params[0].name, "Interval")) { int a = atoi(params[0].value); if (a > 0) { data->currTimers[0].ival_msec = 1000 * a; #ifdef DEBUG fprintf( stderr, "bandwidth module: setting snapshot timer to %d secs\n", a ); #endif } } params++; } *flowdata = data; return 0; }
int main(){ Simulation *sim = malloc(sizeof(struct simulation)); Settings *sett = malloc(sizeof(struct settings)); Grid *g = malloc(sizeof(struct grid)); Boundary regionBoundaryMap[9]; int i, j, k; double PositionComponentofForceX; double PositionComponentofForceY; double Bz; double TangentVelocityComponentOfForceX; double TangentVelocityComponentOfForceY; double Mass; double vxminus; double vyminus; double t_z; double s_z; double vxprime; double vyprime; double vxplus; double vyplus; double timeStep = sett->timeStep; int region; /**X index of local origin i.e. nearest grid point BEFORE particle push*/ int xStart; /**Y index of local origin i.e. nearest grid point BEFORE particle push*/ int yStart; /**X index of local origin i.e. nearest grid point AFTER particle push*/ int xEnd; /**Y index of local origin i.e. nearest grid point AFTER particle push*/ int yEnd; /**Normalized local x coordinate BEFORE particle push*/ double x; /**Normalized local y coordinate BEFORE particle push*/ double y; /**Normalized distance covered in X direction*/ double deltaX; /**Normalized distance covered in X direction*/ double deltaY; readInputData(sim, g, sett); createBoundaryMap(regionBoundaryMap, sett->simulationWidth, sett->simulationHeight); for(j = 0; j < sett->iterations; j++){ for(i = 0; i < sett->numOfParticles; i++){ /*--------------------------------------------------------------------------/ /---------------- Step 1: particlePush()------------------------------------/ /--------------------------------------------------------------------------*/ //a) particle.storePosition() sim->particles[i].prevX = sim->particles[i].x; sim->particles[i].prevY = sim->particles[i].y; //b)solver.timeStep(particle, force, timeStep)/----Boris solver-----/ PositionComponentofForceX = getPositionComponentofForceX(sim->particles[i]); PositionComponentofForceY = getPositionComponentofForceY(sim->particles[i]); Bz = getBz(sim->particles[i]); TangentVelocityComponentOfForceX = getTangentVelocityComponentOfForceX(sim->particles[i]); TangentVelocityComponentOfForceY = getTangentVelocityComponentOfForceY(sim->particles[i]); Mass = sim->particles[i].mass; // remember for complete() sim->particles[i].prevpositionComponentForceX = PositionComponentofForceX; sim->particles[i].prevpositionComponentForceY = PositionComponentofForceY; sim->particles[i].prevBz = Bz; sim->particles[i].prevtangentVelocityComponentOfForceX = TangentVelocityComponentOfForceX; sim->particles[i].prevtangentVelocityComponentOfForceY = TangentVelocityComponentOfForceY; vxminus = sim->particles[i].vx + PositionComponentofForceX * timeStep / (2.0 * Mass); vyminus = sim->particles[i].vy + PositionComponentofForceY * timeStep / (2.0 * Mass); t_z = sim->particles[i].charge * Bz * timeStep / (2.0 * Mass); //t vector s_z = 2 * t_z / (1 + t_z * t_z); //s vector vxprime = vxminus + vyminus * t_z; vyprime = vyminus - vxminus * t_z; vxplus = vxminus + vyprime * s_z; vyplus = vyminus - vxprime * s_z; sim->particles[i].vx = vxplus + PositionComponentofForceX * timeStep / (2.0 * Mass) + TangentVelocityComponentOfForceX * timeStep / Mass; sim->particles[i].vy = vyplus + PositionComponentofForceY * timeStep / (2.0 * Mass) + TangentVelocityComponentOfForceY * timeStep / Mass; sim->particles[i].x = sim->particles[i].x + sim->particles[i].vx * timeStep; sim->particles[i].y = sim->particles[i].y + sim->particles[i].vy * timeStep; //c) boundaries.applyOnParticleCenter(solver, force, particle, timeStep) region = get_region(sim->particles[i].x, sim->particles[i].x, sim->particles[i].y, sim->particles[i].y, sett->simulationWidth, sett->simulationHeight); sim->particles[i].x = sim->particles[i].x - regionBoundaryMap[region].xoffset; sim->particles[i].prevX = sim->particles[i].prevX - regionBoundaryMap[region].xoffset; sim->particles[i].y = sim->particles[i].y - regionBoundaryMap[region].yoffset; sim->particles[i].prevY = sim->particles[i].prevY - regionBoundaryMap[region].yoffset; /*--------------------------------------------------------------------------/ /---Step 4: interpolation.interpolateToGrid(particles, grid, tstep)---------/ /--------------------------------------------------------------------------*/ resetCurrent(g); x = sim->particles[i].prevX / g->cellWidth; y = sim->particles[i].prevY / g->cellHeight; xStart = (int) floor(x + 0.5); yStart = (int) floor(y + 0.5); deltaX = sim->particles[i].x / g->cellWidth; deltaY = sim->particles[i].y / g->cellHeight; xEnd = (int) floor(deltaX + 0.5); yEnd = (int) floor(deltaY + 0.5); deltaX -= x; deltaY -= y; x -= xStart; y -= yStart; double pCharge = sim->particles[i].charge; //4-boundary move? if (xStart == xEnd && yStart == yEnd) { fourBoundaryMove(xStart, yStart, x, y, deltaX, deltaY, pCharge, g); } //7-boundary move? else if (xStart == xEnd || yStart == yEnd) { sevenBoundaryMove(x, y, xStart, yStart, xEnd, yEnd, deltaX, deltaY, pCharge, g); } // 10-boundary move else { tenBoundaryMove(x, y, xStart, yStart, xEnd, yEnd, deltaX, deltaY, pCharge, g); } createBoundaryCells(g); } } // for(i = 0; i < sett->numOfParticles; i++){ // // fscanf(inParticles, "%lg", &sim->particles[i].x); // printf("%lg\n", sim->particles[i].x); // // fscanf(inParticles, "%lg", &sim->particles[i].y); // printf("%lg\n", sim->particles[i].y); // // fscanf(inParticles, "%lg", &sim->particles[i].radius); // printf("%lg\n", sim->particles[i].radius); // // fscanf(inParticles, "%lg", &sim->particles[i].vx); // printf("%lg\n", sim->particles[i].vx); // // fscanf(inParticles, "%lg", &sim->particles[i].vy); // printf("%lg\n", sim->particles[i].vy); // // fscanf(inParticles, "%lg", &sim->particles[i].ax); // printf("%lg\n", sim->particles[i].ax); // // fscanf(inParticles, "%lg", &sim->particles[i].ay); // printf("%lg\n", sim->particles[i].ay); // // fscanf(inParticles, "%lg", &sim->particles[i].mass); // printf("%lg\n", sim->particles[i].mass); // // fscanf(inParticles, "%lg", &sim->particles[i].charge); // printf("%lg\n", sim->particles[i].charge); // // fscanf(inParticles, "%lg", &sim->particles[i].prevX); // printf("%lg\n", sim->particles[i].prevX); // // fscanf(inParticles, "%lg", &sim->particles[i].prevY); // printf("%lg\n", sim->particles[i].prevY); // // fscanf(inParticles, "%lg", &sim->particles[i].Ex); // printf("%lg\n", sim->particles[i].Ex); // // fscanf(inParticles, "%lg", &sim->particles[i].Ey); // printf("%lg\n", sim->particles[i].Ey); // // fscanf(inParticles, "%lg", &sim->particles[i].Bz); // printf("%lg\n", sim->particles[i].Bz); // // fscanf(inParticles, "%lg", &sim->particles[i].prevpositionComponentForceX); // printf("%lg\n", sim->particles[i].prevpositionComponentForceX); // // fscanf(inParticles, "%lg", &sim->particles[i].prevpositionComponentForceY); // printf("%lg\n", sim->particles[i].prevpositionComponentForceY); // // fscanf(inParticles, "%lg", &sim->particles[i].prevtangentVelocityComponentOfForceX); // printf("%lg\n", sim->particles[i].prevtangentVelocityComponentOfForceX); // // fscanf(inParticles, "%lg", &sim->particles[i].prevtangentVelocityComponentOfForceY); // printf("%lg\n", sim->particles[i].prevtangentVelocityComponentOfForceY); // // fscanf(inParticles, "%lg", &sim->particles[i].prevnormalVelocityComponentOfForceX); // printf("%lg\n", sim->particles[i].prevnormalVelocityComponentOfForceX); // // fscanf(inParticles, "%lg", &sim->particles[i].prevnormalVelocityComponentOfForceY); // printf("%lg\n", sim->particles[i].prevnormalVelocityComponentOfForceY); // // fscanf(inParticles, "%lg", &sim->particles[i].prevBz); // printf("%lg\n", sim->particles[i].prevBz); // // fscanf(inParticles, "%lg", &sim->particles[i].prevLinearDragCoefficient); // printf("%lg\n", sim->particles[i].prevLinearDragCoefficient); // } return 0; }
/** \retval RET_OK No problemo, room created. \retval RET_NOINFOS No configuration informations to process. */ long Frouter::createRoom() { FclassInfos classInfo; FconditionLink conditionLink; FstringHash strH; Fport* port; resetCurrent(); if( !gotoChildren()) { // -------------------------------------------------- // IMPORT PORTS // -------------------------------------------------- IMPORT_PORTS( XML_ROOM, "", Frouter) IMPORT_PORTS( XML_BOARD, "", FevenBoard) // -------------------------------------------------- // IMPORTS a default evenData // -------------------------------------------------- setFreeEvenData( new FevenData()); // -------------------------------------------------- // IMPORT DATAS to enable an easy creation of evenData instances // -------------------------------------------------- // -------------------------------------------------- // IMPORT YOUR OWN PORTS // -------------------------------------------------- // -------------------------------------------------- // -------------------------------------------------- // -------------------------------------------------- // IMPORT LINK VALUES BETWEEN evenData, evenDoor AND ports // -------------------------------------------------- if( !Find( XML_LNK, false)) { do { pushCurrent(); getLinkInfos( &conditionLink); if( conditionLink.source.getLen()) { strH.setString( conditionLink.source.getString()); port = ( Fport*) listHash.Search( &strH); if( port) { FevenData* data = getFreeEvenData(); // Set the value to transmit to the door data->setData( XML_LNKSOURCE, conditionLink.source.getString()); data->setData( XML_LNKTYPE, conditionLink.typeFields.getString()); data->setData( XML_LNKVALUE, conditionLink.value.getString()); data->setData( XML_LNKFIELDS, conditionLink.fields.getString()); data->setData( XML_LNKDEST, conditionLink.destination.getString()); // Set the SYSTEM action data->setPortAction( ACT_SYS_ADDDEST, conditionLink.source.getString()); // Send to the evenDoor sendEvenDataSys( data, port); } } popCurrent(); }while( FindNext( XML_LNK, false) == RET_OK); } return RET_OK; } else return RET_NOINFOS; }
//______________________________________________________________________________ // Open the envelope, starting at the crypto layer. // If successful, the envelope is processed // otherwise, the envelope is discarded. // The purpose of this entry point is to allow // integration with our POSIX network-based library // (in this case, the IP address and UDP port are // known only to POSIX, and the HeaderIpUdp flag is // not set so this code never receives UDP/IP headers.) //______________________________________________________________________________ Packet* envelopeOpenStartingAtCrypto(NetInterface *ni, EnvelopeBuffer payload, EnvelopeLocal envelopeLocal, EnvelopeRemote envelopeRemote) { ASSERT(NULL != ni); Packet *packet = NULL; if (ni->headers & HeaderCrypto) { if (! cryptoExtract(&payload, &envelopeRemote)) { goto done; } } Tunnel *tunnel = _envelopeFindTunnel(ni, &envelopeRemote); if (tunnel) { if (envelopeRemote.publicKeyPresent) { if (0!=memcmp(envelopeRemote.ephemeralPublicKey, tunnel->envelopeRemote.ephemeralPublicKey, CryptoBoxPublicKeySize)) { debugXPrint(envelopeDebug, "oops, public key present on existing tunnel " "does not match tunnel's key\n"); debugXPrint(tunnelDebug, "packet key = $[pubboxkey]", envelopeRemote.ephemeralPublicKey); debugXPrint(tunnelDebug, "tunnel key = $[pubboxkey]", tunnel->envelopeRemote.ephemeralPublicKey); goto done; // A bad packet. } } } else if (! ni->locked) { // Create a new tunnel. if ((ni->headers & HeaderCrypto) && (!envelopeRemote.publicKeyPresent)) { debugXPrint(envelopeDebug, "oops, public key not present on created tunnel\n"); envelopeRemotePrint(&envelopeRemote); goto done; // Not really a bug, just a bad packet. } tunnel = _envelopeCreateTunnel(ni, &envelopeRemote); if (NULL == tunnel) { goto done; } debugXPrint(envelopeDebug, "New tunnel created.\n"); envelopeLocalPrint(&envelopeLocal); envelopeRemotePrint(&envelopeRemote); } else { goto done; } static char buffer[2048]; EnvelopeBuffer cleartext = {buffer, sizeof (buffer)}; if (ni->headers & HeaderCrypto) { if (envelopeRemote.nonce <= tunnel->envelopeRemote.nonce) { debugXPrint(envelopeDebug, "bad nonce, ignored -- nonce = $[lluint] el nonce = $[lluint] tunnel nonce = $[lluint]\n", envelopeRemote.nonce, envelopeLocal.nonce, tunnel->envelopeRemote.nonce); goto done; } if (! cryptoDecrypt(payload, &cleartext, &envelopeLocal, &envelopeRemote, tunnel)) { if (! cryptoComputeSymmetricKey(&ni->envelopeLocal, &tunnel->envelopeRemote, NetCryptoKeyPermanent)) { goto done; } if (! cryptoDecrypt(payload, &cleartext, &envelopeLocal, &envelopeRemote, tunnel)) { goto done; } } debugXPrint(envelopeDebug, "Packet decrypted. nonce=$[lluint]\n", envelopeRemote.nonce); tunnel->envelopeRemote.nonce = envelopeRemote.nonce; } else { cleartext = payload; } ulong length = cleartext.size; packet = packetAllocate(length); packet->tunnel = tunnel; packetAppend(packet, (uint8_t *) cleartext.start, length); resetCurrent(packet); debugXPrint(envelopeDebug, "Before tunnelIsNewPacket.\n"); // now process the packet for the reliability and connection layers if (tunnelIsNewPacket(packet)) { debugXPrint(envelopeDebug, "valid packet found!\n"); envelopeRemotePrint(&envelopeRemote); goto done; } // Not useful; toss. packetFree(packet); packet = NULL; done: return packet; }
int exportData( void **exp, int *len, void *flowdata ) { accData_t *data = flowdata; measData_t *curr; int i; /* if no intermediate snapshots were taken then only export current pointers */ if (data->numSets == 0) { long int tstamp = time(NULL); /* calculate bandwidth for this collection interval */ if (tstamp == data->export_ts) { // avoid division by zero data->curr.bandwidth = 0; data->curr.packet_bw = 0; } else { data->curr.bandwidth = data->curr.bytes / (tstamp - data->export_ts); data->curr.packet_bw = data->curr.packets / (tstamp -data->export_ts); } STARTEXPORT(expData); ADD_LIST(1); /* one row of data */ ADD_UINT32( data->curr.packets ); ADD_UINT32( data->curr.bytes ); ADD_UINT32( data->curr.first.tv_sec ); ADD_UINT32( data->curr.first.tv_usec ); ADD_UINT32( data->curr.last.tv_sec ); ADD_UINT32( data->curr.last.tv_usec ); ADD_UINT32( data->curr.packet_bw ); ADD_UINT32( data->curr.bandwidth ); END_LIST(); ENDEXPORT( exp, len ); resetCurrent(data); /* reset counters */ data->export_ts = tstamp; /* remember time of last export */ return 0; } /* else export stored snapshots */ if (expDataSize < data->numSets * sizeof(measData_t) + 20) { expDataSize = data->numSets * sizeof(measData_t) + 20; expData = (char*) realloc( expData, expDataSize ); } STARTEXPORT( expData ); ADD_LIST( data->numSets ); curr = data->dataSets; for( i = 0; i<data->numSets; i++ ) { ADD_UINT32( curr->packets ); ADD_UINT32( curr->bytes ); ADD_UINT32( curr->first.tv_sec ); ADD_UINT32( curr->first.tv_usec ); ADD_UINT32( curr->last.tv_sec ); ADD_UINT32( curr->last.tv_usec ); ADD_UINT32( curr->packet_bw ); ADD_UINT32( curr->bandwidth ); curr++; } END_LIST(); ENDEXPORT( exp, len ); data->numSets = 0; return 0; }