BOSWatch 3
Python Script to receive and decode German BOS Information with rtl_fm and multimon-NG
 
Loading...
Searching...
No Matches
module.moduleBase.ModuleBase Class Reference

Main module class. More...

Public Member Functions

 __init__ (self, moduleName, config)
 init preload some needed locals and then call onLoad() directly
 
 onLoad (self)
 Called by import of the module can be inherited.
 
 doWork (self, bwPacket)
 Called module run can be inherited.
 
 onUnload (self)
 Called on shutdown of boswatch can be inherited.
 

Static Public Member Functions

 registerWildcard (newWildcard, bwPacketField)
 Register a new wildcard.
 

Data Fields

 config
 

Protected Member Functions

 _cleanup (self)
 Cleanup routine calls onUnload() directly.
 
 _run (self, bwPacket)
 start an run of the module.
 
 _getStatistics (self)
 Returns statistical information's from last module run.
 

Protected Attributes

 _moduleName
 
 _cumTime
 
 _moduleTime
 
 _runCount
 
 _moduleErrorCount
 

Static Protected Attributes

list _modulesActive = []
 

Detailed Description

Main module class.

Constructor & Destructor Documentation

◆ __init__()

module.moduleBase.ModuleBase.__init__ (   self,
  moduleName,
  config 
)

init preload some needed locals and then call onLoad() directly

Reimplemented in module.descriptor.BoswatchModule, module.filter.doubleFilter.BoswatchModule, module.filter.modeFilter.BoswatchModule, module.filter.regexFilter.BoswatchModule, module.geocoding.BoswatchModule, module.multicast.BoswatchModule, and module.template_module.BoswatchModule.

31 def __init__(self, moduleName, config):
32 r"""!init preload some needed locals and then call onLoad() directly"""
33 self._moduleName = moduleName
34 self.config = config
35 self._modulesActive.append(self)
36
37 # for time counting
38 self._cumTime = 0
39 self._moduleTime = 0
40
41 # for statistics
42 self._runCount = 0
43 self._moduleErrorCount = 0
44
45 logging.debug("[%s] onLoad()", moduleName)
46 self.onLoad()
47

Member Function Documentation

◆ _cleanup()

module.moduleBase.ModuleBase._cleanup (   self)
protected

Cleanup routine calls onUnload() directly.

48 def _cleanup(self):
49 r"""!Cleanup routine calls onUnload() directly"""
50 logging.debug("[%s] onUnload()", self._moduleName)
51 self._modulesActive.remove(self)
52 self.onUnload()
53

◆ _run()

module.moduleBase.ModuleBase._run (   self,
  bwPacket 
)
protected

start an run of the module.

Parameters
bwPacketA BOSWatch packet instance
Returns
bwPacket or False
54 def _run(self, bwPacket):
55 r"""!start an run of the module.
56
57 @param bwPacket: A BOSWatch packet instance
58 @return bwPacket or False"""
59
60 # --- FIX: Multicast list support for Module ---
61 if isinstance(bwPacket, list):
62 result_packets = []
63 for single_packet in bwPacket:
64 # Recursive call for single packet
65 processed = self._run(single_packet)
66
67 # new logic:
68 if processed is False:
69 # filter called 'False' -> packet discarded
70 continue
71 elif processed is None:
72 # module returned None -> keep packet unchanged
73 result_packets.append(single_packet)
74 elif isinstance(processed, list):
75 # module returned new list -> extend
76 result_packets.extend(processed)
77 else:
78 # module returned modified packet -> add
79 result_packets.append(processed)
80
81 # if list is not empty, return it. else False (filter all).
82 return result_packets if result_packets else False
83 # -----------------------------------------------
84
85 self._runCount += 1
86 logging.debug("[%s] run #%d", self._moduleName, self._runCount)
87
88 tmpTime = time.time()
89 try:
90 logging.debug("[%s] doWork()", self._moduleName)
91 bwPacket = self.doWork(bwPacket)
92 except:
93 self._moduleErrorCount += 1
94 logging.exception("[%s] alarm error", self._moduleName)
95 self._moduleTime = time.time() - tmpTime
96
97 self._cumTime += self._moduleTime
98
99 logging.debug("[%s] took %0.3f seconds", self._moduleName, self._moduleTime)
100
101 return bwPacket
102

