Koala component model - PowerPoint PPT Presentation

1 / 75
About This Presentation
Title:

Koala component model

Description:

Koala component model Maarten Pennings MG-R course day 2 am Contents 1. Concepts 2. The Basic Model 3. More on Interfaces 4. Function Binding 5. Optional Interfaces 6. – PowerPoint PPT presentation

Number of Views:174
Avg rating:3.0/5.0
Slides: 76
Provided by: robvano
Category:
Tags: component | koala | model

less

Transcript and Presenter's Notes

Title: Koala component model


1
Koala component model
  • Maarten Pennings
  • MG-R course
  • day 2 am

2
Contents
  • Koala supports the following concepts
  • why component model
  • components
  • interfaces
  • modules
  • binding
  • 1. Concepts
  • 2. The Basic Model
  • 3. More on Interfaces
  • 4. Function Binding
  • 5. Optional Interfaces
  • 6. Switches

3
Why component model
Concepts
  • Product familyin one LoB 100 products in 5
    years
  • Software size explosionabout factor 2 every 2
    years
  • Product features overlapin multiple LoB similar
    software
  • Diversitymany small differences in hardware and
    user interface
  • Distributed developmentdifferent LoBs,
    research, software lab

4
Product family
Concepts
  • MG98 is a product familywith 100 product types
    over 5 years
  • MG98 is a main stream productcost optimisation
    is important

Cost effective component model
5
Software size explosion
Concepts
100
93
GFL
in 1000 lines of source code
200
95
MID2
450
97
MID98
600
99
MID98
Share components between products
6
Feature overlap
Concepts
LoBs
time
Share components between LOBs
7
Product diversity (overview)
Concepts
  • Many typesaround 50 from 24 till 38
  • Many sets1 000 000 pieces (at 1000)
  • Many countries27 languages, 38 Approbation
    organisations
  • Many standards3 voltages, 11 power plugs, 13
    frequency standards, 9 sound standards, 22
    connector types, 10 TXT standards

8
Product diversity (features)
Concepts
  • Screen4x3/16x9/Shift/PIP/DualScreen/Mosaic/Freeze
    /Zoom/Replay/Photofinish
  • SoundMono/Stereo/Dolby/Equalizer/SmartSound/Cordl
    ess/Surround
  • ChannelsACI/ATS/GiveName/Favourite
  • ModesTV/VCR/Demo/Cable/Web/DVD/Satellite
  • Program GuidesEPGday,channel,theme/VPS,PDC/DualS
    creen/EasyLink/Lock
  • GraphicsOSD/TXT/ChineseTXT/GemStart

Components should be easy to tweak
9
Distributed development
Concepts
  • Eindhoven NatLabarchitectural concepts
  • BriarcliffDigital TV
  • Bruggehigh-end TV europe
  • Eindhoven ASA labFlat TV / component factory
  • Bangalorecomponent factory
  • Singaporebasic TV

Components are developedat different sites
10
Component model
Concepts
multi systemcomposition
single systemdecomposition
11
Koalas Concepts
Concepts
  • A component is a unit of encapsulation.
  • An interface is a small and coherentset of
    functions.
  • A module is a unit of code.
  • A binding is a connection between interfaces.

12
Components
Concepts
A component is a piece of software that is non
trivial in size (an asset to the company), but
that does not contain any configuration specific
information.
  • A component provides and requires interfaces, and
    can interact through these interfaces only.

MS-COM allows for WIN32 calls
13
Interfaces
Concepts
We treat interfaces as first class citizens.
  • interfaces are unidirectional
  • each interface has a definition
  • Interface definitions are units of reuse.
  • an interface definition is always shared between
    a provider and a requirer
  • variants of components may provide or require the
    same interfaces.

--- --- ---
14
Modules
Concepts
For Koala, a module is a hand-written C file and
a generated header file.
  • not all modules in a component need to be
    declared to Koala
  • header files for undeclared modules must be hand
    written (of course)
  • communication between modules within a component
    is completely free
  • communication with the environment must go
    through interfaces.

