Exemple #1
0
void display()
{
	if(lastTime == 0)
	{
		lastTime = glutGet(GLUT_ELAPSED_TIME);
	}
	now = glutGet(GLUT_ELAPSED_TIME);

	delta_t = (now - lastTime) / 1000.0f;
	//lastTime = now; //1 / delta_t here means the frame rate.

	fpsTracker.timestamp();
	//update camera information per frame
	updateCamera();
	checkClear();
	if(moved)
		lastTime = now;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//do raytrace
	raytrace();
	
	//render result as texture
	displayTexture();
	//draw tool bar
	TwDraw();
	drawFps();

	glutSwapBuffers();
	glutPostRedisplay();
}
void TransportSocketCache::onSocketDisconnected(Url url, const ServiceInfo& info)
{
  // remove from the available connections
  boost::mutex::scoped_lock lock(_socketMutex);

  ConnectionMap::iterator machineIt = _connections.find(info.machineId());
  if (machineIt == _connections.end())
    return;
  qiLogDebug() << "onSocketDisconnected: about to erase socket";
  auto attempt = machineIt->second[url];
  attempt->state = State_Error;
  checkClear(attempt, info.machineId());
  auto syncDisconnectInfos = _disconnectInfos.synchronize();
  updateDisconnectInfos(*syncDisconnectInfos, attempt->endpoint);
}
void TransportSocketCache::onSocketDisconnected(TransportSocketPtr socket,
                                                Url url,
                                                const std::string& reason,
                                                const ServiceInfo& info)
{
  // remove from the available connections
  boost::mutex::scoped_lock lock(_socketMutex);

  ConnectionMap::iterator machineIt = _connections.find(info.machineId());
  if (machineIt == _connections.end())
    return;

  machineIt->second[url]->state = State_Error;
  checkClear(machineIt->second[url], info.machineId());
}
Exemple #4
0
void SensorManager::retrieveStatistics(bool ignoreshutdown)
{
	const char* xmlpre = "<vermont>\n\t<sensorData time=\"%s\" epochtime=\"%d.%03d\" host=\"%s\">\n";
	const char* xmlpost = "\t</sensorData>\n</vermont>\n";
	const char* xmlglobals = "\t\t<%s>%s</%s>\n";

	string lockfile = outputFilename + ".lock";
	bool haveGraphLock;
	bool clearFlag;

	// we must not wait for the graph lock, else there may be a race condition with
	// the ConfigManager
	while (! (haveGraphLock = graphIS->tryLockGraph())) {
		if (smExitFlag) break;
		timespec timeout = { 0, 200000 };
		nanosleep(&timeout, NULL);
	}

	if (!ignoreshutdown && smExitFlag) return;

	if ((clearFlag = checkClear())) {
		msg(LOG_WARNING, "Clearing sensor statistics");
	}

	const char* openflags = (append ? "a" : "w");
	FILE* file = fopen(outputFilename.c_str(), openflags);
	if (!file) {
		THROWEXCEPTION("failed to reopen file %s", outputFilename.c_str());
		perror("error:");
	}

	timeval tvcurtime = unixtime();
	time_t curtime = tvcurtime.tv_sec;
	char curtimestr[100];
	ctime_r(&curtime, curtimestr);
	curtimestr[strlen(curtimestr)-1] = 0;
	fprintf(file, xmlpre, curtimestr, curtime, tvcurtime.tv_usec/1000, hostname);
	char text[100];
	snprintf(text, 100, "%u", static_cast<uint32_t>(getpid()));
	fprintf(file, xmlglobals, "pid", text, "pid");
	char lasttimestr[100];
	ctime_r(&lasttime, lasttimestr);
	lasttimestr[strlen(lasttimestr)-1] = 0;
	fprintf(file, xmlglobals, "lastTime", lasttimestr, "lastTime");

#if defined(__linux__)
	const char* xmlglobalsuint = "\t\t<%s>%u</%s>\n";
	ThreadCPUInterface::SystemInfo si = ThreadCPUInterface::getSystemInfo();

	fprintf(file, "\t\t<jiffyFrequency>%llu</jiffyFrequency>\n", (long long unsigned)hertzValue);
	fprintf(file, xmlglobalsuint, "processorAmount", si.noCPUs, "processorAmount");
	for (uint16_t i=0; i<si.sysJiffies.size(); i++) {
		double sysutil = (si.sysJiffies[i]-lastSystemInfo.sysJiffies[i])/(static_cast<double>(curtime)-lasttime)/hertzValue*100;
		double userutil = (si.userJiffies[i]-lastSystemInfo.userJiffies[i])/(static_cast<double>(curtime)-lasttime)/hertzValue*100;
		fprintf(file, "\t\t<processor id=\"%u\"><util type=\"system\">%.2f</util><util type=\"user\">%.2f</util></processor>\n",
				i, sysutil, userutil);
	}
	fprintf(file, "\t\t<memory><free type=\"bytes\">%llu</free><total type=\"bytes\">%llu</total></memory>\n",
			(long long unsigned)si.freeMemory, (long long unsigned)si.totalMemory);
	lastSystemInfo = si;
#endif

	//DPRINTF_INFO("*** sensor data at %s", ctime(&curtime));

	Graph* g = graphIS->getGraph();
	vector<CfgNode*> nodes = g->getNodes();
	vector<CfgNode*>::iterator iter = nodes.begin();
	while (iter != nodes.end()) {
		Cfg* cfg = (*iter)->getCfg();
		Sensor* s = cfg->getInstance();
		if (clearFlag) s->clearStatistics();
		vector<uint32_t> nextids = cfg->getNext();
		writeSensorXML(file, s, cfg->getName().c_str(), cfg->getID(), true, curtime, lasttime, &nextids);

		iter++;
	}

	// iterate through all non-module sensors
	mutex.lock();
	list<SensorEntry>::const_iterator siter = sensors.begin();
	while (siter != sensors.end()) {
        //DPRINTFL(LOG_ERR, "non-module cfg->getName()=%s, s=%u", siter->name.c_str(), siter->sensor);
		Sensor* s = siter->sensor;
		if (clearFlag) s->clearStatistics();
		writeSensorXML(file, s, siter->name.c_str(), siter->id, false, curtime, lasttime, NULL);
		siter++;
	}
	mutex.unlock();

	fprintf(file, "%s", xmlpost);
	fclose(file);

	if (haveGraphLock) graphIS->unlockGraph();
}
/*
 * Corner case to manage (TODO):
 *
 * You are connecting to machineId foo, you are machineId bar. foo and bar are
 * on different sub-networks with the same netmask. They sadly got the same IP
 * on their subnet: 192.168.1.42. When trying to connect to foo from bar, we
 * will try to connect its endpoints, basically:
 *   - tcp://1.2.3.4:1333 (public IP)
 *   - tcp://192.168.1.42:1333 (subnet public IP)
 * If bar is listening on port 1333, we may connect to it instead of foo (our
 * real target).
 */
