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

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

unix.superglobalmegacorp.com

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