m3
15
Compound Components
Concepts
A group of components can be seen as a component
again...
C3
This allows us to create reusable subsystems (or
standard designs). A subcomponent in a compound
component is a copy (instance) of a reusable
component (type).
s1C1
s2C2
r1
p3
16
Configurations
Concepts
  • Definitions
  • a basic component is a component without
    subcomponents
  • a compound component is a component with one or
    more subcomponents
  • a configuration is a component without provides
    and requires interfaces, a top-level component.

C3
s1C1
M1
M2
s2C2
17
Koala
Concepts
workspace C C1 c1.cd m.c c1.c m.h
C2 c2.cd m.c c2.c m.h C3 c3.cd
c3.c I I1.id I2.id D global.h enums.h
workspace C C1 c1.cd m.c C2
c2.cd m.c C3 c3.cd I I1.id
I2.id D global.dd enums.dd
Koala loads the three kinds of definitions, and
writesh files for module andc files for
components
koala -pcr C -pir I -ptr D C3
18
Naming
Concepts
Before we proceed, lets discuss naming
  • a component has a globally unique long name and
    short name (prefix)
  • each interface has a local name unique to the
    component
  • each interface is associated with an interface
    definition
  • Note that two or more interfaces in a single
    component may have the same definition!

ntfIFoundNotify
powIPower
tunITuner
tvttuCTvTerrestrialTuner
drvITunerDriver
nvmINonVolatile
hndIFoundNotify
19
2. The Basic Model
Basic
1. Concepts 2. The Basic Model 3. More on
Interfaces 4. Function Binding 5. Optional
Interfaces 6. Switches
  • Koala supports three languages
  • DD data type definitions
  • ID interface definitions
  • CD component definitions

20
Languages
  • CD - Component definitiondescribes components
    referring to component definitions and interface
    definitions
  • ID - Interface definitiondescribes function
    prototypes and constants referring to datatype
    definitions
  • DD - Datatype definitiondescribes datatypes
    referring to other datatypes

21
DD
Basic
An datatype definition declares a datatype that
is used for typing parameters in functions
(occurring in interfaces)
Ordinary C header file with machine readable
comments embedded
DD
typedef char Int8 / koala type Int8
/ typedef char Bool / koala type Bool /
22
DD - rules
Basic

header file with datatype definitions only
Normal C type declarations
machinereadable comments
/ file SoundTypes.dd // koala group Sound
/ typedef Int8 Volume / koala type Volume
/ / koala using Int8 / typedef Bool Mute
/ koala type Mute / / koala using
Bool /
datatype file is assigned a namefor others to
use
Datatype name must be globally unique
Datatypes may bebased on others
23
ID
Basic
An interface definition describes the syntax and
semantics of a small set of functions
Syntax names and types of functions and
arguments. Semantics a (simple) logical model of
the behaviour. Interfaces consist of constants
and functions only (nullary functions are called
parameters).
ID
interface ISoundControl // sdc void
SetVolume(Volume v) void SetTreble(Treble b)
24
ID - rules
Basic

Interface definition name must be globally unique
Parameter list may be void ...
Result type must be void or simpleO
or must consist of typed and named parameters.
interface I void f(void) int g(int x, int
y) int h(Volume x, Volume y) int j(char
ROM s)
Parameter names must be unique per function
Function names must be unique per interface
Osimple type - datatype - datatype - datatype
tag
Parameter type must be simpleO
Datatype must be known to Koala
25
ID - rules
Basic

Nullary functions do need void...
or they drop the parenthesis
interface I int f0( void ) int f1 int
f2 3 int f3(x) x I.f2 I.f1
Nullary functions are called parameters or
properties
Constants may be defined
Functions may refer to other functions in this
interface
26
CD
Basic
In a component definition, the interfaces
provided and required by the component can be
described.
CD
A component is implemented as a set of C and H
files. It is preferred to have a directory per
component. Part of the internal structure is also
described to Koala.
component C1 provides Ia p1 ...
requires Ib r1 ...
27
CD - rules
Basic

