Adding friendly names to AgentType display.

This commit is contained in:
ZappoMan 2013-04-09 13:00:20 -07:00
parent 2ec3f6b210
commit 712997451b
3 changed files with 41 additions and 3 deletions

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

@ -12,6 +12,12 @@
#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???