Browse Source

Shift testing for second agordejo gui to the start of the program to work with the new auto-detection

master
Nils 2 years ago
parent
commit
41cf802e3f
  1. 2
      engine/api.py
  2. 36
      engine/nsmservercontrol.py
  3. 28
      engine/start.py
  4. 1
      qtgui/mainwindow.py

2
engine/api.py

@ -196,7 +196,7 @@ def startEngine():
#Start Event Loop Processing #Start Event Loop Processing
eventLoop.fastConnect(nsmServerControl.process) eventLoop.fastConnect(nsmServerControl.process)
eventLoop.fastConnect(jackClient._setPlaybackSeconds) eventLoop.fastConnect(jackClient._setPlaybackSeconds)
eventLoop.slowConnect(nsmServerControl.processSingleInstance) eventLoop.slowConnect(nsmServerControl.listenToAnotherInstanceAttempt)
#Send initial data #Send initial data
#The decision if we are already in a session on startup or in "choose a session mode" is handled by callbacks #The decision if we are already in a session on startup or in "choose a session mode" is handled by callbacks

36
engine/nsmservercontrol.py

@ -377,14 +377,19 @@ class NsmServerControl(object):
self.nsmOSCUrl = o.netloc.split(":")[0], o.port self.nsmOSCUrl = o.netloc.split(":")[0], o.port
else: else:
envResult = self._getNsmOSCUrlFromEnvironment() envResult = self._getNsmOSCUrlFromEnvironment()
print(2)
if envResult: if envResult:
#In case there is no actual nsmd running but there still was a NSM_URL env var, e.g. over the network, use this. #In case there is no actual nsmd running but there still was a NSM_URL env var, e.g. over the network, use this.
#There is a corner case that the env is local but the user chose to ignore the GUI way (nsmd 1.6.0) to proivde us directly with a specific URL. #There is a corner case that the env is local but the user chose to ignore the GUI way (nsmd 1.6.0) to proivde us directly with a specific URL.
self.nsmOSCUrl = envResult self.nsmOSCUrl = envResult
else: else:
#This is the default case. User just starts the GUI. The other modes are concious decisions to either start with URL as parameter or in an NSM environment. #This is the default case. User just starts the GUI. The other modes are concious decisions to either start with URL as parameter or in an NSM environment.
#But now we need to test if the user accidentaly opened a second GUI, which would start a second server. #We need to test if the user accidentaly opened a second GUI, which would start a second server.
self._setupAndTestForSingleInstance() #This might quit the whole program and we will never see the next line. self._setupAndTestForSingleInstance() #This might quit the whole program and we will never see the next line.
#TODO: there is a corner case: 1) manually start nsmd locally 2) start agordejo first time and connect to running nsmd 3) start 2nd agordejo and connect to the same server.
#it will not prevent it. But we need it because all other scenarios prevent agordejo multiple times for actual different servers, which is of course wanted.
#Better let something uncorrect slip than to prevent legit usecases!
#The important check here is to see if Agordejo, with internal nsmd, was started twice or not. Which works. That's all.
self.nsmOSCUrl = self._generateFreeNsmOSCUrl() self.nsmOSCUrl = self._generateFreeNsmOSCUrl()
assert self.nsmOSCUrl assert self.nsmOSCUrl
@ -422,7 +427,7 @@ class NsmServerControl(object):
self.dataClientNamesHook = dataClientNamesHook self.dataClientNamesHook = dataClientNamesHook
self.dataClientDescriptionHook = dataClientDescriptionHook self.dataClientDescriptionHook = dataClientDescriptionHook
self.dataClientTimelineMaximumDurationChangedHook = dataClientTimelineMaximumDurationChangedHook self.dataClientTimelineMaximumDurationChangedHook = dataClientTimelineMaximumDurationChangedHook
self.singleInstanceActivateWindowHook = singleInstanceActivateWindowHook #added to self.processSingleInstance() to listen for a message from another wannabe-instance self.singleInstanceActivateWindowHook = singleInstanceActivateWindowHook #added to self.listenToAnotherInstanceAttempt() to listen for a message from another wannabe-instance
self._receiverActive = True self._receiverActive = True
logger.info("nsmservercontrol init is complete. Ready for event loop") logger.info("nsmservercontrol init is complete. Ready for event loop")
@ -430,22 +435,28 @@ class NsmServerControl(object):
#Internal Methods #Internal Methods
def _setupAndTestForSingleInstance(self): def _setupAndTestForSingleInstance(self):
"""on program startup trigger this if there is already another instance of us running. """
This socket is only On program startup trigger this if there is already another instance of us running.
This is before anything NSM was done.
""" """
self.singleInstanceSocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.singleInstanceSocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
logger.info("Testing if another non-specific Agordejo is running.") logger.info("Testing if another non-specific Agordejo is running.")
try: try:
## Create an abstract socket, by prefixing it with null. # This is for the first agordejo instance, when no other is running. We set up
# a socket and listen throughout the runtime of our instance.
#
# Create an abstract socket, by prefixing it with null.
# this relies on a feature only in linux, when current process quits, the # this relies on a feature only in linux, when current process quits, the
# socket will be deleted. # socket will be deleted.
self.singleInstanceSocket.bind('\0' + "agordejo") self.singleInstanceSocket.bind('\0' + "agordejo")
self.singleInstanceSocket.listen(1) self.singleInstanceSocket.listen(1)
self.singleInstanceSocket.setblocking(False) self.singleInstanceSocket.setblocking(False)
logger.info("No other non-specific Agordejo found. Starting GUI") logger.info("No other non-specific Agordejo found. Starting GUI")
#Continue in self.processSingleInstance() #Continue in self.listenToAnotherInstanceAttempt()
return True return True
except socket.error: except socket.error:
# This is for the 2nd agordejo instance that has detected there is already another
# instance running. We will exit here before anything related to NSM has happened.
logger.error("GUI for this nsmd server already running. Informing the existing application to show itself.") logger.error("GUI for this nsmd server already running. Informing the existing application to show itself.")
self.singleInstanceSocket.connect('\0' + "agordejo") self.singleInstanceSocket.connect('\0' + "agordejo")
self.singleInstanceSocket.send("agordejoactivate".encode()); self.singleInstanceSocket.send("agordejoactivate".encode());
@ -454,10 +465,17 @@ class NsmServerControl(object):
#print ("not executed") #print ("not executed")
return False return False
def processSingleInstance(self): def listenToAnotherInstanceAttempt(self):
"""Tests our unix socket for an incoming signal. """
This is for the agordejo instance that keeps running. We inform the GUI via hook
to show info to the user that a 2nd instance wanted to start.
Tests our unix socket for an incoming signal.
if received forward to the engine->gui if received forward to the engine->gui
Can be added to a slower event loop, so it is not in self.process"""
Must be added to an event loop, so will only start once the program has started.
Can be added to a slower event loop, so it is not in self.process
"""
if self.singleInstanceSocket: if self.singleInstanceSocket:
try: try:
connection, client_address = self.singleInstanceSocket.accept() #This blocks and waits for a message connection, client_address = self.singleInstanceSocket.accept() #This blocks and waits for a message

