From 2388cfc8e07bd7491bdb8da14f613707b4cc5221 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 17 Sep 2013 14:33:31 -0700 Subject: [PATCH] first cut at making VoxelServer class run with configuration or standalone --- assignment-client/src/main.cpp | 12 +++++++++++- domain-server/src/main.cpp | 2 +- libraries/voxel-server-library/src/VoxelServer.cpp | 14 ++++++++------ libraries/voxel-server-library/src/VoxelServer.h | 14 ++++++++------ voxel-server/src/main.cpp | 10 ++++++---- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/assignment-client/src/main.cpp b/assignment-client/src/main.cpp index 76fb99839a..f287e1066e 100644 --- a/assignment-client/src/main.cpp +++ b/assignment-client/src/main.cpp @@ -32,6 +32,7 @@ pid_t* childForks = NULL; sockaddr_in customAssignmentSocket = {}; int numForks = 0; Assignment::Type overiddenAssignmentType = Assignment::AllTypes; +std::vector voxelServers; void childClient() { // this is one of the child forks or there is a single assignment client, continue assignment-client execution @@ -100,7 +101,9 @@ void childClient() { } else if (deployedAssignment.getType() == Assignment::AvatarMixerType) { AvatarMixer::run(); } else if (deployedAssignment.getType() == Assignment::VoxelServerType) { - VoxelServer::run(); + VoxelServer* voxelServer = new VoxelServer(); + ::voxelServers.push_back(voxelServer); + voxelServer->run((const char*)deployedAssignment.getPayload()); } else { // figure out the URL for the script for this agent assignment QString scriptURLString("http://%1:8080/assignment/%2"); @@ -162,6 +165,13 @@ void sigchldHandler(int sig) { } } } + + // cleanup voxelServers + for (int i = 0; i < ::voxelServers.size(); i++) { + VoxelServer* voxelServer = ::voxelServers[i]; + delete voxelServer; + } + } void parentMonitor() { diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index fb2869c327..ec7a4a8897 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -169,7 +169,7 @@ int main(int argc, const char* argv[]) { if (voxelServerConfig) { qDebug("Reading Voxel Server Configuration.\n"); qDebug() << " config: " << voxelServerConfig << "\n"; - voxelServerAssignment.setDataPayload((unsigned char*)voxelServerConfig, strlen(voxelServerConfig) + 1); + voxelServerAssignment.setPayload((uchar*)voxelServerConfig, strlen(voxelServerConfig) + 1); } // construct a local socket to send with our created assignments to the global AS diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index b239a180d9..d2c9613619 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -63,22 +63,24 @@ VoxelPersistThread* voxelPersistThread = NULL; pthread_mutex_t treeLock; NodeWatcher nodeWatcher; // used to cleanup AGENT data when agents are killed -int VoxelServer::_argc = 0; -const char** VoxelServer::_argv = NULL; -bool VoxelServer::_dontKillOnMissingDomain = false; - void attachVoxelNodeDataToNode(Node* newNode) { if (newNode->getLinkedData() == NULL) { newNode->setLinkedData(new VoxelNodeData(newNode)); } } +VoxelServer::VoxelServer() { + _argc = 0; + _argv = NULL; + _dontKillOnMissingDomain = false; +} + void VoxelServer::setArguments(int argc, char** argv) { _argc = argc; _argv = const_cast(argv); } -void VoxelServer::setupDomainAndPort(const char* domain, int port) { +void VoxelServer::setupStandAlone(const char* domain, int port) { NodeList::createInstance(NODE_TYPE_VOXEL_SERVER, port); // Handle Local Domain testing with the --local command line @@ -98,7 +100,7 @@ void VoxelServer::setupDomainAndPort(const char* domain, int port) { } //int main(int argc, const char * argv[]) { -void VoxelServer::run() { +void VoxelServer::run(const char* configuration) { pthread_mutex_init(&::treeLock, NULL); qInstallMessageHandler(sharedMessageHandler); diff --git a/libraries/voxel-server-library/src/VoxelServer.h b/libraries/voxel-server-library/src/VoxelServer.h index d51870dbb1..6739f4cfeb 100644 --- a/libraries/voxel-server-library/src/VoxelServer.h +++ b/libraries/voxel-server-library/src/VoxelServer.h @@ -12,23 +12,25 @@ /// Handles assignments of type VoxelServer - sending voxels to various clients. class VoxelServer { public: + VoxelServer(); + /// runs the voxel server assignment - static void run(); + void run(const char* configuration = NULL); /// allows setting of run arguments - static void setArguments(int argc, char** argv); + void setArguments(int argc, char** argv); /// when VoxelServer class is used by voxel-server stand alone executable it calls this to specify the domain /// and port it is handling. When called by assignment-client, this is not needed because assignment-client /// handles ports and domains automatically. /// \param const char* domain domain name, IP address, or local to specify the domain the voxel server is serving /// \param int port port the voxel server will listen on - static void setupDomainAndPort(const char* domain, int port); + void setupStandAlone(const char* domain, int port); private: - static int _argc; - static const char** _argv; - static bool _dontKillOnMissingDomain; + int _argc; + const char** _argv; + bool _dontKillOnMissingDomain; }; diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index f854df84cf..4d82c43343 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -29,17 +29,19 @@ int main(int argc, const char * argv[]) { } printf("portParameter=%s listenPort=%d\n", portParameter, listenPort); } + + VoxelServer ourVoxelServer; if (wantLocalDomain) { - VoxelServer::setupDomainAndPort(local, listenPort); + ourVoxelServer.setupStandAlone(local, listenPort); } else { if (domainIP) { - VoxelServer::setupDomainAndPort(domainIP, listenPort); + ourVoxelServer.setupStandAlone(domainIP, listenPort); } } - VoxelServer::setArguments(argc, const_cast(argv)); - VoxelServer::run(); + ourVoxelServer.setArguments(argc, const_cast(argv)); + ourVoxelServer.run(); }