|
|
@ -85,10 +85,8 @@ class StatBuffer:
|
|
|
|
SLV_NOUI = 3 #Remove all user inputed information (sub, com,name,trip, file info)
|
|
|
|
SLV_NOUI = 3 #Remove all user inputed information (sub, com,name,trip, file info)
|
|
|
|
SLV_HIGH = 0xFF #Keep only post number
|
|
|
|
SLV_HIGH = 0xFF #Keep only post number
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
def __init__(self):
|
|
|
|
self._mutex = Lock()
|
|
|
|
self._mutex = Lock()
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _lock(self):
|
|
|
|
def _lock(self):
|
|
|
|
self._mutex.acquire()
|
|
|
|
self._mutex.acquire()
|
|
|
|
def _unlock(self):
|
|
|
|
def _unlock(self):
|
|
|
@ -176,7 +174,7 @@ class MemoryBuffer(StatBuffer):
|
|
|
|
return super()._decode(self.store[-1])["no"]
|
|
|
|
return super()._decode(self.store[-1])["no"]
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
super()._unlock()
|
|
|
|
super()._unlock()
|
|
|
|
def readno(self, floor):
|
|
|
|
def readno(self, floor, ca=False):
|
|
|
|
super()._lock()
|
|
|
|
super()._lock()
|
|
|
|
posts = list()
|
|
|
|
posts = list()
|
|
|
|
nl = len(self.store)-1
|
|
|
|
nl = len(self.store)-1
|
|
|
@ -185,6 +183,8 @@ class MemoryBuffer(StatBuffer):
|
|
|
|
if(entry["no"]<=floor): break
|
|
|
|
if(entry["no"]<=floor): break
|
|
|
|
posts.append(entry)
|
|
|
|
posts.append(entry)
|
|
|
|
nl-=1
|
|
|
|
nl-=1
|
|
|
|
|
|
|
|
if ca:
|
|
|
|
|
|
|
|
self.store = list()
|
|
|
|
super()._unlock()
|
|
|
|
super()._unlock()
|
|
|
|
return posts
|
|
|
|
return posts
|
|
|
|
|
|
|
|
|
|
|
@ -253,7 +253,7 @@ class FileBuffer(StatBuffer):
|
|
|
|
else: return 0
|
|
|
|
else: return 0
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
super()._unlock()
|
|
|
|
super()._unlock()
|
|
|
|
def readno(self, floor):
|
|
|
|
def readno(self, floor, ca=False):
|
|
|
|
super()._lock()
|
|
|
|
super()._lock()
|
|
|
|
posts = list()
|
|
|
|
posts = list()
|
|
|
|
if self.file.tell()>0:
|
|
|
|
if self.file.tell()>0:
|
|
|
@ -263,6 +263,8 @@ class FileBuffer(StatBuffer):
|
|
|
|
posts.append(ent)
|
|
|
|
posts.append(ent)
|
|
|
|
ent = self._readentry()
|
|
|
|
ent = self._readentry()
|
|
|
|
self.file.seek(0,2)
|
|
|
|
self.file.seek(0,2)
|
|
|
|
|
|
|
|
if ca:
|
|
|
|
|
|
|
|
self.file.truncate(0)
|
|
|
|
super()._unlock()
|
|
|
|
super()._unlock()
|
|
|
|
return posts
|
|
|
|
return posts
|
|
|
|
|
|
|
|
|
|
|
@ -352,9 +354,12 @@ class Daemon(threading.Thread):
|
|
|
|
self.buf = buf
|
|
|
|
self.buf = buf
|
|
|
|
self.running=True
|
|
|
|
self.running=True
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
def _get(self,con, fr):
|
|
|
|
def _get(self,con, fr, ca=False):
|
|
|
|
|
|
|
|
if ca:
|
|
|
|
|
|
|
|
log("[daemon]: Recieved get-clear from "+str(fr))
|
|
|
|
|
|
|
|
else:
|
|
|
|
log("[daemon]: Recieved get from "+str(fr))
|
|
|
|
log("[daemon]: Recieved get from "+str(fr))
|
|
|
|
data = self.buf.readno(fr)
|
|
|
|
data = self.buf.readno(fr, ca)
|
|
|
|
js = json.dumps(data)
|
|
|
|
js = json.dumps(data)
|
|
|
|
con.send(js.encode("utf-8"))
|
|
|
|
con.send(js.encode("utf-8"))
|
|
|
|
def run(self):
|
|
|
|
def run(self):
|
|
|
@ -373,6 +378,8 @@ class Daemon(threading.Thread):
|
|
|
|
self.running=False
|
|
|
|
self.running=False
|
|
|
|
elif cmd.uCommand == Command.CMD_GET: #receive entries from <data>
|
|
|
|
elif cmd.uCommand == Command.CMD_GET: #receive entries from <data>
|
|
|
|
self._get(con, struct.unpack("L", cmd.uData)[0])
|
|
|
|
self._get(con, struct.unpack("L", cmd.uData)[0])
|
|
|
|
|
|
|
|
elif cmd.uCommand == Command.CMD_GET_CLEAR: #receive entries from <data> then clear
|
|
|
|
|
|
|
|
self._get(con, struct.unpack("L", cmd.uData)[0], True)
|
|
|
|
elif cmd.uCommand == Command.CMD_CLEAR: #clear buffer
|
|
|
|
elif cmd.uCommand == Command.CMD_CLEAR: #clear buffer
|
|
|
|
log("[daemon]: Recieved clear")
|
|
|
|
log("[daemon]: Recieved clear")
|
|
|
|
self.buf.clear()
|
|
|
|
self.buf.clear()
|
|
|
|