Logo BCDDLogo CSC
BCDDBehavioural Contract-Driven Design
version 1.0-beta
ITEN

Chapter 5 — Requests

The caretaker of the block of flats asks that, during cleaning, the light stay on for a set time. This request is not a simple press of the button: the installation can accept it or reject it and, if it accepts it, it can conclude it with a successful or a failed outcome. The chapter describes how to write a request.

The request

A request is what the consumer can ask of the provider. It takes place in two successive phases:

  1. the response: the request is accepted or rejected;
  2. the outcome: an accepted request concludes with a successful or a failed outcome.

An input event, by contrast, simply happens: it has neither a response nor an outcome.

In the file the request is written with CAPABILITY, which indicates a capability of the provider:

  CAPABILITY Pulizie(durata: Duration)

Pulizie is the name of the request. The parentheses enclose its parameters, that is the values that accompany the request: here a single parameter, durata, of type Duration, that is a length of time. Each parameter is written as name : type; several parameters are separated by a comma. Types are described in chapter 6.

The lifecycle

The phases of a request have five fixed names, in English; together they make up the lifecycle of the request:

Name Meaning Produced by
requested the request has been made consumer
accepted the request has been accepted provider
rejected the request has been rejected provider
completed the accepted request has succeeded provider
failed the accepted request has failed provider

These names are used in scenarios (chapter 9).

The lifecycle fixes only the order of the phases and imposes no obligation. The guarantees establish when a request is accepted or rejected, how long it lasts and when it fails: every obligation must be written as a guarantee.

The CSC with the request

-- The staircase light, as seen by the person on the stairs and by the caretaker.

CSC UsoLuce VERSION 0.1
  PURPOSE "The person on the stairs presses a button and has light to go up or down"

  CAPABILITY Pulizie(durata: Duration)
  EVENT IN   premuto
  EVENT OUT  avviso
  STATE      accesa : Boolean INITIAL false

  GUARANTEE g1: VERBAL "When someone presses the button, the light switches on"
                VERIFY BY JUDGEMENT "a person who presses the button and watches"
  GUARANTEE g2: VERBAL "The light switches off by itself after a while"
                VERIFY BY JUDGEMENT "a person with a watch"
  GUARANTEE g3: VERBAL "Shortly before switching off, the light gives a warning to the person on the stairs"
                VERIFY BY JUDGEMENT "a person on the stairs who waits for the light to switch off"
  GUARANTEE g4: VERBAL "A cleaning request is rejected if the requested duration exceeds two hours; otherwise it is accepted"
                VERIFY BY JUDGEMENT "the caretaker, who requests cleaning with different durations"
  GUARANTEE g5: VERBAL "After an accepted request the light stays on for the whole requested duration; when it expires the request has succeeded"
                VERIFY BY JUDGEMENT "the caretaker, with a watch"
  GUARANTEE g6: VERBAL "If the light cannot stay on until the duration expires, the request has failed"
                VERIFY BY JUDGEMENT "the caretaker, who removes the lamp during cleaning"
  ASSUME    a1: VERBAL "Whoever presses the button holds it down for at least a tenth of a second"
                VERIFY BY JUDGEMENT "a person who observes how the button is pressed"
END

The three new guarantees concern the two phases of the request: g4 establishes the response, g5 and g6 the outcome. Without g4 the CSC would allow the installation to reject every request.

The caretaker is on the same side as the person on the stairs and is therefore a consumer too, as the comment at the top of the file indicates.

The report

$ bcdd check --strict UsoLuce.csc
bcdd check --strict UsoLuce.csc
lines: 25 (recognised 21, comments 1, blank 3, unrecognised 0)
blocks: 1
  line 3: CSC UsoLuce VERSION 0.1, without STATUS

1. ERRORS: 0

2. DEGREE OF THE CONTRACTUAL LINES
  verbal: 7
  formal: 0
  declared extension: 0
  unrecognised: 0
  line 11: GUARANTEE g1 verbal
  line 13: GUARANTEE g2 verbal
  line 15: GUARANTEE g3 verbal
  line 17: GUARANTEE g4 verbal
  line 19: GUARANTEE g5 verbal
  line 21: GUARANTEE g6 verbal
  line 23: ASSUME a1 verbal

3. UNDECIDED: 0

4. PENDING APPROVAL, NOT CONTRACT: 7
  line 11: GUARANTEE g1
  line 13: GUARANTEE g2
  line 15: GUARANTEE g3
  line 17: GUARANTEE g4
  line 19: GUARANTEE g5
  line 21: GUARANTEE g6
  line 23: ASSUME a1

5. UNRECOGNISED LINES: 0

6. UNDECLARED TYPES: 0

7. CSCs NAMED BUT NOT CHECKED: 0

outcome: no errors

Summary

Special cases

Parameter without the colon. The line CAPABILITY Pulizie(durata Duration) is not recognised:

5. UNRECOGNISED LINES: 1
  line 6: CAPABILITY Pulizie(durata Duration)
…
outcome: no errors; unrecognised lines: 1 (--strict)

Two parameters with the same name. In CAPABILITY Pulizie(durata: Duration, durata: Duration) the second parameter is a name already used:

1. ERRORS: 1
  line 6: [E01] name already used at line 6: durata

Behaviour without a request. The automatic switching off of the light is not a request: nobody requests it and it has neither a response nor an outcome. It is written as a guarantee (g2), not with CAPABILITY.

Request started by the provider. A request started by the provider, that is without anyone requesting it, is written by adding AUTONOMOUS at the end of the line, for example CAPABILITY Collaudo AUTONOMOUS. An autonomous request has neither requested nor rejected: it begins already accepted and concludes with a successful or a failed outcome. bcdd recognises this line.