0% found this document useful (0 votes)
256 views64 pages

Rhapsody Workshop1

rhapody

Uploaded by

sathi420
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
256 views64 pages

Rhapsody Workshop1

rhapody

Uploaded by

sathi420
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 64

®

IBM Software Group

Rational Rhapsody - Software WorkShop

Version 7.5 C++

© 2009 IBM Corporation


IBM Software Group | Rational software

HANDS ON

2
IBM Software Group | Rational software

Storyboard

 Rhapsody has been installed, now let’s start with our WorkShop …
Exercise 1: Testing the environment with a simple Hello World
Exercise 2: Building a StopWatch:
 Architecture
 Statecharts
 Flowcharts
 Design Level Debugging
 Object Collaboration (Relations, Sequence Diagrams etc)
 Telelogic® Rhapsody Webify Toolkit™
 Threads
 Telelogic® Rhapsody ReporterPLUS™
 Rhapsody Panels (APPENDIX)

3
IBM Software Group | Rational software

Testing the Environment


“Hello World”
4
IBM Software Group | Rational software

Creating a Project
 On your hard disc create a folder c:\work
 Start up Rhapsody in C++ (development edition)
 Within Rhapsody use the icon or file->new to create a new project
called HelloWorld in your directory C:\Work

 Click OK> then Yes> to save project


Make sure that the project is saved into the subdirectory
with the same name “HelloWorld” in directory C:\Work
5
IBM Software Group | Rational software

The Browser
Show/Hide
Drawing
Toolbar

Browser
Drawing
Toolbar

Output Object
Window Model
Diagram

The browser shows us everything that is in the model.


Note that Rhapsody creates an Object Model Diagram
6
IBM Software Group | Rational software

Renaming our OMD

 Expand the Object Model Diagrams in the browser.


 Right-click on “Model1” and open the Diagrams feature dialog
 Use the features dialog to rename the diagram from Model1 to “Overview” and
press OK>

7
IBM Software Group | Rational software

Drawing a Class
 In this Object Model Diagram, use the class icon to draw a class named World

Expand the browser to see that the class “World” also


appears in the browser
8
IBM Software Group | Rational software

Remove from View / Delete from Model

 There are two ways of deleting a class, we can either remove the
class from the view (this is what the “delete” key does) or we can
delete the class from the model:
 If we use the delete key or the menu “Remove from View” then the class
World is just removed from this diagram, but remains in the browser.
 If we select “Delete from Model” then we must confirm with “Yes” in order to
remove the class from the entire model.

9
IBM Software Group | Rational software

Adding a Constructor
 The simplest way to add a constructor is to right click on our class and choose
New Constructor>.

 We don’t need any constructor arguments, so click OK> to the following menu.

Constructors may also be added by going through the features


“Operations” tab. Just click on <New> and select “Constructor”.
10
IBM Software Group | Rational software

World Constructor
 We should be able to see that the constructor is now shown in both the browser
and the OMD (Object Model Diagram)

Constructor

11
IBM Software Group | Rational software

Adding an Implementation

 Select the World constructor in the browser and double-click to open the features
window.
 Select the implementation tab and enter the following:

std::cout << “Hello World” << std::endl;

If you want to
close the window by clicking
on the then make sure
that you “Apply” the
changes first.

Depending on your compiler (i.e. with Visual Studio 6), just use
cout and endl instead: cout << “Hello World” << endl;
12
IBM Software Group | Rational software

#include <iostream>

 Since we have used “cout”, we must do an


include of the “iostream” header in our
World class:
 In the browser, select the World class and
