Download presentation
Presentation is loading. Please wait.
Published byDarren Rich Modified over 9 years ago
2
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-1 Essential Rhapsody in C++ Section 4 Advanced Level
3
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-2 Section 4: Advanced Triggered Operations Event Parameters Event Hierarchy Strings / Containers & Iterators Packages Concurrency Configuration Management Useful tips Qualified Associations
4
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-3 Section 4 Advanced Level Triggered Operations
5
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 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.
6
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-5 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.
7
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-6 opRead Set the return type to int
8
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-7 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.
9
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-8 Motor Statechart Add the following statechart to the Motor class. Also add an attribute status of type int
10
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-9 Animating Save / Generate / Make / Run Check that the attribute status changes every two seconds.
11
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-10 Generated Code
12
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-11 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.
13
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-12 Section 4 Advanced Level Event Parameters
14
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-13 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
15
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-14 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.!
16
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-15 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.
17
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-16 Exercise Check that execution is as expected. Why does the output increment by 2 ?
18
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-17 Section 4 Advanced Level Event Hierarchy
19
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-18 Event Hierarchy It is possible for events to inherit from other events. In this example, evCommsError, evDivZeroError and evOutOfMemError all inherit from evError.
20
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-19 Client Generating Events The client sends one of each events to the server
21
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-20 Server Handling Events Note how each event is handled.
22
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-21 Section 4 Advanced Level Strings
23
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-22 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 !
24
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-23 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.
25
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-24 Section 4 Advanced Level Multiplicity
26
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-25 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.
27
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-26 Relations The following table shows how Rhapsody implements relations:
28
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-27 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.
29
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-28 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 }
30
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-29 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.
31
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-30 Using OMUContainers To use the Rhapsody containers that don’t use templates, select the OMUContainers:
32
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-31 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*
33
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-32 Section 4 Advanced Level Collection
34
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-33 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).
35
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-34 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*)
36
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-35 Adding to OMCollection In the motor constructor add Sensors: –addItsSensor(new TemperatureSensor(“Sensor1”,CELSIUS)); –addItsSensor(new TemperatureSensor(“Sensor2”,FAHRENHEIT)); –addItsSensor(new PressureSensor(“Sensor3”) );
37
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-36 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.
38
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-37 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.
39
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-38 Multiple Relation Save / Generate / Make / Run Show that the Motor has a collection of three Sensors.
40
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-39 Statechart Create a simple Statechart for the Motor class that calls a pollSensors() routine every two seconds.
41
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-40 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;
42
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-41 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.
43
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-42 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.
44
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-43 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
45
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-44 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.
46
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-45 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”
47
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-46 Note the differences are highlighted in Magenta. The Comparison
48
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-47 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.
49
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-48 Using the Comparison Options We can set an option so that the constructors are not compared.
50
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-49 The Modified Comparison Note the differences are now grayed out.
51
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-50 Extended Exercise 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.
52
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-51 Section 4 Advanced Level Packages
53
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-52 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”.
54
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-53 Domain Diagram Starting with the previous project create a new Object Model Diagram called “Domain diagram” Draw two packages called SensorPkg and MotorPkg.
55
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-54 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
56
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-55 The Domain Diagram
57
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-56 Completing the Relations Complete the relations in the Domain Diagram
58
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-57 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.
59
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-58 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 !
60
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-59 Overview Diagram Change the Default package for the Overview diagram to the SensorPkg. Package scope
61
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-60 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.
62
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-61 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.
63
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-62 Stereotypes For the Sensor class set the Stereotype to Interface
64
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-63 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
65
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-64 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”.
66
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-65 Extended Exercise Set a namespace for the package
67
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-66 Using Namespace Set the ImplementationProlog property for the Motor class to : using namespace SensorPkg; Save / Make / Generate / Run
68
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-67 Section 4 Advanced Level Concurrency
69
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-68 Code Generation Per Package Generated code for each package can be directed into separate directories:
70
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-69 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:
71
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-70 Active Classes With the browser, change the concurrency of the Sensor class from sequential to active.
72
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-71 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
73
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-72 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 !
74
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-73 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.
75
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-74 Suspending Threads Note that a thread can be suspended.
76
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-75 Extended Exercise I Add two new operations to the Motor class deleteSensor & addSensor
77
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-76 Extended Exercise II Modify the Motor Statechart to add two static reactions in state for evAdd and evDelete.
78
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-77 Extended Exercise III Save / Generate/Make/Run Inject events evAdd and evDelete Note that threads are created & deleted.
79
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-78 Extended Exercise IV Try adding a SpeedSensor that is a new type of Sensor.
80
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-79 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.
81
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-80 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.
82
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-81 The Improved Design
83
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-82 The Singleton Design Pattern I Protected constructor Static attribute
84
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-83 The Singleton Design Pattern II Static factory operation Calling the createRandomSensor operation
85
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-84 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.
86
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-85 Setting Priority, Stack Size,... For an active class, the stack size, priority, name, etc can be set through the following properties:
87
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-86 Section 4 Advanced Mutexes
88
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-87 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();
89
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-88 Animating Mutexes Rhapsody cannot display in animation, the value of attributes of type OMProtected. In order to use animation, the property AnimateAttribute for the attribute must be set to FALSE.
90
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-89 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; };
91
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-90 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 :
92
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-91 Instrumentation Function Name II Set the Animate and AnimateArguments properties for this function to False :
93
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-92 Instrumentation Function Name III For each attribute of type tTempUnits, set the InstrumentationFunctionName to showTempUnits
94
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-93 Instrumentation Function Name IV To generate this operation only during animation, the following properties can be set for this function. New line
95
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-94 Instrumentation Function Name V
96
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-95 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.
97
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-96 Unguarded Behavior Current read() operation is interrupted by another.
98
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-97 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.
99
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-98 Guarded Behavior Concurrent read() operation is blocked by mutex and is executed when current read() ends.
100
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-99 Guarded Operation : Code
101
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-100 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.
102
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-101 Section 4 Advanced Level Configuration Management
103
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-102 Configuration Management Rhapsody can attach to many CM tools such as PVCS, ClearCase, SourceIntegrity … For all these tools, the interface is the same The tool must be selected 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.
104
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-103 CM Units There are six 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 and use cases.cls files
105
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-104 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
106
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-105 CM Interface I The CM interface allows the following operations: –Connect to archive –Add selected items to archive –Show items in archive –Check in selected items –Check out selected items –Lock items –Unlock items –Synchronize items
107
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-106 CM Interface II Use the control key to select multiple items
108
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-107 CM List Archive
109
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-108 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.
110
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-109 Add to Model II Bringing in part of the previous project browse Choice of unit type add copy or reference
111
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-110 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 just one package have been added to a model. The other packages referred to in the OMD are unresolved.
112
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-111 Unresolved Parts of Model (U)
113
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-112 Section 4 Advanced Level Useful Tips
114
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-113 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.
115
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-114 Useful Tips II 4Since there is no UNDO (coming very soon), make sure that you do periodic saves. 4Before modifying a complicated statechart, or diagram, make a copy, by selecting the class or diagram in the browser, holding the control key and moving to somewhere else. 4Don’t start a project until the ‘unguided example’ in the “Specialist” section has 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.
116
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-115 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. 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.
117
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-116 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.
118
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-117 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.
119
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-118 Section 4 Advanced Level Remote Animation
120
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-119 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.
121
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-120 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
122
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-121 Section 4 Advanced Level Qualified Associations
123
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-122 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.
124
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-123 Qualified Associations
125
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-124 Qualified Association Create a component and configuration and generate code. Examine the code. map
126
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-125 Using Qualified Associations Knowing the frequentFlyerNumber, the Airline class can access the appropriate Member as follows.
127
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-126 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.
128
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-127 Prioritized List Example Note that the property UseAsExternal is set to TRUE. Qualified association Mutex used to protect from simultaneous access
129
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-128 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
130
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-129 Section 4 Advanced Global Instances
131
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-130 Global Instances There are two ways of creating global instances. –In the browser, 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.
132
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-131 Global Instances Instance added via OMD Instance added directly in browser
133
The Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 v2.3 25/9/2000 Adv-132
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.