200 likes | 325 Views
פרק 9 נקודות חשובות בתרגיל 10. Guarded Operation. מבנה הפרויקט. הבטים שונים ( OMD1 ) ארכיטקטורה של המערכת-מחלקות. הבטים שונים ( OMD 2 ) מבנה של Composite חשוב. הבטים שונים ( OMD 3 ) בניית המערכת. הבטים שונים ( OMD 4 ) מבנה Packages בלי מחלקות.
E N D
פרק 9נקודות חשובות בתרגיל 10 Guarded Operation תיכון תוכנה: ד"ר ראובן גלנט
מבנה הפרויקט תיכון תוכנה: ד"ר ראובן גלנט
הבטים שונים (OMD1)ארכיטקטורה של המערכת-מחלקות תיכון תוכנה: ד"ר ראובן גלנט
הבטים שונים (OMD 2)מבנה של Composite חשוב תיכון תוכנה: ד"ר ראובן גלנט
הבטים שונים (OMD 3)בניית המערכת תיכון תוכנה: ד"ר ראובן גלנט
הבטים שונים (OMD 4)מבנה Packages בלי מחלקות תיכון תוכנה: ד"ר ראובן גלנט
הבטים שונים (OMD 5)מבנה Packages עם מחלקות תיכון תוכנה: ד"ר ראובן גלנט
בניית מערכת (1): <<Singleton>> תיכון תוכנה: ד"ר ראובן גלנט
בניית מערכת (2): Sysמחלקה המיועדת רק לבנות יתר המופעים Sys::Sys() { Adc::getInstance();} תיכון תוכנה: ד"ר ראובן גלנט
בניית מערכת (3): Sensorשילוב בין singleton ל association Sensor::Sensor() {itsAdc = Adc::getInstance();} תיכון תוכנה: ד"ר ראובן גלנט
התנהגות של המערכת: Statecharts תיכון תוכנה: ד"ר ראובן גלנט
פעולות read() של מחלקות Sensor enum eChannel { VOLTAGE, TEMPERATURE, PRESSURE, CALIBRATION }; int PressureSensor::read() {return( 10 * itsAdc->read( PRESSURE ));} int TemperatureSensor::read() { int n; n = itsAdc->read ( TEMPERATURE ); n *= 5; return n; } int VoltageSensor::read() { int n = itsAdc->read( VOLTAGE ); n *= 3; n /= 2; return n; } תיכון תוכנה: ד"ר ראובן גלנט
פעולות read() של מחלקת Adc (1) תיכון תוכנה: ד"ר ראובן גלנט
פעולות read() של מחלקת Adc (2) //file Mux.h class Mux { private: eChannel channel; . . . //etc. } //file Mux.cpp void Mux::select (eChannel aChannel) {channel=aChannel;} //file Adc.h class Adc { public: int value; . . . //etc. } //file Adc.cpp int Adc::read(echannel aChannel) { int i,n; itsMux.select( aChannel ); for ( i=0,n=0; i<8; i++ ) { if ( itsDataIn.isHigh() ) n = ( n << 1 ) + 1; else n = ( n << 1 ) ; } value = n; return n; } //file DataIn.cpp bool DataIn::isHigh() { return ( rand() % 2 == 0{;( bool DataIn::isLow() { return (!isHigh());} תיכון תוכנה: ד"ר ראובן גלנט
Guarded Operation- Mutexs • 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(); תיכון תוכנה: ד"ר ראובן גלנט
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. תיכון תוכנה: ד"ר ראובן גלנט
Current read() operation is interrupted by another. Unguarded Behavior תיכון תוכנה: ד"ר ראובן גלנט
All operations in a same class, that are guarded will be guarded by the same mutex. 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. תיכון תוכנה: ד"ר ראובן גלנט
Guarded Behavior Concurrent read() operation is blocked by mutex and is executed when current read() ends. תיכון תוכנה: ד"ר ראובן גלנט
Guarded Operation : Code תיכון תוכנה: ד"ר ראובן גלנט