double-click to bring up the features.
 Select the Properties tab (ensure that the
“Common” filter is selected and enter
<iostream> into the “ImpIncludes” property.

“ImpIncludes” is an abbreviation for Implementation Includes


13
IBM Software Group | Rational software

Renaming a Component

 In order to generate code, we must first create a component.


 Expand the components in the browser and rename the existing component called
DefaultComponent to Test.

Executable

14
IBM Software Group | Rational software

The Test Component

 Now expand the “Configurations” and rename the DefaultConfig to Release

15
IBM Software Group | Rational software

Initial Instance

 Select the Initialization tab,


expand the Default package
and select the World class.
 This means that the main will
now create an initial instance of
the World class.

16
IBM Software Group | Rational software

Configure your model to use the appropriate compiler

 We need to select an environment so


that Rhapsody knows how to create an
appropriate Make file and how to
compile the application:
 Select the Settings tab
 *Make sure that MinGW is selected or
select any other on your machine
available environment.

*If you use i.e Visual Studio 6 select Microsoft


17
IBM Software Group | Rational software

Generating Code

 We’re now ready to generate code.


 Save the model
 Select Generate/Make/Run
 Answer Yes> to the question:

18
IBM Software Group | Rational software

Hello World

 You should see the following:

 Before continuing make sure that you stop the executable. You can do this
by either closing the console window or by using the icon

If there was a compilation error during compilation, then


simply double-click on the error and Rhapsody will indicate where
in the model the error occurred.

19
IBM Software Group | Rational software

The Generated Files

 The generated files will be located in the following directory:

Main
Main

Object Files

Executable DRAFT

Project File (Make file)

World Class

20
IBM Software Group | Rational software

Editing the Code

 We can edit the generated files from within


Rhapsody.
 Select the World class, right-click and select
“Edit Code”.

 Both the implementation (.cpp) and specification (.h) are shown in tabbed
windows.
21
IBM Software Group | Rational software

Modifying the Code

 We can modify the generated code:


 In the World.cpp file, change the implementation to
print “Constructed” instead of “Hello World”
 Transfer the focus back to another window to roundtrip the modifications back into the
model

 Note that the model has been updated automatically

In general, the roundtriping works very well, but beware not


everything can be roundtriped!
22
IBM Software Group | Rational software

Displaying the Main and Make

 The Main and Make file can be displayed from within Rhapsody by simply
double clicking on the hyperlinks underneath the release configuration.

23
IBM Software Group | Rational software

Project Files

AutoSave

The Model

Generated Code

Rhapsody WorkSpace

Visual Basic Macros

24
IBM Software Group | Rational software

Adding Helper Application to Rhapsody Menu


 We can customise Rhapsody to allow us to get quick access to the location of
current project
 Select “Customize…” in the Tools menu

25
IBM Software Group | Rational software

Customize Menu Content

 Use the icon to enter a new


entry “Explore” to the Tools
menu.
 Set the Command to
“explorer.exe”
 Set Arguments to “.”
 Click OK>

26
IBM Software Group | Rational software

Launch Tool

 Now go to the “Tools” menu and select the new entry “Explore”

 You’re automatically placed into your working directory

27
IBM Software Group | Rational software

Building a StopWatch

28
IBM Software Group | Rational software

Stopwatch Requirements

 To get familiar with the fundamentals of Rhapsody we will build a


simple StopWatch model which is part of a Radio-Stop Watch
System:
 The Stop Watch has a single button to start and stop and a display. The
stopwatch displays minutes and seconds
 Every time the button is pressed and released within two seconds then
the stopwatch is started/stopped
 However if the button is held pressed for longer than two seconds then
the stopwatch is reset to 0 and stopped

29
IBM Software Group | Rational software

Copying a Project

 We will reuse our HelloWorld Project for this:


 In Rhapsody select “File->Save As”
 Press to select the work folder
 Press to create a new folder
 Rename “New Folder” to “StopWatch”
 Double click the new folder “StopWatch”
 Save the project as StopWatch.rpy
 The new StopWatch project is opened in Rhapsody with the previous workspace
preserved

Each time there is auto-save,


Rhapsody will only save just what has
changed since the last auto-save.

30
IBM Software Group | Rational software

31
IBM Software Group | Rational software

Designing the StopWatch

32
IBM Software Group | Rational software

Adding Attributes minutes and seconds

 Rename the World Class to Timer


 To add an attribute double-click on the Timer class to bring up the features and
select the “Attributes” tab
 Click on <New> to add an attribute minutes and seconds of type int
 Set the initial value to 0

33
IBM Software Group | Rational software

Adding Operations

 Using the features for the Timer class, select the operations tab and add a new
“Primitive Operation” called tick and timerReset

34
IBM Software Group | Rational software

Display Options
 We would expect to see the Attributes and Operations
shown on the class on our Object Model Diagram.

 We can control what gets displayed on this view of the


class using the “Display Options”.
Right-click on the Timer class and select “Display
Options”, set the options to display “All” attributes and
“All” operations.

35
IBM Software Group | Rational software

Timer Initializer

 We should be able to see that the operations and attributes are now shown in both
the browser and the OMD (Object Model Diagram)

36
IBM Software Group | Rational software

Adding an Implementation

 Select the Timer timerReset() operation in the browser and double-click to open
the features window
 Select the implementation tab and enter the following:

If you want to close the window by clicking on the


then make sure that you “Apply” the changes first.

37
IBM Software Group | Rational software

Using Active Code Viewer


 Choose View->Active Code View (or press ALT + 2) and a little window will appear
down in the bottom left corner.
 In the browser click on the minutes attribute and you will see that the window
shows the code for it
 This is a code editor that tracks your movements and shows code whenever
appropriate for both the C++ and header files.

Active Code View

38
IBM Software Group | Rational software

Active Code View #2

 Select the Timer.cpp file


 To get line numbers right click in the code window and choose Properties.
 Under Line Numbering in the “Misc” tab choose Decimal and 1

39
IBM Software Group | Rational software

Adding Code to the tick() operation

 We want to add the code below to the tick operation.


 We will do this directly in the code window rather than the feature dialog like we
did earlier.
 Type in s and then hit Ctrl-Space. This brings up our IntelliVisor with options of model
elements you can select - choose seconds (Select with Tab or mouse click)
 After this, type in the rest of the code as it is listed below.
 Then press Ctrl-S to save this source file.
 Make sure to add this code between the lines with the //#

40
IBM Software Group | Rational software

Roundtripping

 Whenever you click somewhere outside the editor window, this code now gets
dynamically brought back into the Rhapsody Model

41
IBM Software Group | Rational software

Adding a New Operation show

 In Active Code View click Timer.h to


open the specification file

 Underneath the operation timerReset() type void show(); in the code to add a
new operation show() and press CTRL+S

 The new operation show gets dynamically brought into the


model

42
IBM Software Group | Rational software

Implement show() Operation

 Select the show operation in the browser and double-click to open the features
window.
 Select the implementation tab and enter the following:

Or you type the code


into the implementation file

43
IBM Software Group | Rational software

Adding a Statechart

 Next we will add some behavior to the Timer using a Statechart


 Right-Click on the Timer class and select “Add New” -> “Statechart”

44
IBM Software Group | Rational software

Very Simple Statechart


 Draw the following Statechart:

Default Transition Actions

Timeout

State Transition

You will find more information about how to type the


transition text on the next slide
45
IBM Software Group | Rational software

Transitions

 Once a transition has been drawn, there are two ways in which to enter
information:
 In text format ex: tm(1000)/tick();
 By the features of the transition (activated by double-clicking or right-clicking on the
transition)

An empty line forces the


action to appear on a new
line
46
IBM Software Group | Rational software

The Timer Mechanism

 Rhapsody provides a timer that can be used within the Statecharts


 tm(1000) acts as an event that will be taken 1000ms after the state has been
entered.
 On entering into the state, the timer will be started.
 On exiting from the state, the timer will be stopped.

The timer uses the OS Tick and so will only generate timeouts
that are a multiple of ticks.

47
IBM Software Group | Rational software

Statechart Symbol

 Now that the Timer class is “Reactive”, it has a special symbol in both the browser
and the OMD.
 Also note that the Statechart appears in the browser

A Reactive class is one that reacts to receiving


events or timeouts.
48
IBM Software Group | Rational software

Compile and Run

 Save & Generate/Make/Run

constructor

default transition

running state

Don’t forget to Stop the application, before doing


another Generate / Make / Run !
49
IBM Software Group | Rational software

Extending the Statechart

 Actually our StopWatch starts immediately counting, which is good but doesn‘t fit
yet to customers requirements.
 Complete the following Statechart by adding an idle state with transitions back and forth to
the running state.

50
IBM Software Group | Rational software

Extended Exercise: Flowcharts


 A flowchart is the classic way programmers draw a schematic representation of an
algorithm or a process.
 In UML/Rhapsody flowcharts can be seen as a subset of activity diagrams defined
on methods and functions.
seconds++;
 Instead of typing this algorithm, we could also
if (seconds>59) {
represent it as a flowchart:
seconds=0;
 Right click on the operation tick() in the Timer minutes++; }
Class and add a Flowchart.

51
IBM Software Group | Rational software

Drawing a Flowchart

 Draw the following Flowchart Action Default Flow

Condition

Termination State

52
IBM Software Group | Rational software

Generated Code

 The previous implementation code of the operation tick will be ignored.


 Instead Rhapsody will generate the code based on the associated Flowchart
 Observe the generated code of the Flowchart in Active CodeView

53
IBM Software Group | Rational software

Design Level Debugging

54
IBM Software Group | Rational software

Design Level Debugging

 Up to now we have generated code and executed it, hoping that it works! However
as the model gets more and more complicated we need to validate the model
 From now on we are going to validate our model by doing design level debugging,
this is known as “Animation”

55
IBM Software Group | Rational software

Animation

 Create a new configuration by copying the Release configuration.


 Hold the control key and drag the Release configuration onto the “Configurations”
folder
 Rename the new configuration to Debug
 Under Settings set the instrumentation to “Animation”

Animation

56
IBM Software Group | Rational software

Multiple Configurations

 Now that we have more than one configuration, we must select which one we want
to use
 There are two ways to do this:
 Either select the configuration using the following pull-down box

 Or right-click on the configuration and select “Set as Active Configuration”

57
IBM Software Group | Rational software

Animating
 Make sure that the active configuration is “Debug” before doing Save
 Then Generate / Make / RUN the application

Animation Bar

Event Queue

Call Stack

58
IBM Software Group | Rational software

Animation toolbar in detail

Go Idle Breakpoints
Runs the model until all pending events have been consumed. Opens the Breakpoints window.

Go Step Pause
Takes a Single Simulation Call Operation
Step
Quit Simulation

Go Command Prompt
Allows running of scripts etc Send Event Toggle
Runs the model until
you pause it. Watch
Mode
Go Event Threads
Consumes a single event Opens the Threads window.
then pauses.

59
IBM Software Group | Rational software

Animated Browser

 Press Go to start
the application

 In the browser, note


that there is now an
instance of the Timer
class

 Double-click on this
instance of Timer
and note that the
attribute minutes and
seconds have been
initialized to 0

60
IBM Software Group | Rational software

Animated Statechart

 Right-click on the instance to “Open Instance Statechart”

Highlighted state

If you don’t see a highlighted state, then perhaps you are looking
at the statechart of the class rather than the statechart of the instance
61
IBM Software Group | Rational software

Injecting Events
 The Timer is in an idle state waiting for some events
 Generate the event evStartStop by right-clicking anywhere in the animated statechart
and selecting “Generate Event”
 Press OK> to inject evStartStop into the Timer

Events can also be generated via the Command prompt or via the
Event Generator
62
IBM Software Group | Rational software

Go Idle / Go

 Watch how the state changes and that the Timer starts counting

Note that the


value of the attribute
minutes and seconds also
changes and that the
transition taken in the
statechart is highlighted
63
IBM Software Group | Rational software

Design Level Breakpoints

 Setting breakpoints can be done in a similar way to injecting events


 Simple right-click on the animated state where you would like to break, choose Add
Breakpoint and select okay

Breakpoints can be added/removed via the breakpoint


icon on the animation toolbar.
64

You might also like