/* * This Software is the original work of Daniel TUNG * This Software is submitted in partial fulfillment of the * requirements for the degree of BCSE. * Dept. Computer Science, Monash University 2000 * * Copyright (c) 2000 beetung@cs.monash.edu.au * beetung@geocities.com */ #ifndef CAR_H #define CAR_H #include #include #include #include "semaphore.h" #include "consumer.h" // consumer and producer class #include "carop.h" // car operation command set //// //// This class encapsulates our car prototype, mainly for control //// related task... //// //////////////////////////////////////// class Car { //////////////////////////////////////// ///// Note: aSem is a class data variable that dies when ~Car is invoked. ///// It _MUST_ die alone with this object and _MUST NEVER_ ///// die before Consumer or Producer! private: /// Producer and Consumer Loop, using semaphore as /// a synchronization tool, refer to "semaphore.h" /// MySemaphore aSem; // this one should die with the object!!! Producer producer; // command sender, to produce Consumer consumer; // controller loop, to consume public: //--------------------- Car() : aSem(),producer(aSem),consumer(aSem) { //--------------------- consumer(); // setup Controller as Consumer } //--------------------- ~Car() { //--------------------- producer.SemDie(); consumer.SemDie(); } //--------------------- void steerOn( int a ) { //--------------------- producer.setCommand( a ); producer.Produce(); } }; #endif