Design Pattern Examples
Overview of object-oriented design patterns
facade_highlevelsystem.py
Go to the documentation of this file.
8
9from .facade_interface import IDeviceNetworkHighLevel
10from .facadesubsystem_interface import IDeviceNetworkLowLevel
11from .facade_complicatedsubsystem import CreateLowLevelInstance
12
13
21
22
26 def __init__(self, system : IDeviceNetworkLowLevel) -> None:
27 if not system:
28 raise ValueError("The system being wrapped cannot be None.")
29 self._lowLevelSystem = system # type: IDeviceNetworkLowLevel
30
31
33
34
35 #====================================================================
36 # IDeviceNetworkHighLevel methods
37 #====================================================================
38
39 # @copydoc IDeviceNetworkHighLevel.GetNumChains()
40 def GetNumChains(self) -> int:
41 return self._lowLevelSystem.GetNumChains()
42
43
44 # @copydoc IDeviceNetworkHighLevel.GetIdcodes()
45 def GetIdcodes(self, chainIndex : int) -> list:
46 idcodes = []
47
48 if self._lowLevelSystem.LockDeviceChain(chainIndex):
49 idcodes = self._lowLevelSystem.GetIdcodes(chainIndex)
50 self._lowLevelSystem.UnlockDeviceChain(chainIndex)
51
52 return idcodes
53
54
55 # @copydoc IDeviceNetworkHighLevel::EnableDevicesInDeviceChain()
56 def EnableDevicesInDeviceChain(self, chainIndex: int, selectMask : int) -> None:
57 if self._lowLevelSystem.LockDeviceChain(chainIndex):
58 self._lowLevelSystem.EnableDevicesInDeviceChain(chainIndex, selectMask)
59 self._lowLevelSystem.UnlockDeviceChain(chainIndex)
60
61
62 # @copydoc IDeviceNetworkHighLevel::DisableDevicesInDeviceChain()
63 def DisableDevicesInDeviceChain(self, chainIndex : int) -> None:
64 if self._lowLevelSystem.LockDeviceChain(chainIndex):
65 self._lowLevelSystem.ResetDeviceChain(chainIndex)
66 self._lowLevelSystem.UnlockDeviceChain(chainIndex)
67
68
69
70
72
73_instance = None # type: DeviceNetworkHighLevel
74
75
82def CreateHighLevelInstance() -> IDeviceNetworkHighLevel:
83 global _instance
84 if not _instance:
85 lowlevelSystem = CreateLowLevelInstance()
86 _instance = DeviceNetworkHighLevel(lowlevelSystem)
87 return _instance
static bool LockDeviceChain(int chainIndex)
Lock the specified device chain to indicate exclusive access is desired.
static void ResetDeviceChain(int chainIndex)
Reset the visibility of all devices on the given device chain so that all devices except the first ar...
static bool UnlockDeviceChain(int chainIndex)
Unlock the specified device chain to indicate exclusive access is no longer desired.
static int GetNumChains(void)
Retrieve the number of device chains.
This class wraps the IDeviceNetworkLowLevel interface and implements the high level IDeviceNetworkHig...
list GetIdcodes(self, int chainIndex)
Returns a list of all idcodes from all selected devices in the given device chain.
None DisableDevicesInDeviceChain(self, int chainIndex)
Resets the given device chain so that all devices except the TAP controller is no longer visible.
None EnableDevicesInDeviceChain(self, int chainIndex, int selectMask)
Make visible certain devices in the given device chain.
Represents a high level view of a complex network of device chains.
IDeviceNetworkHighLevel CreateHighLevelInstance()
Class factory for a singleton instance of the IDeviceNetworkHighLevel interface.