Architecture & Design of Embedded Real-Time Systems (TI-AREM) Architectural Design Patterns 2. Components & Connectors and Component Architecture Patterns and UML 2.0 Ports (BPD. Chapter 4. p. 184-201) Version: 23-2-2014
Agenda Component Notation Component-based architecture Pattern Component & Connectors ROOM Pattern Design with UML 2.0 Ports Slide 2
UML Component Notation (1) MyInterface «component» Component requiredinterface Provided interface Required interface An interface: defines operation signatures (name, parameters and return type) NB! UML 2.0 Component notation and concepts Slide 3
UML Component Notation (2) OrderEntry «component» Order Person Compact view «Interface» OrderEntry +create() +validatedetails() +addorderline() Detailed view «component» Order «use» «Interface» Person +create() +findbyname() +getdeatils() Slide 4
UML Component Notation (3) Assembly Connector Slide 5
Component-Based Architecture A component in UML is a run-time artifact that forms the basic replaceable unit of software Component examples: static libraries, dynamic link libraries (DLLs), OCX and ActiveX components Slide 6
Component Based Pattern Structure Slide 7
Component Based Pattern Example Slide 8
Slide 9
Component & Connectors Existing research has focused on Component structure Component Interfaces Component functionality More focus needed on component interactions embodied in the notation of software connectors Slide 10
Connectors Connector definition: Connectors mediates interactions among components, that is, they establish the rules that govern component interaction and specify any auxiliary mechanism required Connectors should be first-class modeling constructs Ref. Article: Towards a Taxanomy of Software Connectors Slide 11
ROOM Pattern ROOM (Real-Time Object-Oriented Methodology). The ROOM Pattern is appropriate when the interaction of some large-scale objects is complex and requires special means to mediate and control. Slide 12
ROOM Pattern Structure Slide 13
ROOM Pattern Example Slide 14
ROOM Ports (~UML Ports) Master: Comm Object isender ireceiver Slave: Comm Object ROOM Ports => UML 2.x Ports Slide 15
ROOM Pattern Example State Chart Model Slide 16
UML 2.0 Ports Ports The Ports subpackage provides mechanisms for isolating a classifier from its environment. This is achieved by providing a point for conducting interactions between the internals of the classifier and its environment. This interaction point is referred to as a port. Multiple ports can be defined for a classifier, enabling different interactions to be distinguished based on the port through which they occur. By decoupling the internals of the classifier from its environment, ports allow a classifier to be defined independently of its environment, making that classifier reusable in any environment that conforms to the interaction constraints imposed by its ports. Ref. UML 2.0 Superstructure spec. Slide 17
New UML 2.0 Concepts for Classes A port groups interfaces belonging to a particular stakeholder. A port can have as well provided as required interfaces. Ref. Article Architecting Systems with UML 2.0, IEEE Software jul/aug. 2003. Slide 18
Example with Internal Structure Black Box View White Box View Structured Class Slide 19
Example with Behavioral Port Slide 20
Example: Home Alarm System version 1 home alarm detect intrusions <<extend>> occupation simulation «extend» intruder sound alarm arming and di sarming homeowner via keypad <<in clud e>> via remote code entry ch anging code <<inclu de>> Ref. Rhapsody 7.0 Slide 21
Home Alarm System version 1 Slide 22
Home Alarm System version 1 AlarmPkg «Facad e» AlarmController Without Using ports itsalarmcontroller 1 HardwarePkg thehardware 1 «Interface» IHardware Slide 23
AlarmController a Composite Class «Facade» AlarmController 1 t hekey pad:keypad 1 thelightcontroller:lightcontroller 1 1 thegreenled:led 1 theredled:led itsalarmcontroller thehardware 1 «Interf ace» IHardware setlight(alight:tlights,state:tonoff):void onarm():void ondisarm():void onkeyoff():void onkeyon():void onkey(n:int):void onmovement():void ondoor():void setled(ident:tled,state:tonoff):void setsiren(state:tonoff):void Slide 24
AlarmController State Diagram /init(); armed off evtemporise exiting active tm(exit_time) evarm detecting entering evdoor evdisarm evmovement tm(silence_time) evmovement tm(entry_time) intrusion tm(alarm_time) silence Slide 25
AlarmController Public Operations «Facade» AlarmController configure(ahardware:ihardware*):void AlarmController() flashgreenled():void onarm():void ondisarm():void ondoor():void onkey(n:int):void onkeyoff():void onkeyon():void onmovement():void evarm():void evmovement():void evdoor():void evtemporise():void evdisarm():void 1 itsalarmcontroller thehardware 1 «Interface» HardwarePkg::IHardware setlight(alight:tlights,state:t... onarm():void ondisarm():void onkeyoff():void onkeyon():void onkey(n:int):void onmovement():void ondoor():void setled(ident:tled,state:tono... setsiren(state:tonoff):void Slide 26
Possible Hardware Implementations AlarmHw 486Pkg Hw Poll Hw Irq AlarmHw 68kPkg SimulatedHw Pkg Hw guidlg «Interf ace» IHardw are onarm():void ondisarm():void onkeyoff() :void onkeyon():void onkey( n:int):void onmovement():void ondoor():void setled(ident:tled,state:to... setsiren(state:tonoff):void TestPkg Hw Slide 27
Home Alarm version 2 with Ports Ports are a new UML2.x modeling concept that allows strong encapsulation of classes from the environment. In this case, the Hardware and Alarm Controller are decoupled by specifying ports as their boundary interaction points. Slide 28
Package Diagram PORT: hwobserver With 3 provided interface AlarmPkg hwobserver IDoorListener,IKey Listener,IMov ementlistener HardwarePkg AbstractHW AbsHardware «F acade» AlarmController IKey Listener,I Mov ementlist ener, IDoorListener ctrl hwctrl ILedCtrl,ILightCtrl,ISirenCtrl PORT: ctrl PORT: hwctrl With 3 required interface ILedCt rl,ilight Ct rl,isirenctrl SimulatedHwPkg HwTestPkg guidlg Hw Slide 29
Home Alarm version 2 with Ports PORT: hwobserver hwobserver 1 «F acade» Alarm Controller thekeypad:keyp ad IDoorListener,IKey Listener,IMov ementlistener hw 1 thesiren:siren Co ntroll er ISirenCtrl PORT: hwctrl hw ILightC trl 1 th el igh tcontroller:lightc on trol ler hwc trl ILedC trl,ilightctrl,isirenc trl hw 1 thegreenled:led ILedCtrl hw 1 theredled:le d ILedC trl Slide 30
Classes: KeyPad, SirenController, Led newcode:int count:int oldcode:int Keypad Keypad() iscodecorrect():omboolean iscodeentered():omboolean changecode():void evkeyoff():void evkey():void evkeyon():void hw ISirenCtrl hw ILedCtrl SirenController setsirenon():void setsirenoff():void Led Led() evtoggle():void evflash():void evon():void evoff():void Slide 31
KeyPad State Diagram active armingdisarmingreprogr amming evkeyoff [IS_IN(cor rect)]/ itscontroller- >GEN(evDisarm) ; idle evkey/ codeentry newcode = (10 * new Code ) + params ->n; c ount++; evkey/ new Code = params->n; tm(5000) count=1; enteringcode ev KeyOff evkeyon [IS_IN(cor rect)]/ itscontroller- >GEN(evTemporise); [iscodeenter ed() ] evkeyon[is_in(different) ]/ changecode(); [IS_IN(notEntered) ] reprogramming [else] [is CodeCorrect()] waitoldcode currentcode evkey On [else] dif ferent correct evkeyoff [IS_IN(c orrect)] waitnew Code tm(3000) notentered tm(3000) tm(10000) 2 AND states Slide 32
Test Configuration hwobserver 1 «Facade» thealarm Ctrl:AlarmController IDoorListener,IKeyLis tener,imovementlistener IKeyListener,IMovem entlistene r,idoorlistener ILedC trl,ilightctrl,isirenctrl ctrl 1 thehw:hw hwctrl ILedCtrl,ILightCtrl,ISi renc trl Slide 33
Rhapsody Implementation of a Port (1) PORT: hwobserver AlarmController IDoorListener, IKeyListener, IMovementListener «Interface» IDoorListener «Interface» IKeyListener «Interface» IMovementListener ondoor():void onkey(n:int):void onkeyoff():void onkeyon():void onarm():void ondisarm():void onmovement():void Auto generated Port Class AlarmController hwobserver_c::inbound_c Slide 34
Rhapsody Implementation of a Port (2) AlarmController PORT: hwctrl ILedCtrl, ILIghtCtrl, ISirenCtrl «Interface» ILedCtrl «Interface» ILightCtrl «Interface» ISirenCtrl setled(ident:tled,state:tonoff)... setlight(alight:tlights,stat... setsiren(state:tonoff):void hwctrl_c::outbound_c Auto generated Port Class Slide 35
Rhapsody Implementation of a Port (3) PORT: hwobserver AlarmController PORT: hwctrl ILedCtrl, ILIghtCtrl, ISirenCtrl IDoorListener, IKeyListener, IMovementListener hwobserver_c hwctrl_c InBound_C x OutBound_C IDoorListener IKeyListener IMovementListener x InBound_C OutBound_C ISirenCtrl ILightCtrl ILedCtrl Slide 36
Rhapsody Implementation of a Port (4) thehw: Hw ctrl:ctrl_c OutBound: OutBound_C thealarmcrtl: AlarmController hwobserver: hwobserver_c InBound: InBound_C InBound: InBound_C hwctrl: hwctrl_c OutBound: OutBound_C Slide 37
AlarmController thealarmctrl; Hw thehw; Test Setup thehw.getctrl()->setitsikeylistener( thealarmctrl.gethwobserver()->getitsikeylistener()); thehw.getctrl()->setitsimovementlistener( thealarmctrl.gethwobserver()->getitsimovementlistener()); thehw.getctrl()->setitsidoorlistener( thealarmctrl.gethwobserver()->getitsidoorlistener()); thealarmctrl.gethwctrl()->setitsiledctrl(thehw.getctrl()->getitsiledctrl()); thealarmctrl.gethwctrl()->setitsilightctrl(thehw.getctrl()->getitsilightctrl()); thealarmctrl.gethwctrl()->setitsisirenctrl(thehw.getctrl()->getitsisirenctrl()); Slide 38
UML 2.0 Component Diagram «Executable» Gui <<Usage>> HWAbsLib AlarmCtrlLib <<Usage>> Slide 39 <<Callback>> (via ports)
Summary Component patterns and ports: Component-Based Architecture ROOM Pattern (=>UML 2.x Ports) Designing with Ports in UML 2.x Slide 40