Component name must be globally unique
Interface names must be unique per component
There may be multiple sections in any order (not
recommended)
component C1 provides Ia p1, p2
Ib p3 requires Ib r1 Ic r2, r3
Interface definitions must be known to Koala
28
Binding
Basic
Interfaces must be bound tip to base
interface I void f(void) void g(int x)
component C1 requires I r
s1C1
rI
CD
contains component C1 s1 component C2
s2 connects s1.r s2.p
component C2 provides I p
pI
s2C2
Note that components get a local name here...
29
Gluing
Basic
  • Glue code may be inserted in a binding in the
    form of a module...

s1C1
contains component C1 s1 component C2 s2
module mconnects s1.r m m s2.p
  • the header file of m is generated
  • the C file of m is hand written.

rI
m
This allows to fine tune components at the level
of configurations.
pI
s2C2
30
CD - rules
Basic

Definitions must be known to Koala
Names must be locally unique
p
C1
p
component C1 provides I p requires I r
contains component C s module m
connects p s.p s.r m m
r
SC
r
Sections may be in any order (not recommended)
m
r
Must be a base interface or a module
Must be a tip interface or a module
Every tip interface must be bound
Every base interface may be bound zero or more
times
31
Basic

Function names
p
mustdefine
p_f
Compprefix pr
s1C1
s1_rr_f
rr
m
mayuse
f
pp
s2_pp_f
pr_f
s2C2
r_f
r
32
Example
/ file m1.c / include m1.h void
SomeFunc(void) r_Func(54)
/ Koala generated m1.h / define r_Func
C__p_func extern void C__p_Func(int x)
m1
r
Koala generated
handcrafted
No runtime nor size penalty!
p
/ file m2.c / include m2.h void p_Func(int
x) x
/ Koala generated m2.h / define p_Func
C__p_func extern void C__p_Func(int x)
C
m2
33
Basic

Name mangling by binding
p
p_f
pr__p_f
Compprefix pr
Physicalnames
Logicalnames
s1C1
s1_rr_f
pr__s1_rr_f
rr
m
pp
s2_pp_f
?__?_f
s2C2
This is not pp!
r_f
?__?_f
r
34
Example
Basic
tunITuner
/ file tvttu_m.c / include _tvttu_m.h void
tun_StartSearch(void) s1_snd_SetOutput(0)
tdr_StartSearch(54)void f_fin_GoUp(void)
...
You write
CTvTerrestrialTuner prefix tvttu
fCFineTuner
Koala generates
fin
m
/ file _tvttu_m.h / define tun_StartSearch
tvttu__tun_StartSearch define f_fin_GoUp
tvttu__f_fin_GoUp extern void tvttu__tun_StartSear
ch(void) extern void tvttu__f_fin_GoUp(void) d
efine s1_snd_SetOutput ??? define
tdr_StartSearch ??? extern void
s1_snd_SetOutput(int vol) extern void
tdr_StartSearch(int freq)
snd
s1CSwitch
tdrITunerDriver
35
CD - rules
Basic

component C1 specials prefix c
library uses infrartk
Specifies that component is available as
library
Specifiesshortnameof component
If you need accessto data types thatare not
availablethrough usedinterfaces
36
Exercise
Hello, MG-R!
37
3. More on Interfaces
More
1. Concepts 2. The Basic Model 3. More on
Interfaces 4. Function Binding 5. Optional
Interfaces 6. Switches
  • We discuss
  • private interfaces
  • interface compatibility

38
Interface Chains
More
  • binding connecting modules to interfaces to
    interfaces to modules.
  • components only serve as scope restrictors during
    the binding.
  • each tip should be connected to precisely one
    base or module
  • each base may be connected to zero or more tips
    or modules
  • modules cannot be bound to modules (un-typed
    lined)!

