Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v3.0 1/29/2001 Adv-1 Essential Rhapsody in C++ Section 4 Advanced Level.

Slides:



Advertisements
Similar presentations
Lecture 10 Sharing Resources. Basics of File Sharing The core component of any server is its ability to share files. In fact, the Server service in all.
Advertisements

Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 Bas-1 Essential Rhapsody in C++ Section 2 Basic Level.
Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-1 Section 4 Advanced Mutexes.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
CS320n –Visual Programming LabVIEW Foundations. Visual ProgrammingLabVIEW Foundations2 What We Will Do Today Hand back and review the midterm Look at.
Road Map Introduction to object oriented programming. Classes
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 EI-1 “Essential” Rhapsody in C++ Introduction.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Chapter 14: Overloading and Templates
© I-Logix Rhapsody C++ V /01/2004 E1-1 Exercise 2 : Count Down.
אביב תשס"ה JCTתיכון תוכנה: ד"ר ראובן גלנט1 פרק 8 נקודות חשובות בתרגילים 7-9.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 Adv-1 Essential Rhapsody in C++ Section 4 Advanced Level Modified.
Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-1 Section 4 Advanced Level Concurrency.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Int-1 Section 3 Intermediate Inherited Sensor.
© Copyright Eliyahu Brutman Programming Techniques Course.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment Chapter 8: Implementing and Managing Printers.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment, Enhanced Chapter 8: Implementing and Managing Printers.
© I-Logix Rhapsody C++ V /01/2004 E1-1 Exercise 3 : Dishwasher.
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 Int-1 Essential Rhapsody in C++ Section 3 Intermediate Level.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment Chapter 8: Implementing and Managing Printers.
Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-1 Section 4 Advanced Level Multiplicity.
SE-565 Software System Requirements More UML Diagrams.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
C++ fundamentals.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Pointer Data Type and Pointer Variables
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Microsoft Visual Basic 2005: Reloaded Second Edition
1 I-Logix Professional Services Specialist Rhapsody IDF (Interrupt Driven Framework) CPU External Code RTOS OXF Framework Rhapsody Generated.
07 Coding Conventions. 2 Demonstrate Developing Local Variables Describe Separating Public and Private Members during Declaration Explore Using System.exit.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
The Java Programming Language
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
The Rhapsody in C++ Tool Training "Essential" © I-Logix v2.3 25/9/2000 Adv-1 Essential Rhapsody in C++ Section 4 Advanced Level.
Rhapsody V4.2 "Specialist" Tool Training © I-Logix /08/20031 Specialist Rhapsody Getting Rhapsody In C generated code to run.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
1 Class Diagrams. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are for visualizing, specifying and documenting.
Chapter 5 Introduction to Defining Classes
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
© I-Logix Rhapsody C++ V /01/2004E1-1 “Essential” Tool Training Basic Rhapsody Basic Rhapsody Rhapsody in C++ V /01/04.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Active-HDL Server Farm Course 11. All materials updated on: September 30, 2004 Outline 1.Introduction 2.Advantages 3.Requirements 4.Installation 5.Architecture.
Advanced Taverna Aleksandra Pawlik University of Manchester materials by Katy Wolstencroft, Aleksandra Pawlik, Alan Williams
How to develop a VoIP softphone in C# by using OZEKI VoIP SIP SDK This presentation demonstrates the first steps concerning to how to develop a fully-functional.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Processes and threads.
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Chapter 2: System Structures
CIS16 Application Development Programming with Visual Basic
Tonga Institute of Higher Education
Essential Rhapsody in C++
四時讀書樂 (春) ~ 翁森 山光照檻水繞廊,舞雩歸詠春風香。 好鳥枝頭亦朋友,落花水面皆文章。 蹉跎莫遣韶光老,人生唯有讀書好。
Presentation transcript:

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-1 Essential Rhapsody in C++ Section 4 Advanced Level

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-2 Section 4: Advanced Triggered Operations Event Parameters Event Hierarchy Strings / Containers & Iterators Packages Concurrency Configuration Management Useful tips Qualified Associations

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-3 Section 4 Advanced Level Triggered Operations

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-4 Triggered Operations Triggered operations are a way of tuning a model for rapid response. They act as events except that they are executed immediately rather than being queued and executed later as for events. They do not have a body. The reply() operation allows the triggered operation to return a value. Care should be taken not to mix triggered operations with events in the same statechart since there would be potential race conditions.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-5 Race Condition

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-6 Project Triggered Create a new project “Triggered” and in an OMD, draw a composite class Motor containing one instance of Sensor. Add a triggered operation opRead for the Sensor class.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-7 opRead Set the return type to int

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-8 Sensor Statechart Add the following statechart to the Sensor class. Add a getStatus operation to the Sensor class that returns a random number as an int.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-9 Motor Statechart Add the following statechart to the Motor class. Also add an attribute status of type int

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-10 Animating Save / Generate / Make / Run Check that the attribute status changes every two seconds.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-11 Generated Code

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-12 Extended Exercise If the triggered operation is called when in the active state then we could return a status of -1. Add a reaction in state for the active state so that if opRead is received, -1 is replied.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-13 Section 4 Advanced Level Event Parameters

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-14 Event Parameters Events ( and Triggered Operations ) can be passed parameters Rhapsody provides a pointer called params to access these parameters. For instance if an event evGo has a parameter n then n can be accessed using params->n

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-15 Project Parameters Create a new project “Parameters” and in an OMD, draw a simple class Motor with statechart as shown: Note that GEN(evGo) broadcasts the event evGo to itself.!

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-16 Adding a Parameter Add an argument n of type int to the event evGo. Add an attribute cycles of type int. Create a constructor to initialize cycles to 0.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-17 Exercise Check that execution is as expected. Why does the output increment by 2 ?

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-18 Section 4 Advanced Level Event Hierarchy

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-19 Event Hierarchy It is possible for events to inherit from other events. In this example, evCommsError, evDivZeroError and evOutOfMemError all inherit from evError.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-20 Client Generating Events The client sends one of each events to the server

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-21 Server Handling Events Note how each event is handled.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-22 Section 4 Advanced Level Strings

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-23 OMString Class Rhapsody provides a string class that we have already used. This class allows operations such as: stringA = stringB stringA += stringB; length = string.GetLength(); character = string[5]; Note that the GetLength operation starts with a capital ‘G’ which is contrary to the normal style !

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-24 OMString Class This class reserves memory off the heap in blocks of 256 bytes and will add extra memory if needed during an operation such as stringA += stringB. The operation setDefaultBlock(n) allows the block size to be changed.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-25 Section 4 Advanced Level Multiplicity

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-26 Containers A container is a collection of objects. Rhapsody uses containers for managing all “1 to many” and “many to many” relations. The containers are implemented using template classes. The Rhapsody containers are called OMContainers. Rhapsody also provides containers called OMUContainers that don’t use templates.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-27 Relations The following table shows how Rhapsody implements relations:

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-28 OMCollection

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-29 OMList

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-30 OMMap

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-31 Iterators An iterator is a friend class to a container, that is used to keep a pointer to the current element in the container. Iterators are needed so that many classes can have concurrent access to the same container.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-32 Using OMIterator Rhapsody provides an OMIterator class that can be used as follows to iterate through a container: OMCollection itsSensor; // a container OMIterator iSensor(itsSensor); iSensor.reset(); // point to first while ( *iSensor != NULL ) { (*iSensor)->print();// print ++iSensor;// point to next }

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-33 Other Libraries Other libraries can be used instead of OMContainers and OMString, such as : –STL (Standard Template Library) ( See the appropriate Specialist section for more information ). –Rhapsody OMUContainers ( This is a container set similar to OMContainers except that templates are not used, this can help reduce code size ). It is also possible to add your own container set or integrate a third party container set such as the RogueWave libraries.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-34 Using OMUContainers To use the Rhapsody containers that don’t use templates, select the OMUContainers:

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-35 Using OMUIterator Rhapsody provides an OMUIterator class that can be used as follows to iterate through a container: OMUCollection itsSensor; // a container OMUIterator iSensor(itsSensor); iSensor.reset(); // point to first while ( *iSensor != NULL ) { (static_cast (*iSensor))->print(); ++iSensor; // point to next } Note the static_cast to convert from void* to Sensor*

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-36 Section 4 Advanced Level Collection

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-37 Collection of Sensors Load the “Virtual” project and save as “Collection” Delete from Model the relations between the Motor and the Sensors. Check in the Browser that these relations have been deleted from the model not just the view. Add a directed aggregation itsSensor from the Motor to the Sensor. Set Multiplicity to * (many).

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-38 OMCollection Delete implementation of Motor constructor Save / Generate / Examine code for Motor Note that the relation has been implemented as a collection of Sensors: OMCollection itsSensor; Note also that there is an operation addItsSensor(Sensor* p_Sensor);

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-39 Adding to OMCollection In the motor constructor add Sensors: –addItsSensor(new TemperatureSensor(“Sensor1”,CELSIUS)); –addItsSensor(new TemperatureSensor(“Sensor2”,FAHRENHEIT)); –addItsSensor(new PressureSensor(“Sensor3”) );

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-40 Dependencies In order to compile, the Motor needs to include the Pressure and Temperature Sensors header files. To do this we will add dependencies from the Motor to those classes: Double-click on each dependency and select the stereotype Usage.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-41 Implementation Includes Alternatively instead of drawing dependencies, we can just modify the properties for the Motor class and for CPP_CG->Class->ImpIncludes add TemperatureSensor.h,PressureSensor.h CPP_CG means C++ Code Generation.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-42 Multiple Relation Save / Generate / Make / Run Show that the Motor has a collection of three Sensors.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-43 Statechart Create a simple Statechart for the Motor class that calls a pollSensors() routine every two seconds.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-44 pollSensors() Create the pollSensors() operation that will poll all the Sensors in the collection: Note that if any more Sensors of any other type are added, the operation still functions! OMIterator iSensor(itsSensor); for ( iSensor.reset(); *iSensor; ++iSensor ) { (*iSensor)->print(); (*iSensor)->read(); } cout << " " << endl;

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-45 Output Save / Generate / Make / Run Verify the output The syntax for an iterator is a little complex, but it’s used in the same way every time.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-46 Sequence Diagram Create a sequence diagram entitled “What we expect” as shown in the next slide. Create the instances by dragging the classes onto the sequence diagram from the browser. Right click on each TemperatureSensor line to bring up the features where the instance name can be entered. Note that an other way is to drag instances rather than classes onto the sequence diagram. Now that we have several instances of a class, on a sequence diagram we have to indicate the instance name and not just the class.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-47 Another way is to drag instances from the browser during animation. (Drag the instances from TemperatureSensor and the PressureSensor classes not the Sensor class). Sequence Diagram

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-48 Animated Sequence Diagram Save / Generate / Make / Run. Animate and check that what we expect is what we get. When executing the code, then only if a SD is open, will an animated SD will be created.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-49 When executing the code, then only if a SD is open, will an animated SD will be created. Comparing Sequence Diagrams Use “Tools>Sequence Diagram Compare” to examine the differences between “What we expect” and “Animated What we expect”

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-50 Note the differences are highlighted in Magenta. The Comparison

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-51 Interpreting the Comparison As we can see the result is not as we expected, (the order of constructing the instances is different). This is because, Rhapsody does not consider an object to exist until it’s constructor has terminated, this is why all the constructors come from the system border.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-52 Using the Comparison Options We can set an option so that the constructors are not compared.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-53 Using the Comparison Options We can set an option so that the constructors are not compared.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-54 The Modified Comparison Note the differences are now grayed out.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-55 Extended Exercise For the Sensor class, add a static attribute numberOfSensors of type int with initial value 0. In the Sensor Constructor add numberOfSensors++; For the Sensor class, add a virtual Destructor with implementation : numberOfSensors--; Add the following to pollSensors() cout << “Number of sensors = “ << Sensor::getNumberOfSensors() << endl; Generate code and execute to check that numberOfSensors = 3.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-56 Section 4 Advanced Level Packages

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-57 Packages A package is a convenient way of grouping classes together. It is good practice not to use the Default package. (This makes it easier to import packages from other models without getting name conflicts). In our example we are going to put all the Sensors in a Sensor Package “SensorPkg” and the Motor in a Motor Package “MotorPkg”.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-58 Domain Diagram Starting with the previous project (Collection), create a new Object Model Diagram called “Domain diagram” Draw two packages called SensorPkg and MotorPkg.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-59 Moving Classes Between Packages There are two ways of moving classes from one package to another. Drag from the Browser onto the Domain Diagram, the Sensor class into the SensorPkg and the Motor class into the MotorPkg. Drag the TemperatureSensor and the PressureSensor within the browser from the default to the SensorPkg package We do not have to show all the classes in a package on an OMD

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-60 The Domain Diagram

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-61 Completing the Relations Complete the relations in the Domain Diagram

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-62 Configuration Scope Move the tTempUnits type to the SensorPkg. We can modify the component so that it includes just these new packages and not the Default package which should be empty.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-63 Diagram Default Package Note that all the OMD’s and SD’s can have a default package. Setting this to a particular package means two things: First all new classes drawn on that diagram will be in that package. Secondly any class on the diagram, not in that package, will display its package scope. Not to be confused with the package called Default !

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-64 Overview Diagram Change the Default package for the Overview diagram to the SensorPkg. Package scope

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-65 Save / Generate / Make / Run Save / Generate / Make / Run to check that our model still works. Note also that the sequence diagrams now show package scope.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-66 Abstract Class Set the read() operation of the Sensor class to be Abstract by setting the property Kind: Note that the read operation is pure virtual. This means that if we try to create an instance with “new Sensor”, the compiler will generate an error.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-67 Stereotypes For the Sensor class set the Stereotype to Interface

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-68 Stereotypes For the Sensor class set the Stereotype to Interface

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-69 Nested Packages Packages can be nested inside other packages. Diagrams can also be moved inside packages In our example, create a package OurPkg and move everything that we have done so far into it. Nested packages Diagrams in a package

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-70 Main Diagram For classes and packages, we can select a Main Diagram, this is very useful for navigation in a model. In our model, set the Main Diagram for the SensorPkg and the MotorPkg to be the Overview diagram. Now we can navigate from the Domain Diagram to the Overview diagram, by “Open Main Diagram”.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-71 Extended Exercise Set a namespace for the package

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-72 Using Namespace Set the ImplementationProlog property for the Motor class to : using namespace SensorPkg; Save / Make / Generate / Run

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-73 Section 4 Advanced Level Concurrency

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-74 Code Generation Per Package Generated code for each package can be directed into separate directories:

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-75 Concurrency We want each Sensor to run on its own thread (active class). To do so, we need each Sensor to be Reactive (class that waits for events). So we will create a Statechart for the base Sensor class as follows:

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-76 Active Classes With the browser, change the concurrency of the Sensor class from sequential to active.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-77 Inheriting Behavior Open the Statecharts for the PressureSensor and TemperatureSensor. Note that they have inherited the base class Statechart. Specialize the behavior of the TemperatureSensor as below: Grayed out indicating inherited behavior

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-78 Starting the Behavior Add a call to startBehavior() from the TemperatureSensor and PressureSensor constructors to initialize the statecharts. If we had used a composite class, Rhapsody would have done this for us, but that would have been too easy !

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-79 Multi-threads Save / Generate / Make / Run Check that there are four active threads. Setting the focus to a particular thread displays the call stack and event queue for that thread. There will always be one thread called mainThread.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-80 Suspending Threads Note that a thread can be suspended.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-81 Extended Exercise I Add two new operations to the Motor class deleteSensor & addSensor

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-82 Extended Exercise II Modify the Motor Statechart to add two static reactions in state for evAdd and evDelete.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-83 Extended Exercise III Save / Generate/Make/Run Inject events evAdd and evDelete Note that threads are created & deleted.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-84 Extended Exercise IV Try adding a SpeedSensor that is a new type of Sensor.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-85 Problems with the Design With the current design there are a few potential problems: –The Motor class needs to know about all the different types of Sensor. –If another class wants access to the Sensors, it too will need to depend upon all the different types of Sensor. –Starting the behavior of a Sensor, in the constructor is not very elegant. –Adding a new type of Sensor means finding and modifying all classes that use Sensor.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-86 Improving the Design Using the “factory method design pattern” will solve all these concerns. A SensorFactory class can be introduced that is used by all classes ( ex: Motor ) that need to get a Sensor. This decouples the Motor class from the actual Sensors and can also start the behavior of the Sensors. The SensorFactory will be implemented using the “Singleton design pattern” (to ensure that there is only one instance of SensorFactory). See the “SensorFactory” example.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-87 The Improved Design

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-88 The Singleton Design Pattern I Protected constructor Static attribute

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-89 The Singleton Design Pattern II Static factory operation Calling the createRandomSensor operation

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-90 More Design Improvements In all the constructors of the sensors passing a string by value is not very efficient, it would be better to pass a reference to a string.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-91 Setting Priority, Stack Size,... For an active class, the stack size, priority, name, etc can be set through the following properties:

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-92 Section 4 Advanced Mutexes

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-93 Mutexes Rhapsody provides OMProtected which is a mutex (or binary semaphore) for protecting consecutive access to devices. OMProtected can be used as follows: –attribute OMProtected myMutex; –free myMutex.free(); –lock myMutex.lock();

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-94 Animating Mutexes Rhapsody cannot display in animation, the value of attributes of type OMProtected. In order to use animation, the property AnimateAttributes for the attribute must be set to FALSE.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-95 Animating Attributes For animating attributes of a user defined type, the same problem can occur. To allow animation: –either set the property AnimateAttributes to FALSE –or add a global function operator<< for the user defined type –Or use the InstrumentationFunctionName ostream& operator<<(ostream& out, const tDate& d) { out << d.day << "/" << d.month << "/" << d.year; return out; };

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-96 Instrumentation Function Name I To animate an attribute of type tTempUnits that is an enum of CELSIUS and FAHRENHEIT : Add a function showTempUnits as follows :

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-97 Instrumentation Function Name II Set the Animate and AnimateArguments properties for this function to False :

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-98 Instrumentation Function Name III For each attribute of type tTempUnits, set the InstrumentationFunctionName to showTempUnits

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-99 Instrumentation Function Name IV To generate this operation only during animation, the following properties can be set for this function. New line

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-100 Instrumentation Function Name V

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-101 Unguarded Access to Adc::read() In the following example, each Sensor calls the Adc::read() operation to measure Voltage / Temperature or Pressure. The read operation selects the appropriate multiplexor input and does eight serial reads on DataIn.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-102 Unguarded Behavior Current read() operation is interrupted by another.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-103 Guarding Operations Rhapsody can use the mutex OMProtected to guard access to a particular operation to stop concurrent access. This can be done by setting the property concurrency from sequential to guarded. All operations in a same class, that are guarded will be guarded by the same mutex.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-104 Guarded Behavior Concurrent read() operation is blocked by mutex and is executed when current read() ends.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-105 Guarded Operation : Code

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-106 Guarding Relations Rhapsody can also use the mutex OMProtected to guard access to a particular relation to stop concurrent access. This can be done by setting the property isGuarded from none to all ( mutator & accessor operations ) or just mutator.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-107 Section 4 Advanced Level Configuration Management

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-108 Configuration Management Rhapsody can attach to many CM tools such as PVCS, ClearCase, SourceIntegrity … The connection can be done by using either the SCC interface or the command line interface. The selection is made in the project properties (or setup in the site.prp file) File->Configuration Items… opens the CM interface Rhapsody checks in and out parts of the model, these parts are called Units. Units checked out without a lock are Read- Only.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-109 CM Units There are eight types of units that can be checked in/out with the CM tool: –packages.sbs files –object model diagrams.omd files –sequence diagrams.msc files –components.cmp files –use case diagrams.ucd files –classes, actors & use cases.cls files –collaboration diagrams.clb files –component diagrams.ctd files

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-110 Units Each unit can be seen in the browser as having the symbol. By default classes are not “Units”, to be able to check in/out a single class, select the class in the browser, right-click and select “Edit Unit”. Class is a unit

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-111 Using the SCC Interface

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-112 Connecting to an archive The first time that the user connects to an archive, the SCC tool will allow a CM archive to be selected. Some tools will also allow a new CM archive to be created. Each time the Rhapsody project is opened, it is necessary to reconnect to the CM archive.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-113 SCC : CM Commands Connect to Archive Show items in Archive Fetch from Archive Checkout items Uncheckout items Check in items Add items to Archive File History for items File properties for items

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-114 Using the Command Line Interface

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-115 CM Commands Connect to archive List items in archive Check out selected items Check in selected items Add items to archive Synchronize items Lock items Unlock items Diff with Rhapsody

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-116 Directly calling CM Operations

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-117 Diff and merge I The Diff and merge tool can be invoked by running the executable “DiffMerge.exe” or if the command line interface is used, then can be invoked directly from the CM Interface.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-118 Diff and merge II

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-119 Diff and merge III

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-120 Add to Model I Add to model can be used to import part of another model. The model can either be added to the model or simply referenced. By using packages other than the default package, name clashes can be avoided during adding to model.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-121 Add to Model II Bringing in part of the previous project browse Choice of unit type add copy or reference

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-122 Unresolved Parts of Model When using Configuration Management, it is possible that there are some unresolved references in the model. These are indicated by (U). In the following example on the next slide, just the diagram and one package have been added to a model. The other packages referred to in the OMD are unresolved.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-123 Unresolved Parts of Model (U)

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-124 Section 4 Advanced Level Useful Tips

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-125 Useful Tips I 4Keep statecharts simple, if they are too complex then divide the object into several smaller ones or use sub- statecharts. 4Draw states as small as possible and as close as possible to other states. This helps greatly during animating, since they are more readable, especially when there are several diagrams open at the same time. 4Don’t call many actions on a statechart, it makes the diagram very difficult to read. Instead call a new operation that calls the actions.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-126 Useful Tips II 4Don’t start a project until the ‘unguided examples’ in the “Specialist” section have been completed successfully. 4Don’t give the same name to several different elements of the model ex: package and class. The generated files will overwrite each other. 4When working with large projects, it is essential to divide up the model into domains. The interfaces between these domains should be defined. Then work can be carried out simultaneously and independently by different teams on each domain.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-127 Useful Tips III 4Don’t put everything onto a single diagram, this can make reading the diagram difficult. Using a couple of diagrams, depicting different views can really help in understanding the model. 4As a rule of thumb, there should be 7 ± 5 graphical objects ( state / class ) per diagram. 4To aid navigation within the model, set up a main diagram for every class and package.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-128 Useful Tips IV 4Use an iterative approach similar to that taken during this training, constantly model / save / generate / make / run. Don’t wait until the model is too large before animating. 4Make use of the Framework Base classes ( OMReactive, OMEvent, … ) to help de-couple classes. 4Beware of using names such as res, id, execute, start, suspend, resume, event, since OMThread & OMReactive use these operations. This can lead to problems that are very hard to track down.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-129 Useful Naming Conventions 4Start Event names with ev –ex: evStart 4Start Triggered operation with op –ex: opPress 4Start Condition operations with is –ex: isPressed() 4Start Interface classes with a I –ex: IHardware These conventions help when reading diagrams.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-130 Section 4 Advanced Level Remote Animation

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-131 Remote Animation An executable can be run on a remote PC from the host connected via a TCP/IP link. In the properties sheet for Microsoft, set the Remote Host, to either the IP address for the host, or to the host name as shown in the next slide. Set UseRemoteHost to TRUE.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-132 Remote Animation Generate an executable and transfer it to the target PC. With the project loaded into Rhapsody on the host, start the executable on the target The animation bar should appear on the host and animation can proceed as if the code was running on the host This can be very easily demonstrated with two networked PC’s

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-133 Section 4 Advanced Level Qualified Associations

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-134 Qualified Associations Create a new project called “Qualified” Create an OMD containing two classes Airline and Member. Add attributes name, frequentFlyerNumber and miles to the Member class. Add a directed association from the Airline to the member with multiplicity *. Set the Qualifier to be the frequentFlyerNumber attribute.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-135 Qualified Associations

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-136 Qualified Association Create a component and configuration and generate code. Examine the code. map

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-137 Using Qualified Associations Knowing the frequentFlyerNumber, the Airline class can access the appropriate Member as follows.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-138 Prioritized List Example The example PrioritizedList shows how a qualified association can be used to manage a list of prioritized commands: In this example, the Writer creates commands with a specific priority and passes them to a CommandList class that inserts them into a list according to the priority. The Reader asks the CommandList to read the next highest priority message. The Reader and Writer run on separate threads with different priorities.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-139 Prioritized List Example Note that the property UseAsExternal is set to TRUE. Qualified association Mutex used to protect from simultaneous access

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-140 Displaying Bitmaps To display a bitmap on a class, add a stereotype ex: Coffee Add a bitmap with the same name as the stereotype ex: Coffee.bmp to the folder Rhapsody\Share\PredefinedPictures With the Display Options for the class, set Show stereotype to Icon

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-141 Section 4 Advanced Global Instances

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-142 Global Instances There are two ways of creating global instances. –In the browser, for a package, add a Global instance –Create a class and check the box “This box is also an instance”. Examine the Rhapsody generated code in the package file: default.cpp Any relations between global instances will be initialized by Rhapsody. Note that the second “visual” method is preferred.

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-143 Global Instances Instance added via OMD Instance added directly in browser

Rhapsody in C++ Tool Training "Essential" © I-Logix v3.0 1/29/2001 Adv-144