Design Pattern Examples
Overview of object-oriented design patterns
Facade_ComplexSystem.c File Reference

Implementation of the IDeviceNetworkLowLevel interface and the complex system it represents for the Facade Pattern. More...

#include <stdio.h>
#include "Facade_Interface.h"
#include "Facade_ComplexSystem.h"
Include dependency graph for Facade_ComplexSystem.c:

Go to the source code of this file.

Classes

struct  DeviceNode
 Represents a single device. Part of the Facade Pattern example. More...
 
struct  DeviceChain
 Represents a single device chain, a collection of DeviceNode objects. More...
 

Functions

static void DeviceChain_ShowHideNodes (int chainIndex, uint32_t nodeSelectMask, bool makeVisible)
 Helper function to show or hide devices on the device chain.
 
static void DeviceChain_ResetVisibility (int chainIndex)
 Resets the specified device chain so that all devices that are not device controllers are no longer visible in the device chain.
 
static void DeviceChain_SelectNodes (int chainIndex, uint32_t nodeSelectMask)
 Make visible one or more devices in the device chain.
 
static void DeviceChain_DeselectNodes (int chainIndex, uint32_t nodeSelectMask)
 Make invisible one or more devices in the device chain.
 
static void DeviceChain_GetIdCodesForVisibleNodes (int chainIndex, UIntArray *idcodes)
 Retrieve a list of idcodes for all devices that are visible in the device chain.
 
static int GetNumChains (void)
 Retrieve the number of device chains.
 
static bool LockDeviceChain (int chainIndex)
 Lock the specified device chain to indicate exclusive access is desired.
 
static bool UnlockDeviceChain (int chainIndex)
 Unlock the specified device chain to indicate exclusive access is no longer desired.
 
static void ResetDeviceChain (int chainIndex)
 Reset the visibility of all devices on the given device chain so that all devices except the first are not visible.
 
static void EnableDevicesInDeviceChain (int chainIndex, uint32_t deviceselectMask)
 Select one or more devices in the given device chain so those devices are visible.
 
static void DisableDevicesInDeviceChain (int chainIndex, uint32_t deviceselectMask)
 Deselect one or more devices in the given device chain so those devices are no longer visible.
 
static void GetIdcodes (int chainIndex, UIntArray *idcodes)
 Retrieve a list of idcodes of all visible devices in the given device chain.
 
IDeviceNetworkLowLevelFacade_GetLowLevelDeviceService (void)
 Retrieve a set of function pointers to the low-level device service used in the Facade Pattern example.
 

Variables

static DeviceNode deviceChain0 []
 Device Chain 0, with 3 devices. The first device is always the device controller, which is always visible.
 
static DeviceNode deviceChain1 []
 Device Chain 1, with 3 devices. The first device is always the device controller, which is always visible.
 
static DeviceChain deviceChains []
 Device chains. There are two device chains, which are accessed separately. Each chain has its own lock for access, which is initially unlocked.
 
static int deviceChainCount = (int)(sizeof(deviceChains) / sizeof(deviceChains[0]))
 Number of device chains that have been pre-defined.
 
IDeviceNetworkLowLevel lowlevelService
 Definition of the IDeviceNetworkLowLevel interface, using function pointers to each function.
 

Detailed Description

Implementation of the IDeviceNetworkLowLevel interface and the complex system it represents for the Facade Pattern.

Definition in file Facade_ComplexSystem.c.

Function Documentation

◆ DeviceChain_DeselectNodes()

static void DeviceChain_DeselectNodes ( int  chainIndex,
uint32_t  nodeSelectMask 
)
static

Make invisible one or more devices in the device chain.

Parameters
chainIndexIndex of the device chain to manipulate.
nodeSelectMaska bit mask specifying which device or devices to hide, where bit 0 is the first device, bit 1 is the second, etc. Bit 0 is ignored as the first device is always visible.

Definition at line 179 of file Facade_ComplexSystem.c.

References DeviceChain_ShowHideNodes().

Referenced by DisableDevicesInDeviceChain().

◆ DeviceChain_GetIdCodesForVisibleNodes()

static void DeviceChain_GetIdCodesForVisibleNodes ( int  chainIndex,
UIntArray idcodes 
)
static

Retrieve a list of idcodes for all devices that are visible in the device chain.

Parameters
chainIndexIndex of the device chain to manipulate.
idcodesReturns an array of idcodes for each visible device, with the first device being at index 0. This UIntArray object needs to be initialized before use with UIntArray_Initialize() and freed after use with UIntArray_Clear().

Definition at line 194 of file Facade_ComplexSystem.c.

References deviceChainCount, deviceChains, DeviceChain::nodes, DeviceChain::numNodes, and UIntArray_AddInt().

