Implementing the adapter classes

About this task

To implement the adapter classes, you inherit from the OXF classes defined in the os.h file and provide an implementation for each of these classes. You must implement the following classes:

It is common practice to add the <env> prefix to each implemented class.

For example, you would implement the OMOSMutex class for VxWorks as follows:

Procedure

  1. The OXF class for a mutex is OMOSMutex, so the VxWorks adapter class that inherits from OMOSMutex is named VxMutex.
  2. Implement each of the interface operations defined for the class. The OMOSMutex class is defined in os.h as follows:

    class RP_FRAMEWORK_DLL OMOSMutex {
    OM_DECLARE_FRAMEWORK_MEMORY_ALLOCATION_OPERATORS
    public:
    virtual ~OMOSMutex(){};
    virtual void lock() = 0;
    virtual void unlock() = 0;
    virtual void* getOsHandle() const = 0;
    #ifndef OSE_DELTA
    // backward compatibility support for non-OSE
    // applications
    void free() {unlock();}
    #endif
    };
  3. Place the specification of the new adapter class in the VxOS.h:

    class VxMutex: public OMOSMutex {
    private:
    SEM_ID hMutex;
    public:
    void lock() {semTake(hMutex, WAIT_FOREVER);}
    void unlock() {semGive(hMutex);}
    VxMutex() {
    // hMutex = semBCreate(SEM_Q_FIFO, SEM_FULL);
    hMutex = semMCreate(SEM_Q_FIFO);
    }

    ~VxMutex() {semDelete(hMutex);}

    void* getHandle() {return (void *)hMutex;}
    virtual void* getOsHandle() const {return (void*)
    hMutex;}
    };

Feedback