mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2025-12-06 07:12:04 +01:00
add docstrings to the router classes
This commit is contained in:
parent
54676f9f06
commit
05166cfdca
|
|
@ -17,14 +17,22 @@
|
|||
|
||||
|
||||
class Route:
|
||||
"""!Class for single routing points"""
|
||||
def __init__(self, name, callback):
|
||||
"""!Create a instance of an route point
|
||||
|
||||
@param name: name of the route point
|
||||
@param callback: instance of the callback function
|
||||
"""
|
||||
self._name = name
|
||||
self._callback = callback
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""!Property to get the route point name"""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def callback(self):
|
||||
"""!Porperty to get the callback function instance"""
|
||||
return self._callback
|
||||
|
|
|
|||
|
|
@ -21,16 +21,29 @@ logging.debug("- %s loaded", __name__)
|
|||
|
||||
|
||||
class Router:
|
||||
"""!Class for the Router"""
|
||||
def __init__(self, name):
|
||||
"""!Create a new router
|
||||
|
||||
@param name: name of the router"""
|
||||
self._name = name
|
||||
self._routeList = []
|
||||
logging.debug("[%s] new router", self._name)
|
||||
|
||||
def addRoute(self, route):
|
||||
"""!Adds a route point to the router
|
||||
|
||||
@param route: instance of the Route class
|
||||
"""
|
||||
logging.debug("[%s] add route: %s", self._name, route.name)
|
||||
self._routeList.append(route)
|
||||
|
||||
def runRouter(self, bwPacket):
|
||||
"""!Run the router
|
||||
|
||||
@param bwPacket: instance of Packet class
|
||||
@return a instance of Packet class
|
||||
"""
|
||||
logging.debug("[%s] started", self._name)
|
||||
for routeObject in self._routeList:
|
||||
logging.debug("[%s] -> run route: %s", self._name, routeObject)
|
||||
|
|
@ -50,8 +63,10 @@ class Router:
|
|||
|
||||
@property
|
||||
def name(self):
|
||||
"""!Property to get the name of the router"""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def routeList(self):
|
||||
"""!Property to get a list of all route points of this router"""
|
||||
return self._routeList
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
@description: Class for the BOSWatch packet router manager class
|
||||
"""
|
||||
|
||||
|
||||
# todo think about implement threading for routers and the plugin calls (THREAD SAFETY!!!)
|
||||
import logging
|
||||
import importlib
|
||||
|
|
@ -27,15 +26,24 @@ logging.debug("- %s loaded", __name__)
|
|||
|
||||
|
||||
class RouterManager:
|
||||
"""!Class to manage all routers"""
|
||||
def __init__(self):
|
||||
"""!Create new router"""
|
||||
self._routerDict = {}
|
||||
|
||||
def __del__(self):
|
||||
"""!Destroy the internal routerDict
|
||||
All routers and route point instances will be destroyed too
|
||||
Also destroys all instances from modules or plugins"""
|
||||
# destroy all routers (also destroys all instances of modules/plugins)
|
||||
del self._routerDict
|
||||
|
||||
# if there is an error, router list would be empty (see tmp variable)
|
||||
def buildRouter(self, config):
|
||||
"""!Initialize Routers from given config file
|
||||
|
||||
@param config: instance of ConfigYaml class
|
||||
@return True or False"""
|
||||
self._routerDict = {} # all routers and instances of modules/plugins would be destroyed
|
||||
routerDict_tmp = {}
|
||||
logging.debug("build routers")
|
||||
|
|
@ -91,6 +99,10 @@ class RouterManager:
|
|||
return True
|
||||
|
||||
def runRouter(self, routerRunList, bwPacket):
|
||||
"""!Run given Routers
|
||||
|
||||
@param routerRunList: string or list of router names in string form
|
||||
@param bwPacket: instance of Packet class"""
|
||||
if type(routerRunList) is str: # convert single string name to list
|
||||
routerRunList = [routerRunList]
|
||||
|
||||
|
|
@ -99,6 +111,7 @@ class RouterManager:
|
|||
self._routerDict[routerName].runRouter(bwPacket)
|
||||
|
||||
def _showRouterRoute(self):
|
||||
"""!Show the routes of all routers"""
|
||||
for name, routerObject in self._routerDict.items():
|
||||
logging.debug("Route for %s", name)
|
||||
counter = 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue