Aligned participant documentation

This commit is contained in:
Pascal Serrarens 2025-04-28 18:13:12 +02:00
parent e4f0cc68f9
commit 2fe73b39be

View File

@ -8,6 +8,8 @@ class Participant:
""" """
def __init__(self, ip_address, port): def __init__(self, ip_address, port):
"""! Create a new participant with the given communcation info """! Create a new participant with the given communcation info
@param ip_address The IP address of the participant
@param port The UDP port of the participant
""" """
## The Ip Address of a participant. When the participant is local, this contains 0.0.0.0 ## The Ip Address of a participant. When the participant is local, this contains 0.0.0.0
@ -15,16 +17,27 @@ class Participant:
## The port number for UDP communication with the participant. This is 0 for isolated participants. ## The port number for UDP communication with the participant. This is 0 for isolated participants.
self.port = port self.port = port
## The network ID of the participant ## he network Id to identify the participant.
self.network_id =0 self.network_id =0
## The things managed by this participant ## The things managed by this participant
self.things = set() self.things = set()
def Get(self, thing_id):
"""! Get the thing with the given properties
@param thing_id The ID of the thing
@return The thing if found, None in other cases
"""
for thing in self.things:
if thing is not None and thing.id == thing_id:
return thing
return None
def Add(self, thing, check_id = True): def Add(self, thing, check_id = True):
"""! Add a new thing for this participant. """! Add a new thing for this participant.
@param thing The thing to add @param thing The thing to add
@param check_id When true, the thing ID of the thing is checked. If it is 0, a new thing Id will be assigned. @param check_id If true, the thing.id is regenerated if it is zero
""" """
if check_id and thing.id == 0: if check_id and thing.id == 0:
thing.id = len(self.things) + 1 thing.id = len(self.things) + 1
@ -34,25 +47,16 @@ class Participant:
if found_thing == None: if found_thing == None:
self.things.add(thing) self.things.add(thing)
def Get(self, thing_id):
"""! Find a thing managed by this participant
@param thing_id The ID of the thing
@return The thing if found or nullptr when no thing has been found
"""
for thing in self.things:
if thing is not None and thing.id == thing_id:
return thing
return None
def Remove(self, thing): def Remove(self, thing):
"""! Remove a thig for this participant """! Remove a thing for this participant
@param thing The thing to remove @param thing The thing to remove
""" """
self.things.remove(thing) self.things.remove(thing)
## Update all things def Update(self, currentTimeMs=0):
def Update(self, currentTimeMs): """! Update all things for this participant
@param The current time in milliseconds (optional)
"""
for thing in list(self.things): for thing in list(self.things):
if thing is not None: if thing is not None:
thing.Update(currentTimeMs) thing.Update(currentTimeMs)