Referenced by GetIdcodes().

◆ DeviceChain_ResetVisibility()

static void DeviceChain_ResetVisibility ( int  chainIndex)
static

Resets the specified device chain so that all devices that are not device controllers are no longer visible in the device chain.

Parameters
chainIndexIndex of the device chain to manipulate.

Definition at line 144 of file Facade_ComplexSystem.c.

References deviceChainCount, deviceChains, DEVICECONTROLLER, DeviceChain::nodes, DeviceChain::numNodes, and DeviceNode::Visible.

Referenced by ResetDeviceChain().

◆ DeviceChain_SelectNodes()

static void DeviceChain_SelectNodes ( int  chainIndex,
uint32_t  nodeSelectMask 
)
static

Make visible one or more devices in the device chain.

Parameters
chainIndexIndex of the device chain to manipulate.
nodeSelectMaska bit mask specifying which device or devices to make visible, where bit 0 is the first device, bit 1 is the second, etc. Bit 0 is ignored as the first device is always visible.

Definition at line 167 of file Facade_ComplexSystem.c.

References DeviceChain_ShowHideNodes().

Referenced by EnableDevicesInDeviceChain().

◆ DeviceChain_ShowHideNodes()

static void DeviceChain_ShowHideNodes ( int  chainIndex,
uint32_t  nodeSelectMask,
bool  makeVisible 
)
static

Helper function to show or hide devices on the device chain.

Parameters
chainIndexIndex of the device chain to manipulate.
nodeSelectMaskA bit mask where the position of each bit corresponds to a device in the device chain, with bit 0 being the first device, bit 1 being the second device, and so on.
makeVisibletrue if the device is to be made visible on the device chain; otherwise false, the device cannot be seen on the device chain.

Definition at line 112 of file Facade_ComplexSystem.c.

References deviceChainCount, deviceChains, DeviceChain::nodes, DeviceChain::numNodes, and DeviceNode::Visible.

Referenced by DeviceChain_DeselectNodes(), and DeviceChain_SelectNodes().

◆ DisableDevicesInDeviceChain()

static void DisableDevicesInDeviceChain ( int  chainIndex,
uint32_t  deviceselectMask 
)
static

Deselect one or more devices in the given device chain so those devices are no longer visible.

Parameters
chainIndexThe index of the device chain to access (0..n-1).
deviceselectMaskA bit mask indicating which devices to make invisible, with bit 0 corresponding to the first device, bit 1 corresponding to the second device, etc. Bit 0 is ignored as the first device is always visible.

Definition at line 319 of file Facade_ComplexSystem.c.

References DeviceChain_DeselectNodes(), and deviceChainCount.

◆ EnableDevicesInDeviceChain()

static void EnableDevicesInDeviceChain ( int  chainIndex,
uint32_t  deviceselectMask 
)
static

Select one or more devices in the given device chain so those devices are visible.

Parameters
chainIndexThe index of the device chain to access (0..n-1).
deviceselectMaskA bit mask indicating which devices to make visible, with bit 0 corresponding to the first device, bit 1 corresponding to the second device, etc. Bit 0 is ignored as the first device is always visible.

Definition at line 302 of file Facade_ComplexSystem.c.

References DeviceChain_SelectNodes(), and deviceChainCount.

◆ Facade_GetLowLevelDeviceService()

IDeviceNetworkLowLevel * Facade_GetLowLevelDeviceService ( void  )

Retrieve a set of function pointers to the low-level device service used in the Facade Pattern example.

Returns
Returns an IDeviceNetworkLowLevel interface representing the full device network.

Definition at line 368 of file Facade_ComplexSystem.c.

References lowlevelService.

Referenced by _InitializeLowLevelSystem().

◆ GetIdcodes()

static void GetIdcodes ( int  chainIndex,
UIntArray idcodes 
)
static

Retrieve a list of idcodes of all visible devices in the given device chain.

Parameters
chainIndexIndex of the device chain (0..n-1).
idcodesReturns an array of idcodes for each visible TAP, with the first TAP being at index 0. This UIntArray object needs to be initialized before use with UIntArray_Initialize() and freed after use with UIntArray_Clear().

Definition at line 335 of file Facade_ComplexSystem.c.

References DeviceChain_GetIdCodesForVisibleNodes(), and deviceChainCount.

◆ GetNumChains()

static int GetNumChains ( void  )
static

Retrieve the number of device chains.

Returns
Returns the number of device chains

Definition at line 229 of file Facade_ComplexSystem.c.

References deviceChainCount.

Referenced by DeviceNetworkHighLevel::GetNumChains().

◆ LockDeviceChain()

static bool LockDeviceChain ( int  chainIndex)
static

Lock the specified device chain to indicate exclusive access is desired.

