GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



next up previous contents
Next: Resource Management Up: Some Useful Programs Previous: What is Big, Red,   Contents

Who lives at 1600 Pennsylvania Avenue?

Who lives at 1600 Pennsylvania Avenue? It's often the case that one has the POSIX path of an advertisable in a GATAdvertService but yet has no information, short of the POSIX path itself, describing this advertisable. Our next command line program remedies this situation. In honour of the old C64 command peek which would allow the application programmer to peek at the contents of memory we will call our new command line program sonofpeek.

Our new baby sonofpeek when presented with a POSIX path will print out all the key/value paris describing the advertisable present at that POSIX path. For example, it could be called as follows

% sonofpeek /earth/usa/DC/1600PennsylvaniaAvenue

and then might respond with the following information

FirstName=George
MiddleName=Walker
LastName=Bush
Age=58
Height=183cm
Weight=87Kg
IQ=91

The full source for sonofpeek is as follows

#include <stdio.h>
#include <string.h>
#include "GAT.h"

int main( int argc, char *argv[] )
{
  int counter;
  char *keys[];
  int returnValue;
  GATTable table;  
  GATResult result;
  GATString string;
  char value[2048];
  GATContext context;
  GATAdvertService advertService;
  
  /* Check command line arguments */
  if( 2 != argc )
  {
    /* Print out error message */
    printf( "usage: sonofpeek path\n" );
    
    /* Return to OS */
    return 1;
  }
  
   /* Set result to a memory failure */
   result = GAT_MEMORYFAILURE;
      
   /* Create GATContext */
   context = GATContext_Create();
   
   /* Check GATContext creation */
   if( NULL != context )
   {
     /* Create GATAdvertService */
     advertService = GATAdvertService_Create( context, NULL );
     
     /* Check GATAdvertService creation */
     if( NULL != advertService )
     {
       /* Create GATString */
       string = GATString_Create( argv[1], 
                                  (GATuint32) (strlen( argv[1] ) + 1), 
                                  "ASCII" );
       
       /* Check GATString creation */
       if( NULL != string )
       {
         /* Get description */
         result = GATAdvertService_GetMetaData( advertService, string, &table );
         
         /* Check success of GATAdvertService_GetMetaData */
         if( GAT_SUCCEEDED( result ) )
         {
           /* Get keys */
           keys = (char **) GATTable_GetKeys( table );
           
           /* Loop over keys */
           counter = 0;
           while( NULL != keys[counter] )
           {
             /* Get value */
             result = GATTable_Get_String( table, keys[counter], value, 2048 );
             
             /* Check success of GATTable_Get_String */
             if( GAT_SUCCEEDED( result ) )
             {
               /* Print key/value pair */
               printf( "%s=%s\n", keys[counter], value );
             }
             else
             {
               /* Print error */
               printf( "Error obtaining value for key %s\n", keys[counter] );
             }
             
             /* Increment counter */
             counter = counter + 1;
           }
           
           /* Destroy keys */
           GATTable_ReleaseKeys( table, keys );
         }
       
         /* Destroy GATString */
         GATString_Destroy( &string );
       }
       
       /* Destroy GATAdvertService */
       GATAdvertService_Destroy( &advertService );
     }
     
     /* Destroy GATContext */
     GATContext_Destroy( &context );
   }
   
   /* Set returnValue and print error message */
   returnValue = 0;
   if( GAT_FAILED( result ) )
   {
     returnValue = 1;
     
     printf( "There was an error in execution of sonofpeek\n" );
   }
   
   /* Return to OS */
   return returnValue;
}



Andre Merzky 2004-05-13