Module meshtastic.globals
Globals singleton class.
Instead of using a global, stuff your variables in this "trash can". This is not much better than using python's globals, but it allows us to better test meshtastic. Plus, there are some weird python global issues/gotcha that we can hopefully avoid by using this class instead.
Expand source code
"""Globals singleton class.
Instead of using a global, stuff your variables in this "trash can".
This is not much better than using python's globals, but it allows
us to better test meshtastic. Plus, there are some weird python
global issues/gotcha that we can hopefully avoid by using this
class instead.
"""
class Globals:
"""Globals class is a Singleton."""
__instance = None
@staticmethod
def getInstance():
"""Get an instance of the Globals class."""
if Globals.__instance is None:
Globals()
return Globals.__instance
def __init__(self):
"""Constructor for the Globals CLass"""
if Globals.__instance is not None:
raise Exception("This class is a singleton")
else:
Globals.__instance = self
self.args = None
self.parser = None
self.target_node = None
self.channel_index = None
def reset(self):
"""Reset all of our globals. If you add a member, add it to this method, too."""
self.args = None
self.parser = None
self.target_node = None
self.channel_index = None
def set_args(self, args):
"""Set the args"""
self.args = args
def set_parser(self, parser):
"""Set the parser"""
self.parser = parser
def set_target_node(self, target_node):
"""Set the target_node"""
self.target_node = target_node
def set_channel_index(self, channel_index):
"""Set the channel_index"""
self.channel_index = channel_index
def get_args(self):
"""Get args"""
return self.args
def get_parser(self):
"""Get parser"""
return self.parser
def get_target_node(self):
"""Get target_node"""
return self.target_node
def get_channel_index(self):
"""Get channel_index"""
return self.channel_index
Classes
class Globals-
Globals class is a Singleton.
Constructor for the Globals CLass
Expand source code
class Globals: """Globals class is a Singleton.""" __instance = None @staticmethod def getInstance(): """Get an instance of the Globals class.""" if Globals.__instance is None: Globals() return Globals.__instance def __init__(self): """Constructor for the Globals CLass""" if Globals.__instance is not None: raise Exception("This class is a singleton") else: Globals.__instance = self self.args = None self.parser = None self.target_node = None self.channel_index = None def reset(self): """Reset all of our globals. If you add a member, add it to this method, too.""" self.args = None self.parser = None self.target_node = None self.channel_index = None def set_args(self, args): """Set the args""" self.args = args def set_parser(self, parser): """Set the parser""" self.parser = parser def set_target_node(self, target_node): """Set the target_node""" self.target_node = target_node def set_channel_index(self, channel_index): """Set the channel_index""" self.channel_index = channel_index def get_args(self): """Get args""" return self.args def get_parser(self): """Get parser""" return self.parser def get_target_node(self): """Get target_node""" return self.target_node def get_channel_index(self): """Get channel_index""" return self.channel_indexStatic methods
def getInstance()-
Get an instance of the Globals class.
Expand source code
@staticmethod def getInstance(): """Get an instance of the Globals class.""" if Globals.__instance is None: Globals() return Globals.__instance
Methods
def get_args(self)-
Get args
Expand source code
def get_args(self): """Get args""" return self.args def get_channel_index(self)-
Get channel_index
Expand source code
def get_channel_index(self): """Get channel_index""" return self.channel_index def get_parser(self)-
Get parser
Expand source code
def get_parser(self): """Get parser""" return self.parser def get_target_node(self)-
Get target_node
Expand source code
def get_target_node(self): """Get target_node""" return self.target_node def reset(self)-
Reset all of our globals. If you add a member, add it to this method, too.
Expand source code
def reset(self): """Reset all of our globals. If you add a member, add it to this method, too.""" self.args = None self.parser = None self.target_node = None self.channel_index = None def set_args(self, args)-
Set the args
Expand source code
def set_args(self, args): """Set the args""" self.args = args def set_channel_index(self, channel_index)-
Set the channel_index
Expand source code
def set_channel_index(self, channel_index): """Set the channel_index""" self.channel_index = channel_index def set_parser(self, parser)-
Set the parser
Expand source code
def set_parser(self, parser): """Set the parser""" self.parser = parser def set_target_node(self, target_node)-
Set the target_node
Expand source code
def set_target_node(self, target_node): """Set the target_node""" self.target_node = target_node