|
|
@ -41,6 +41,7 @@ from uuid import uuid4 |
|
|
|
from datetime import datetime |
|
|
|
from sys import exit as sysexit |
|
|
|
from time import sleep |
|
|
|
from ctypes import c_ulong |
|
|
|
|
|
|
|
#Our files |
|
|
|
from .comparedirectories import md5_dir |
|
|
@ -316,7 +317,7 @@ class NsmServerControl(object): |
|
|
|
#Deactivate hooks for now. During init no hooks may be called, |
|
|
|
#but some functions want to do that already. We setup the true hooks at the end of init |
|
|
|
self.sessionOpenReadyHook= self.sessionOpenLoadingHook= self.sessionClosedHook= self.clientStatusHook= self.singleInstanceActivateWindowHook= self.dataClientNamesHook= self.dataClientDescriptionHook= nothing |
|
|
|
|
|
|
|
self.lockfile_directory = getenv("XDG_RUNTIME_DIR") |
|
|
|
self._queue = list() #Incoming OSC messages are buffered here. |
|
|
|
|
|
|
|
#Status variables that are set by our callbacks |
|
|
@ -1413,10 +1414,39 @@ class NsmServerControl(object): |
|
|
|
return True |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def _simple_hash(self, s:str) -> int: |
|
|
|
"""This is a translation from the nsm/file.c function of the same name. |
|
|
|
We use it to find the lock file on our system. |
|
|
|
|
|
|
|
It is a djb2 hash modulo 65521 |
|
|
|
""" |
|
|
|
hashAddress = 5381 |
|
|
|
for i, char in enumerate(s): |
|
|
|
hashAddress = ((hashAddress << 5) + hashAddress ) + ord(char) |
|
|
|
|
|
|
|
hashAddress = c_ulong(hashAddress).value #wrap around for whatever number of bits unsinged long is on this system. 2**64 most likely |
|
|
|
return hashAddress % 65521 |
|
|
|
|
|
|
|
|
|
|
|
def _get_lock_file_name(self, session_name:str, full_absolute_session_path:str) -> pathlib.Path: |
|
|
|
"""This is a translation from the nsm/nsmd.c function of the same name. |
|
|
|
We use it to find the lock file on our system. |
|
|
|
|
|
|
|
To avoid collisions of two simple session names under either different subdirs or even |
|
|
|
different session roots.""" |
|
|
|
#session_name in Agordejo includes subdirs. We want only the basename, like in nsmd. Luckily they are paths. |
|
|
|
session_name = pathlib.Path(session_name).name #basename |
|
|
|
session_hash:int = self._simple_hash(full_absolute_session_path) |
|
|
|
session_lock = pathlib.Path(self.lockfile_directory, "nsm", session_name + str(session_hash)) |
|
|
|
return session_lock |
|
|
|
|
|
|
|
|
|
|
|
def _checkIfLocked(self, nsmSessionName:str)->bool: |
|
|
|
basePath = pathlib.Path(self.sessionRoot, nsmSessionName) |
|
|
|
assert basePath.exists() |
|
|
|
lockFile = pathlib.Path(basePath, ".lock") |
|
|
|
#basePath = pathlib.Path(self.sessionRoot, nsmSessionName) |
|
|
|
#assert basePath.exists() |
|
|
|
#lockFile = pathlib.Path(basePath, ".lock") |
|
|
|
lockFile = self._get_lock_file_name(nsmSessionName, str(pathlib.Path(self.sessionRoot, nsmSessionName))) |
|
|
|
return lockFile.exists() |
|
|
|
|
|
|
|
def getSessionFiles(self, nsmSessionName:str)->list: |
|
|
|