Ejemplo n.º 1
0
void *removeSilentAgents(void *args) {
    AgentList* agentList = (AgentList*) args;
    long long checkTimeUSecs, sleepTime;
    
    while (!silentAgentThreadStopFlag) {
        checkTimeUSecs = usecTimestampNow();
        
        for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); ++agent) {
            
            if ((checkTimeUSecs - agent->getLastHeardMicrostamp()) > AGENT_SILENCE_THRESHOLD_USECS
            	&& agent->getType() != AGENT_TYPE_VOXEL_SERVER) {
            
                printLog("Killed ");
                Agent::printLog(*agent);
                
                agent->setAlive(false);
            }
        }
        
        sleepTime = AGENT_SILENCE_THRESHOLD_USECS - (usecTimestampNow() - checkTimeUSecs);
        #ifdef _WIN32
        Sleep( static_cast<int>(1000.0f*sleepTime) );
        #else
        usleep(sleepTime);
        #endif
    }
    
    pthread_exit(0);
    return NULL;
}
Ejemplo n.º 2
0
void *pingUnknownAgents(void *args) {
    
    AgentList* agentList = (AgentList*) args;
    const int PING_INTERVAL_USECS = 1 * 1000000;
    
    timeval lastSend;
    
    while (!pingUnknownAgentThreadStopFlag) {
        gettimeofday(&lastSend, NULL);
        
        for(AgentList::iterator agent = agentList->begin();
            agent != agentList->end();
            agent++) {
            if (!agent->getActiveSocket() && agent->getPublicSocket() && agent->getLocalSocket()) {
                // ping both of the sockets for the agent so we can figure out
                // which socket we can use
                agentList->getAgentSocket()->send(agent->getPublicSocket(), &PACKET_HEADER_PING, 1);
                agentList->getAgentSocket()->send(agent->getLocalSocket(), &PACKET_HEADER_PING, 1);
            }
        }
        
        long long usecToSleep = PING_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSend));
        
        if (usecToSleep > 0) {
            usleep(usecToSleep);
        }
    }
    
    return NULL;
}
Ejemplo n.º 3
0
std::vector<double> beatTrack(const AgentParameters &params,
                              const EventList &events,
                              const EventList &beats)
      {
      AgentList agents;
      int count = 0;
      double beatTime = -1;
      if (!beats.empty()) {
            count = beats.size() - 1;
            EventList::const_iterator itr = beats.end();
            --itr;
            beatTime = itr->time;
            }
      if (count > 0) {        // tempo given by mean of initial beats
            double ioi = (beatTime - beats.begin()->time) / count;
            agents.push_back(new Agent(params, ioi));
            }
      else            // tempo not given; use tempo induction
            agents = Induction::beatInduction(params, events);

      if (!beats.empty()) {
            for (AgentList::iterator itr = agents.begin(); itr != agents.end(); ++itr) {
                  (*itr)->beatTime = beatTime;
                  (*itr)->beatCount = count;
                  (*itr)->events = beats;
                  }
            }
      agents.beatTrack(events, params, -1);

      Agent *best = agents.bestAgent();
      std::vector<double> resultBeatTimes;

      if (best) {
            best->fillBeats(beatTime);
            for (EventList::const_iterator itr = best->events.begin();
                        itr != best->events.end(); ++itr) {
                  resultBeatTimes.push_back(itr->time);
                  }
            }
      for (AgentList::iterator ai = agents.begin(); ai != agents.end(); ++ai) {
            delete *ai;
            }

      return resultBeatTimes;
      }
StringList WorldFacadeSmartPointerImpl::getAgentsInLocation(string lName) {
	AgentList agentsInside = locations[lName]->agentsInside();
	list<string> l;

	for (AgentList::iterator iter = agentsInside.begin();
			iter != agentsInside.end(); iter++) {
		l.push_back(iter->second->getName());
	}

	return l;
}
StringList WorldFacadeSmartPointerImpl::getAgentsInWorld() {
	StringList l;
	cout << "locsInWorld size: " << locations.size() << endl;

	for (LocationSmartPointerMap::const_iterator it = locations.begin();
			it != locations.end(); it++) {
		LocationSmartPointerPtr location = it->second;
		AgentList agentsInside = location->agentsInside();

		for (AgentList::const_iterator it2 = agentsInside.begin();
				it2 != agentsInside.end(); it2++) {
			AgentPointer agent = it2->second;
			l.push_back(agent->getName());
		}
	}
	cout << "locsInWorld size: " << locations.size() << endl;
	return l;
}
AgentPointer WorldFacadeSmartPointerImpl::findAgentByName(string name) {
	for (LocationSmartPointerMap::const_iterator it = locations.begin();
			it != locations.end(); it++) {
		LocationSmartPointerPtr location = it->second;
		//cout << "FOUND LOCATION: " << *location << endl;
		AgentList agentsInside = location->agentsInside();
		for (AgentList::const_iterator it2 = agentsInside.begin();
				it2 != agentsInside.end(); it2++) {
			AgentPointer agent = it2->second;
			//cout << "FOUND AGENT: " << *agent << endl;
			if (name == agent->getName()) {
				//cout << "AGENT MATCH NAME: " << name << endl;
				return agent;
			}
		}
	}
	return NULL;
}