void TransportSocketCache::onSocketParallelConnectionAttempt(Future<void> fut,
                                                             MessageSocketPtr socket,
                                                             Url url,
                                                             const ServiceInfo& info)
{
  boost::mutex::scoped_lock lock(_socketMutex);

  if (_dying)
  {
    qiLogDebug() << "ConnectionAttempt: TransportSocketCache is closed";
    if (!fut.hasError())
    {
      _allPendingConnections.remove(socket);
      socket->disconnect();
    }
    return;
  }

  ConnectionMap::iterator machineIt = _connections.find(info.machineId());
  std::map<Url, ConnectionAttemptPtr>::iterator urlIt;
  if (machineIt != _connections.end())
    urlIt = machineIt->second.find(url);

  if (machineIt == _connections.end() || urlIt == machineIt->second.end())
  {
    // The socket was disconnected at some point, and we removed it from our map:
    // return early.
    _allPendingConnections.remove(socket);
    socket->disconnect();
    return;
  }

  ConnectionAttemptPtr attempt = urlIt->second;
  attempt->attemptCount--;
  if (attempt->state != State_Pending)
  {
    qiLogDebug() << "Already connected: reject socket " << socket.get() << " endpoint " << url.str();
    _allPendingConnections.remove(socket);
    socket->disconnect();
    checkClear(attempt, info.machineId());
    return;
  }
  if (fut.hasError())
  {
    // Failing to connect to some of the endpoint is expected.
    qiLogDebug() << "Could not connect to service #" << info.serviceId() << " through url " << url.str();
    _allPendingConnections.remove(socket);
    // It's a critical error if we've exhausted all available endpoints.
    if (attempt->attemptCount == 0)
    {
      std::stringstream err;
      err << "Could not connect to service #" << info.serviceId() << ": no endpoint replied.";
      qiLogError() << err.str();
      attempt->promise.setError(err.str());
      attempt->state = State_Error;
      checkClear(attempt, info.machineId());
    }
    return;
  }
  qi::SignalLink disconnectionTracking = socket->disconnected.connect(
        &TransportSocketCache::onSocketDisconnected, this, url, info)
      .setCallType(MetaCallType_Direct);
  attempt->state = State_Connected;
  attempt->endpoint = socket;
  attempt->promise.setValue(socket);
  attempt->disconnectionTracking = disconnectionTracking;
  qiLogDebug() << "Connected to service #" << info.serviceId() << " through url " << url.str() << " and socket "
               << socket.get();
}
Exemple #6
0
void render()
{    
    // Clears the buffer with this colour attribute
    clearBuffer(0x00);

    // Set up sample colours, and output shadings
    const WORD colors[] =   {
	                        0x1A, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F,
	                        0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6
	                        };
	
    COORD c;

    // displays the framerate
    std::ostringstream ss;
    ss << std::fixed << std::setprecision(3);
    ss << 1.0 / deltaTime << "fps";
    c.X = ConsoleSize.X-9;
    c.Y = 0;
    writeToBuffer(c, ss.str());

    // displays the elapsed time
    ss.str("");
    ss << elapsedTime << "secs";
    c.X = 0;
	c.Y = ConsoleSize.Y - 1;
    writeToBuffer(c, ss.str(), 0x59);

	if (!levelStart)
		levelStart = initLevel();

	renderShip();
	moveBullets();
	checkBulletCollision(enemyArr, levelInfo.number);
	renderBullets();
	if (!spawnBufferCount && enemiesSpawned < levelInfo.number)
	{
		if (spawnEnemy(enemyArr, levelInfo.number))
		{
			spawnBufferCount += levelInfo.spawnBuffer;
			enemiesSpawned++;
		}
	}
	else if (spawnBufferCount) spawnBufferCount--;
	moveEnemy(enemyArr, levelInfo.number);
	checkBulletCollision(enemyArr, levelInfo.number);
	checkEnemyCollision(enemyArr, levelInfo.number);
	renderEnemy(enemyArr, levelInfo.number);
	if (levelInfo.bullets)
	{
		if (spawnEnemyBullet(enemyArr))
		{
				spawnBufferCount += bulletInfo.spawnBuffer;
		}
		moveEnemy(enemyBulletArr, bulletInfo.number);
		checkEnemyCollision(enemyBulletArr, bulletInfo.number);
		renderEnemy(enemyBulletArr, bulletInfo.number);
	}
	
	// Writes the buffer to the console, hence you will see what you have written
    flushBufferToConsole();

	if (enemiesSpawned == levelInfo.number) 
	{
		if (checkClear(enemyArr, levelInfo.number)) 
		{
			levelStart = false;
			enemiesSpawned = 0;
			spawnBufferCount = 0;
			delete[] enemyArr;
			delete[] enemyBulletArr;
			levelInfo.level = levelInfo.nextLevel;
		}
	}
}