diff --git a/LaunchScript/VirtualAcousticStarterConfig.json b/LaunchScript/VirtualAcousticStarterConfig.json index 134e6ec2a8bf4907526a31311e86f872d768b1ff..4fba0d7854570d319b76845adbf93358ba58b5db 100644 --- a/LaunchScript/VirtualAcousticStarterConfig.json +++ b/LaunchScript/VirtualAcousticStarterConfig.json @@ -3,7 +3,7 @@ "nLauncherPort": 41578, "nVAServerPort": 12340, "nDefaultSleep": 3, - "tReproductionModules": ["TalkthroughHP", "CTC"], + "lsReproductionModules": ["TalkthroughHP", "CTC"], "dVAServerDirectories": { "2018.a": "../v2018.a", diff --git a/LaunchScript/VirtualAcousticsStarterServer.py b/LaunchScript/VirtualAcousticsStarterServer.py index 2d90eaf59cf59779e1f138663faa2e47f59f9907..4208740251f4002b58511972f5cc9c4e320d25d6 100644 --- a/LaunchScript/VirtualAcousticsStarterServer.py +++ b/LaunchScript/VirtualAcousticsStarterServer.py @@ -25,7 +25,7 @@ class LauncherConfig: conf.nLauncherPort = json_config["nLauncherPort"] conf.nVAServerPort = json_config["nVAServerPort"] conf.nDefaultSleep = json_config["nDefaultSleep"] - conf.tReproductionModules = json_config["tReproductionModules"] + conf.lsReproductionModules = json_config["lsReproductionModules"] except KeyError as e: print( "ERROR reading the json config. Missing " + str(e.args[0]) ) sys.exit( ErrorCodes.ERROR_INCOMPLETE_CONFIG ) @@ -105,15 +105,16 @@ class VirtualAcousticsLauncher: self.start() - + #Start the launcher def start(self): print( "VirtualAcoustics Starter script - press ctrl+c to quit" ) - self.readConfig() - self.openLauncherServerSocket() - self.runLauncher() + self.read_config() + self.open_server_socket() + self.run() - def readConfig(self): + #Reads the launcher config and initializes all respective class parameters + def read_config(self): sHostConfigurationFile = "VirtualAcousticStarterConfig." + socket.gethostname() + ".json" sGeneralConfigurationFile = "VirtualAcousticStarterConfig.json" @@ -135,7 +136,8 @@ class VirtualAcousticsLauncher: self.oConfig = LauncherConfig( sUsedConfigFile ) - def openLauncherServerSocket(self): + #Open network socket used for the communication + def open_server_socket(self): print( "Creating server socket at " + self.oConfig.sLocalIP + ":" + str( self.oConfig.nLauncherPort ) ) self.oLauncherServerSocket = socket.socket() @@ -149,8 +151,8 @@ class VirtualAcousticsLauncher: sys.exit( ErrorCodes.ERROR_BINDING_SOCKET ) self.oLauncherServerSocket.settimeout( 1.0 ) - - def runLauncher(self): + #Actually starts the launcher listening for VAServer start requests + def run(self): try: while True: print( "Waiting for launcher connection..." ) @@ -175,11 +177,11 @@ class VirtualAcousticsLauncher: self.oVAProcess.kill() self.oVAProcess = None - sVAServerDir = self.ReadVAServerIDToStart() + sVAServerDir = self.receive_va_server_id() if not sVAServerDir: continue - self.StartRequestedVAServer(sVAServerDir) + self.start_va_server(sVAServerDir) except KeyboardInterrupt: print( "Caught keyboard interrupt, quitting" ) @@ -187,7 +189,8 @@ class VirtualAcousticsLauncher: - def ReadVAServerIDToStart(self): + #Checks for a message containing the ID of the VAServer instance to be started and returns the respective VAServer directory + def receive_va_server_id(self): try: self.sVAServerID = self.oLauncherConnection.recv( 512 ) if type( self.sVAServerID ) is bytes: @@ -211,7 +214,8 @@ class VirtualAcousticsLauncher: return sVAServerDir - def StartRequestedVAServer(self, sVAServerDir): + #Starts the VAServer from given directory + def start_va_server(self, sVAServerDir): # Check for VAServer.exe sVAExecutableFile = "bin/VAServer.exe" @@ -258,7 +262,7 @@ class VirtualAcousticsLauncher: print( "sending go token" ) self.oLauncherConnection.send( b'g' )#answer 'go, VAServer is correctly started' - self.ListenForRequestsByVAServer() + self.listen_for_requests() #if the above terminates a quit request was received: # kill VA instance @@ -268,7 +272,8 @@ class VirtualAcousticsLauncher: self.oVAProcess.kill() self.oVAProcess = None - def ListenForRequestsByVAServer(self): + #Listens for requests while the VAServer is running + def listen_for_requests(self): while True: try: sResult = self.oLauncherConnection.recv( 128 ) @@ -277,7 +282,7 @@ class VirtualAcousticsLauncher: #check whether we are about to reveive a file sMessage = sResult.decode("utf-8") if sMessage.startswith("file"): - self.ReceiveFile(sMessage) + self.receive_file(sMessage) else: #NOT sMessage.startswith("file") print( "Received quit event: "+sMessage ) break @@ -291,7 +296,7 @@ class VirtualAcousticsLauncher: except (KeyboardInterrupt, SystemExit): raise #re-raise for higher instance to catch - def ReceiveFile(self, sMessage): + def receive_file(self, sMessage): aMessageParts = sMessage.split(":") iBytesToReceive = int(aMessageParts[2]) Path, Filename = os.path.split(aMessageParts[1])