component based software building concurrent systems from reusable parts david knight apr05

25
Component based software Building concurrent systems from reusable parts David Knight Apr05

Upload: walter-walters

Post on 27-Dec-2015

219 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Component based software Building concurrent systems from reusable parts David Knight Apr05

Component based software

Building concurrent systems from reusable parts

David Knight Apr05

Page 2: Component based software Building concurrent systems from reusable parts David Knight Apr05

Component construction

• A Component:– Encapsulates some interesting behaviour

– Has inputs and/or outputs

• An input or output can be:– A Signal: A value of any type that can be changed at

any time without warning

– An Event: A notification that something has happened, accompnaied by optional parameters of any type

Page 3: Component based software Building concurrent systems from reusable parts David Knight Apr05

A component, in pictures

ClassName

InstanceName

inSignal

inEvent

outSignal

outEvent

Page 4: Component based software Building concurrent systems from reusable parts David Knight Apr05

Interfaces

• An interface is a group of logically-related signals and/or events that are treated as a unit– An interface can contain a mixture of in and out signals or

events• A component can implement an interface, in which case it must

provide inputs and outputs as described by the interface• A component can implement an interface in reverse, in which case

the in/out direction of all signals/events is reversed• A component can implement multiple interfaces, including the

same interface multiple times• An interface can also contain other interfaces, in normal or

reversed direction, to arbitrary depth

Page 5: Component based software Building concurrent systems from reusable parts David Knight Apr05

Interfaces in pictures

ComponentName

IfcN

ame

IfcN

ame

Normaldirectioninterface

Reversedirectioninterface

Page 6: Component based software Building concurrent systems from reusable parts David Knight Apr05

Connection rules

• An output of a component can be connected to the input of one or more other components (including itself)

• Interconnection is only permitted between signals and events of the same type

• An interconnected network of components can itself be viewed as a component. This can be carried to any depth.

Page 7: Component based software Building concurrent systems from reusable parts David Knight Apr05

Connection in pictures

C1 C2

C1

U1 U2

U3

ClkIn

ClkIn

Enable

Enable

ClkOut

ClkOut

Carry

Carry

Clk

A

B Run

Error

Page 8: Component based software Building concurrent systems from reusable parts David Knight Apr05

Component interfaces

• The external view of a component is specified by an interface.

• Several different components can implement the same interface, and thus would be plug-compatible.

Page 9: Component based software Building concurrent systems from reusable parts David Knight Apr05

Component interface in pictures

Dte

Byt

eStr

eam

inStreammodem

clock

enable

error

speed

ready

Page 10: Component based software Building concurrent systems from reusable parts David Knight Apr05

Interface as text

interface Example;

ByteStream inStream;

in event clock();

in boolean enable;

reverse Dte modem;

out event error(int reason);

out boolean ready;

out int speed;

endinterface;

Page 11: Component based software Building concurrent systems from reusable parts David Knight Apr05

Component as text...component cName implements iName;interface

in int ival;in event clock();out boolean ready;

staticDoofer d= new Doofer(...);Scronge s= new Scronge(...);Gadget g= new Gadget(...);connect clock d.tick g.clk s.clock;connect s.ready g.enable;connect s.out ready;connect ival d.speed;

dynamic

(see next slide)

Page 12: Component based software Building concurrent systems from reusable parts David Knight Apr05

...component as text

dynamicmachine mName;initial

initialisationActions;next s1;

state s1;entryActions;when event1(int b)

doThis;next s2;

when event2();doThat;next s1;

endwhen;state s2;

etc...endmachine;

endcomponent;

Page 13: Component based software Building concurrent systems from reusable parts David Knight Apr05

Example 1 Simple producer/consumer

See the pages:ByteStream.ifc

Producer.ifc

Consumer.ifc

Example.ifc

Producer.cmp

Consumer.cmp

Pc.cmp

Page 14: Component based software Building concurrent systems from reusable parts David Knight Apr05

Example 1 - interfaces

data

ByteStream

data

Byt

eStr

eam

Clock

Producer

stream

Byt

eStr

eam

stream

Consumer

clock

Example

Page 15: Component based software Building concurrent systems from reusable parts David Knight Apr05

Pc.cmp

Byt

eStr

eam

Clock

SimpleProducer

stream

Byt

eStr

eam

stream

SimpleConsumer

Clock

Page 16: Component based software Building concurrent systems from reusable parts David Knight Apr05

Example 2Bounded queue

See files

Queue.ifc

Queue.cmp

Pqc.cmp

Pqqc.cmp

Page 17: Component based software Building concurrent systems from reusable parts David Knight Apr05

Queue interface

Byt

eStr

eam

inStream

Queue

outStreamB

yteS

trea

m

Page 18: Component based software Building concurrent systems from reusable parts David Knight Apr05

Pqc.cmp

Byt

eStr

eam

inStream

Queue

outStream

Byt

eStr

eam

Byt

eStr

eam

Clock

SimpleProducer

stream

Byt

eStr

eam

stream

SimpleConsumer

Clock

Page 19: Component based software Building concurrent systems from reusable parts David Knight Apr05

Pqqc.cmp

Byt

eStr

eam

inStream

Queue

outStream

Byt

eStr

eam

Byt

eStr

eam

Clock

SimpleProducer

stream

Byt

eStr

eam

stream

SimpleConsumer

Clock

Byt

eStr

eam

inStream

Queue

outStream

Byt

eStr

eam

Page 20: Component based software Building concurrent systems from reusable parts David Knight Apr05

Example 3Async data transmission

See filesAsyncTransmitter.ifc

AsyncReceiver.ifc

AsyncTransmitter.cmp

AsyncReceiver.cmp

Ptrc.cmp

Pqtrqc.cmp

Page 21: Component based software Building concurrent systems from reusable parts David Knight Apr05

Example 3 interfaces

Byt

eStr

eam

stream

AsyncTransmitter

clock

txd

Byt

eStr

eam

Clock

AsyncReceiver

streamrxd

Page 22: Component based software Building concurrent systems from reusable parts David Knight Apr05

Ptrc.cmp

Byt

eStr

eam

stream

AsyncTransmitter

clock

txd

Byt

eStr

eam

Clock

AsyncReceiver

streamrxd

Byt

eStr

eam

Clock

SimpleProducer

stream

Byt

eStr

eam

stream

SimpleConsumer

Clock

Page 23: Component based software Building concurrent systems from reusable parts David Knight Apr05

Pqtrqc.cmp

Byt

eStr

eam

stream

AsyncTransmitter

clock

txd

Byt

eStr

eam

Clock

AsyncReceiver

streamrxd

Byt

eStr

eam

Clock

SimpleProducer

stream

Byt

eStr

eam

stream

SimpleConsumer

Clock (Queue in here)

(Queue in here)

Page 24: Component based software Building concurrent systems from reusable parts David Knight Apr05

StatMux/StatDemux

• A StatMux interleaves two data independent streams onto a single channel, to make better use of the channel data capacity

• A StatDemux reverses the process, and separates the two streams again

Page 25: Component based software Building concurrent systems from reusable parts David Knight Apr05

StatMux/StatDemux

Byt

eStr

eam

StatDemux

port0

Byt

eStr

eam

line

Byt

eStr

eam

port1

port0

StatMux line

Byt

eStr

eam

Byt

eStr

eam

port1

Byt

eStr

eam