/*****************************************************************/
/**                                                             **/
/**             (C) Copyright 1992 the Regents of the           **/
/**        University of California.  All Rights Reserved.      **/
/**                                                             **/
/**        This work was produced under the sponsorship of      **/
/**         the U.S. Department of Energy.  The Government      **/
/**                retains certain rights therein.              **/
/**                                                             **/
/**                         Written by                          **/
/**         Distributed Programming Environments Project        **/
/**           Computer Software and Networking Division,        **/
/**                   Livermore Computer Center,                **/
/**            Lawrence Livermore National Laboratory           **/
/**                                                             **/
/*****************************************************************/
 
Interface sample_compat; 
 
Names 
   Integer(1)	tok1	101, 
   Integer(2)	tok2	102, 
   Integer(4)	tok4	104, 
   Integer(2)	index	5; 
 
/* Stupid Test Functions */ 
 
   Invoke req1 1000 
      tok1,tok2; 
 
   Invoke req2 1001 
      tok4; 
 
   Result reply 1002 
      tok4; 
 
   Error err1 10 
      index; 
 
   Error err2 20 
      index; 
 
End; 
  

main(argc,argv) 
   int argc; 
   char *argv[]; 
{ 
   Control (sample_compat) inst1; 
   Control (sample_compat) inst2; 
 
   Integer(4) t4var; 
   Integer(1) t1var; 
   Integer(2) t2var,ivar; 
  
   long *iv,*lv; 
   int r1id,r2id; 
   char f1[64],f2[64]; 
 
   if (argc != 2) 
      exit(1);    
   strcpy(f1,argv[1]); 
   strcat(f1,"1"); 
   strcpy(f2,argv[1]); 
   strcat(f2,"2"); 
  
/***************** send it out ************************/

   Bind_STUB(inst1,f1,"w", Asn_1_ber); 
 
   Give inst1 
   { 
      Set_invokeID(inst1,3);  
      req1(tok1: 5,tok2: 192); 
      req2(tok4: 1042103); 
   } 
 
   Unbind(inst1); 
 
/***************** receive it back ********************/

   Bind_STUB(inst1,f1,"r", Asn_1_ber); 
   Accept [iv,lv] inst1 
   { 
      On req1(tok1:t1var,tok2:t2var) 
       { 
         r1id = *iv; 
      }  
   } 
   Accept [iv,lv] inst1 
   { 
      On req2(tok4:t4var) 
       { 
         r2id = *iv; 
      }  
   } 

   /* Unbind after second instance bound */
 
/***************** send it out ************************/

   Bind_STUB(inst2,f2,"w", Asn_1_ber); 
 
   Give inst2 
   { 
      reply[-5](tok4: 55); 
      reply[r1id](tok4: 99); 
      err1[r2id](index:5); 
      err2[5](index:10); 
   } 
 
   Unbind(inst1); 
   Unbind(inst2); 
  
/***************** receive it back ********************/

   Bind_STUB(inst2,f2,"r", Asn_1_ber); 
 
   Accept [iv,lv] inst2 
   { 
     On reply(tok4: t4var) 
     { 
       if (t4var != 55 || *iv!=-5) 
          printf("###bad reply (1) t4var=%d,*iv=%d\n",t4var,*iv); 
     }  
   } 
   Accept [iv,lv] inst2 
   { 
     On reply(tok4: t4var) 
     { 
      if (t4var != 99 || *iv!=3) 
         printf("###bad reply (2) t4var=%d,*iv=%d\n",t4var,*iv); 
     }  
   } 
   Accept [iv,lv] inst2 
   { 
     On err1(index: ivar) 
     { 
      if (ivar != 5 || *iv!=4) 
         printf("###bad err1 ivar=%d,*iv=%d\n",ivar,*iv); 
     }  
   } 
   Accept [iv,lv] inst2 
   { 
     On err2(index: ivar) 
     { 
       if (ivar != 10 || *iv!=5) 
          printf("###bad err2 ivar=%d,*iv=%d\n",ivar,*iv); 
     }  
   } 
 
   Unbind(inst2); 
  
   printf("test completed\n");
   return(0); 
} 
