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 / handles / auto / autos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-11  |  5.6 KB  |  165 lines

  1. /****************************************************************************
  2.                    Microsoft RPC Version 2.0
  3.            Copyright Microsoft Corp. 1992, 1993, 1994- 1996
  4.                           Auto Example
  5.  
  6.     FILE:       autos.c
  7.  
  8.     USAGE:      autos   -p protocol_sequence
  9.                         -e endpoint
  10.                         -m maxcalls
  11.                         -n mincalls
  12.                         -f flag for RpcServerListen wait
  13.                         -a auto_sample_nsi_entry_name
  14.                         -t name_syntax_type
  15.  
  16.     PURPOSE:    Server side of RPC distributed application Auto
  17.  
  18.     FUNCTIONS:  main() - registers server as RPC server
  19.  
  20.     COMMENTS:   This distributed application (time stamp) is implemented
  21.                 using an auto handle.  The server side of the application
  22.                 must export its binding information and make it available
  23.                 to the clients.  The auto handle requires a location
  24.                 service running on a server that is accessible to the client.
  25.  
  26. ****************************************************************************/
  27.  
  28. #include <stdlib.h>
  29. #include <stdio.h>
  30. #include <ctype.h>
  31. #include "auto.h"    // header file generated by MIDL compiler
  32.  
  33. void Usage(char * pszProgramName)
  34. {
  35.     fprintf(stderr, "Usage:  %s\n", pszProgramName);
  36.     fprintf(stderr, " -p protocol_sequence\n");
  37.     fprintf(stderr, " -e endpoint\n");
  38.     fprintf(stderr, " -m maxcalls\n");
  39.     fprintf(stderr, " -n mincalls\n");
  40.     fprintf(stderr, " -f flag for RpcServerListen wait\n");
  41.     fprintf(stderr, " -a auto_sample_nsi_entry_name\n");
  42.     fprintf(stderr, " -t name_syntax_type\n");
  43.     exit(1);
  44. }
  45.  
  46. void _CRTAPI1 main(int argc, char * argv[])
  47. {
  48.     RPC_STATUS status;
  49.     RPC_BINDING_VECTOR * pBindingVector;
  50.  
  51.     unsigned char * pszAutoEntryName    = "/.:/Autohandle_sample";
  52.     unsigned char * pszEndpoint         = "\\pipe\\auto";
  53.     unsigned char * pszProtocolSequence = "ncacn_np";
  54.     unsigned char * pszSecurity         = NULL;
  55.     unsigned int    cMinCalls           = 1;
  56.     unsigned int    cMaxCalls           = 20;
  57.     unsigned int    fDontWait           = FALSE;
  58.     unsigned int    fNameSyntaxType     = RPC_C_NS_SYNTAX_DEFAULT;
  59.     int i;
  60.  
  61.     /* allow the user to override settings with command line switches */
  62.     for (i = 1; i < argc; i++) {
  63.         if ((*argv[i] == '-') || (*argv[i] == '/')) {
  64.             switch (tolower(*(argv[i]+1))) {
  65.             case 'p':  // protocol sequence
  66.                 pszProtocolSequence = argv[++i];
  67.                 break;
  68.             case 'e':
  69.                 pszEndpoint = argv[++i];
  70.                 break;
  71.             case 'm':
  72.                 cMaxCalls = (unsigned int) atoi(argv[++i]);
  73.                 break;
  74.             case 'n':
  75.                 cMinCalls = (unsigned int) atoi(argv[++i]);
  76.                 break;
  77.             case 'f':
  78.                 fDontWait = (unsigned int) atoi(argv[++i]);
  79.                 break;
  80.             case 'a':
  81.                 pszAutoEntryName = argv[++i];
  82.                 break;
  83.             case 't':
  84.                 fNameSyntaxType = (unsigned int) atoi(argv[++i]);
  85.                 break;
  86.             case 'h':
  87.             case '?':
  88.             default:
  89.                 Usage(argv[0]);
  90.             }
  91.         }
  92.         else
  93.             Usage(argv[0]);
  94.     }
  95.  
  96.     status = RpcServerUseProtseqEp(pszProtocolSequence,
  97.                                    cMaxCalls,
  98.                                    pszEndpoint,
  99.                                    pszSecurity);  // Security descriptor
  100.     printf("RpcServerUseProtseqEp returned 0x%x\n", status);
  101.     if (status) {
  102.         exit(status);
  103.     }
  104.  
  105.     status = RpcServerRegisterIf(autoh_ServerIfHandle,  // interface to register
  106.                                  NULL,   // MgrTypeUuid
  107.                                  NULL);  // MgrEpv; null means use default
  108.     printf("RpcServerRegisterIf returned 0x%x\n", status);
  109.     if (status) {
  110.         exit(status);
  111.     }
  112.  
  113.     status = RpcServerInqBindings(&pBindingVector);
  114.     printf("RpcServerInqBindings returned 0x%x\n", status);
  115.     if (status) {
  116.         exit(status);
  117.     }
  118.  
  119.     status = RpcNsBindingExport(fNameSyntaxType,   // name syntax type
  120.                                 pszAutoEntryName,  // nsi entry name
  121.                                 autoh_ServerIfHandle,
  122.                                 pBindingVector,    // set in previous call
  123.                                 NULL);             // UUID vector
  124.     printf("RpcNsBindingExport returned 0x%x\n", status);
  125.     if (status) {
  126.         exit(status);
  127.     }
  128.  
  129.     printf("Calling RpcServerListen\n");
  130.     status = RpcServerListen(cMinCalls,
  131.                              cMaxCalls,
  132.                              fDontWait);  // wait flag
  133.     printf("RpcServerListen returned: 0x%x\n", status);
  134.     if (status) {
  135.         exit(status);
  136.     }
  137.  
  138.     if (fDontWait) {
  139.         printf("Calling RpcMgmtWaitServerListen\n");
  140.         status = RpcMgmtWaitServerListen();  //  wait operation
  141.         printf("RpcMgmtWaitServerListen returned: 0x%x\n", status);
  142.         if (status) {
  143.             exit(status);
  144.         }
  145.     }
  146.  
  147. }  // end main()
  148.  
  149.  
  150. /*********************************************************************/
  151. /*                 MIDL allocate and free                            */
  152. /*********************************************************************/
  153.  
  154. void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
  155. {
  156.     return(malloc(len));
  157. }
  158.  
  159. void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
  160. {
  161.     free(ptr);
  162. }
  163.  
  164. /* end file autos.c */
  165.