39
Implementing Components
More
p1
p2
p3
p4
p5
  • An example implementation of a component
  • m1 implements p1 in terms of r1
  • m2 and m3 communicate by themselves
  • m4 and m5 communicate through private interfaces.

C1
i1
m2
m4
m1
i2
m3
m5
r1
r2
r3
r4
r5
40
CD - private interfaces
More

definition must be known to Koala
names must be locally unique
p
C
component C provides I p requires I r
contains interface I i module m1, m2
connects p m1 m1 i i m2
m2 r
i
sections may be in any order (not recommended)
r
is bound by the base here
is bound by the tip here
the tip must be bound once
the base may be bound zero or more times
41
Interface Compatibility
More
  • Once defined, an interface definition may not be
    changed any more(unless all components
    referring to the definition are changed
    simultaneously)
  • but it is allowed to define new interfaces that
    are supersets (or subsets) of old interfaces.
  • Koala allows to connect such new interfaces to
    the old interfaces.

42
Compatibility Rules
More
  • Rule a tip may be connected to any base, if for
    every function in the tip interface there is a
    function in the base interface with
  • the same function name
  • the same result type
  • the same parameter list, where each formal
    parameter has
  • the same name
  • the same type

43
Illustration
More
The pictures show how old and new interfaces may
be connected.
interface I void f(int x) void g(int y)
Cb
I
I
C1
interface I void h(int z) void g(int y)
void f(int x)
44
Exercise more on interfaces
interface I1 int f(int x, int y) void
g(char c)
1
2
interface I2 void g(char c) int f(int x,
int y)
3
4
interface I3 void g(char c) int h(void)
int f(int x, int y)
5
6
7
8
interface I4 int f(int x, int y) void
g(char ch)
bI2
aI1
cI3
Your assignment Which of 1..8 are ok?
45
Answer more on interfaces
ü
ü
interface I1 int f(int x, int y) void
g(char c)
1
2
I1I2
I1I2
û
ü
interface I2 void g(char c) int f(int x,
int y)
I3ËI1no h
3
4
I1ÍI3
û
û
interface I3 void g(char c) int h(void)
int f(int x, int y)
5
6
I1ËI4g(c)¹g(ch)
I4ËI1 g(c)¹g(ch)
û
ü
I1ÍI3, I2ÍI3
7
8
down split
interface I4 int f(int x, int y) void
g(char ch)
bI2
aI1
cI3
46
4. Function Binding
FuBi
1. Concepts 2. The Basic Model 3. More on
Interfaces 4. Function Binding 5. Optional
Interfaces 6. Switches
  • We discuss
  • diversity interfaces
  • Koala expressions
  • in-line expressions
  • constant folding

47
Implementing Functions
FuBi
  • Rule every function in every interface that is
    connected with the tip to a module should be
    implemented by that module.
  • Implementation can be
  • either in C
  • or in Koala
  • The latter is sometimes called function binding
    its main purpose is to support diversity.

48
Diversity Interfaces
FuBi
Component diversity may be controlled through
diversity interfaces.
  • These are requires interfaces, allowing us to
  • assign values to diversity parameters using the
    binding mechanism
  • delay static/dynamic decision
  • optimise on certain constant values.

connects s.d m within m s.d.Flag()
true
interface I Bool Flag()
dI
m
sC
49
Diversity Interfaces
FuBi
  • Diversity interfaces are not provided interfaces
    (using SetColor instead of required with Color)
  • hard to optimize away(now a define suffices)
  • provided needs notification(propagate changes)
  • initialisation problems(when can a component use
    property)