◆ _getStatistics()

module.moduleBase.ModuleBase._getStatistics (   self)
protected

Returns statistical information's from last module run.

Returns
Statistics as pyton dict
103 def _getStatistics(self):
104 r"""!Returns statistical information's from last module run
105
106 @return Statistics as pyton dict"""
107 stats = {"type": "module",
108 "runCount": self._runCount,
109 "cumTime": self._cumTime,
110 "moduleTime": self._moduleTime,
111 "moduleErrorCount": self._moduleErrorCount}
112 return stats
113

◆ onLoad()

module.moduleBase.ModuleBase.onLoad (   self)

Called by import of the module can be inherited.

Reimplemented in module.descriptor.BoswatchModule, module.filter.doubleFilter.BoswatchModule, module.filter.modeFilter.BoswatchModule, module.filter.regexFilter.BoswatchModule, module.multicast.BoswatchModule, and module.template_module.BoswatchModule.

114 def onLoad(self):
115 r"""!Called by import of the module
116 can be inherited"""
117 pass
118

◆ doWork()

module.moduleBase.ModuleBase.doWork (   self,
  bwPacket 
)

Called module run can be inherited.

Parameters
bwPacketbwPacket instance

Reimplemented in module.descriptor.BoswatchModule, module.filter.doubleFilter.BoswatchModule, module.filter.modeFilter.BoswatchModule, module.filter.regexFilter.BoswatchModule, module.geocoding.BoswatchModule, module.multicast.BoswatchModule, and module.template_module.BoswatchModule.

119 def doWork(self, bwPacket):
120 r"""!Called module run
121 can be inherited
122
123 @param bwPacket: bwPacket instance"""
124 logging.warning("no functionality in module %s", self._moduleName)
125

◆ onUnload()

module.moduleBase.ModuleBase.onUnload (   self)

Called on shutdown of boswatch can be inherited.

Reimplemented in module.descriptor.BoswatchModule, module.filter.doubleFilter.BoswatchModule, module.filter.modeFilter.BoswatchModule, module.filter.regexFilter.BoswatchModule, module.multicast.BoswatchModule, and module.template_module.BoswatchModule.

126 def onUnload(self):
127 r"""!Called on shutdown of boswatch
128 can be inherited"""
129 pass
130

◆ registerWildcard()

module.moduleBase.ModuleBase.registerWildcard (   newWildcard,
  bwPacketField 
)
static

Register a new wildcard.

Parameters
newWildcardwildcard where parser searching for
bwPacketFieldfield from bwPacket where holds replacement data
132 def registerWildcard(newWildcard, bwPacketField):
133 r"""!Register a new wildcard
134
135 @param newWildcard: wildcard where parser searching for
136 @param bwPacketField: field from bwPacket where holds replacement data"""
137 if not newWildcard.startswith("{") or not newWildcard.endswith("}"):
138 logging.error("wildcard not registered - false format: %s", newWildcard)
139 return
140 if bwPacketField == "":
141 logging.error("wildcard not registered - bwPacket field is empty")
142 return
143 wildcard.registerWildcard(newWildcard, bwPacketField)

Field Documentation

◆ _modulesActive

list module.moduleBase.ModuleBase._modulesActive = []
staticprotected

◆ _moduleName

module.moduleBase.ModuleBase._moduleName
protected

◆ config

module.moduleBase.ModuleBase.config

◆ _cumTime

module.moduleBase.ModuleBase._cumTime
protected

◆ _moduleTime

module.moduleBase.ModuleBase._moduleTime
protected

◆ _runCount

module.moduleBase.ModuleBase._runCount
protected

◆ _moduleErrorCount

module.moduleBase.ModuleBase._moduleErrorCount
protected