home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / rpc / rpcssm / rpcssmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-11  |  4.0 KB  |  159 lines

  1. /****************************************************************************
  2.                    Microsoft RPC Version 2.0
  3.            Copyright Microsoft Corp. 1992, 1993, 1994- 1996
  4.                         rpcssm Example
  5.  
  6.     FILE:       rpcssmp.c
  7.  
  8.     PURPOSE:    Remote procedures used in server application rpcssms
  9.  
  10.     FUNCTIONS:  InOutList() - Adds new nodes to the list.
  11.  
  12.     COMMENTS:   This distributed application uses the rpcssm package.
  13.  
  14. ****************************************************************************/
  15.  
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include "rpcssm.h"    // header file generated by MIDL compiler
  20.  
  21. void AllocateSmList( PBOX * ppBox, short sListSize );
  22. void InitList( PBOX  pBox, long lStartValue );
  23. void PrintList( PBOX pBox );
  24.  
  25. void * pvPersistent    = NULL;
  26. void * pvNonPersistent = NULL;
  27.  
  28. void
  29. InOutList( PBOX * ppBox )
  30. {
  31.     /* As this routine executes in the enabled memory environment,
  32.        a convienient way to allocate a non-persistent memory
  33.        is to use RpcSmAllocate or RpcSsAllocate.
  34.     */
  35.  
  36.     if ( ppBox) {
  37.  
  38.         PBOX p = *ppBox;
  39.         while ( p->next )
  40.             p = p->next;
  41.  
  42.         AllocateSmList( & p->next, 2 );
  43.     }
  44.     else {
  45.         AllocateSmList( ppBox, 5 );
  46.     }
  47.  
  48.     InitList( *ppBox, 0x98760000 );
  49.     PrintList( *ppBox );
  50.  
  51.     /* To allocate a memory to be available after the call, means other
  52.        than RpcS*Allocate with default allocators should be used.
  53.     */
  54.  
  55.     if ( pvPersistent == NULL )
  56.         {
  57.         pvPersistent = malloc(100); /* or midl_user_allocate(100) */
  58.         }
  59.  
  60.     pvNonPersistent = RpcSsAllocate( 100 );
  61. }
  62.  
  63. /* The Shutdown procedure tells the server to stop listening */
  64. /* for client requests.                                      */
  65. void Shutdown(void)
  66. {
  67.     RPC_STATUS status;
  68.  
  69.     /* Freeing the persistent memory */
  70.  
  71.     if ( pvPersistent )
  72.         free( pvPersistent );
  73.  
  74.     printf("Calling RpcMgmtStopServerListening\n");
  75.     status = RpcMgmtStopServerListening(NULL);
  76.     printf("RpcMgmtStopServerListening returned: 0x%x\n", status);
  77.     if (status) {
  78.         exit(status);
  79.     }
  80.  
  81.     printf("Calling RpcServerUnregisterIf\n");
  82.     status = RpcServerUnregisterIf(NULL, NULL, FALSE);
  83.     printf("RpcServerUnregisterIf returned 0x%x\n", status);
  84.     if (status) {
  85.         exit(status);
  86.     }
  87. }
  88.  
  89. //=====================================================================
  90. //        List allocation/deallocation routines
  91. //=====================================================================
  92.  
  93. void
  94. AllocateSmList( PBOX * ppBox, short sListSize)
  95. {
  96.     PBOX    pBox, head;
  97.     int     i = 0;
  98.  
  99.     //.. Allocate a list of boxes, if needed (when *ppBox==NULL).
  100.  
  101.     if ( *ppBox == NULL ) {
  102.  
  103.         RPC_STATUS status;
  104.  
  105.         head = 0;
  106.         for (i = 0; i < sListSize; i++)
  107.         {
  108.             pBox = (PBOX) RpcSmAllocate( sizeof(LBOX), &status);
  109.             if ( status != RPC_S_OK )
  110.             {
  111.                 printf("AllocateList FAILED: not enough memory\n");
  112.                 break;
  113.             }
  114.             pBox->next = head;
  115.             head = pBox;
  116.         }
  117.         *ppBox = head;
  118.     }
  119.     printf("%d nodes allocated.\n", i);
  120. }
  121.  
  122. //=====================================================================
  123. //        Initialization and pprint routines
  124. //=====================================================================
  125.  
  126. void  InitList( PBOX  pBox, long lStartValue )
  127. {
  128.     int i = 0;
  129.  
  130.     while( pBox ) {
  131.         pBox->data = lStartValue + ++i;
  132.         pBox = pBox->next;
  133.     }
  134.     printf("%d nodes inited.\n", i);
  135. }
  136.  
  137. // --------------------------------------------------------------------
  138.  
  139. void
  140. PrintList( PBOX  pBox )
  141. {
  142.     int i = 0;
  143.  
  144.  
  145.     while( pBox ) {
  146.  
  147.         if ( (i % 4) != 0 )
  148.             printf("  data[%d]= %lx", i, pBox->data);
  149.         else
  150.             printf("\n  data[%d]= %lx", i, pBox->data);
  151.         pBox = pBox->next;
  152.         i++;
  153.     }
  154.     printf("\n" );
  155. }
  156.  
  157.  
  158. /* end file rpcssmp.c */
  159.