home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / TIERRA40.ZIP / ALMOND / ALCOMM / SRC / TRY2.C < prev   
C/C++ Source or Header  |  1992-07-06  |  4KB  |  172 lines

  1. /*
  2. * try2.c
  3. *
  4. *
  5. * Copyright (c) 1991, 1992 by Marc W. Cygnus and Virtual Life
  6. * All Rights Reserved.
  7. *
  8. */
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <sys/types.h>
  13.  
  14. #include <arpa/inet.h>
  15.  
  16. #include "mlayer.h"
  17. #include "trequest.h"
  18. #include "debug.h"
  19.  
  20.  
  21. void    TProcOrganismLifeEvent P_(( ));
  22. void    TProcIPEvent P_(( ));
  23.  
  24.  
  25. static MtDefaultRoutines    _dataflow_fns[] = {
  26.   { TrtOrgLifeEvent,    TProcOrganismLifeEvent },
  27.   { TrtIPEvent,        TProcIPEvent }
  28. };
  29.  
  30.  
  31.  
  32.  
  33.  
  34. int main( argc, argv )
  35.   int        argc;
  36.   char *    argv[];
  37. {
  38.   int            iRet;
  39.   int            iPort;
  40.   char            sText[100];
  41.   int            iTLen;
  42.   int            iLoop;
  43.   int            hLink;
  44.  
  45.   /* _debug_state = DBGAll; */
  46.  
  47.   if ( argc != 3 ) {
  48.     puts( "Please specify: <hostname> <port>" );
  49.     exit( -1 );
  50.   }
  51.   printf( "trying %s : %s\n", argv[1], argv[2] );
  52.  
  53.   puts( "initialising mlayer" );
  54.   if (( iRet = MInitialise( 0, 0, M_NoFns, 0, M_NoFns, 0, _dataflow_fns, 2,
  55.                 M_NoFns, 0 )) != MsOK )
  56.     ALGripe( "MInitialise", "error %d\n", iRet ), exit( -1 );
  57.  
  58.   iPort = atoi( argv[2] );
  59.   puts( "trying connect" );
  60.   if (( iRet = MConnectTo( argv[1], iPort, &hLink )) != MsOK )
  61.     ALGripe( "MConnectTo", "error %d\n", iRet ), exit( -1 );
  62.  
  63.   printf( "operating with LIT handle %d\n", hLink );
  64.  
  65.   puts( "turning on flowcontrol of 5:2" );
  66.   (void) MSetFlowcontrol( hLink, 5, 2 );
  67.  
  68.   iLoop = 0;
  69.   while ( 1 ) {
  70.  
  71.     printf( "==> " );
  72.     fflush( stdout );
  73.     gets( sText );
  74.  
  75.     if ( strcmp( sText, "enable" ) == 0 ) {
  76.       int    iWhich;
  77.  
  78.       iWhich = M_Enable;
  79.       if (( iRet = MGenRequest( hLink, MrModifyDataflow, TrtOrgLifeEvent,
  80.                     (pMtOpaque)&iWhich, sizeof( int ) )
  81.       ) != MsOK )
  82.     ALGripe( "MGenRequest", "error %d\n", iRet );
  83.  
  84.     } else if ( strcmp( sText, "disable" ) == 0 ) {
  85.       int    iWhich;
  86.  
  87.       iWhich = M_Disable;
  88.       if (( iRet = MGenRequest( hLink, MrModifyDataflow, TrtOrgLifeEvent,
  89.                     (pMtOpaque)&iWhich, sizeof( int ) )
  90.       ) != MsOK )
  91.     ALGripe( "MGenRequest", "error %d\n", iRet );
  92.  
  93.     } else if ( strcmp( sText, "Eip" ) == 0 ) {
  94.       int    iWhich;
  95.  
  96.       iWhich = M_Enable;
  97.       if (( iRet = MGenRequest( hLink, MrModifyDataflow, TrtIPEvent,
  98.                     (pMtOpaque)&iWhich, sizeof( int ) )
  99.       ) != MsOK )
  100.     ALGripe( "MGenRequest", "error %d\n", iRet );
  101.     } else if ( strcmp( sText, "Dip" ) == 0 ) {
  102.       int    iWhich;
  103.  
  104.       iWhich = M_Disable;
  105.       if (( iRet = MGenRequest( hLink, MrModifyDataflow, TrtIPEvent,
  106.                     (pMtOpaque)&iWhich, sizeof( int ) )
  107.       ) != MsOK )
  108.     ALGripe( "MGenRequest", "error %d\n", iRet );
  109.  
  110.     } else if ( strcmp( sText, "query" ) == 0 ) {
  111.       pTtGenStats        pGS;
  112.       int            iGSLen;
  113.  
  114.       if (( iRet = MGenRequestWithReply( hLink, MrQuery, TrtGeneralStats,
  115.                      M_NoData, 0, (pMtOpaque)&pGS,
  116.                      &iGSLen )) != MsOK )
  117.     ALGripe( "MGenRequestWithReply", "unhappy: %d\n", iRet );
  118.       else {
  119.     
  120.     printf( "*** Sent a status request; got pGS" );
  121.     if ( pGS == NULL )
  122.       printf( " = <null>\n" );
  123.     else {
  124.       printf( "->memsize = (%d); length = %d\n", pGS->memsize, iGSLen );
  125.       (void) ALFree( pGS );
  126.     }
  127.  
  128.       } /* end req w/ reply happy */
  129.       
  130.     }
  131.  
  132.     if (( iRet = MServiceRequests( M_NoWait )) != MsOK )
  133.       ALGripe( "MServiceRequests", "error %d\n", iRet );
  134.  
  135.   }
  136.  
  137. }
  138.  
  139.  
  140. void TProcOrganismLifeEvent( ucOp, pData, hLink )
  141.   u_char    ucOp;
  142.   pMtOpaque    pData;
  143.   hMtLinkInfo    hLink;
  144. {
  145.   register pTtOrgEvent    pOEV;
  146.  
  147.   pOEV = (pTtOrgEvent)pData;
  148.  
  149.   printf( "[%c @ %d x %d]", pOEV->event, pOEV->start, pOEV->length );
  150.  
  151. } /* end TProcOrganismEvent() */
  152.  
  153. void TProcIPEvent( ucOp, pData, hLink )
  154.   u_char    ucOp;
  155.   pMtOpaque    pData;
  156.   hMtLinkInfo    hLink;
  157. {
  158.   register pTtIPEvent    pIEV;
  159.  
  160.   pIEV = (pTtIPEvent)pData;
  161.  
  162.   printf( "[%c @ %d x %d]", pIEV->event, pIEV->start, pIEV->position );
  163.  
  164. } /* end TProcOrganismEvent() */
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171. /* end try.c */
  172.