From OpenHome
Contents |
ohTopology
Overview
ohTopology is a software stack which provides a means of controlling devices, on a local network, via their UPnP service actions. Devices are grouped based on their Room names and presented as a tree structure based on their interconnectivity. It consists of a number of distinct layers. Each layer focuses on exposing specific properties and actions that are intended to be utilised by the layers above. Clients of ohTopology need only interface directly with the highest layer of the stack to gain access to the properties and actions exposed by the lower layers.
Watchable System
Overview
Actions exposed by a layer can be called directly, but property values can only be monitored through a callback notification system (observer pattern). Properties are exposed as "watchable" values that may be monitored by "watcher" clients. When a (watchable) property changes, all of its watchers are automatically notified of the change and the property's new value. Watchers can be added and removed at any time. The IWatchable interface is used to expose single value properties and the IWatchableUnordered and IWatchableOrdered interfaces are used for multivalue property lists. Property client objects must conform to the appropriate Iwatchable/IWatchableUnordered/IWatchableOrdered interface for the property that they wish to observe.
Watchable Thread
Although ohTopology is designed to run on multithreaded platforms, actions are executed in a single thread through the use of a thread scheduler class, WatchableThread. Enforcing single threaded execution removes the burden of having to manage thread safety, simplifies debugging and reduces the risk of deadlock. The WatchableThread class provides three methods; Execute, Schedule and Assert.
Schedule Method
Schedule provides a mechanism for asynchronous callback. The specified callback is placed in a queue (FIFO) to be run on the watchable thread, in turn, at some point in the future. Schedule takes a functor, for the callback method, and a generic void* argument to be passed to the callback.
Execute Method
Execute provides a mechanism for synchronous callback. If called from the watchable thread it executes the callback immediately. Otherwise it schedules the callback, for execution on the watchable thread. In either case, it blocks until the callback has completed. Execute takes a functor for the callback method and a generic void* argument to be passed to the callback.
Assert Method
Assert provides a way of checking if the current thread is the watchable thread.
Injector
Network
Topology1
Overview
Topology1 maintains a collection of all discovered devices, that feature the Product Service. It presents the collection as a list of Product Service proxies.
Topology1
Topology1 requests a list of devices with the Product Service, from Network, and watches this list for changes. It creates a corresponding list of ProxyProduct objects that is updated whenever the Network device list changes. The ProxyProduct list is exposed as Products which is of type IWatchableUnordered.
Topology2
Overview
Topology2 collects the list of discovered products from Topology1 and exposes a collection of Groups. Each Group exposes a Sources collection and pertinent properties and actions of the Product Service. Each Source exposes the standard set of Source properties.
Topology2
Topology2 watches Topology1::Products and creates a corresponding list of Topology2Group objects that is updated whenever Topology1::Products changes. The Groups method exposes the Topology2Group list as an IWatchableUnordered.
Topology2Source
Topology2Group
It creates a Topology2Source list having retrieved the source information from the source XML of each ProxyProduct.
Topology3
Overview
Topology3 collects the list of Groups from Topology2 and exposes a collection of Groups. Each Group exposes a Sources collection, pertinent actions and properties of the Product Service, a Sender property and a SetSender action.
Topology3
Topology3 watches Topology2::Groups and creates a corresponding list of Topology3Group objects that is updated whenever Topology2::Groups changes. The Groups method exposes the Topology3Group list as an IWatchableUnordered.
Topology3Group
Receiver Watcher
Sender Watcher
Topology4
Overview
Topology4 collects the list of Groups from Topology3 and exposes a collection of Rooms. Each Room exposes a collection of Groups that have a matching RoomName property.
Topology4
Topology4 watches Topology3::Groups and creates a Topology4Room list that is updated whenever there is a change to the RoomName property of any Topology3Group. The RoomName property of each Topology3Group is monitored by a dedicated Topology4GroupWatcher object.
Topology4Room
Topology4GroupWatcher
Topology4GroupWatcher watches the RoomName property of one specific Topology3Group and updates Topology4 whenever there is a change.
Topology5
Overview
Topology5 collects the list of Rooms from Topoolgy4 and organises the Groups in each room, evaluating their interrelationship as a hierarchical tree, and exposes a list of Rooms. Each Room exposes a Roots list and a Sources list. A Root is defined as a product whose outputs are not connected to the inputs of any other product. In essence a Root is the main product in the Room whose outputs are connected to the speakers and typically, once configured correctly, each Room should contain only one Root.
Topology5
Topology5 watches Topology4::Rooms, updating Topology5Room list whenever a Topology4Room is added/removed.
Each Room's Group list is filtered to remove all Child groups, and a super list of all sources of all groups in each room is maintained that is filtered to remove any Parent sources. A Child group is defined as one whose outputs are connected to the inputs of another group. A Parent source is defined as one whose input is fed from the outputs of another (Child) group.
Topology5Room
Topology5Room watches Topology4Room::Groups updating Topology3Group list whenever a Topology3Group is added/removed. The Standby, Name and Sources properties of each Topology3Group are then watched for changes. A dedicated Topology5GroupWatcher is employed to monitor Name and Sources of each group. Although the Standby state of each group is boolean, Topology5Room exposes a tristate Standby property. This is to accommodate a third state "mixed" when there is an inconsistent Standby state across all groups in the room. The Topology3Group list is used to maintain a corresponding Topology5Group list, a subset of which is exposed as a Roots list. A Root (ITopology5Root) is defined as a Topology5Group that does not have a Parent group. A super list of all Sources of every Root in the Room is exposed as Sources.
Topology5Group
Topology5Source
Topology5GroupWatcher
Monitors the two properties, Name and Sources, of Topology3Group, updating (CreateTree) Topology5Room when any poperty change occurs.