From 2ec3f6b21092c1c62adf563ce2c505a8db939265 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 9 Apr 2013 10:37:07 -0700 Subject: [PATCH] Adding new AgentTypes.h and moving over to new constants --- domain/src/main.cpp | 6 ++++-- interface/src/main.cpp | 3 ++- mixer/src/main.cpp | 3 ++- shared/src/AgentList.cpp | 13 ++++++++----- shared/src/AgentTypes.h | 21 +++++++++++++++++++++ voxel/src/main.cpp | 3 ++- 6 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 shared/src/AgentTypes.h diff --git a/domain/src/main.cpp b/domain/src/main.cpp index 7ef0967e1b..9235091660 100644 --- a/domain/src/main.cpp +++ b/domain/src/main.cpp @@ -25,6 +25,8 @@ #include #include #include "AgentList.h" +#include "AgentTypes.h" +#include #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; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index cb3341c9d9..b8e2c190e7 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -55,6 +55,7 @@ #include "Texture.h" #include "Cloud.h" #include +#include #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; diff --git a/mixer/src/main.cpp b/mixer/src/main.cpp index 7a8705b645..10040a05a9 100644 --- a/mixer/src/main.cpp +++ b/mixer/src/main.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #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) { diff --git a/shared/src/AgentList.cpp b/shared/src/AgentList.cpp index 1e01487348..aa04d99c9a 100644 --- a/shared/src/AgentList.cpp +++ b/shared/src/AgentList.cpp @@ -11,6 +11,7 @@ #include #include #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::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"; diff --git a/shared/src/AgentTypes.h b/shared/src/AgentTypes.h new file mode 100644 index 0000000000..1d91f8cb65 --- /dev/null +++ b/shared/src/AgentTypes.h @@ -0,0 +1,21 @@ +// +// 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 + +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 diff --git a/voxel/src/main.cpp b/voxel/src/main.cpp index 09834a2d3e..3990a82eac 100644 --- a/voxel/src/main.cpp +++ b/voxel/src/main.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "VoxelAgentData.h" #include @@ -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;