Annotation of mstools/samples/rpc/data/xmit/xmitc.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:                        xmit Example
        !             5: 
        !             6:     FILE:       xmitc.c
        !             7: 
        !             8:     USAGE:      xmitc  -n network_address
        !             9:                        -p protocol_sequence
        !            10:                        -e endpoint
        !            11:                        -o options
        !            12:                        -c count of elements in linked list
        !            13:                        -v value of first element in linked list
        !            14:                        -d delta between values in linked list
        !            15: 
        !            16:     PURPOSE:    Client side of RPC distributed application.
        !            17:                 This sample demonstrates the transmit_as example.
        !            18:                 A doubly-linked list is transmitted over the network
        !            19:                 as a sized array.
        !            20: 
        !            21:     RELATED:    xmits.c - server main
        !            22:                 xmitp.c - remote procedures
        !            23:                 xmitu.c - utility procedures
        !            24: 
        !            25:     FUNCTIONS:  main() - bind to server and call remote procedure
        !            26: 
        !            27:     COMMENTS:   This sample program generates a linked list to
        !            28:                 demonstrate how a list with aliasing can be transmitted
        !            29:                 using the transmit_as attribute as a sized array.
        !            30:                 The pointers are rebuilt on the server side.
        !            31: 
        !            32:                 The [transmit_as] attribute (used in the typedef of
        !            33:                 DOUBLE_LINK_TYPE in the file XMIT.IDL) requires the
        !            34:                 four user-supplied functions whose names start with
        !            35:                 the name of the presented type, DOUBLE_LINK_TYPE.
        !            36: 
        !            37:                 The [in, out] attributes applied to remote procedure
        !            38:                 parameters require the two user-supplied functions
        !            39:                 midl_user_allocate and midl_user_free.
1.1       root       40: 
1.1.1.3 ! root       41:                 The other functions are utilities that are used to
        !            42:                 build or display the data structures.
1.1       root       43: 
                     44: 
                     45: ****************************************************************************/
1.1.1.3 ! root       46: 
1.1       root       47: #include <stdlib.h>
1.1.1.3 ! root       48: #include <stdio.h>
        !            49: #include <ctype.h>
1.1       root       50: #include "xmit.h"     // header file generated by MIDL compiler
1.1.1.2   root       51: #include "xmitu.h"    // utility function prototypes
                     52: 
1.1       root       53: #define PURPOSE \
                     54: "This Microsoft RPC Version 1.0 sample program demonstrates\n\
                     55: the use of the [transmit_as] attribute. For more information\n\
                     56: about the attributes and the RPC API functions, see the\n\
                     57: RPC programming guide and reference.\n\n"
                     58: 
                     59: #define MAX_ELEMENTS 50
                     60: 
                     61: void Usage(char * pszProgramName)
                     62: {
                     63:     fprintf(stderr, "%s", PURPOSE);
                     64:     fprintf(stderr, "Usage:  %s\n", pszProgramName);
                     65:     fprintf(stderr, " -p protocol_sequence\n");
                     66:     fprintf(stderr, " -n network_address\n");
                     67:     fprintf(stderr, " -e endpoint\n");
                     68:     fprintf(stderr, " -o options\n");
                     69:     fprintf(stderr, " -c count_of_elements\n");
                     70:     fprintf(stderr, " -v value\n");
                     71:     fprintf(stderr, " -d delta\n");
                     72:     exit(1);
                     73: }
                     74: 
