Annotation of mstools/samples/rpc/doctor/doctors.c, revision 1.1.1.2

1.1       root        1: /****************************************************************************
                      2:                          Microsoft RPC Version 1.0
                      3:                        Copyright Microsoft Corp. 1992
                      4:                               Doctor Example
                      5: 
1.1.1.2 ! root        6:     FILE:      doctors.c
        !             7:     USAGE:     doctors  -p protocol_sequence
1.1       root        8:                         -e endpoint
1.1.1.2 ! root        9:                         -m max calls
        !            10:                         -n min calls
        !            11:                         -s security descriptor
        !            12:                         -f flag for RpcServerListen
        !            13: 
1.1       root       14:     PURPOSE:   Server side of RPC distributed application Doctor
                     15:     FUNCTIONS:  main() - registers server as RPC server
                     16:     COMMENTS:  RPC version of an example program provided with:
                     17:                Microsoft LISP Artificial Intelligence Programming
                     18:                Environment for the MS-DOS Operating System
                     19:                Portions Copyright (C) Microsoft Corporation 1986
                     20:                Copyright (C) Soft Warehouse, Inc.1979,1980,1982,1983,1985,1986
                     21:                Converted from LISP to C by David Bullock
                     22:                Copyright (C) Microsoft Corporation 1992
                     23: ****************************************************************************/
                     24: #include <stdlib.h>
                     25: #include <windows.h>
                     26: #include <string.h>
                     27: #include <stdio.h>
                     28: #include <ctype.h>
                     29: #include <rpc.h>       // RPC data structures and APIs
                     30: #include "doctor.h"    // header file generated by MIDL compiler
                     31: 
                     32: #define PURPOSE \
                     33: "This Microsoft RPC Version 1.0 sample program demonstrates\n\
                     34: the use of the [string] and [size_is] attributes. For more\n\
                     35: information about attributes and RPC API functions, see the\n\
                     36: RPC programming guide and reference.\n\n"
                     37: 
                     38: void Usage(char * pszProgramName)
                     39: {
                     40:     fprintf(stderr, "%s", PURPOSE);
                     41:     fprintf(stderr, "Usage:  %s\n", pszProgramName);
                     42:     fprintf(stderr, " -p protocol_sequence\n");
                     43:     fprintf(stderr, " -e endpoint\n");
1.1.1.2 ! root       44:     fprintf(stderr, " -m maxcalls\n");
        !            45:     fprintf(stderr, " -n mincalls\n");
        !            46:     fprintf(stderr, " -f flag_wait_op\n");
        !            47:     fprintf(stderr, " -s security_descriptor\n");
1.1       root       48:     exit(1);
                     49: }
                     50: 
1.1.1.2 ! root       51: void _CRTAPI1 main(int argc, char * argv[])
1.1       root       52: {
                     53:     RPC_STATUS status;
                     54:     unsigned char * pszProtocolSequence = "ncacn_np";
1.1.1.2 ! root       55:     unsigned char * pszSecurity        = NULL;
1.1       root       56:     unsigned char * pszEndpoint        = "\\pipe\\doctor";
1.1.1.2 ! root       57:     unsigned int    cMinCalls          = 1;
        !            58:     unsigned int    cMaxCalls          = 20;
        !            59:     unsigned int    fDontWait          = FALSE;
1.1       root       60:     int i;
                     61: 
                     62:     // allow the user to override settings with command line switches
                     63:     for (i = 1; i < argc; i++) {
                     64:        if ((*argv[i] == '-') || (*argv[i] == '/')) {
                     65:            switch (tolower(*(argv[i]+1))) {
                     66:                case 'p':  // protocol sequence
                     67:                    pszProtocolSequence = argv[++i];
                     68:                    break;
                     69:                case 'e':
                     70:                    pszEndpoint = argv[++i];
                     71:                    break;
1.1.1.2 ! root       72:                case 'm':
        !            73:                    cMaxCalls = (unsigned int) atoi(argv[++i]);
        !            74:                    break;
        !            75:                case 'n':
        !            76:                    cMinCalls = (unsigned int) atoi(argv[++i]);
1.1       root       77:                    break;
1.1.1.2 ! root       78:                case 'f':
        !            79:                    fDontWait = (unsigned int) atoi(argv[++i]);
        !            80:                    break;
        !            81:                case 's':
        !            82:                    pszSecurity = argv[++i];
1.1       root       83:                    break;
                     84:                case 'h':
                     85:                case '?':
                     86:                default:
                     87:                    Usage(argv[0]);
                     88:            }
                     89:        }
                     90:        else
                     91:            Usage(argv[0]);
                     92:     }
                     93:     status = RpcServerUseProtseqEp(pszProtocolSequence,
1.1.1.2 ! root       94:                                   cMaxCalls, // max concurrent calls
1.1       root       95:                                    pszEndpoint,
1.1.1.2 ! root       96:                                   pszSecurity);  // Security descriptor
        !            97:     printf("RpcServerUseProtseqEp returned 0x%x\n", status);
1.1       root       98:     if (status) {
1.1.1.2 ! root       99:        exit(status);
1.1       root      100:     }
                    101: 
1.1.1.2 ! root      102:     status = RpcServerRegisterIf(
        !           103:                 doctor_ServerIfHandle, // interface to register
        !           104:                 NULL,                // MgrTypeUuid
        !           105:                 NULL);               // MgrEpv; null means use default
        !           106:     printf("RpcServerRegisterIf returned 0x%x\n", status);
1.1       root      107:     if (status) {
1.1.1.2 ! root      108:        exit(status);
1.1       root      109:     }
                    110:     printf("The doctor is in.\n");
1.1.1.2 ! root      111: 
        !           112:     printf("Calling RpcServerListen\n");
        !           113:     status = RpcServerListen(cMinCalls,
        !           114:                             cMaxCalls,
        !           115:                             fDontWait);
        !           116:     printf("RpcServerListen returned: 0x%x\n", status);
1.1       root      117:     if (status) {
1.1.1.2 ! root      118:        exit(status);
1.1       root      119:     }
                    120: 
1.1.1.2 ! root      121:     if (fDontWait) {
        !           122:        printf("Calling RpcMgmtWaitServerListen\n");
        !           123:        status = RpcMgmtWaitServerListen();  //  wait operation
        !           124:        printf("RpcMgmtWaitServerListen returned: 0x%x\n", status);
        !           125:        if (status) {
        !           126:            exit(status);
        !           127:        }
        !           128:     }
1.1       root      129: } /* end main() */
                    130: 
                    131: 
                    132: // ====================================================================
                    133: //                MIDL allocate and free
                    134: // ====================================================================
                    135: 
                    136: void * MIDL_user_allocate(size_t len)
                    137: {
                    138:     return(malloc(len));
                    139: }
                    140: 
                    141: void MIDL_user_free(void * ptr)
                    142: {
                    143:     free(ptr);
                    144: }
1.1.1.2 ! root      145: /* end Doctors.c */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.