50
Diversity Spreadsheet
FuBi
Compound components may have diversity interfaces
as well.
d
The inner diversity interfaces may be expressed
in terms of constants, functions and parameters
in the outer diversity interface. This allows to
use different languages for diversity depending
on the level of decomposition. Catch
re-evaluated every time
m
sC
d
r
connects s.d m m d m r within m
s.d.f() ! d.f() s.d.g() - r.g()
51
CD - within clause
FuBi
multiple within sections, any order
component C provides I p requires I r
contains module m connects p m
m r within m p.f(x) r.g(2,x)

module must be declared
pI
p must be bound with the tip to m
C
r must be bound with the base to m
rI
f must be declared in p ( I)
g must be declared in r ( I)
parameter list length must match
interface definition
f may not be bound twice!
parameter names must be unique
parameter names may differ from interface
definition
52
CD - expressions
FuBi
symbolic constant must be defined in type header
file
parameter must be declared
integer constant
within m p.f(x) x0 ? 1
r.g(x) p.f(x-BLUE)
all C operatorsare available inKoala expressions
function calls must have the right number
of parameters
calling a required function
calling a provided function
53
CD - inline operator
FuBi
use of ( ) recommended
calling a required function
calling a provided function
calling an auxiliary function
using a global variable
within m p.f(x) inline (1 x
r_f(x) p_f(x) my_f(x) my_var) using
r.f , p.f , extern void
my_f(int x) , extern Int8 my_var
, Int8
Note the difference!
all C declarations necessary should be put here
this should be proper C (dont forget the )!
Datatype mustexist
54
Inline Expressions
FuBi
  • Ingredients of inline expressions are
  • constants (1, BLUE, true)
  • operators (, )
  • foreign functions legacy_func
  • optimizations my_var.

Not needed, already possible in Koala
Make unique withcomponent shortname (prefix)
55
Constant Folding
FuBi
  • Koala recognizes
  • integer constant expressions (i)
  • boolean constant expressions (b)
  • 11 function bindings (f)
  • other expressions (e)
  • We shall give some examples and some rules.

56
Constant Folding Examples
FuBi
  • f(x) 3 4 has value 7
  • g(x ) 5 f(x) has value 12
  • h(x) x 1 is not constant
    folding
  • p(x) h(5) is not constant
    folded either
  • q( ) green is constant with value
    green
  • r( ) green 1 is not constant folded
  • a(x,y) b(x,y) is function bound
  • a(x,y) 0 b(x,y) is not function bound
  • b( ) 0 true has the value false
  • c( ) b()?d( )e( ) is function bound to
    e()

57
The CONSTANT Macro
FuBi
  • Whenever Koala determines that a function f in
    interface i is boolean or integer constant, it
    generates a macro with the name i_f_CONSTANT and
    with the value of the function as value.

ifdef i_f_CONSTANT if i_f_CONSTANT / its
true! / else / its false! / endif else
/ maybe true, maybe false / endif
i
58
5. Optional Interfaces
Opt
1. Concepts 2. The Basic Model 3. More on
Interfaces 4. Function Binding 5. Optional
Interfaces 6. Switches
  • We discuss
  • optional interfaces
  • iPresent
  • ICONNECTED

59
Evolving Components
Opt
  • Interfaces must be connected at the tip, unless
    they are declared optional.

Optional interfaces allow components to evolve
over time, without having to change existing
configurations.
A2

B
C2
60
Optional - Well Formedness
Opt
optional only influences the preceding declaration
p1
p2
component C provides I p1, p2 optional
requires I r1, r2 optional contains interface
I i1, i2 optional module m1, m2
connects p1 m1 p2 m1 m1 i1 m1
i2 i1 m2 i2 m2 m2
r1 m2 r2
i1
i2
r1
r2
61
iPresent
Opt
Every optional interface is augmented with a
nullary boolean function iPresent (with a
_CONSTANT macro).
Koala sets iPresentto false
Only allowed if thelower interface canbe
guaranteed to bepresent at compiletime
iPresent must bedefined by the module(in Koala
expressionsor in C)
Koala sets iPresentto true
iPresent is passedthrough
iPresent can beused by the module(in Koala
expressionsor in C)
62
iPresent optimised away
  • If iPresent is statically knownthe compiler will
    optimise
  • remove guard
  • remove either then or else part
  • If iPresent is dynamic code still works

