MAINSAIL STREAMS User's Guide, Appendix D

previous   next   top   contents   index   framed top   this page unframed


D. Extended C RPC Client Example

The examples in this section demonstrate a greater variety of argument types used in a C client than shown in
Chapter 5. Example D–2 is a C client that calls a MAINSAIL server with an interface PROCEDURE xxx with the header shown in Example D–1. The MAINSAIL remote MODULE is called R01.

Example D–1. MAINSAIL RPC Server Interface PROCEDURE Header
PROCEDURE xxx (
        
MODIFIES STRING ARRAY(1 TO 11) Ary1;
        
PRODUCES LONG INTEGER ARRAY(-2 TO 2) Ary2;
        
PRODUCES STRING ZS3;
        
CHARADR PdfBuf4PdfLONG INTEGER PdfBuf4Length;
        
CHARADR TxtBuf5LONG INTEGER TxtBuf5Length;
        
ADDRESS DatBuf6LONG INTEGER DatBuf6Size;
                
PRODUCES LONG INTEGER DatBuf6Length;
        
USES STRING S7;
        
USES LONG INTEGER Li8);

Example D–2. C Client That Calls MAINSAIL Remote Module
#include <mrpc.h>
#
include "r01cli.h"

MRPCMOD *rem;

newAry1(a,typeCode,lb1,ub1,elements)
ARRAY *a;
int typeCode,lb1,ub1;
char *elements;
{
a->ary_dims = 1;
a->ary_type = typeCode;
a->ary_lb1 = lb1a->ary_ub1 = ub1;
a->ary_first_elem = elements;
}



newAry2(a,typeCode,lb1,ub1,lb2,ub2,elements)
ARRAY *a;
int typeCode,lb1,ub1,lb2,ub2;
char *elements;
{
newAry1(a,typeCode,lb1,ub1,elements);
a->ary_dims = 2;
a->ary_lb2 = lb2a->ary_ub2 = ub2;
}



newAry3(a,typeCode,lb1,ub1,lb2,ub2,lb3,ub3,elements)
ARRAY *a;
int typeCode,lb1,ub1,lb2,ub2,lb3,ub3;
char *elements;
{
newAry2(a,typeCode,lb1,ub1,lb2,ub2,elements);
a->ary_dims = 3;
a->ary_lb3 = lb3a->ary_ub3 = ub3;
}



main (argc,argv)
int argc;
char *argv[];
{
int descr;
char hostAndServ[100],emsg[100];
char *hostAndServS;

long xxxx;
ARRAY Ary1;
char **eAry1;
ARRAY Ary2;
long *eAry2;
char *ZS3;
char *PdfBuf4Pdflong PdfBuf4Length;
char *TxtBuf5long TxtBuf5Length;
char *DatBuf6long DatBuf6Size;
long DatBuf6Length;
char *S7;
long Li8;

if (argc <= 1) {
    
printf("Host:server: "); gets(hostAndServ);
    
hostAndServS = hostAndServ; }
else { hostAndServS = argv[1]; }

if ((descr = connectServer(hostAndServS)) < 0) exit(1);

if (! (rem = r01_init(descr,0,0,emsg))) {
    
printf("Could not init: %s\n",emsg);
    
exit();
    }

eAry1 = (char **) calloc(11,sizeof(char *));
newAry1(&Ary1,stringCode,1,11,eAry1);

... set up parms...

r01_xxx(rem,&Ary1,&Ary2,&ZS3,PdfBuf4Pdf,PdfBuf4Length,
        
TxtBuf5,TxtBuf5Length,DatBuf6,DatBuf6Size,
        &
DatBuf6Length,S7,Li8);

... use results...

Ary1.ary_alloc_status = ARY_DATA_DYN | ARY_STRING_DYN;
dispose_array(&Ary1);
Ary2.ary_alloc_status = ARY_DATA_DYN;
dispose_array(&Ary2);
if (ZS3) { cfree(ZS3); }
}

r01_final(rem);
disconnserver(descr);
free(rem);
}


previous   next   top   contents   index   framed top   this page unframed

MAINSAIL STREAMS User's Guide, Appendix D