home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / msc7.zip / CALLBACK.CPP < prev    next >
C/C++ Source or Header  |  1992-02-12  |  1KB  |  65 lines

  1. //
  2. // (C) Copyright 1992 Qualitas, Inc.  All rights reserved.
  3. //
  4. // callback.cpp - member functions of CallBack class for Qualitas DPMI library
  5. //
  6. #include <dos.h>
  7. #include "callback.h"
  8.  
  9. #define nCallBacks 16
  10.  
  11. extern "C" void (far *setCBDispatch(int, void (*)(dpmiRegs_t)))();
  12.  
  13. CallBack* activeCallBacks[nCallBacks];
  14. static boolean cbInitialized = FALSE;
  15.  
  16. //
  17. // Constructor
  18. //
  19. // The constructor allocates a callback and a locked stack from the DPMI host.
  20. //
  21. CallBack::CallBack(void (*cbHandler)(dpmiRegs_t))
  22. {
  23.     if (!cbInitialized)
  24.     {
  25.         int i;
  26.         for (i=0; i < nCallBacks; i++)
  27.             activeCallBacks[i] = 0;
  28.         cbInitialized = TRUE;
  29.     }
  30.  
  31.  
  32.     for (cbNumber = 0; cbNumber < nCallBacks; cbNumber++)
  33.         if (activeCallBacks[cbNumber] == 0)
  34.         {
  35.             activeCallBacks[cbNumber] = this;
  36.             break;
  37.         }
  38.  
  39.     if (cbNumber == nCallBacks)
  40.     {
  41.         cbAddr = 0;
  42.         cbNumber = -1;
  43.         return;
  44.     }
  45.  
  46.     DPMIAllocateRealCallBack(&cbRegs, 
  47.         setCBDispatch(cbNumber, cbHandler),
  48.                   (void (far**)())&cbAddr);
  49. }
  50.  
  51. //
  52. // Destructor
  53. //
  54. // Release the callback to DPMI host and deallocate the local stack
  55. //
  56. CallBack::~CallBack(void)
  57. {
  58.  
  59.     if (cbNumber != -1)
  60.     {
  61.         DPMIFreeRealCallBack((void (far*)())cbAddr);
  62.         activeCallBacks[cbNumber] = 0;
  63.     }
  64. }
  65.