r
if( r_iPresent() ) / can make call to r
/ x r_SomeFunc() else / do it
yourself / x 0
63
Exercise
Hello you (twice)
64
6. Switches
Switch
1. Concepts 2. The Basic Model 3. More on
Interfaces 4. Function Binding 5. Optional
Interfaces 6. Switches
  • We discuss
  • switches
  • compatibility and optionality
  • reachablility

65
Flexible Connections
Switch
  • A switch allows to create bindings that depend on
    the value of certain functions.

In the example, p is connected through the switch
to either pp or i, depending on the value of the
control function in interface d. Koala optimises
switches if the setting is known at compile time,
and generates switch code otherwise.
p
d
pp
i
sC
66
Switch - Well Formedness
Switch
must be a base interface, and must be non
optional!
must be a nullary function defined in d (I)
default values are 0, 1, 2...
component C provides I p1,p2 requires I
d contains component C s1,s2
interface I i1,i2 module m
connects switch d.f in p1 , p2
out s1.p1, s1.p2 ,
i1 , i2 on 7 , s2.p1,
s2.p2 i1 m i2 m
p1
p2
2
0
7
these are bound by the tip
i1
i2
s1C
s2C
these are bound by the base
must be an integer, boolean or symbolic constant
all lists must have the same length
67
Interface Compatibility
Switch
  • A switch is a special form of binding. The
    compatibility rules are the same. This means that
    any function in any interface in the in clause
    must have an implementation in the corresponding
    interface in every out clause!

f,g
f,g,h2
h1,g,f
68
Optional Interfaces
Switch
  • Rules for connecting optional interfaces can be
    derived from the general binding rules

d
Koala calculates iPresent to bed.f()?truej.iPre
sent()
t
f
switch d.f in p out i , j

i
j
Is allowed, provided that Koala canguarantee at
compile time that- d.f() true, or-
j.iPresent() true
d
i
j
69
Reachability
Switch
  • Some functions are called by Magic, i.e.
    outside the Koala domain
  • main()
  • interrupt handlers
  • If a module contains such a function, declare it
    as present

C
sD
component C ... contains module m0
present ...
70
Reachability
  • Koala generates header files for all modules in
    reachable components.
  • Informally a component is reachable if it is
    (indirectly) called from a present module.

71
Reachability
Switch
  • modules marked present are reachable
  • if a module is reachable, then an interface bound
    with its base to the module is reachable
  • if an interface is reachable, then an interface
    or module bound to its tip (directly or via a
    switch) is reachable
  • a component is reachable if at least one of its
    modules is reachable
  • a module is reachable if its container component
    is reachable.

72
Reachability
We build C1. Which components are reachable from
C1..C8? Which modules are built and linked
fromm1a..m8?
73
Reachability
Koala assumesa call from m6b to m6a
Module m2 is present.
Note that we buildcomponent C1, but that C1 is
not reachable!
74
Reachability
Switch
  • However, reachability stops when reaching an
    optional interface
  • This allows us to haveoptional initialisation

start
void s0_start_Init() if( s1_init_iPresent()
) s1_init_Init() if( s2_init_iPresent() )
s2_init_Init() if( s3_init_iPresent() )
s3_init_Init() start_Init()
start
s
init
init
init
m
 
 
s1
s2
s3
s0
 
75
ICONNECTED
Switch
  • For every interface i bound with the tip to a
    module, a macro i_ICONNECTED is generated if that
    interface is bound with the base (possibly
    through other interfaces) to a reachable module.
  • This macro can only be used in C (not in Koala
    expressions).

/ m.c / IFDEF p1_ICONNECTED / functions
for p1 / int p1_f(int x) return xx
ENDIF
Write a Comment
User Comments (0)
About PowerShow.com