home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / QPROC.ZIP / QPINIT.C < prev    next >
C/C++ Source or Header  |  1990-10-18  |  5KB  |  181 lines

  1. /*****************************************************************/ 
  2. /**             Microsoft LAN Manager            **/ 
  3. /**           Copyright(c) Microsoft Corp., 1985-1990        **/ 
  4. /*****************************************************************/ 
  5. /****************************** Module Header ******************************\
  6.  
  7. Module Name: QPINIT.C
  8.  
  9. This file contains the initialization code for the PM Spooler Queue Processor
  10. package (PMPRINT.QPR).
  11.  
  12. Public Procedures:
  13.  
  14.     EnterSplSem             - code to enter the spooler semaphore
  15.     LeaveSplSem             - code to leave the spooler semaphore
  16.     SplExitListProc         - called by OS/2 during process exit
  17.     SplLoadProc             - called by OS/2 during process startup
  18.     SplInit                 - called by PMSHELL during boot
  19.     SplQmInitialize         - called by PMSPOOL.EXE during startup
  20.     SplInstall              - called by SPOOL.EXE to install spooler
  21.     SplQmSpoolerPresent     - called by DevOpenDC in PMGPI to see if spooler
  22.                               running.
  23.     SplQmChooseLogAddr      - called by DevOpenDC in PMGPI to map a queue name
  24.                               to a port address.
  25.  
  26. History:
  27.  16-Aug-88 [stevewo]  Created.
  28.  14-Feb-90 [thomaspa] DBCS fixes.
  29.  
  30.   WARNING:  This module placed in a code segment other than the default
  31.             segment.  All function calls from this module to others in
  32.             the default segment must be far calls.  For this reason,
  33.             do not use the standard str*f() functions directly.  Instead
  34.             use the wrapper functions as found in strwrap.c.
  35.  
  36. \***************************************************************************/
  37.  
  38. #define INCL_DOSPFS
  39. #define INCL_WINP_MISC
  40. #define INCL_WINWINDOWMGR
  41.  
  42. #include "pmprint.h"
  43. #include <netlib.h>
  44. #include <strapi.h>
  45.  
  46. /*
  47.  * internal function prototypes
  48.  */
  49. VOID FreeQProcInstResources(PID uPid, USHORT uExitReason);
  50.  
  51.  
  52. /* Global Variables */
  53. SEL selGlobalSeg;  /* Pointer to global info segment */
  54. USHORT usCodePage; /* The current Code page */
  55.  
  56. /* change the offset from the beginning of the job structure to a pointer */
  57. #define OFFSETTOPTR(p, np) np->p = (PVOID)((PBYTE)np + OFFSETOF(np->p))
  58.  
  59.  
  60. VOID EXPENTRY SplExitListProc( uExitType )
  61. USHORT uExitType;
  62. {
  63.     if (uExitType)
  64.         SplWarning( "SplExitListProc called for PID: %0x  Reason: %2x",
  65.                     pLocalInfo->pidCurrent, uExitType );
  66.  
  67.     if (bInitDone) {
  68.       EnterSplSem();
  69.         FreeQProcInstResources(pLocalInfo->pidCurrent, uExitType);
  70.       ExitSplSem();
  71.     }
  72.  
  73.     DosExitList( EXLST_EXIT, (PFNEXITLIST)SplExitListProc );
  74. }
  75.  
  76.  
  77. BOOL near SplLoadProc( hModule, cbHeap )
  78. HMODULE hModule;
  79. USHORT cbHeap;
  80. {
  81.     SEL selGInfo, selLInfo;
  82.  
  83.     /* Do one time initialization first time through */
  84.  
  85.     if (!hSplModule) {
  86.         /* Remember our module handle for resources */
  87.         hSplModule = hModule;
  88.  
  89.         /* Remember our heap size for WinCreateHeap */
  90.         cbSplHeap  = cbHeap;
  91.         hSplHeap   = NULL;
  92.  
  93.         /* Initialize our fast, safe, RAM semaphore */
  94.         memsetf( &semPMPRINT, 0, sizeof( FSRSEM ));
  95.         semPMPRINT.Length = sizeof( FSRSEM );
  96.         semPMPRINT.Timeout = -1L;
  97.  
  98.         szNull[0] = '\0';
  99.  
  100.         pQProcInstances = NULL;
  101.  
  102.         DosGetInfoSeg( &selGInfo, &selLInfo );
  103.         pGlobalInfo = MAKEPGINFOSEG(selGInfo);
  104.         pLocalInfo  = MAKEPLINFOSEG(selLInfo);
  105.         SplInit();
  106.  
  107.         }
  108.  
  109.     /* Fill in the array of string pointers so it is visible for each process */
  110.     WinLoadStringTable( HABX, hSplModule, SPL_MIN_STRING_ID,
  111.                                           SPL_MAX_STRING_ID,
  112.                                           pszSplStrings );
  113.  
  114.     /* For each process that attaches to us, install an exitlist handler */
  115.  
  116.     DosExitList( EXLST_ADD, (PFNEXITLIST)SplExitListProc );
  117.  
  118.     /* Return success */
  119.  
  120.     return( 1 );
  121. }
  122.  
  123. BOOL EXPENTRY SplInit( VOID )
  124. {
  125.     BOOL result;
  126.     SEL selLocalSeg;
  127.     USHORT cbCodePgLst;
  128.  
  129.     if (bInitDone) {
  130.         SplPanic( "SplInit called twice", 0, 0 );
  131.         return( FALSE );
  132.     }
  133.  
  134.     bInitDone = TRUE;
  135.  
  136.     init_strlib();
  137.  
  138.   EnterSplSem();
  139.  
  140.     if (!(hSplHeap = WinCreateHeap( (SEL)(((ULONG)((PCH)&hSplHeap)) >> 16),
  141.                                     cbSplHeap, 0, 0, 255,
  142. #ifdef DEBUG
  143.                                     HM_VALIDSIZE | HM_MOVEABLE
  144. #else
  145.                                     0
  146. #endif
  147.                              )      )) {
  148.         SplPanic( "Unable to create local heap", 0, 0 );
  149.         result = FALSE;
  150.     }
  151.  
  152.  
  153.   DosGetInfoSeg(&selGlobalSeg, &selLocalSeg);
  154.  
  155.   DosGetCp(2, &usCodePage, &cbCodePgLst);
  156.  
  157.   LeaveSplSem();
  158.  
  159.     return( result );
  160. }
  161.  
  162.  
  163. VOID FreeQProcInstResources(PID uPid, USHORT uExitReason)
  164. {
  165.     PQPROCINST pQProc = pQProcInstances;
  166.  
  167.     while (pQProc)
  168.         if (pQProc->uPid == uPid) {
  169.             SplWarning( "SplExitList: HPROC: %0x not freed by PMPRINT",
  170.                         pQProc, 0);
  171.             pQProc = DestroyQProcInst( pQProc );
  172.             }
  173.         else
  174.             pQProc = pQProc->pNext;
  175.  
  176.     return;
  177.  
  178.     /* not reached: */
  179.     uExitReason;
  180. }
  181.