Annotation of mstools/samples/rpc/handles/auto/autos.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:                           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:     
1.1       root       18:     FUNCTIONS:  main() - registers server as RPC server
1.1.1.3 ! root       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.
1.1       root       25: 
                     26: ****************************************************************************/
1.1.1.3 ! root       27: 
1.1       root       28: #include <stdlib.h>
                     29: #include <stdio.h>
1.1.1.3 ! root       30: #include <ctype.h>                             
        !            31: #include "auto.h"    // header file generated by MIDL compiler
1.1       root       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");
1.1.1.2   root       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");
1.1       root       43:     exit(1);
                     44: }
                     45: 
1.1.1.2   root       46: void _CRTAPI1 main(int argc, char * argv[])
1.1       root       47: {
                     48:     RPC_STATUS status;
                     49:     RPC_BINDING_VECTOR * pBindingVector;
                     50: 
1.1.1.3 ! root       51:     unsigned char * pszAutoEntryName    = "/.:/Autohandle_sample";
        !            52:     unsigned char * pszEndpoint         = "\\pipe\\auto";
1.1       root       53:     unsigned char * pszProtocolSequence = "ncacn_np";
1.1.1.3 ! root       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;
1.1       root       59:     int i;
                     60: 
1.1.1.3 ! root       61:     /* allow the user to override settings with command line switches */
1.1       root       62:     for (i = 1; i < argc; i++) {
1.1.1.3 ! root       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]);
1.1       root       94:     }
                     95: 
                     96:     status = RpcServerUseProtseqEp(pszProtocolSequence,
1.1.1.3 ! root       97:                                    cMaxCalls,   
1.1       root       98:                                    pszEndpoint,
1.1.1.3 ! root       99:                                    pszSecurity);  // Security descriptor
1.1       root      100:     printf("RpcServerUseProtseqEp returned 0x%x\n", status);
                    101:     if (status) {
1.1.1.3 ! root      102:         exit(status);
1.1       root      103:     }
                    104: 
1.1.1.3 ! root      105:     status = RpcServerRegisterIf(autoh_ServerIfHandle,  // interface to register
        !           106:                                  NULL,   // MgrTypeUuid
        !           107:                                  NULL);  // MgrEpv; null means use default
1.1       root      108:     printf("RpcServerRegisterIf returned 0x%x\n", status);
                    109:     if (status) {
1.1.1.3 ! root      110:         exit(status);
1.1       root      111:     }
                    112: 
                    113:     status = RpcServerInqBindings(&pBindingVector);
                    114:     printf("RpcServerInqBindings returned 0x%x\n", status);
                    115:     if (status) {
1.1.1.3 ! root      116:         exit(status);
1.1       root      117:     }
                    118: 
1.1.1.3 ! root      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 
1.1       root      124:     printf("RpcNsBindingExport returned 0x%x\n", status);
                    125:     if (status) {
1.1.1.3 ! root      126:         exit(status);
1.1       root      127:     }
1.1.1.3 ! root      128: 
1.1       root      129:     printf("Calling RpcServerListen\n");
1.1.1.2   root      130:     status = RpcServerListen(cMinCalls,
1.1.1.3 ! root      131:                              cMaxCalls,
        !           132:                              fDontWait);  // wait flag 
1.1       root      133:     printf("RpcServerListen returned: 0x%x\n", status);
                    134:     if (status) {
1.1.1.3 ! root      135:         exit(status);
1.1       root      136:     }
                    137: 
1.1.1.2   root      138:     if (fDontWait) {
1.1.1.3 ! root      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:         }
1.1.1.2   root      145:     }
1.1       root      146: 
1.1.1.3 ! root      147: }  // end main() 
        !           148: 
1.1       root      149: 
1.1.1.3 ! root      150: /*********************************************************************/
        !           151: /*                 MIDL allocate and free                            */
        !           152: /*********************************************************************/
1.1       root      153: 
1.1.1.3 ! root      154: void __RPC_FAR * __RPC_API midl_user_allocate(size_t len)
1.1       root      155: {
                    156:     return(malloc(len));
                    157: }
                    158: 
1.1.1.3 ! root      159: void __RPC_API midl_user_free(void __RPC_FAR * ptr)
1.1       root      160: {
                    161:     free(ptr);
                    162: }
                    163: 
1.1.1.3 ! root      164: /* end file autos.c */

unix.superglobalmegacorp.com

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