/*****************************************************************/
/**                                                             **/
/**             (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           **/
/**                                                             **/
/*****************************************************************/
 
#include "Imatrix.i" 

#define l_exit(x) exit(x) 
 
#include <netdb.h> 
 
extern unsigned long Stksize; 
int anycount = 0; 
int totalcount = 0;
 
char *ip; 
char addrbuffer[64]; 
unsigned char *ipvalue; 
struct hostent *hostip;


main(argc,argv) 
   int argc; 
   char *argv[]; 
{ 
   Task MyId; 
   int imat_task(); 
   int MAXTASKS = 3; 
   Stksize = 100 * 1024; 
 
   /* Parse command line args */
 
   if (argc < 2) {
     printf("First arg must be server host name\n");
     exit (1);
   }

   ip = argv[1];

   hostip = gethostbyname(ip);

   if (hostip == NULL) {
     printf("Invalid host server name: %s\n",ip);
     exit (1);
   }
 
   /* Get server address */

   ipvalue = (unsigned char *)(hostip->h_addr); 

   sprintf(addrbuffer,"Internet=%ld.%ld.%ld.%ld+18002", 
           ipvalue[0], ipvalue[1], ipvalue[2], ipvalue[3]); 

   while ( totalcount < MAXTASKS * 10 ) 
   { 
     while ( anycount < MAXTASKS ) 
     { 
        MyId = Ego(); 
        Newtask( imat_task, MyId ); 
	anycount++; 
     } 
     SLEEP; 
     totalcount +=1;
   } 

   printf("test completed\n");
   return(0); 
} 
 
 
int imat_task() 
{ 
   Control (matrixcomp) inst; 
   MatText textin,text1,text2; 
   Mat1 m1; 
   Mat2 m2; 
  
   int i; 
   int timeout = 300; 
   Bind_address addr; 
   long *iid; 
 
   Init_isode_addr(&addr,Responder,addrbuffer); 
 
   /*** Begin client/server activity ***/

   printf("Binding..."); fflush(stdout);
  
   Bind_addr( inst, Asn_1_ber, &addr, timeout ); 
 
   Accept[iid]inst 
   { 
      On act(textin) 
       { 
         __ROr_convert_Integer_const(&(m1[0][0]),sizeof(m1[0][0]),4,0,textin[0][0],&__ROc_type_information); 
         __ROr_convert_Integer_const(&(m1[0][1]),sizeof(m1[0][0]),4,0,textin[0][1],&__ROc_type_information); 
         __ROr_convert_Integer_const(&(m1[1][0]),sizeof(m1[0][0]),4,0,textin[1][0],&__ROc_type_information); 
         __ROr_convert_Integer_const(&(m1[1][1]),sizeof(m1[0][0]),4,0,textin[1][1],&__ROc_type_information); 
 
         __ROr_convert_Integer_const(&(m2[0][0]),sizeof(m2[0][0]),9,0,textin[0][0],&__ROc_type_information); 
         __ROr_convert_Integer_const(&(m2[0][1]),sizeof(m2[0][0]),9,0,textin[0][1],&__ROc_type_information); 
         __ROr_convert_Integer_const(&(m2[1][0]),sizeof(m2[0][0]),9,0,textin[1][0],&__ROc_type_information); 
         __ROr_convert_Integer_const(&(m2[1][1]),sizeof(m2[0][0]),9,0,textin[1][1],&__ROc_type_information); 
      }  
   } 
 
   Give inst 
   { 
  
         strcpy(text1[0][0],__ROr_format_Integer(&(m1[0][0]),sizeof(m1[0][0]),4,0,&__ROc_type_information)); 
         strcpy(text1[0][1],__ROr_format_Integer(&(m1[0][1]),sizeof(m1[0][0]),4,0,&__ROc_type_information)); 
         strcpy(text1[1][0],__ROr_format_Integer(&(m1[1][0]),sizeof(m1[0][0]),4,0,&__ROc_type_information)); 
         strcpy(text1[1][1],__ROr_format_Integer(&(m1[1][1]),sizeof(m1[0][0]),4,0,&__ROc_type_information)); 
 
         strcpy(text2[0][0],__ROr_format_Integer(&(m2[0][0]),sizeof(m2[0][0]),9,0,&__ROc_type_information)); 
         strcpy(text2[0][1],__ROr_format_Integer(&(m2[0][1]),sizeof(m2[0][0]),9,0,&__ROc_type_information)); 
         strcpy(text2[1][0],__ROr_format_Integer(&(m2[1][0]),sizeof(m2[0][0]),9,0,&__ROc_type_information)); 
         strcpy(text2[1][1],__ROr_format_Integer(&(m2[1][1]),sizeof(m2[0][0]),9,0,&__ROc_type_information)); 
  
      acted[*iid](m1,m2,text1,text2); 
   } 
 
   Unbind(inst); 

   printf("Unbound");  
   printf("task completed\n"); 

   anycount--; 
   Wake((Task)Tvarb); 

   return 0; 
   } 
  
 