28
engine/start.py

@ -223,6 +223,34 @@ def checkJackOrExit(prettyName):
exitWithMessage("JACK Audio Connection Kit is not running. Please start it.") exitWithMessage("JACK Audio Connection Kit is not running. Please start it.")
def isAnotherAgordejoInstanceRunning()->bool:
import socket
tempSocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
# This is for the first agordejo instance, when no other is running. We set up
# a socket and listen throughout the runtime of our instance.
#
# Create an abstract socket, by prefixing it with null.
# this relies on a feature only in linux, when current process quits, the
# socket will be deleted.
tempSocket.bind('\0' + "agordejo")
tempSocket.listen(1)
tempSocket.setblocking(False)
return False
except socket.error:
# This is for the 2nd agordejo instance that has detected there is already another
# instance running. We will exit here before anything related to NSM has happened.
tempSocket.connect('\0' + "agordejo")
tempSocket.send("agordejoactivate".encode());
tempSocket.close()
return True
def checkAgordejoOrExit():
if (not args.url) and isAnotherAgordejoInstanceRunning():
exitWithMessage("Another Agordejo instance is already running. Informing it of our start attempt.")
checkAgordejoOrExit()
checkJackOrExit(METADATA["name"]) checkJackOrExit(METADATA["name"])
try: try:

1
qtgui/mainwindow.py

@ -166,6 +166,7 @@ class MainWindow(QtWidgets.QMainWindow):
#nsmd 1.6.0 #nsmd 1.6.0
xdgVersionChange(self.qtApp) #may present a blocking dialog, may do nothing. xdgVersionChange(self.qtApp) #may present a blocking dialog, may do nothing.
#If another Agordejo is running, and no --nsm-url was set, we will never reach this point.
checkForRunningNsmd(self.qtApp, PATHS) #may present a blocking dialog, may do nothing. Injects nsm url into PATHS checkForRunningNsmd(self.qtApp, PATHS) #may present a blocking dialog, may do nothing. Injects nsm url into PATHS
#Api Callbacks #Api Callbacks

Loading…
Cancel
Save