M2-PT-DRP/source/managers/Manager.py

30 lines
No EOL
877 B
Python

from . import CommunicationManager
from source import packets
from source.behaviors import roles
class Manager:
def __init__(self, interface: str):
self.communication = CommunicationManager(interface)
self.communication.register_packet_type(b"DISC", packets.DiscoveryPacket)
# define the role of our machine
# TODO(Faraphel): give the manager to the role directly ? register ?
self.role = roles.UndefinedRole()
def sendLoop(self):
while True:
self.role.run(self)
def receiveLoop(self):
try:
while True:
packet, address = self.communication.receive()
print(f"Received message from {address}: {packet}")
# get corresponding event
# handle it
except KeyboardInterrupt:
print("Stopping listener.")