Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1

2 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

3 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

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

5 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

7 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

9 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

10 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

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

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

13 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

15 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

16 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.!

17 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

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

20 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

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

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

24 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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 !

25 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

27 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

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

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

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

32 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

33 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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 }

34 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

36 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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*

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

38 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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).

39 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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);

40 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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”) );

41 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

42 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

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

45 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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;

46 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

47 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

48 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

49 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

50 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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”

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

52 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

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

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

56 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

58 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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”.

59 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

60 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

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

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

63 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

64 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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 !

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

66 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

67 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

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

70 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

71 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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”.

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

73 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

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

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

76 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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:

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

78 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

79 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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 !

80 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

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

83 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

84 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

86 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

87 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

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

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

91 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

92 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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:

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

94 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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();

95 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

96 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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; };

97 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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 :

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

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

100 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

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

102 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

104 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

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

107 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

109 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

110 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

111 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

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

113 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

114 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

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

116 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

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

118 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

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

121 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

122 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

123 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

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

126 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

127 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

128 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

129 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

130 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

132 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

133 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

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

135 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

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

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

139 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

140 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

141 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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

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

143 Rhapsody in C++ Tool Training "Essential" © I-Logix 1999-2000 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.

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

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


Download ppt "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."

Similar presentations


Ads by Google