Parameters
chainIndexThe index of the device chain to access (0..n-1).
Returns
Returns true if the device chain was successfully locked; otherwise, returns false (chain index out of range or the device chain is already locked)

Definition at line 241 of file Facade_ComplexSystem.c.

References deviceChainCount, deviceChains, and DeviceChain::IsLocked.

Referenced by DeviceNetworkHighLevel::DisableDevicesInDeviceChain(), DeviceNetworkHighLevel::EnableDevicesInDeviceChain(), and DeviceNetworkHighLevel::GetIdcodes().

◆ ResetDeviceChain()

static void ResetDeviceChain ( int  chainIndex)
static

Reset the visibility of all devices on the given device chain so that all devices except the first are not visible.

Parameters
chainIndexThe index of the device chain to access (0..n-1).

Definition at line 285 of file Facade_ComplexSystem.c.

References DeviceChain_ResetVisibility(), and deviceChainCount.

Referenced by DeviceNetworkHighLevel::DisableDevicesInDeviceChain().

◆ UnlockDeviceChain()

static bool UnlockDeviceChain ( int  chainIndex)
static

Unlock the specified device chain to indicate exclusive access is no longer desired.

Parameters
chainIndexThe index of the device chain to access (0..n-1).
Returns
Returns true if the device chain was successfully unlocked; otherwise, returns false (chain index out of range or the device chain is already unlocked)

Definition at line 264 of file Facade_ComplexSystem.c.

References deviceChainCount, deviceChains, and DeviceChain::IsLocked.

Referenced by DeviceNetworkHighLevel::DisableDevicesInDeviceChain(), DeviceNetworkHighLevel::EnableDevicesInDeviceChain(), and DeviceNetworkHighLevel::GetIdcodes().

Variable Documentation

◆ deviceChain0

DeviceNode deviceChain0[]
static
Initial value:
=
{
{ "DDD_DEVCTRL0", 0x10101010, DEVICECONTROLLER, true },
{ "DDD_CORE0" , 0x20202020, CORE , false },
{ "DDD_GTE0" , 0x30303030, GTE , false },
}
@ DEVICECONTROLLER
device controller. This is always visible.
@ CORE
Core device.
@ GTE
GTE device.

Device Chain 0, with 3 devices. The first device is always the device controller, which is always visible.

Definition at line 67 of file Facade_ComplexSystem.c.

◆ deviceChain1

DeviceNode deviceChain1[]
static
Initial value:
=
{
{ "DDD_DEVCTRL1", 0x10101011, DEVICECONTROLLER, true },
{ "DDD_PCH0" , 0x40404040, PCH , false },
{ "DDD_PMC0" , 0x50505050, PMC , false },
}
@ PMC
PMC device.
@ PCH
PCH device.

Device Chain 1, with 3 devices. The first device is always the device controller, which is always visible.

Definition at line 78 of file Facade_ComplexSystem.c.

◆ deviceChainCount

◆ deviceChains

DeviceChain deviceChains[]
static
Initial value:
= {
{ "CHAIN0", false, deviceChain0, sizeof(deviceChain0) / sizeof(deviceChain0[0]) },
{ "CHAIN1", false, deviceChain1, sizeof(deviceChain1) / sizeof(deviceChain0[1]) }
}
static DeviceNode deviceChain0[]
Device Chain 0, with 3 devices. The first device is always the device controller, which is always vis...
static DeviceNode deviceChain1[]
Device Chain 1, with 3 devices. The first device is always the device controller, which is always vis...

Device chains. There are two device chains, which are accessed separately. Each chain has its own lock for access, which is initially unlocked.

Definition at line 89 of file Facade_ComplexSystem.c.

Referenced by DeviceChain_GetIdCodesForVisibleNodes(), DeviceChain_ResetVisibility(), DeviceChain_ShowHideNodes(), LockDeviceChain(), and UnlockDeviceChain().

◆ lowlevelService

IDeviceNetworkLowLevel lowlevelService
Initial value:
=
{
}
static void DisableDevicesInDeviceChain(int chainIndex, uint32_t deviceselectMask)
Deselect one or more devices in the given device chain so those devices are no longer visible.
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 void GetIdcodes(int chainIndex, UIntArray *idcodes)
Retrieve a list of idcodes of all visible devices in the given device chain.
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.
static void EnableDevicesInDeviceChain(int chainIndex, uint32_t deviceselectMask)
Select one or more devices in the given device chain so those devices are visible.

Definition of the IDeviceNetworkLowLevel interface, using function pointers to each function.

The function pointers set here must be in the same order they are defined in the IDeviceNetworkLowLevel structure representing the interface.

Definition at line 355 of file Facade_ComplexSystem.c.

Referenced by Facade_GetLowLevelDeviceService().