1.1.1.2   root       75: void _CRTAPI1 main(int argc, char **argv)
1.1       root       76: {
1.1.1.3 ! root       77:     RPC_STATUS status;
        !            78:     unsigned char * pszUuid             = NULL;
1.1       root       79:     unsigned char * pszProtocolSequence = "ncacn_np";
                     80:     unsigned char * pszNetworkAddress   = NULL;
1.1.1.3 ! root       81:     unsigned char * pszEndpoint         = "\\pipe\\xmit";
1.1       root       82:     unsigned char * pszOptions          = NULL;
1.1.1.3 ! root       83:     unsigned char * pszStringBinding    = NULL;
1.1       root       84:     int i;
                     85:     int cElements = 10;
                     86:     short sValue = 100;
                     87:     short sDelta = 10;
                     88: 
1.1.1.3 ! root       89:     DOUBLE_LINK_TYPE *pFirst, *pCurrent;
1.1       root       90: 
1.1.1.3 ! root       91:     /* allow the user to override settings with command line switches */
1.1       root       92:     for (i = 1; i < argc; i++) {
1.1.1.3 ! root       93:         if ((*argv[i] == '-') || (*argv[i] == '/')) {
        !            94:             switch (tolower(*(argv[i]+1))) {
        !            95:             case 'p':  // protocol sequence
        !            96:                 pszProtocolSequence = argv[++i];
        !            97:                 break;
        !            98:             case 'n':  // network address
        !            99:                 pszNetworkAddress = argv[++i];
        !           100:                 break;
        !           101:             case 'e':
        !           102:                 pszEndpoint = argv[++i];
        !           103:                 break;
        !           104:             case 'o':
        !           105:                 pszOptions = argv[++i];
        !           106:                 break;
        !           107:             case 'c':
        !           108:                 cElements = atoi(argv[++i]);
        !           109:                 if (cElements > MAX_ELEMENTS)
        !           110:                     cElements = MAX_ELEMENTS;
        !           111:                 break;
        !           112:             case 'v':
        !           113:                 sValue = (short)atoi(argv[++i]);
        !           114:                 break;
        !           115:             case 'd':
        !           116:                 sDelta = (short)atoi(argv[++i]);
        !           117:                 break;
        !           118:             case 'h':
        !           119:             case '?':
        !           120:             default:
        !           121:                 Usage(argv[0]);
        !           122:             }
        !           123:         }
        !           124:         else
        !           125:             Usage(argv[0]);
1.1       root      126:     }
1.1.1.3 ! root      127: 
        !           128:     /* initialize a list with a number of elements */
1.1       root      129:     pFirst = InsertNewNode(sValue, NULL);
1.1.1.3 ! root      130:     pCurrent = pFirst;   // assign some values to the list nodes 
        !           131:     sValue += sDelta;    // make them different values 
1.1       root      132: 
                    133:     for (i = 1; i < cElements; i++) {
1.1.1.3 ! root      134:         pCurrent = InsertNewNode(sValue, pCurrent);
        !           135:         sValue += sDelta;
1.1       root      136:     }
                    137:     ListWalkProc(pFirst);
                    138: 
1.1.1.3 ! root      139:     /* Use a convenience function to concatenate the elements of the string */
        !           140:     /* binding into the syntax needed by RpcBindingFromStringBinding.       */
1.1       root      141:     status = RpcStringBindingCompose(pszUuid,
                    142:                                      pszProtocolSequence,
                    143:                                      pszNetworkAddress,
                    144:                                      pszEndpoint,
                    145:                                      pszOptions,
                    146:                                      &pszStringBinding);
                    147:     printf("RpcStringBindingCompose returned 0x%x\n", status);
                    148:     printf("pszStringBinding = %s\n", pszStringBinding);
1.1.1.3 ! root      149:     if (status) {
        !           150:         exit(status);
        !           151:     }
1.1       root      152: 
1.1.1.3 ! root      153:     /* Set the binding handle that will be used to bind to the server. */
1.1       root      154:     status = RpcBindingFromStringBinding(pszStringBinding,
1.1.1.3 ! root      155:                                          &hXmit);
1.1       root      156:     printf("RpcBindingFromStringBinding returned 0x%x\n", status);
1.1.1.3 ! root      157:     if (status) {
        !           158:         exit(status);
        !           159:     }
1.1       root      160: 
                    161:     printf("Calling the remote procedure 'ModifyListProc'\n");
1.1.1.3 ! root      162:     ModifyListProc(pFirst);  // call the remote procedure
1.1       root      163: 
                    164:     printf("Calling the remote procedure 'Shutdown'\n");
1.1.1.3 ! root      165:     Shutdown();  // shut down the server side
1.1       root      166: 
                    167:     printf("After ModifyListProc, the list appears as follows:\n");
                    168:     ListWalkProc(pFirst);  // call the utility that displays the list
                    169: 
1.1.1.3 ! root      170:     /* The calls to the remote procedures are complete.            */
        !           171:     /* Free the string and the binding handle using RPC API calls. */
        !           172:     status = RpcStringFree(&pszStringBinding);   
1.1       root      173:     printf("RpcStringFree returned 0x%x\n", status);
1.1.1.3 ! root      174:     if (status) {
        !           175:         exit(status);
        !           176:     }
1.1       root      177: 
1.1.1.3 ! root      178:     status = RpcBindingFree(&hXmit);
1.1       root      179:     printf("RpcBindingFree returned 0x%x\n", status);
1.1.1.3 ! root      180:     if (status) {
        !           181:         exit(status);
        !           182:     }
1.1       root      183: 
1.1.1.3 ! root      184:     exit(0)        !           185: 
        !           186: }  // end main()
        !           187: 
        !           188: /* end file xmitc.c */

unix.superglobalmegacorp.com

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