mirror of
https://github.com/craigerl/aprsd.git
synced 2024-09-27 15:46:53 -04:00
Hemna
94fb481014
This patch reworks all the packet processing to use the new Packets objects. Nuked all of the messaging classes. backwards incompatible changes all messaging.py classes are now gone and replaced by packets.py classes
49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
from multiprocessing import RawValue
|
|
import threading
|
|
|
|
import wrapt
|
|
|
|
|
|
class PacketCounter:
|
|
"""
|
|
Global Packet id counter class.
|
|
|
|
This is a singleton based class that keeps
|
|
an incrementing counter for all packets to
|
|
be sent. All new Packet objects gets a new
|
|
message id, which is the next number available
|
|
from the PacketCounter.
|
|
|
|
"""
|
|
|
|
_instance = None
|
|
max_count = 9999
|
|
lock = threading.Lock()
|
|
|
|
def __new__(cls, *args, **kwargs):
|
|
"""Make this a singleton class."""
|
|
if cls._instance is None:
|
|
cls._instance = super().__new__(cls, *args, **kwargs)
|
|
cls._instance.val = RawValue("i", 1)
|
|
return cls._instance
|
|
|
|
@wrapt.synchronized(lock)
|
|
def increment(self):
|
|
if self.val.value == self.max_count:
|
|
self.val.value = 1
|
|
else:
|
|
self.val.value += 1
|
|
|
|
@property
|
|
@wrapt.synchronized(lock)
|
|
def value(self):
|
|
return self.val.value
|
|
|
|
@wrapt.synchronized(lock)
|
|
def __repr__(self):
|
|
return str(self.val.value)
|
|
|
|
@wrapt.synchronized(lock)
|
|
def __str__(self):
|
|
return str(self.val.value)
|