home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / aspisrc.zip / INIT.C < prev    next >
C/C++ Source or Header  |  1998-11-29  |  3KB  |  120 lines

  1. #include <devdebug.h>
  2. #include <devhelp.h>
  3. #include <devtype.h>
  4. #include <devrp.h>
  5. #include <string.h>
  6. #include <conio.h>
  7. #include "AspiRout.h"
  8.  
  9. // Constant debugging strings (only defined when DEBUG is defined)
  10.  
  11. #if defined(DEBUG)
  12.  
  13. static const char* MSG_CS =                     "Resident Code Size = ";
  14. static const char* MSG_DS =                     "Resident Data Size = ";
  15.  
  16. #else
  17.  
  18. #define            MSG_DEBUG              0
  19. #define            MSG_CS                 0
  20. #define            MSG_DS                 0
  21.  
  22. #endif // DEBUG
  23.  
  24.  
  25.  
  26. // Sign on and installation messages
  27.  
  28. static const char WELCOME[] =
  29.   "\r\n"
  30.   "ASPI Router Version 1.01 installed\r\n"
  31.   "1997 by Daniel Dorau\r\n";
  32. const int WELCOME_LENGTH = sizeof(WELCOME) - 1;
  33.  
  34. static const char NO_SCSIMGR[] =
  35.  "Could not get SCSIMGR$ entry point! ASPI Router NOT loaded.\r\n"
  36.  "Check if OS2ASPI.DMD is loaded.\r\n";
  37. const int NO_SCSIMGR_LENGTH = sizeof(NO_SCSIMGR) - 1;
  38.  
  39. static const char DEVCTXFAILED[] =
  40.  "Device Helper call allocating context hook failed. ASPI Router NOT loaded.\r\n";
  41. const int DEVCTXFAILED_LENGTH = sizeof(DEVCTXFAILED) - 1;
  42.  
  43. static char* AttachName =                       "SCSIMGR$";
  44.  
  45. // Initialize device driver
  46.  
  47. WORD16 StratInit(RP FAR* _rp)
  48.   {
  49.  
  50.   RPInit FAR* rp = (RPInit FAR*)_rp;
  51.   int result=0;
  52.  
  53.   // MANDATORY: Initialize the Device Driver libraries.
  54.   DevInit(rp->In.DevHlp);
  55.  
  56.   // Signal that we've installed successfully by setting the size of
  57.   // our code and data segments.
  58.   rp->Out.FinalCS = OffsetFinalCS;
  59.   rp->Out.FinalDS = OffsetFinalDS;
  60.  
  61. #if defined(DEBUG)
  62.   // Print a sign on message to the debugging terminal.
  63.   cdbg << ALL << endl;
  64.   cdbg << WELCOME << endl;
  65.   cdbg << MSG_CS << hex << setw(4) << OffsetFinalCS
  66.        << setw() << dec << 'h' << endl;
  67.   cdbg << MSG_DS << hex << setw(4) << OffsetFinalDS
  68.        << setw() << dec << 'h' << endl;
  69.   cdbg << endl;
  70. #endif
  71.  
  72.   // Print a sign on message to the console.
  73.   DosPutMessage(1, WELCOME_LENGTH, WELCOME);
  74.  
  75.   //user code
  76.   if (DevAttachDD(AttachName, &idc))
  77.   {
  78. #if defined(DEBUG)
  79.     cdbg << "Could not get SCSIMGR$ entry point!" << endl;
  80. #endif
  81.     DosPutMessage(1, NO_SCSIMGR_LENGTH, NO_SCSIMGR);
  82.     rp->Out.FinalCS=0;
  83.     rp->Out.FinalDS=0;
  84.     return RPDONE | RPERR;
  85.   }
  86.   else
  87. #if defined(DEBUG)
  88.     cdbg << "DevAttachDD successful." << endl;
  89.     cdbg << "Segment=" << hex << setw(4) << idc.Segment << setw() << dec << 'h' << endl;
  90.     cdbg << "Offset=" << hex << setw(4) << idc.Offset << setw() << dec << 'h' << endl;
  91.     cdbg << "Data=" << hex << setw(4) << idc.Data << setw() << dec << 'h' << endl;
  92. #endif
  93.     AspiEntry=idc.Segment;
  94.     AspiEntry=AspiEntry << 16;
  95.     AspiEntry=AspiEntry | (idc.Offset);
  96.     AspiData=idc.Data;
  97. #if defined(DEBUG)
  98.     cdbg << "AspiEntry=" << hex << setw(8) << AspiEntry << setw() << dec << 'h' << endl;
  99.     cdbg << "AspiData=" << hex << setw(4) << AspiData << setw() << dec << 'h' << endl;
  100. #endif
  101.  
  102.   // Allocate Context hook
  103.   Hook1 = DevCtxAllocate((VOID FAR*) ctx_hand);
  104.   if (!Hook1)
  105.   {
  106.     // Signal that we will not initialize without a context hook
  107. #if defined(DEBUG)
  108.     cdbg << "DevCtxAllocate failed." << endl;
  109. #endif
  110.     DosPutMessage(1, DEVCTXFAILED_LENGTH, DEVCTXFAILED);
  111.     rp->Out.FinalCS=0;
  112.     rp->Out.FinalDS=0;
  113.   }
  114. #if defined(DEBUG)
  115.   else cdbg << "DevCtxAllocate returned successfully." << endl;
  116. #endif
  117.   return RPDONE;
  118. }
  119.  
  120.