Rose Tutorials
Rose Tutorials
Tutorials
RATIONAL ROSE® REALTIME
VERSION: 2002.05.20
WINDOWS/UNIX
support@rational.com
http://www.rational.com
IMPORTANT NOTICE
COPYRIGHT
Copyright ©1993-2002, Rational Software Corporation. All rights reserved.
Microsoft, the Microsoft logo, Active Accessibility, Active Channel, Active Client,
Active Desktop, Active Directory, ActiveMovie, Active Platform, ActiveStore,
ActiveSync, ActiveX, Ask Maxwell, Authenticode, AutoSum, BackOffice, the
BackOffice logo, BizTalk, Bookshelf, Chromeffects, Clearlead, ClearType, CodeView,
Computing Central, DataTips, Developer Studio, Direct3D, DirectAnimation,
DirectDraw, DirectInput, DirectMusic, DirectPlay, DirectShow, DirectSound, DirectX,
DirectXJ, DoubleSpace, DriveSpace, FoxPro, FrontPage, Funstone, IntelliEye, the
IntelliEye logo, IntelliMirror, IntelliSense, J/Direct, JScript, LineShare, Liquid Motion,
the Microsoft eMbedded Visual Tools logo, the Microsoft Internet Explorer logo, the
Microsoft Office Compatible logo, Microsoft Press, the Microsoft Press logo, Microsoft
QuickBasic, MS-DOS, MSDN, Natural, NetMeeting, NetShow, the Office logo, One
Thumb, OpenType, Outlook, PhotoDraw, PivotChart, PivotTable, PowerPoint,
QuickAssembler, QuickShelf, Realmation, RelayOne, Rushmore, SourceSafe,
TipWizard, TrueImage, TutorAssist, V-Chat, VideoFlash, Virtual Basic, the Virtual
Basic logo, Visual C++, Visual FoxPro, Visual InterDev, Visual J++, Visual SourceSafe,
Visual Studio, the Visual Studio logo, Vizact, WebBot, WebPIP, Win32, Win32s, Win64,
Windows, the Windows CE logo, the Windows logo, Windows NT, the Windows Start
logo, and XENIX are trademarks or registered trademarks of Microsoft Corporation in
the United States and other countries.
Purify is licensed under Sun Microsystems, Inc., U.S. Patent No. 5,404,499.
GOVERNMENT RIGHTS LEGEND
Use, duplication, or disclosure by the U.S. Government is subject to restrictions set
forth in the applicable Rational Software Corporation license agreement and as
provided in DFARS 277.7202-1(a) and 277.7202-3(a) (1995), DFARS
252.227-7013(c)(1)(ii) (Oct. 1988), FAR 12.212(a) (1995), FAR 52.227-19, or FAR 227-14,
as applicable.
WARRANTY DISCLAIMER
This document and its associated software may be used as stated in the underlying
license agreement. Rational Software Corporation expressly disclaims all other
warranties, express or implied, with respect to the media and software product and its
documentation, including without limitation, the warranties of merchantability or
fitness for a particular purpose or arising from a course of dealing, usage, or trade
practice.
Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Audience. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Other Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Contacting Rational Technical Publications . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Contacting Rational Technical Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xii
1 Rational Rose RealTime Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Navigating the Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Printing the Tutorial. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2 QuickStart Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Rational Rose RealTime User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Online Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Sample Model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Model Description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Creating a New Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Creating the Logical View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Creating a Capsule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Adding a State to a Capsule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Drawing an Initial Transition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Adding a Port to a Capsule. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Saving a Model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Adding the Detail Code to a State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Creating the Component View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Creating a Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Building the Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Creating the Deployment View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Creating a Component Instance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Contents v
Running the Component Instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46
Tutorial Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .47
Viewing the Generated Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
What’s Next?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
3 Card Game Tutorial. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
What You Will Learn?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49
Why a Card Game? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Card Game Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51
Tutorial Lessons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Adding Detail Code to Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Build Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Several Ways of Doing the Same Thing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Lesson 1: Creating a New Model and Configuring the Toolset . . . . . . . . . . .53
Opening a New Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Configuring Toolset Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Lesson 2: Creating a Use Case and Initial Capsules. . . . . . . . . . . . . . . . . . .59
Adding the Use Case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Documentation Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Are Elements Owned by the Class Diagram? . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Meaning of the Delete key in Class Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .66
Defining the Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Classes Versus Capsules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
Describing the Behavior of the Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Creating Classes and Capsules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
RTClasses Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Changing Element Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Creating HeadsUpPoker Capsule Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Creating the HeadsUpPoker Capsule Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74
Lesson 3: Sequence Diagrams, Protocols, Ports, and Connectors . . . . . . . .79
Creating the Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Creating Ports and Connectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Documenting the Responsibilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
vi Contents
Lesson 4: Building and Running . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103
Prototyping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Building a Model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Creating a Component. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Creating the Deployment View. . . . . . . . . . . . . . . . . . . . . . . ...... ....... . 111
Starting the Build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...... ....... . 112
Where is the Source Code Generated? . . . . . . . . . . . . . . . . ...... ....... . 114
Running the Component Instance . . . . . . . . . . . . . . . . . . . . ...... ....... . 114
Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...... ....... . 118
Lesson 5: Adding Behavior to the Capsules . . . . . . . . . . . . . . . . . . . . . . . .119
Opening Capsule State Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . ....... . 119
Creating the Dealer’s Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....... . 120
Creating the Player’s Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....... . 130
Creating the State Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....... . 131
Adding Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Creating the Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Lesson 6: Navigating and Searching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .143
Suggested Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Lesson 7: Using Traces and Watches to Debug the Design . . . . . . . . . . . .144
Rebuilding the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Setting Up the Runtime Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Problems with the Player Capsule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Unexpected Messages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Warning Message for No Defined Trigger? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Building the Player Capsule . . . . . . . . . . . . . . . . . . ....... ...... ....... . 153
Debugging the Player Capsule. . . . . . . . . . . . . . . . ....... ...... ....... . 153
Verifying the Fix . . . . . . . . . . . . . . . . . . . . . . . . . . . ....... ...... ....... . 161
Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....... ...... ....... . 162
Lesson 8: Class Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .162
Importing Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Creating a Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Creating the Initial Class Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Creating Relationships Between Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Adding Attributes to the Card Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Adding Details to the CardList Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Contents vii
Generating Code for the Association Ends. . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Encoding and Decoding by the Services Library . . . . . . . . . . . . . . . . . . . . . . . 183
Encoding and Decoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .183
NumElementsFunctionBody code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .184
Adding Details to the Deck Class . . . . . . . . . . . . . . . . . ....... ...... ..... 185
Adding Details to the Hand Class . . . . . . . . . . . . . . . . . ....... ...... ..... 188
Adding Details to the PokerHand Class . . . . . . . . . . . . ....... ...... ..... 192
Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....... ...... ..... 194
Lesson 9: Adding Card Classes to the Capsule Behavior . . . . . . . . . . . . . .195
Completing the Dealer Capsule Behavior. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Adding a Destructor to the Dealer Capsule . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Completing the Player Capsule Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Using Attributes Versus Aggregations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Adding Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Dependency Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .210
Adding Inclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Building and Running the Card Game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Trace Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Fixing compilation errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Lesson 10: Aggregating in a State Diagram . . . . . . . . . . . . . . . . . . . . . . . .215
Aggregating the Receiving Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Tutorial Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .218
4 Rational Rose RealTime Extensibility Interface Tutorials . . . . . 219
RRTEI Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .219
Previewing the Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Creating a Summit Basic Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .221
Writing a Script . . . . . . . . . . . . . . . . . . . . . . . . . ...... ....... ...... ..... 221
Running and Testing a Script . . . . . . . . . . . . . . ...... ....... ...... ..... 223
Compiling a Script . . . . . . . . . . . . . . . . . . . . . . ...... ....... ...... ..... 223
Creating a Menu File . . . . . . . . . . . . . . . . . . . . ...... ....... ...... ..... 223
Adding Entries to the Registry . . . . . . . . . . . . . ...... ....... ...... ..... 224
Running and Testing the Script from the Menu ...... ....... ...... ..... 225
viii Contents
Creating a Visual Basic Add-in. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .225
Creating the Active X DLL . . . . . . . . . . . . . . . . . . . ....... ...... ....... . 226
Creating the Add-in Menu File . . . . . . . . . . . . . . . . ....... ...... ....... . 229
Adding Entries to the Registry . . . . . . . . . . . . . . . . ....... ...... ....... . 230
Testing the New Add-in . . . . . . . . . . . . . . . . . . . . . ....... ...... ....... . 231
Common Problems . . . . . . . . . . . . . . . . . . . . . . . . ....... ...... ....... . 231
Creating an Add-in Which Extends the Context Menus . . . . . . . . . . . . . . . .232
How Context Menus Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Menus Associated with Default or Specific Elements . . . . . . . . . . . . . . . . . . . 233
Creating the ActiveX DLL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Adding Entries to the Registry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Testing the New Add-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
5 Concept Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .241
Messages and Capsule State Machines . . . . . . . . . . . . . . . . . . . . . . . . . . .242
Capsule Hierarchical State Machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . .243
Capsules and Capsule Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .243
Ports, Protocols, and Protocol Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .243
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Contents ix
Preface
Contents
This manual provides introduction and concept tutorials to help you become familiar
with Rational Rose RealTime.
This chapter is organized as follows:
■
Audience on page xi
■
Other Resources on page xi
■
Contacting Rational Technical Publications on page xi
■
Contacting Rational Technical Support on page xii
Audience
This guide is intended for all readers, including managers, project leaders, analysts,
developers, and testers.
Other Resources
■ Online Help is available for Rational Rose RealTime.
Select an option from the Help menu.
All manuals are available online, either in HTML or PDF format. To access the
online manuals, click Rose RealTime Online Documentation from the Start menu.
■
For more information on training opportunities, see the Rational University Web
site: http://www.rational.com/university.
xi
Contacting Rational Technical Support
If you have questions about installing, using, or maintaining this product, contact
Rational Technical Support.
Note: When you contact Rational Technical Support, please be prepared to supply the
following information:
■ Your name, telephone number, and company name
■
Your computer’s make and model
■
Your computer’s operating system and version number
■
Product release number and serial number
■
Your case ID number (if you are following up on a previously-reported problem)
xii Preface
Rational Rose RealTime
Tutorials 1
Contents
This chapter is organized as follows:
■
Overview on page 13
■
Navigating the Tutorials on page 15
■
Printing the Tutorial on page 15
Overview
Rational Rose RealTime provides tutorials to help you learn how to use the main
features of the development tool. There are two types of tutorials: hands-on and concept
overviews.
The hands-on tutorials show you how to build models, while demonstrating key
concepts and toolset features required when developing your own Rational Rose
RealTime models. Both the Quickstart and Card Game tutorials provide sample models
that you can use to review the procedures and concepts introduced in each tutorial.
These models are located in the Rational Rose RealTime installation directory
$ROSERT_HOME/Tutorials.
Concept tutorials are meant to provide an introduction to important Rational Rose
RealTime concepts. They expand and summarize the explanations and examples
provided in the Rational Rose RealTime Modeling Language Guide.
13
If you do not know where to begin, the following table may help you find the tutorial
recommended for your individual modeling experience.
Tutorial New Rose 98 ObjecTime
Modeling User Developer
Tool User User
Contents (hands-on) X X X
QuickStart: Create a simple "Hello World" model. This is the quickest way to get
started without having to read extensively.
Card Game: Learn the most important features of the tool by designing, and
developing a fun application in C++.
Rational Rose RealTime Extensibility Interface: Learn how to write a simple script in
Summit Basic and Visual Basic that will control the Rational Rose RealTime
application. Learn the basics of creating add-ins.
Messages and Capsule State Machines: For users who want an introduction to the basics
of message passing between capsules.
Capsule Hierarchical State Machines: For users who want to review the basic elements of
state machines and understand some of the complexities involved with hierarchical
capsule state machines.
Capsules and Capsule Roles: For users who already understand class modeling, and
want to understand the additional concepts involved when modeling with capsules.
Ports, Protocols, and Protocol Roles: For users who want an introduction to the use of
protocols and protocol roles in a Rational Rose RealTime model.
Getting Started
As a new Rational Rose RealTime user, this QuickStart tutorial gets you
up-and-running in Rose RealTime as quickly as possible. Using a simple example, the
tutorial guides you through the basic steps involved in constructing a model in Rose
RealTime using the C++ language add-in.
Note: Although this tutorial is based on the C++ language, Rose RealTime also
supports the Java and C languages.
In this tutorial, you learn how to:
■ Construct elements in the Logical View, including:
❑ capsules
❑ capsule state diagrams
❑ ports
■
Build and execute a model in the Rose RealTime execution environment.
Note: Ensure that your environment is properly configured for your compiler. For
additional information about configuring your environment, see Installation Guide
Rational Rose RealTime.
17
The Rational Rose RealTime toolset provides a complete development environment
for using UML to create executable models.
The UML provides a wide range of visual modeling constructs. Not all of these
constructs are directly applicable to creating a working model. Many exist for
purposes of building more complex systems, communicating designs to other team
members, capturing design decisions, and for organizing models, but are not strictly
required to build a simple model.
Rose RealTime provides additional constructs that are based on UML modeling
elements and are specialized for creating executable real-time models. In order to
produce a working model, it is important to understand the model elements that must
be defined, and the sequence of the elements.
Because this tutorial is geared toward the new user, the focus is only on those
elements and tools that are required to create a basic executable model. If you want to
construct a more complicated Rose RealTime model, you should familiarize yourself
with some of the advanced elements that are outside the scope of this tutorial. For
example: use cases and use case diagrams, actors, packages, sequence diagrams,
collaboration diagrams, and so on.
Note: To complete this tutorial, you need to have Rational Rose RealTime and a
compiler (such as, Visual C++ 6.0) installed on your computer.
The main features of the Rational Rose RealTime user interface are:
■
The Standard Toolbar remains the same for all views and diagrams. It contains
standard Windows functions as well as those specific to Rational Rose RealTime.
■
The Diagram Toolbox is used for adding elements to the model by drawing them on
a diagram. The toolbox elements change depending on the active diagram. For
example, the Use-Case Diagram has a tool for adding actors, but the Component
Diagram does not have this tool.
■
Browsers are hierarchical and can be expanded and contracted. When you start
Rational Rose RealTime, the Model View, the Containment View, and the Inheritance
View browsers are docked on the left side of the interface in a stacked format. They
can be set to visible/invisible, docked, or floating. To activate a specific browser,
select the appropriate tab located at the bottom of the interface.
There are two additional browsers, also referred to as editors, that can be opened
to perform specific tasks: the Structure/State Diagram Browser/Editor, and the Run
Time System (RTS) Browser/Editor. These browsers cannot be moved.
■ Rational Rose RealTime offers four main views located on the Model View browser.
Each view is related to a software lifecycle phase, and the diagrams are artifacts of
those phases.
Online Help
For more information about the Rational Rose RealTime user interface, or how to
complete a specific task, see the Rational Rose RealTime online Help.
Sample Model
In addition to the online Help, Rational Rose RealTime includes a sample model,
QuickstartTutorial.rtmdl. You can use this model to explore the various elements of
Rational Rose RealTime, and to practice the procedures for model building and
execution.
Model Description
In this tutorial, your goal is to create a new model with one capsule that prints "Hello
world!" to the console.
This is a very simple model that could easily be accomplished in a native
development environment by writing the code in the C++ programming language
(see below), and then compiling the code into an executable file.
#include <iostream.h>
main() {
cout << "Hello world!\n";
However, you will generate the equivalent executable from within the Rational Rose
RealTime modeling environment by following a basic workflow consisting of these
simple tasks:
1 Creating a new model.
2 Creating the Logical View.
3 Creating the Component View.
4 Building the component.
5 Creating the Deployment View.
6 Running the component instance.
Typically, there are four frameworks listed: Empty, RTC, RTC++, and RTJava. However,
you may have additional optional frameworks, such as the Gateway.
To open a model containing all the classes required for development using the C, C++,
or Java language, click the framework for the specified language. The Model View
browser appears with the packages and classes populated in the Logical View and
Component View.
Note: The language and environment used in your model defaults to the same
language that you specified in the framework. You can change the language or
environment settings in the Language/Environment tab (Options dialog box, Tools menu).
Note: The Empty framework is useful for creating use case designs but should not be
used for developing RealTime applications.
2 Double-click RTC++.
You are now ready to build and execute a Rational Rose RealTime model.
Creating a Capsule
Capsules are special forms of classes with some supporting mechanisms that enforce a
higher degree of encapsulation and abstraction than classes. Capsules are very useful
for building concurrent, event-driven systems, and are an important element in
Rational Rose RealTime.
The code required to implement this example could easily be defined in an operation
on a regular class, but something needs to initiate the activity. Operations do not run
by themselves. They must be invoked.
In Rational Rose RealTime, you place the code in a capsule that is automatically
invoked by the main() program in the Rational Rose RealTime Services Library. The
main() block in the Services Library creates the capsule in your model, and starts the
state machine. You describe the capsule and define the state machine, and they are
automatically created and executed by the Services Library.
Note: A model must include at least a top-level capsule that initiates behavior in the
system, and results in generated code which forms the executable. In this case, your
model will contain only one top-level capsule that prints "Hello world!" from within
the body of its state machine.
You will create a capsule class in the Logical View of the Model View browser, and name it
HelloWorld. This simple capsule class implements the design model.
The state diagram contains an initial point, , and an initial state called SaidHello. An
initial point is a special point which explicitly shows the beginning of the state
machine. You connect the initial point to a start state (in this case, SaidHello). Where
To draw a transition:
1 In the toolbox for the State Diagram dialog box, click State Transition .
2 Click and hold the left mouse button on the Initial Point in the state diagram, .
The Initial Point is the black circle that appears in the top-left corner of the State
Diagram.
Now that you created an initial transition - a transition from the initial point to the
initial state - you specified that at runtime, the SaidHello state is the first state to
receive a specified event and the behavior moves from the initial point to the
SaidHello state.
Next, you will create a port to communicate with the HelloWorld capsule instance by
sending and receiving messages.
3 From the list of protocol classes available for the model, double-click to select Log.
5 Click the Structure Diagram tab in the Logical View diagram for the HelloWorld capsule.
Saving a Model
Before you continue with the tutorial, we recommend that you save your model.
To save a model:
1 On the File menu, click Save Model As....
2 In the File Name box, type HelloWorld.
3 In the Save In box, select the folder where you want to save the model.
4 Click Save.
5 If prompted to create a default workspace with a HelloWorld.rtwks path name,
click Yes.
Note: When you create a workspace, all components, specifications and windows
in your model are saved as they exist in your model. You can also save a model
without saving these specifications by using the file extension .rtmdl.
Note: If you prefer, you can also double-click on the Initial transition line to open
the Transition Specification dialog.
2 In the Code window, select Action from the drop-down list.
3 Type the following C++ code:
log.log("Hello world!");
Ensure that you include the semi-colon at the end of the line.
Your Code window will look like the following:
Creating a Component
You will create a component by opening a series of dialog boxes so that you can
become familiar with the common features of the Rational Rose RealTime user
interface. Step 1 provides with two ways of creating a component. Choose only one
method.
Note: You can also use the Component Wizard to create a component. The wizard guides
you through creating and configuring a component, and running the component
instance. To access the wizard, click Component Wizard on the Build menu.
To create a component:
1 In the Model View tab in the browser, select Component View, and click
New > Component.
Or . . .
In the Toolbar, select the Browse Component Diagram button . For the Component
View package, select Component Diagram: Component View / Main in the Component
diagrams list, and click OK. From the Toolbox, select the Component tool , then
click in the diagram.
2 Rename the component HelloWorldComponent.
If you used the second method, you will have a visual representation of your
component in the Component Diagram for Main.
You drag the HelloWorld capsule onto the References tab because the items in the
References tab identify what is compiled with the HelloWorld component.
10 Click Select....
The Select Top Capsule dialog box appears. In this dialog box, you select the capsule
that will be the top capsule in the model.
11 Click HelloWorld to designate it as the top capsule.
14 Click Select....
17 To close the Component Specification for HelloWorldComponent dialog box, click OK.
To build a component:
1 In the Model View browser, right-click HelloWorldComponent, and click Set As Active.
Because you will be building and running the same component and component
instances often, you should configure an active component. Setting the
Set As Active option ensures that the toolbar build icons and menu items, for the
common run and build commands, become available for easy access.
The Build Component tool becomes active.
2 Click Build Component.
The Add Missing References dialog box appears.
4 If not currently selected, click Generate and compile, and click OK.
The Build Log tab of the Output Window shows the results of code generation and
compilation. When the build finishes, the Build Log should indicate "Build successful".
Note: If there are compile errors, double-click on an error message on the Build Errors
tab. Rational Rose RealTime opens the appropriate editor where the source of the
error appears. You can then resolve any errors.
Or . . .
2 In the Model View tab in the browser, drag the HelloWorldComponent from the
Component View folder onto LocalHost.
Or . . .
If you created a processor on the Deployment Diagram for Main, from the Model View
tab in the Browser, drag the HelloWorldComponent from the Component View folder
onto LocalHost processor in the Deployment Diagram.
After dragging the HelloWorldComponent, the Deployment Diagram: Deployment View /
Main dialog looks like the following:
Tutorial Summary
In the QuickStart tutorial, you created a capsule and constructed a system that had one
capsule instance. As part of the capsule definition, you defined a log port to access the
Log service for printing messages to the console window. You also defined a state
machine for the capsule with a single state and an initial transition.
After creating the capsule, you defined a component and deployed the component to
enable the generation, compilation, and execution of code for the model.
Finally, you ran the model. At execution time, the Rational Rose RealTime Services
Library created a single instance of the top-level capsule class in the model (in this
case, the only class in the model), and then called a function to execute the initial
transition of the capsule's state machine. The initial transition in turn called a function
on Log port to print "Hello world!" in the console window.
After the initial transition executed, the capsule entered the SaidHello state where it
waited to process any incoming messages. Since there is nothing else in the model,
there was no further activity.
What’s Next?
Try constructing some simple models of your own. Explore the online Help for
information on the various modeling tools. You can also use the
QuickstartTutorial.rtmdl for further practice on building and compiling a model.
49
Why a Card Game?
Since most people know how to play cards, you can concentrate on how the tool
works without having to spend time understanding the requirements of the tutorial
model. Using this model, you will explore the main features of Rose RealTime.
You may also want to refer to the C++ Reference to understand the functionality that
the language add-in provides.
Tutorial Lessons
The tutorial develops the Card Game application in ten lessons. You will start with a
simple design, and add features as you complete each lesson.
Each lesson includes a set of procedures and conceptual information that guides you
through the Rose RealTime modeling process.
Build Information
As you progress though the tutorial, adding code as you read, you should
occasionally build the version of the model that you’ve been developing. After you
complete Lesson 5: Adding Behavior to the Capsules, you can build the model or any
capsules you need to test. You can also browse the generated source files at any point.
For details on where you can find the generated C++ source files, see Where is the
Source Code Generated? on page 114.
If you encounter problems building the model because there are too many errors
reported at build time, you can continue using the finished models that are shipped
with the tutorial.
Suggested Reading
■ Opening and Saving Models, (see the Rational Rose RealTime Toolset Guide)
■
Model Browser, (see the Rational Rose RealTime Toolset Guide)
Suggested Reading
■
Options Dialog, (see the Rational Rose RealTime Toolset Guide)
2 You may want to consider changing the following attributes to suit your
preferences. The options are grouped by the tab on which they can be found:
❑
Font/Color: You may want a fixed width font, or change the default diagram
colors.
Suggested Reading
■ Use Cases, Rational Rose RealTime Modeling Language Guide
■
Capsules, Rational Rose RealTime Modeling Language Guide
■
Toolboxes, Rational Rose RealTime Toolset Guide
■
Specification dialogs, Rational Rose RealTime Toolset Guide
2 Ensure that the Use Case Diagram: Use Case View / Main window is the active window,
3 From the toolbox, select the Text tool .
As you move your mouse over the Use Case Diagram, your cursor changes to the
text tool .
4 Left-click in the diagram, and drag (it will show as an outlined rectangle as you
drag).
3 Click OK.
This scenario defines what the simulation application must do, but not how to do it.
Determining how to implement this simulation is independent of the requirements. In
fact, there can be an unlimited number of ways to implement an application that
satisfies the above requirements.
Suggested Reading:
■
Documentation window, (see the Rational Rose RealTime Toolset Guide)
In the remainder of this tutorial, you will add documentation to almost every model
element you create. It is important to document the responsibilities of all elements
and any additional information that would make the model more understandable.
Click on the new use case to view the flow of events in the documentation window.
Suggested Reading
■
Capsules, (see the Rational Rose RealTime Modeling Language Guide)
■ Classes, (see the Rational Rose RealTime Modeling Language Guide)
2 From the Main class diagram toolbox, click the Capsule tool .
3 Move the mouse over the diagram, and left-click in the window.
5 Repeat the above steps to add the Player and Dealer capsules.
Note: You can change any model element’s property (including the name) with the
Specification dialog box.
6 To add the classes, select the Class tool from the Main class diagram toolbox.
7 Move the mouse over the diagram, and left-click in the window.
RTClasses Package
The RTClasses package exists in each model and contains a set of predefined classes
and protocols implemented by the Services Library. Most models require the use of
one or many of these predefined classes. For example, the package contains a Timing
protocol used to communicate with the timing service.
Suggested Reading
■
Capsules, Rational Rose RealTime Modeling Language Guide
■ Capsule structure diagrams, Rational Rose RealTime Modeling Language Guide
■
Sequence Diagrams, Rational Rose RealTime Modeling Language Guide
■
Interactions, Rational Rose RealTime Modeling Language Guide
7 In the Logical View folder, double-click to open the Class Diagram: Logical View / Main
dialog.
You should see the three capsules and three classes that you have previously
created.
In the Class Diagram: Logical View / Main diagram, you will see aggregation
relationships between the HeadsUpPoker capsule and the Dealer and Player capsules.
The capsule role names appear at the part-of end of the aggregation relationship.
Both representations are essentially the same, with one exception. As you will see
later from the Structure Diagram, you can interconnect capsule roles, something that
is not possible in the class diagram.
Before proceeding with Lesson 3, we recommend that you save your work.
2 Using the SHIFT key, select both the outer boxes for the player and dealer capsule
roles.
3 Right-click on an empty area within the border of the Structure Diagram (do not
right-click on capsule roles or the back border), and click Create Sequence Diagram.
The diagram appears in the Model View tab in the browser under the Structure
Diagram for the HeadsUpPoker capsule.
4 Double-click on the message line (not the label for the line) to open the Send
Message Specification dialog box.
9 Double-click on the message line (not the label for the line) to open the Send
Message Specification dialog box.
11 Click OK.
The Focus of Control (FOC) shows the period of time during which an object is
performing an action, either directly or through an underlying procedure. The FOC is
portrayed through narrow rectangles that adorn lifelines (the dashed vertical
lines descending from each object). The length of an FOC indicates the amount of time
it takes for a message to be performed. When you move a message vertically, each
dependent message moves vertically as well. To enlarge the FOC, select the FOC, click
on a pic handle surrounding the rectangle, then drag the mouse until you change the
rectangle to the desired size.
For example, you can select the FOC as in the following diagram:
17 Click OK.
22 Click OK.
Note: After adding the message exchanged between the Player and Dealer you
will realize that the scenario must be started somehow, either when the simulation
is started (when the player capsule is instantiated) or after some other specified
event occurs. For this tutorial, you will use a timer to start the simulation, this will
make it possible to adjust the delay between each game and make it easier to
observe the running model.
23 Select the Asynchronous Send Message tool from the toolbox.
Note: By adding this new message, the number labelling for the messages changed
to one level deeper. For example, the message label 1:Ante changed to 1.1:Ante,
and 1.5.1:HandValue changed to 1.1.5.1:HandValue.
25 Double-click on the message line (not the label for the line) to open the Send
Message Specification dialog box.
26 On the General tab, type timeout in the Name box.
27 Click OK.
33 Create 3 more text boxes and include the text that appears in the following
diagram.
Suggested Reading:
■
Ports, Rational Rose RealTime Modeling Language Guide
■
Protocols, Rational Rose RealTime Modeling Language Guide
Note: The protocol was added to the Logical View folder in the Model View tab in the
browser.
4 Type CommHeadsUp and press ENTER.
8 Click OK.
The protocol on the Class Diagram: Logical View / Main changes to include these new In
and Out signals.
Note: Later, you will add more details to this protocol as the model evolves. For
example, you have not yet specified which data class to send with the ACard signal.
Suggested Reading:
■
Ports, Rational Rose RealTime Modeling Language Guide
■ Connectors, Rational Rose RealTime Modeling Language Guide
To create ports
1 Open the Structure Diagram for the Dealer capsule.
Note: You can double-click on a capsule role to open the capsule structure diagram
of the capsule. This capsule role represents in the structure diagram.
2 From the Model View tab in the browser, drag the CommHeadsUp protocol to the black
border of the Dealer’s structure diagram.
The port graphic changes from to indicate that it is an End Port. End ports
provide a connection between the behavior of the capsule containing the end port and
the outside world. To send and receive messages, a capsule must have end ports. The
end port's protocol defines the set of messages that can be sent.
4 Rename the port player_comm.
To enable communication between capsules, you must connect together the ports on
their interfaces. You can only connect compatible ports together. For a port to be com-
patible, the out signals on each side must be a subset of the in signals on the other
side.
9 Right-click on the dealer_comm port in the Structure Diagram for the Player capsule,
and click Conjugate.
10 Right-click on the dealer_comm port in the Structure Diagram for the Player capsule,
and click Wired if it not currently selected.
By creating these ports and connectors, the Class Diagram: Logical View / Main changes to
include the ports on the Dealer and Player capsules and the HeadsUpPoker capsule.
Before proceeding with Lesson 4, we recommend that you save your work.
Prototyping
One of the fundamental impacts Rational Rose RealTime is that it encourages a highly
iterative development workflow at the individual software developer level. An
iterative approach:
■
helps to resolve major risks before making large investments
■
enables early user feedback
■
makes testing and integration continuous
Building a Model
You will build and run for the first time an executable version of the card game
simulation. Although you have not yet added any detailed behavior, this is a good
time to build and run a model.
Suggested Reading
■
Components, Rational Rose RealTime Modeling Language Guide
■
Build basics, Rational Rose RealTime Toolset Guide
■
Building and running models, Rational Rose RealTime Toolset Guide
To run your model, you need to build it, and then execute it on a processor. A
component describes how to build a set of capsules and classes. The deployment of a
component describes on what processor to execute the built component.
Creating a Component
The Component View specifies how to compile various parts of the model. The primary
element of the Component View is a component that you need to create. This component
specifies the capsules and classes to compile, how to compile those elements, and the
inclusions and libraries to incorporate into the build.
You must create a component for the top-level capsule in order to build and execute
your model. You can draw component diagrams for situations where you have many
related components or packages of components.
To create a component:
1 In the Model View browser, right-click Component View, and click New > Component.
Or . . .
In the Main diagram for the Component View, from the toolbox, select the Component
tool , then click on the Main diagram.
A component appears with the default name NewComponent1.
8 In the Model View tab in the browser, drag the HeadsUpPoker capsule onto the
References tab.
You drag the HeadsUpPoker capsule onto the References tab because the items in the
References tab identify what is compiled with the HeadsUpPoker component.
10 Click Select....
The Select Top Capsule dialog box appears. In this dialog box, you select the capsule
that will be the top capsule in the model.
11 Click HeadsUpPoker to designate it as the top capsule.
13 Click Apply.
15 Click Select....
18 To close the Component Specification for CardGameComponent dialog box, click OK.
To create a processor
1 In the Model View tab in the browser, right-click Deployment View, and click New >
Processor.
Or . . .
In the Deployment View, open the Main diagram, from the toolbox, select the Processor
tool , then click on the diagram to add a processor.
A processor appears with the default name NewProcessor.
Suggested Reading
■
Build menu, Rational Rose RealTime Toolset Guide
■
Build settings dialog, Rational Rose RealTime Toolset Guide
■
Build log, Rational Rose RealTime Toolset Guide
■ Starting a build, Rational Rose RealTime Toolset Guide
■ Common build errors, Rational Rose RealTime Toolset Guide
Note: If there are compile errors, double-click on an error message on the Build Errors
tab. Rose RealTime opens the appropriate editor where the source of the error
appears. You can then resolve any errors.
If you do not see "Build Successful", review the topic on Common build errors. The
most common error is not having one of the supported compilers for your platform
installed or accessible in your path. Also, check the Rational Rose RealTime product
web site for any known issues, or updates to tutorials and model examples.
Suggested Reading
■ Building and running models, Rational Rose RealTime Toolset Guide
2 When prompted to rebuild the component, click No. You already built the
component in an earlier step.
The Build Log appears while dependencies are recalculated. If the toolset
determines that model elements changed since the last build the component is
rebuilt before the component instance is run.
A console window appears showing output to stderr or stdout.
6 Right-click on the HeadsUpPoker capsule instance, and click Open Structure Monitor.
The following diagram shows a run-time view of the structure of this capsule
instance.
Review
You have now completed the following activities:
1 Described the requirements of the simulation in a use case.
2 Discovered from the requirements the initial design objects needed to implement
the simulation: capsules and classes.
3 Described the communication paths and scenarios between capsules using
sequence and structure diagrams.
4 Created the protocols which describe the sets of signals which are exchanged
between capsules.
5 Build and run the model.
You used Rose RealTime to describe and develop the high-level Design of a card game
simulation in a way that allows others to understand the system you are building.
The key parts of a design consist of:
■ The name of the key components in the system (viewable from the Model View tab
in the browser).
■
The main responsibility of each component (captured in the Documentation box).
■
The communication patterns between the components (captured in Structure and
Sequence diagrams).
The sample model showing the completed procedures covered to this point in the
tutorial is located in the Rational Rose RealTime installation directory:
$ROSERT_HOME/Tutorials/cardgame/cardgame_step1.rtmdl.
Next, you will incrementally add details to the simulation, first adding behavior to the
capsules, and then implementing the required card classes.
Suggested Reading
■
Creating capsule state diagrams, Rational Rose RealTime Toolset Guide
■
State diagrams, Rational Rose RealTime Modeling Language Guide
■
Signal events, Rational Rose RealTime Modeling Language Guide
In the State Diagram editor, the state diagram is in the right pane and the Navigator in the
left. The Navigator allows you to quickly access and browse capsule behavior.
Suggested Reading
■
Creating capsule state diagrams, Rational Rose RealTime Modeling Language Guide
■
TopState, Rational Rose RealTime Modeling Language Guide
■
Transitions, Rational Rose RealTime Modeling Language Guide
■
States, Rational Rose RealTime Modeling Language Guide
Note: You can resize the black border of the State Diagram by selecting it, then
click and hold your mouse over a pic handle and change the size.
4 Repeat the steps above and create the transitions as shown in the following state
diagram.
Use this dialog to define the ports and signals that trigger this particular transition
to be taken.
4 In the Port list, select the player_comm port.
The incoming signals defined for this port automatically appear in the Signal list.
The trigger you defined now appears on the Triggers tab of the Transition
Specification dialog box.
7 Click OK.
8 Repeat the steps above to create a trigger for the Calc_hands transition using the
following:
Port Signal
player_comm HandValue
When Deal_Cards transition is taken, the dealer sends the ACard signal out the
player_comm port. A total of five cards are sent. This is the first iteration of the
behavior. After you develop the card classes, you can send actual cards to the
player and take cards for the dealers hand. This level of detail code allows you to
run the simulation, and to observe the interactions between the player and dealer
capsules.
6 Click OK.
In the Calc_hands transition, the dealer uses the rtdata argument to extract the data sent
with the signal. The rtdata parameter is available to all transition code and is a casted
version of the data in a message. The rtdata parameter is casted to the highest
common superclass of the possible data classes for the given code segment. In this
Suggested Reading
■
Functionality of the language add-in, Rational Rose RealTime C++ Reference.
2 From the capsule Structure Diagram toolbox, select the Port tool .
4 Double-click to select the Timing protocol from the list of available protocol classes.
5 Rename the port to timer.
1 If not currently open, open the State Diagram for the Player capsule.
2 Click the State tool from the State Diagram toolbox.
3 Move the mouse over the State Diagram and within the state diagram border.
Note: You can rotate the choice point by grabbing one of its pic handles and
turning. You can change the True and False branches using the popup menu.
Next, you want to create transitions.
1 From the State Diagram toolbox, click the State Transition tool .
2 Click and hold the left mouse button on the Initial Point in the state diagram, .
3 Drag the State Transition tool to the top of the WaitingToStart state.
4 Repeat the steps above and create the transitions as shown in the following State
Diagram.
Note: You can change the position of the transition lines and the labels for the
transitions by selecting and moving the object.
You will notice that some transition lines are broken . This broken line means that
these transitions do not have a trigger defined.
Use this dialog to define the ports and signals that trigger this particular transition
to be taken.
4 In the Port list, select the timer port.
The incoming signals defined for this port automatically appear in the Signal list.
5 In the Signal list, select the timeout signal.
6 Click OK.
7 Click OK.
Note: Transitions out of the choice point do not require triggers. They belong to the
same transition chain as the transition incoming to the choice point.
Verify that there are no broken transition lines. If you have a broken transition,
check that you have defined a trigger for a transition.
You State Diagram should look like the following:
Adding Attributes
The Player’s attributes manage the data required to track the bet, the winnings, and
the number of cards received. These attributes can be accessed in the action code of
the capsule state diagram and in its operations (very similar to how classes attributes
are available in its operations).
_bet Stores the amount of money (rounded up to the dollars) that the
player bets for each hand.
_money Stores the money for the player. The player starts with $150.
This value is updated after each hand to reflect either a win or a
loss.
_ncards Stores the number of cards the player receives. This attribute
helps the player know when they have received all five cards.
To add Attributes:
Note: The following steps show you how to add an attribute using the
Specification dialogs; however, you can also use the Attribute wizard. Right-click
on a capsule and click Attribute Tool.
1 Open the Specification dialog box for the Player capsule.
2 Click the Attributes tab.
3 Right-click in the Attributes list, and click Insert.
4 Type _bet and press ENTER.
5 Press TAB twice to advance to the Type column.
6 Press F8 and select int from the list.
7 Press TAB to advance to the Initial column.
8 Press F8, type 5, and press ENTER.
9 Click Apply.
10 Repeat steps 3 through 9 to add the following attributes:
_ncards int 0
11 Click OK.
2 Right-click on the WaitingToStart state, click Open Specification, then click the Entry
Actions tab.
Or . . .
Click the WaitingToStart state, on the Code tab in the documentation window, select
Entry Action from the drop-down list.
3 Type the following code in the Code box:
_ncards = 0;
timer.informIn( RTTimespec( 2, 0 ) );
State entry actions are executed every time a transition is taken which terminates
on the state. The _ncards attribute resets for each game. The timer requests that
one time-out message be sent to this capsule in two seconds; this enables the
simulation to run continuously.
4 Click Apply.
By adding this code, you specify that the player starts the game by sending an ante
to the dealer.
4 Click Apply.
4 Click Apply.
Note: The card classes are not developed, so you will send a dummy hand value to
the dealer. You will have to update this code after you develop the card classes.
4 Click Apply.
If the player wins, the dealer sends the bet multiplier to calculate the amount of
money relative to the bet that the player has won.
4 Click Apply.
By adding this code, you specify that if the player loses, subtract the bet from total
money for the player.
This code forces the branch to take the False transition until the player receives all
five cards.
4 Click Apply.
Before proceeding with the next lesson, we recommend that you save and build your
model. For details on building the model, see Lesson 4: Building and Running. If you
encounter any errors, review this lesson and fix any errors until you receive the
message "Build successful" in the Log window.
Review
The Player and Dealer capsules are not complete. Later, you will add code to complete
the Transition actions. The capsules are complete enough to allow you to build, run,
and debug the simulation.
Suggested Reading
■ Summary of the observability options, Rational Rose RealTime Toolset Guide
3 Right-click on the Player capsule instance, and click Open State Monitor.
Note: Use the Watch window to specify attributes that you want to watch while
debugging your running component instance. You can also modify the value of a
variable using the Watch window.
You will place watches on three attributes for the Player capsule instance.
2 From the browser in the Player State Monitor, expand the Attributes folder located in
the left hand pane.
3 Drag each attribute individually from the Attributes folder into the Watch window.
The attributes appear in the window. The value is not updated until the
component instance starts.
Messages appear in the Trace window, and the Value fields for the attributes appear
in the Watch window. Since you implemented the simulation so that the player
always wins, the player’s value for money will increase.
Suggested Reading
■
Probes, Rational Rose RealTime Toolset Guide
This topic highlights a very powerful feature of Rational Rose RealTime. You can
build any capsule independently in order to run and debug it. Since the Player and
Dealer capsules do not run individually, they do not encapsulate a flow of events; they
are part of one. When they are built and run, they will not do anything unless you
simulate messages that it expects to trigger behavior. All behavior in a capsule is
triggered by received messages; therefore, when a capsule is run by itself, or out of
context of it’s flow of events, you have to generate these messages to test it’s behavior.
Unexpected Messages
Ensure the component instance is started, then observe the behavior monitors for the
player and dealer instances. Is the behavior what you expected? Now look at the Trace
window. Are all the messages that you expect there?
If you examine the results closely, you will notice that the Player instance is not actually
receiving all five cards. The Player should receive five cards, and then send the hand
value to the dealer. However, the Player only receives one card, and the four others are
being ignored.
The Services Library prints this warning when a capsule instance receives a message
and there is no transition event defined from the current state which can handle the
event.
In this case, messages printed to the console indicate that the Player instance is in the
GameResults state when it received the ACard signal on the dealer_comm port. This
occurred several times.
7 From the Runtime View tab, click the Start button to start the execution of the
loaded component instance.
The Player remains in the ReceiveCards state until receiving cards from the
dealer_comm port. Since a dealer instance is not running, you will inject messages
into the player instance.
11 Click OK.
You created the specification for an inject message that appears in the inject list of
the Probe Specification dialog box.
12 In the Probe Specification dialog box, select the inject message, right-click, and click
Inject.
The state monitor shows the behavior moving from the ReceiveCards state to the
GameResults. This is incorrect, and is a symptom of the problem with the Player
capsule. The Player capsule should remain in the ReceiveCards state until it receives
five cards. Instead, it only receives one card before it changes state.
This indicates that there is an error with the logic in the choice point. In the next
steps, you will correct the error and test the changes.
Note: Ensure that the PlayerComponentInstance component instance is running. You
can check the status by looking at the Status field at the top of the RTS Browser on
the Runtime View tab: the status should indicate Running.
5 Click OK.
The RTS Browser closes.
12 Click Inject.
13 Repeat steps 11 and 12 four more times, for a total of five inject messages.
After you inject five cards, the Player capsule instance changes to the GameResults
state. You will now inject a Win message.
If you look at the State Diagram, the current state is GameResults. Now, you will
create a Win inject message to test the Win transition and complete one hand of the
HeadsUp poker game.
14 In the Structure Diagram for the Player capsule, right-click on the probe you created
earlier, then select Open Inject.
15 On the Detail tab of the Probe Specification dialog box, right-click and select Insert.
This inject message requires an integer data value that represents the bet
multiplier.
18 Click OK.
19 On the Probe Specification dialog box, select the Win signal, right-click and select
Inject.
You can see the Win transition being taken. If you have a watch on the _money
attribute, you can see that value is updated correctly to reflect the fact that the
player has won.
CardList Responsible for providing basic memory and access services for a list
of cards of any size.
Hand A hand refers to the cards a player holds in a card game. A hand is a
general concept and alone does not represent a specific game hand. It
should be specialized for each particular game.
Deck A deck refers to the cards the dealer holds and distributes in a card
game. The deck can be shuffled and re-ordered.
PokerHand Is a specialized hand for poker games. It knows how to evaluate the
value of a poker hand. This kind of hand can contain a maximum of
five cards.
Importing Classes
To implement the classes, you will add detail code to the classes.
Note: If you are already familiar with class modeling (for example, if you are an
experienced Rose user), you have the option of importing the completed classes into
the model. We recommend that you read the tutorial (without having to create the
classes and enter the detail level code) because there are some added properties that
are specific to Rose RealTime for associations and classes.
If you import the classes, see Review on page 194, and then continue with Lesson 9:
Adding Card Classes to the Capsule Behavior on page 195.
Creating a Package
A package is a collection of classes, relationships, use-case realizations, diagrams, and
other packages. A package structures the model by dividing it into smaller parts.
Packages are used primarily for model organization, and serve as a unit of
configuration management. By grouping design model elements into packages, and
showing how those groupings relate to one another, it is easier to understand the
overall structure of the model.
You will create a package to organize the card classes that will be created.
2 Repeat the previous steps for the Deck and Card classes.
When finished, your Logical View folder will look like the following:
Suggested Reading:
■ The Class Diagram, Rational Rose RealTime Toolset Guide
■ Creating associations, Rational Rose RealTime Toolset Guide
3 Right-click on the association end nearest to the CardList class, and clear
Navigable if it is selected.
The arrow appears that near the Card class means that it is not possible to navigate
from the Card class to the CardList class using the association.
4 Right-click on the association end near Card, and click End Name.
5 Rename to _contents.
By default, when an end is named, association, aggregation, and composition
relationships are represented in the code as an attribute in the client class. The code
generation does not generate attributes for ends which are not named.
6 Right-click on the association end near Card, and click Protected.
Protected means that it is visible to this class, any subclasses of this class, and any
designated friend classes.
7 Right-click on the association end near CardList, and ensure that
Aggregation > Aggregate is selected.
Only use aggregation for a composition relationship between classes, where one
class is composed of other classes, where the "parts" are incomplete outside the
context of the whole.
Next, you will create an aggregation relationship between the CardList class and the
Deck class. You want to create this relationship because the cards selected for a
Player’s hand are a subset of the cards from a deck.
3 Right-click on the association end closest to the CardList class, and click End Name.
4 Rename the end name to _cards.
5 Right-click on the association end near CardList, and click Protected so that it is
checked.
6 Right-click on the association end near Deck, and click Aggregation > Composite.
Composition is a form of aggregation with strong ownership and coincident
lifetime of the part with the aggregate. By implication, a composite aggregation
forms a "tree" of parts, with the root being the aggregate, and the "branches" the
parts.
7 Right-click on the association end near Deck, and clear Navigable if it is currently set.
3 Right-click on the association end closest to the CardList class, and click End Name.
4 Rename the end name to _fivecards.
11 Repeat steps 3 through 10 to create a suit attribute of type int. Set the initial
value to 0.
12 Click OK.
_size This attribute holds the number of cards that the list contains.
~CardList The CardList destructor returns the memory allocated for the
cards.
Note: The following steps show you how to add attributes and operations using the
Specification dialogs; however, you can also use the Attribute and Operation
wizards. Right-click on an element, such as a class or capsule) and click Attribute Tool
to add or modify and attribute, or click Operation Tool to add or modify an operation.
14 Click OK to save the changes, and to return to the Operations tab for CardList.
Next, you will create the copy constructor with one parameter called other of type
const CardList &.
15 On the Operations tab, right-click and click Insert.
21 Press TAB to advance to the Type column, press F8, then type const CardList &.
22 In the Code box, type the following C++ code to the copy constructor:
if( other._size < 0 )
_size = 0;
else
{
_size = other._size;
_contents = new Card [ (unsigned)_size ];
24 Type the following into the ConstructorInitializer box for this copy constructor:
: _contents( (Card *)0 )
25 Click OK to save the changes, and to return to the Operations tab for CardList.
6 Click OK to save the changes, and to return to the Operations tab for CardList.
9 Click OK to save the changes, and return to the Operations tab for CardList.
10 On the Operations tab, right-click and click Insert.
17 Press TAB to advance to the Type column, press F8, then type const int.
19 Click OK to save the changes, and to return to the Operations tab for CardList.
27 Press TAB to advance to the Type column, press F8, then type const CardList &.
When finished, your Class Specification for CardList will look like the following:
29 Click OK.
Note: At this point in the lesson, we recommend that you save, then build your
model. If there are compile errors, double-click on an error message on the Build Errors
tab. Rose RealTime opens the appropriate editor where the source of the error
appears. You can then resolve any errors.
Suggested Reading
■
Watch window, Rational Rose RealTime Toolset Guide
■
Type descriptors, Rational Rose RealTime C++ Reference
NumElementsFunctionBody code
The code entered into this property is added to an operation created by the code
generator:
int _rtg_nefb_CardList__contents( const RTTypeModifier * modifier,
const CardList * source )
{
return( source->size() );
}
Attribute/ Description
Operation
_top Tracks the index of the next card taken from the deck.
shuffle Shuffles the cards in the deck (for any size of deck).
get If the deck is not empty, it removes a card from the top of the
deck.
15 Press TAB to advance to the Type column, press F8, then select int.
18 Click OK.
return 1;
_top = 0;
init();
// swap cards
temp = _cards[ index1 ];
_cards[ index1 ] = _cards[ index2 ];
_cards[ index2 ] = temp;
}
20 Click OK.
add Adds a card to the Hand at a specified offset within the hand.
get Returns the specified card (at an offset within the hand).
13 Press TAB to advance to the Type column, press F8, then select int.
17 Click OK.
18 Follow the steps above to add the following operations to the Hand class:
Note: Setting the size operation to Query makes the operation const. Setting the value
operation to Polymorphic makes the operation virtual.
19 Double-click the Hand operation and click the C++ tab.
Attribute/ Description
Operation
8 Click OK.
9 On the Operations tab, right-click and click Insert.
10 Rename the operation to value.
Note: The Operations tab already contains an operation called value. The existing
value operation is for the Hand class. The value operation that you are adding is for
the PokerHand class.
11 Double-click the value operation.
int result = 0;
for( int i = 0 ; i < size() ; i++ )
{
for( int j = i + 1; j < size() ; j++ )
{
if( _fivecards[i].rank == _fivecards[j].rank )
result++;
}
}
return result;
17 Click OK.
Note: We recommend that you save, then build your model. If there are compile
errors, double-click on an error message on the Build Errors tab. Rose RealTime opens
the appropriate editor where the source of the error appears. You can then resolve any
errors.
Review
The goal of Lesson 8 was to create the classes used by the Dealer and Player capsules to
implement the card simulation. The classes represent the information used in the
system, namely the data that describes the cards used in a card game.
Rose RealTime allowed you to add all implementation details to the classes from
within the toolset.
The key points to remember when class modeling are:
■
Classes must be well-formed. The developer is responsible for ensuring that their
classes do not leak memory. Rose RealTime can generate default copy constructors,
assignment operators, and destructors for classes. However, these default
operations only work with simple classes, that is, classes without pointers
(dynamic memory). Most often, you will have to implement the copy constructor,
assignment operator, and destructor.
5 Click OK.
2 Double-click the Initial transition line, and click the Actions tab.
3 In the Code window at the bottom right, type the following code to initialize a new
PokerHand and shuffle the deck:
_hand = new PokerHand;
_deck.shuffle();
4 Click OK.
Now, you will use the Code window in the lower right-hand corner to perform the
same task of adding code to transitions rather than using the Specification dialogs.
5 Select the Deal_cards transition line.
6 In the Code window, select Action from the drop-down list if it is not currently
selected.
7 In the Code window, replace the existing code with the following code that
determines who deals the cards:
// distribute hands to player and take one for myself
Card card;
for( int i = 0; i < _hand->size(); i++ )
{
_deck.get( card );
player_comm.ACard( card ).send();
8 Click Apply.
Note: You can either use the Code window or the Specification dialogs to type code
for the remaining transitions. The tutorial lesson will continue using the
Specification dialogs.
9 Double-click the Calc_hands transition line, and click the Actions tab.
10 In the Code box, replace the existing code with the following code that determines
who won the game:
// compare the players hand to ours. If the Player has a better
// hand then the Player wins; otherwise, the Dealer wins.
if( *rtdata > _hand->value() )
player_comm.Win(2).send();
else
player_comm.Lose().send();
11 Click OK.
5 Click OK.
6 Click OK.
4 Click OK.
5 Double-click the Received_card transition line, and click the Actions tab.
6 In the Code box, replace the existing code with the following code that receives a
card, and add the value to the hand:
_hand->add( *rtdata, _ncards++ );
7 Click OK.
8 Double-click the All_cards Choice Point, and click the Condition tab.
9 In the Code box, replace the existing code with the following code that determines
whether the player received all cards from the Dealer:
return( _ncards >= _hand->size() );
10 Click OK.
11 Double-click the Got_all_cards transition line, and click the Actions tab.
12 In the Code box, replace the existing code with the following code that sends the
value of the Player’s hand to the Dealer:
// Send the value of the hand to the Dealer
dealer_comm.HandValue( _hand->value() ).send();
13 Click OK.
6 Click OK.
Note: The dependencies are added to the model by the Add Class Dependencies
add-in. However they are not automatically added to class diagrams. When
working with a model in source control or on a large model, you do not necessarily
want to check out or modify diagrams because you add dependencies. In this
tutorial, you will add dependencies to the diagrams to show that they have been
created.
10 Click OK.
Note: There is a dependency that was not created by the Add Class Dependency
add-in. This dependency is between the PokerHand and Card class.
11 In the Toolbox, click the Dependency tool .
12 Click the PokerHand class and drag the mouse to the Card class to create a
dependency between the PokerHand and Card class.
Your Class Diagram will look like this:
14 From the Toolbox, select the Class tool , and add a PokerHand class to the
diagram.
15 From the Toolbox, select the Dependency tool , and create a dependency between
ALL of the following:
❑
the Dealer capsule and the Card class
❑
the Dealer capsule and the PokerHand class
❑
the Player capsule and the PokerHand class
Now, you can use Filter Relationships to crete the other dependencies.
16 On the Query menu, select Filter Relationships.
17 Click OK.
Note: The C++ compiler needs to know the size of the Deck class within the Dealer
capsule during compilation. Forward references can only be used when attributes
are declared as pointers.
18 Double-click on the dependency between the Dealer capsule and the Deck class.
22 Click OK.
Dependency Properties
A dependency is converted by the code generator as an #include or forward reference
directive in either the header or implementation files generated for the class or
capsule. By default, a dependency generates a forward reference in the header file and
an inclusion in the implementation. This kind of dependency is the most conservative
in terms of keeping compilation dependencies to a minimum.
You can change how a dependency is generated (either as an include directive or a
forward reference) from the dependency relationship properties in the C++ tab.
Adding Inclusions
For the implementation of the Deck, you used services included in the system header
files time.h and stdlib.h. You need to include those in the Component Specification so
that when the component compiles, the header files are included.
Your Class Specification for Deck dialog box will look like the following.
3 Click OK.
We recommend that you save your model at this time.
A capsule trace window is a type of message trace that shows capsule instances
with messages listed in separate columns for recording event flow between
instances. The left column displays the time at which the message occurred, the
subsequent columns display the source and destination ports, the signal name,
optional data, and the capsule instances.
2 Either click the Start button, , or the Step button, , to begin.
3 In the Trace window, select a signal.
Note: If you clicked the Start button, you can click the Stop button to pause the
execution of the component instance.
4 Right-click and click Open Specification.
You can view any Sender and Receiver information for your selected signal.
Also, take note of the value of _money in the Watch window. Depending on whether the
Player wins or loses, the value increases or decreases for each hand.
Trace Summary
Typically when a message fails to flow through a set of capsules as expected, it is
important to see where the message flow was first in error. To debug these kinds of
errors, we can first use capsule instance traces to look at the messages originating and
terminating from the capsules in the message flow. If the messages are incorrect and
the fault origination cannot be identified, you can then place probes on specific ports
Review
The sample model showing the completed procedures covered to this point in the
tutorial is located in the Rational Rose RealTime installation directory:
$ROSERT_HOME/Tutorials/cardgame/cardgame_step4.rtmdl.
2 Multi-select the elements to aggregate by pressing the CTRL key and, at the same
time, select the ReceiveCards state and the All_cards choice point.
3 On the Parts menu, click Aggregate.
A composite state appears (the selected elements are removed from this state
diagram) called S1.
Note: A composite state icon appears in the bottom right-hand corner of the state
indicating that the state contains sub-states.
Note: The elements that you chose to aggregate are part of the ReceivingCards state.
Both state diagrams remain functionally equivalent.
Review
The sample model showing the completed procedures covered in this tutorial is
located in the Rose RealTime installation directory:
$ROSERT_HOME/Tutorials/cardgame/cardgame_step2.rtmdl.
Tutorial Summary
In this tutorial, you learned how to use the main features of Rose RealTime to build a
model.
You may want to explore Rose RealTime further by:
■
Expanding the card game model, and adding more players so that you can play
multiple games at the same time. You may want to add dynamic structure and
replication. The possibilities are endless.
■
Customizing Rational Rose RealTime. For details, see the tutorials for the Rational
Rose RealTime Extensibility Interface in RRTEI Tutorial Overview.
■ Looking at the Examples. They show common design patterns used in beginner
and intermediate level models.
219
Basic Scripts
The Rational Rose RealTime scripting language is an extension of the Summit
BasicScript. The extensions allow you to automate specific functions of Rational Rose
RealTime using the RRTEI interface. The script editor runs within the Rational Rose
RealTime user interface.
Automation
Rational Rose RealTime automation works in two ways:
■ Using Rational Rose RealTime as an automation controller that allows you to call
an OLE automation object from within a Basic Script. For example, to execute
functions in an application such as Microsoft Word or Microsoft Excel.
■ Using Rational Rose RealTime as an automation server that allows other
applications to call functions in the RRTEI to control Rational Rose RealTime. This
can be done from any OLE-compliant development tool, such as, Visual Basic,
Visual C++, and so on.
Note: The tutorials use Rational Rose RealTime as an automation server.
Writing a Script
The script you will write will prompt the user for a capsule name and then use the
RRTEI to create a new capsule and add an initial transition and a state to the state
diagram of this newly created capsule.
1 Start Rational Rose RealTime.
2 Click Tools > New Script.
3 Type in the following lines of Basic code, or cut and paste from this document:
4 Select File > Save Script As to save the new script. Name it CreateCapsules.ebs.
Compiling a Script
Select File > Edit Path Map. Note which directory is mapped to the $SCRIPT_PATH
symbol, and which is mapped to $ROSERT_HOME.
With the script edit window selected, select Debugger > Compile to compile the
script file. Name the compiled script CreateCapsules.ebx, and save it to the Rational
Rose RealTime $SCRIPT_PATH directory.
Key Description
Active A Yes indicates that this add-in should be enabled in the Tool
menu. (It also indicates that the add-in should receive special
event notifications when Rational Rose RealTime starts and
stops).
HelpFileName The name of the HTML help file that corresponds to a specific
help topic, if necessary.
RoseRTAddIn A Yes indicates that add-in was created using the RRTEI.
Omitting this entry or an entry with a No value indicates that this
is a Rose REI add-in. To run Rose add-ins, Rational Rose
RealTime has to be started in emulation mode.
InstallDir The directory where Rational Rose RealTime can find the menu
file.
MenuFile The name of the file with the menu commands. This file specifies
the menu entry name for the Tools menu, and the method to
invoke in the automation server.
Troubleshooting
If Rational Rose RealTime has problems loading the add-in it will display any errors
in the log. The most common errors are typos in the registry entries and menu file.
This usually causes the .ebx and .mnu files not to be found. Remember that you have
to restart Rational Rose RealTime every time you change the registry settings.
Note: This is not a tutorial on using Microsoft Visual Basic. It is assumed that you
have some basic knowledge of the environment and language.
This Sub takes one parameter of type RoseRT.Application. This is the operation that
will be invoked when your add-in is called from Rational Rose RealTime.
7 Then create a new form called frmSelections that has two list boxes named lstClasses
and lstCapsules. You can create something similar to:
9 Add the code to the RunRRTEITutorial sub that will populate the list boxes in the
frmSelections form.
Public Sub RunRRTEITutorial(theRTApp As RoseRT.Application)
' create a form object
Dim mainForm As New frmSelections
' initialize local vars
Dim theModel As Model
Dim SelectedClasses As ClassCollection
Dim SelectedCapsules As CapsuleCollection
Dim aClass As Class
Dim aCapsule As Capsule
You create an instance of the frmSelections form. Then you get a reference to the
model instance from the Application object passed to the sub by Rational Rose
RealTime when the add-in was called. By calling the GetSelectedClasses and
GetSelectedCapsules operations on the model reference, you can get the collection of
classes and capsules which are selected. Then the list boxes are populated and the
form is displayed.
10 Build the add-in DLL file by selecting File > Make rrtei_intro_tutorial.dll.
This will compile the DLL and register it in the Windows registry.
Key Description
Active A Yes indicates that this add-in should be enabled in the Tool
menu. (It also indicates that the add-in should receive special
event notifications when Rational Rose RealTime starts and
stops).
HelpFileName The name of the HTML help file that corresponds to a specific
help topic, if necessary.
RoseRTAddIn A Yes indicates that add-in was created using the RRTEI.
Omitting this entry or an entry with a No value indicates that this
is a Rose REI add-in. To run Rose add-ins, Rational Rose
RealTime has to be started in emulation mode.
InstallDir The directory where Rational Rose RealTime can find the menu
file.
MenuFile The name of the file with the menu commands. This file specifies
the menu entry name for the Tools menu, and the method to
invoke in the automation server.
OLEServer The name of the registered automation server (ActiveX DLL) and
the name of the interface to associate with this add-in. This is
also called the ProgID.
Common Problems
The most common problem is that your registry entries (InstallDir, OLEServer) are
incorrect. If any of these entries are wrong either the Add-In won’t register when
Rational Rose RealTime loads or the Add-In will not run when you select the menu
item. Ensure that you have the following names correct:
■
Registry key name entry under the Addin subfolder: used in the .mnu file.
■
DLL name (usually the same as your VB project name): used as the first
parameter in the OLEServer registry key.
■ Class name in which your add-in entry sub is declared: used as the second
parameter in the OLEServer registry key.
■
Procedure name which should be invoked by Rational Rose RealTime to run the
add-in: used in the .mnu file.
Benefits
■
Provides shortcut access to an add-in.
■
Ability to create one shortcut menu item that works for items selected in the
browser as well as in a diagram (you do not have to create one menu item for items
selected in the browser and another menu item for items selected in the diagram).
■
Can add submenus.
■
Can control the state in which the context menu appears (disabled, checked ...).
Limitations
The position on the shortcut menu where your menu item displays is controlled by
Rational Rose RealTime. If you have more than one item on the shortcut menu,
however, you can control the order in which those items display by adding the items
(using the AddContextMenuItem method) in the order in which you want the menu
items displayed.
Note: The steps for setting-up and configuring a Visual Basic project for an add-in
were covered in the previous tutorial. For information, see Creating a Visual Basic
Add-in.
' context menu internal names used to identify individual menu items
Const CMID_COMMAND1 As String = "command1"
Const CMID_COMMAND2 As String = "command2"
Const CMID_COMMAND3 As String = "command3"
The first variable MyAddin_ is used to keep a reference to this add-in for quick access
in other functions. The MyMenuItems_(3) array holds references to all the new menu
items that will be added. This again allows quick access to the menu items.
The constants represent the declaration of the internal names that will be used for the
menu items. These internal names will be used when a menu item is created and
when an item is selected. The internal name will be passed to the
OnSelectedContextMenuItem function to identify which menu item has been
pressed.
The first part of the function simply tries to obtain a reference to the add-in object that
represents this add-in within the Rational Rose RealTime application object. The
add-in is searched by name.
Next the add-in reference is used to call the AddContextMenuForClass operation to
add the menu items. The menu item references are saved on the MyMenuItems_(3)
array for use later on. See the RRTEI reference for a description of the parameters that
are passed to the AddContextMenuForClass function.
' activate this menu item only if two or more model elements are
selected
If items.Count > 1 Then
MyMenuItems_(1).MenuState = RoseRT.rsEnabled
OnEnableContextMenuItemsForObjects = True
Else
MyMenuItems_(1).MenuState = RoseRT.rsDisabled
OnEnableContextMenuItemsForObjects = False
End If
End Function
The events subkey is used to tell Rational Rose RealTime that we want to receive the
OnActivate event when the add-in is registered in Rational Rose RealTime.
Overview
The Concept tutorials provide an introduction to the important Rational Rose
RealTime concepts. They expand and summarize the explanations and examples
given in the Rational Rose RealTime Modeling Language Guide.
Note: The Concept tutorials are presented as Shockwave animations that you
activate from the online help. To view the tutorials, you must install the Shockwave
plug-in. The tutorials are displayed in the Help browser with text shown on the left
side of the window, with graphics and animations on the right. You control the
tutorial by using the navigation buttons at the bottom of the left-hand frame.
241
Figure 3 Tutorial Window
Note: These tutorials cannot be viewed with the UNIX Help viewer. You can install
the UNIX Netscape plug-in from Shockwave, and load the tutorials using a Netscape
4.Xbrowser. For more information, see $ROSERT_HOME/Tutorials/unix/index.htm.
Index 245
communication protocol 93 connectors 98
compiling deployment view 44, 111
Summit Basic script 223 initial capsules 59
component 111 logical view 24
building 42 menu file 223
component instance 44, 111 model 53
running 46 new model 53
terminating 47 packages 164
trace 212 ports 98
component view 20 processor 111
creating 35, 105 protocol signals 94
component wizard 36, 105 protocols 92
concept tutorials relationships between classes 167
capsule hierarchical state machines 243 sequence diagram 80
capsules and capsule roles 243 sequence diagram interactions 82
messages and capsule state machines 242 signals for a protocol 94
overview 241 somponents using Component wizard 105
ports, protocols, and protocol roles 243 state diagram 131
configuring states 120
runtime windows 145 summit Basic script 221
toolset 53 timing port 130
toolset options 55 transitions 122
connector 98 triggers 124
ConstructorInitializer 177, 195 use case
contacting Rational technical publications xi use case
contacting Rational technical support xii creating 62
Context Menus use cases 59
how they work 232 Visual Basic Add-in 225
context menus
overview 232
ControllableElementCollection 238 D
crating
debugging
destructor 179
inject messages 154
creating
injecting 154
a new model 22
trace 154
actions 127
using traces 144
Active X DLL 226, 234
using watches 144
add-in menu file 229
decoding
capsules 24, 68
Services Library 183
choice point 133
defining
classes 68
classes 66
component 36, 105
deleting
component instance 44, 111
elements from diagram only 66
component view 35, 105
elements from model 66
components using Component wizard 36
246 Index
dependency inject
properties 210 messages 154
deployment view 20 injecting 154
creating 44, 111
destructor 179
documentation feedback xi L
logical view 20
creating 24
E
element types 73
encoding M
Services Library 183
menus
end ports 33
context 232
errors
messages
troubleshooting Summit Basic scripts 225
inject 154
extending the context menus using add-ins 232
injecting 154
tracing 154
models
F description of QuickStart 21
filter relationships 78 sample 20
FOC 85 MyAddin_ 235
focus of control 85 MyMenuItems_ 235
G N
generated code 48 NumElementsFunctionBody 184
getting started NumFunctionElementsBody 195
QuickStart tutorial 17
O
H OnActivate 235
HeaderPreface 211 OnEnableContextMenuItemsForClass 236
online help 20
OnSelectedContextMenuItem 237
I opening
new model 53
importing
classes 163
Inclusions 210
initial capsules 59
P
initial point 27, 122 package
initial state 27, 122 creating 164
initial transition 28, 122 RTClasses 73
Index 247
port 98 testing a script 223
adding to capsule 29 testing add-ins 239
creating 98 testing new add-ins 231
timing 130 Visual Basic add-in 225
ports writing a script 221
end port 33 RTClasses package 73
protected 30, 32 rtdata 129
unprotected 32 running
protected port 30 component instance 46
protocol Summit Basic script 223
creating 92 runtime windows 145
signals 94
prototyping 103
S
sample model 20
R saving a model 33
Rational technical publications sequence diagram
contacting xi creating 80
Rational technical support sequence diagrams
contacting xii interactions 82
rebuilding a model 144 Sequence Event Message dialog 214
referenced classes 43, 113 state diagram
registry aggregating 215
adding entries 224, 230, 238 creating 131
relationships 78 drawing an initial transition 28, 122
roles initial point 27, 122
connecting 101 initial state 27, 122
RRTEI tutorials initial transition 28, 122
Active X DLL 226, 234 state machine
add-in menu file, creating 229 adding detail code 34
adding entries to the registry 224, 230, 238 stdlib.h 210
adding module variables 235 Summit Basic
automation 220 compiling a script 223
building add-ins 238 creating a script 221
common add-in problems 231 running a script 223
compiling a Summit Basic Script 223 testing a script 223
context menu overview 232
creating a menu file 223
creating a Summit Basic script 221 T
extending the context menus using
testing
add-ins 232
Summit Basic script 223
overview 219
time.h 210
previewing 220
timing port 130
running a script 223
top-level capsule 36, 105
248 Index
trace W
capsule instance 148
component instance 212 watch window 147
traces 144 watches 144
tracing 154 writing a Summit Basic script 221
transitions 122
drawing 28, 122
initial 28, 122
triggers 124
troubleshooting
common new add-in problems 231
Summit Basic scripts 225
tutorials
environment configuration 17, 51
navigating 15
printing 15
QuickStart 17
U
use case
adding 59
documentation 64
flow of events 63
use cases
creating 59
use-case view 20
user interface
main features 19
Rational Rose RealTime 18
views 19
V
viewing
generated code 48
views
component 20
deployment 20
logical 20
use-case 20
Index 249