Merge branch 'master' of github.com:/worklist/hifi into 19170B

This commit is contained in:
Leonardo Murillo 2013-04-09 14:01:38 -06:00
commit e0c31d68d1
8 changed files with 80 additions and 13 deletions

View file

@ -25,6 +25,8 @@
#include <fcntl.h>
#include <map>
#include "AgentList.h"
#include "AgentTypes.h"
#include <PacketHeaders.h>
#include "SharedUtil.h"
#ifdef _WIN32
@ -46,7 +48,7 @@ const int LOGOFF_CHECK_INTERVAL = 5000;
#define DEBUG_TO_SELF 0
int lastActiveCount = 0;
AgentList agentList('D', DOMAIN_LISTEN_PORT);
AgentList agentList(AGENT_TYPE_DOMAIN, DOMAIN_LISTEN_PORT);
unsigned char * addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) {
*currentPosition++ = agentToAdd->getType();
@ -82,7 +84,7 @@ int main(int argc, const char * argv[])
char agentType;
unsigned char *broadcastPacket = new unsigned char[MAX_PACKET_SIZE];
*broadcastPacket = 'D';
*broadcastPacket = PACKET_HEADER_DOMAIN;
unsigned char *currentBufferPos;
unsigned char *startPointer;

View file

@ -55,6 +55,7 @@
#include "Texture.h"
#include "Cloud.h"
#include <AgentList.h>
#include <AgentTypes.h>
#include "VoxelSystem.h"
#include "Lattice.h"
#include "Finger.h"
@ -70,7 +71,7 @@ using namespace std;
int audio_on = 1; // Whether to turn on the audio support
int simulate_on = 1;
AgentList agentList('I');
AgentList agentList(AGENT_TYPE_INTERFACE);
pthread_t networkReceiveThread;
bool stopNetworkReceiveThread = false;

View file

@ -17,6 +17,7 @@
#include <fstream>
#include <limits>
#include <AgentList.h>
#include <AgentTypes.h>
#include <SharedUtil.h>
#include <StdDev.h>
#include "AudioRingBuffer.h"
@ -60,7 +61,7 @@ const int AGENT_LOOPBACK_MODIFIER = 307;
const int LOOPBACK_SANITY_CHECK = 0;
AgentList agentList('M', MIXER_LISTEN_PORT);
AgentList agentList(AGENT_TYPE_MIXER, MIXER_LISTEN_PORT);
StDev stdev;
void plateauAdditionOfSamples(int16_t &mixSample, int16_t sampleToAdd) {

View file

@ -7,6 +7,7 @@
//
#include "Agent.h"
#include "AgentTypes.h"
#include <cstring>
#include "UDPSocket.h"
#include "SharedUtil.h"
@ -90,10 +91,40 @@ Agent::~Agent() {
delete linkedData;
}
char Agent::getType() {
char Agent::getType() const {
return type;
}
// Names of Agent Types
const char* AGENT_TYPE_NAME_DOMAIN = "Domain";
const char* AGENT_TYPE_NAME_VOXEL = "Voxel Server";
const char* AGENT_TYPE_NAME_INTERFACE = "Client Interface";
const char* AGENT_TYPE_NAME_HEAD = "Avatar Head"; // Is this needed???
const char* AGENT_TYPE_NAME_MIXER = "Audio Mixer";
const char* AGENT_TYPE_NAME_UNKNOWN = "Unknown";
const char* Agent::getTypeName() const {
const char* name = AGENT_TYPE_NAME_UNKNOWN;
switch (this->type) {
case AGENT_TYPE_DOMAIN:
name = AGENT_TYPE_NAME_DOMAIN;
break;
case AGENT_TYPE_VOXEL:
name = AGENT_TYPE_NAME_VOXEL;
break;
case AGENT_TYPE_INTERFACE:
name = AGENT_TYPE_NAME_INTERFACE;
break;
case AGENT_TYPE_HEAD:
name = AGENT_TYPE_NAME_HEAD;
break;
case AGENT_TYPE_MIXER:
name = AGENT_TYPE_NAME_MIXER;
break;
}
return name;
}
void Agent::setType(char newType) {
type = newType;
}
@ -174,7 +205,7 @@ std::ostream& operator<<(std::ostream& os, const Agent* agent) {
sockaddr_in *agentPublicSocket = (sockaddr_in *)agent->publicSocket;
sockaddr_in *agentLocalSocket = (sockaddr_in *)agent->localSocket;
os << "T: " << agent->type << " PA: " << inet_ntoa(agentPublicSocket->sin_addr) <<
os << "T: " << agent->getTypeName() << " (" << agent->type << ") PA: " << inet_ntoa(agentPublicSocket->sin_addr) <<
":" << ntohs(agentPublicSocket->sin_port) << " LA: " << inet_ntoa(agentLocalSocket->sin_addr) <<
":" << ntohs(agentLocalSocket->sin_port);
return os;

View file

@ -40,7 +40,8 @@ public:
pthread_mutex_t deleteMutex;
char getType();
char getType() const;
const char* getTypeName() const;
void setType(char newType);
uint16_t getAgentId();
void setAgentId(uint16_t thisAgentId);

View file

@ -11,6 +11,7 @@
#include <cstdlib>
#include <cstdio>
#include "AgentList.h"
#include "AgentTypes.h"
#include "PacketHeaders.h"
#include "SharedUtil.h"
@ -180,13 +181,13 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
newAgent.activatePublicSocket();
}
if (newAgent.getType() == 'M' && audioMixerSocketUpdate != NULL) {
if (newAgent.getType() == AGENT_TYPE_MIXER && audioMixerSocketUpdate != NULL) {
// this is an audio mixer
// for now that means we need to tell the audio class
// to use the local socket information the domain server gave us
sockaddr_in *publicSocketIn = (sockaddr_in *)publicSocket;
audioMixerSocketUpdate(publicSocketIn->sin_addr.s_addr, publicSocketIn->sin_port);
} else if (newAgent.getType() == 'V') {
} else if (newAgent.getType() == AGENT_TYPE_VOXEL) {
newAgent.activatePublicSocket();
}
@ -199,7 +200,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
return true;
} else {
if (agent->getType() == 'M' || agent->getType() == 'V') {
if (agent->getType() == AGENT_TYPE_MIXER || agent->getType() == AGENT_TYPE_VOXEL) {
// until the Audio class also uses our agentList, we need to update
// the lastRecvTimeUsecs for the audio mixer so it doesn't get killed and re-added continously
agent->setLastRecvTimeUsecs(usecTimestampNow());
@ -210,6 +211,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
}
}
// XXXBHG - do we want to move these?
const char* AgentList::AGENTS_OF_TYPE_HEAD = "H";
const char* AgentList::AGENTS_OF_TYPE_VOXEL_AND_INTERFACE = "VI";
const char* AgentList::AGENTS_OF_TYPE_VOXEL = "V";
@ -229,7 +231,7 @@ void AgentList::pingAgents() {
*payload = PACKET_HEADER_PING;
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
if (agent->getType() == 'I') {
if (agent->getType() == AGENT_TYPE_INTERFACE) {
if (agent->getActiveSocket() != NULL) {
// we know which socket is good for this agent, send there
agentSocket.send(agent->getActiveSocket(), payload, 1);
@ -268,7 +270,8 @@ void *removeSilentAgents(void *args) {
pthread_mutex_t * agentDeleteMutex = &agent->deleteMutex;
if ((checkTimeUSecs - agent->getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS && agent->getType() != 'V'
if ((checkTimeUSecs - agent->getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS
&& agent->getType() != AGENT_TYPE_VOXEL
&& pthread_mutex_trylock(agentDeleteMutex) == 0) {
std::cout << "Killing agent " << &(*agent) << "\n";

27
shared/src/AgentTypes.h Normal file
View file

@ -0,0 +1,27 @@
//
// AgentTypes.h
// hifi
//
// Created by Brad Hefta-Gaub on 2013/04/09
//
//
// Single byte/character Agent Types used to identify various agents in the system.
// For example, an agent whose is 'V' is always a voxel server.
//
#ifndef hifi_AgentTypes_h
#define hifi_AgentTypes_h
// NOTE: If you add a new AGENT_TYPE_XXX then you also should add a new AGENT_TYPE_NAME_XXX and a new "case" to the
// switch statement in Agent.cpp specifically Agent::getTypeName().
// If you don't then it will make things harder on your co-developers in debugging because the Agent
// class won't know the name and will report it as "Unknown".
// Agent Type Codes
const char AGENT_TYPE_DOMAIN = 'D';
const char AGENT_TYPE_VOXEL = 'V';
const char AGENT_TYPE_INTERFACE = 'I'; // could also be injector???
const char AGENT_TYPE_HEAD = 'H'; // Is this needed???
const char AGENT_TYPE_MIXER = 'M';
#endif

View file

@ -13,6 +13,7 @@
#include <cstdio>
#include <OctalCode.h>
#include <AgentList.h>
#include <AgentTypes.h>
#include <VoxelTree.h>
#include "VoxelAgentData.h"
#include <SharedUtil.h>
@ -45,7 +46,7 @@ const int PACKETS_PER_CLIENT_PER_INTERVAL = 2;
const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4;
AgentList agentList('V', VOXEL_LISTEN_PORT);
AgentList agentList(AGENT_TYPE_VOXEL, VOXEL_LISTEN_PORT);
VoxelTree randomTree;
bool wantColorRandomizer = false;