home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / dax1.exe / CP / CPS / CPINIT.C < prev    next >
Text File  |  1992-07-15  |  4KB  |  112 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      cpinit.c                                              ║
  4. //   ║ abstract:    This module contains the initialization code for the  ║
  5. //   ║              server side of the communication protocol layer.      ║
  6. //   ║                                                                    ║
  7. //   ║ environment: NetWare 3.x v3.11                                     ║
  8. //   ║              Network C for NLMs SDK                                ║
  9. //   ║              CLib v3.11                                            ║
  10. //   ║                                                                    ║
  11. //   ║  This software is provided as is and carries no warranty           ║
  12. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  13. //   ║  warranties of merchantability, title and fitness for a particular ║
  14. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  15. //   ║  your requirements or that the software is without defect or error ║
  16. //   ║  or that operation of the software will be uninterrupted.  You are ║
  17. //   ║  using the software at your risk.  The software is not a product   ║
  18. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  19. //   ║                                                                    ║
  20. //   ╟────────────────────────────────────────────────────────────────────╢
  21. //   ║ maintenance history:                                               ║
  22. //   ║ level    date      pi   description                                ║
  23. //   ╟────────────────────────────────────────────────────────────────────╢
  24. //   ║  001   01/29/92    kl   initial release.                           ║
  25. //   ╚════════════════════════════════════════════════════════════════════╝
  26.  
  27. #include <string.h>
  28. #include <conio.h>
  29. #include <process.h>
  30. #include <library.h>
  31. #include <sap.h>
  32. #include "cp/cpsys.h"
  33.  
  34. //------------------------------------------------------------------------
  35.  
  36. STATIC  WORD    messageSocket;              // socket messages received on
  37. STATIC  WORD    cpInited;                   // TRUE if we're initialized
  38.  
  39. //
  40. //  This API returns the socket that we are advertising our services on
  41. //
  42.  
  43. WORD    CPGetAdvertisingSocket()
  44. {
  45.         return messageSocket;
  46. }
  47.  
  48. //------------------------------------------------------------------------
  49.  
  50. STATIC  LONG    SAPHandle;                  // handle Advertise returns...
  51.  
  52. //
  53. //  This API initializes the server application.  It begins advertising
  54. //  our service using SAP.
  55. //
  56.  
  57. T_RC    CPInitialize(char *srvname, 
  58.                      WORD type, 
  59.                      void (*EnqueueAPI)(UINT32, void *),
  60.                      int (*ioRoutine)(char *fmt, ...))
  61. {
  62.         //
  63.         //  Don't be initialized twice!
  64.         //
  65.         if( cpInited ) return TRUE;
  66.         cpInited = TRUE;
  67.         //
  68.         //  ioRoutine is called to print messages to the console.
  69.         //
  70.         if( ioRoutine ) _CPioRoutine = ioRoutine;
  71.         //
  72.         //  Open the socket, then initialize the remaining modules.
  73.         //
  74.         if( IpxOpenSocket(&messageSocket) != NULL ) goto error0;
  75.         if( CPInitializeSendLogic() )               goto error1;
  76.         if( CPInitializeRecvLogic(EnqueueAPI) )     goto error1;
  77.         if( CPInitializeConnLogic() )               goto error1;
  78.         //
  79.         //  Start advertising the server
  80.         //
  81.         if((SAPHandle = AdvertiseService(type,srvname,messageSocket)) == -1){
  82.             goto error1;
  83.         }
  84.         return CP_SUCCESS;
  85.     error0:
  86.         return CP_TRANSPORT_ERROR;
  87.     error1:
  88.         CPDeInitialize();
  89.         goto error0;
  90. }
  91.  
  92. void    CPDeInitialize()
  93. {
  94.         if( cpInited ){
  95.             IpxCloseSocket(messageSocket);      // kill receiving ECBs
  96.             if( SAPHandle ) ShutdownAdvertising(SAPHandle);
  97.             CPDeInitializeConnLogic();
  98.             CPDeInitializeRecvLogic();
  99.             CPDeInitializeSendLogic();
  100.             _CPioRoutine = __CPIgnoreIO;
  101.             cpInited = FALSE;
  102.         }
  103. }
  104.  
  105. main()
  106. {
  107.         ConsolePrintf("CPLayer: APIs ready for use\r\n");
  108.         AtUnload(CPDeInitialize);
  109.         xDIAG1(RenameThread(GetThreadID(),"CP_INIT"));
  110.         while(1) SuspendThread(GetThreadID());
  111. }
  112.