GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

adaptor.c

Go to the documentation of this file.
00001 /** @file adaptor.c
00002  * Main file for the filestream adaptor.
00003  * 
00004  * Test adaptor to check the GATFileStream API. Provides a simple
00005  * file GATFileStreamCPI implementation.
00006  * 
00007  * @date $Date: 2004/04/22 10:25:05 $
00008  * 
00009  * @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/filestream/adaptor.c,v 1.6 2004/04/22 10:25:05 hartmutkaiser Exp $
00010  *
00011  *  Copyright (C) Kelly Davis
00012  *  This file is part of the GAT Engine.
00013  *  Contributed by Kelly Davis <kdavis@aei.mpg.de>.
00014  *
00015  *  Use, modification and distribution is subject to the Gridlab Software
00016  *  License. (See accompanying file GLlicense.txt or copy at
00017  *  http://www.gridlab.org/GLlicense.txt)
00018  */
00019 
00020 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/filestream/adaptor.c,v 1.6 2004/04/22 10:25:05 hartmutkaiser Exp $";
00021 
00022 /* System Header Files */
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #include <errno.h>
00027 
00028 /* GAT Header Files */
00029 #include <GATCPI.h>
00030 
00031 /* Macros */
00032 #define __countof(x) (sizeof(x)/sizeof(x[0]))
00033 
00034 /* Structures, unions and enums */
00035 
00036 /* Instance data -- not used */ 
00037 typedef struct GATFileStreamInstance_Data {
00038   FILE *file;
00039 } GATFileStreamInstance_Data;
00040 
00041 /* Static function prototypes */
00042 static void 
00043 filestream_adaptor_FileStreamCPI_Destroy(void *data);
00044 
00045 /* instance specific functions */
00046 GATResult 
00047 filestream_adaptor_FileStreamCPI_CreateInstance(void *adaptor_data, 
00048   GATFileStreamCPI_Instance *data);
00049 
00050 void 
00051 filestream_adaptor_FileStreamCPI_DestroyInstance(void *adaptor_data, 
00052   GATFileStreamCPI_Instance *data);
00053 
00054 GATResult 
00055 filestream_adaptor_FileStreamCPI_CloneInstance(void *adaptor_data, 
00056   GATFileStreamCPI_Instance const *data, 
00057   GATFileStreamCPI_Instance *new_data);
00058 
00059 GATResult 
00060 filestream_adaptor_FileStreamCPI_EqualsInstance(void *adaptor_data, 
00061   GATFileStreamCPI_Instance const *lhs, GATFileStreamCPI_Instance const *rhs, 
00062   GATBool *isequal);
00063 
00064 /* Streamable functions */
00065 static GATResult 
00066 filestream_adaptor_FileStreamCPI_Read(void *data, 
00067   GATFileStreamCPI_Instance const *instance_data, void *buffer, GATuint32 size, 
00068   GATuint32 *readBytes);
00069   
00070 static GATResult 
00071 filestream_adaptor_FileStreamCPI_Write(void *data, 
00072   GATFileStreamCPI_Instance const *instance_data, void const *buffer, 
00073   GATuint32 size, GATuint32 *writtenBytes);
00074   
00075 static GATResult 
00076 filestream_adaptor_FileStreamCPI_Seek(void *data, 
00077   GATFileStreamCPI_Instance const *instance_data, GATOrigin origin, 
00078   GATint32 offset, GATuint32 *new_position);
00079   
00080 static GATResult 
00081 filestream_adaptor_FileStreamCPI_Close(void *data, 
00082   GATFileStreamCPI_Instance *instance_data);
00083           
00084 /* Execute a GATFileStream get_metrics operation */
00085 static GATResult 
00086 filestream_adaptor_FileStreamCPI_GetMetrics(void *data, 
00087   GATFileStreamCPI_Instance const *instance_data, GATList_GATMetric *metrics);
00088 
00089 /* Execute a GATFileStream get_metric_event operation */
00090 static GATResult 
00091 filestream_adaptor_FileStreamCPI_GetMetricEvent(void *data, 
00092   GATFileStreamCPI_Instance const *instance_data, GATMetric metric, 
00093     GATMetricEvent *event);
00094     
00095 /* local helper functions */
00096 static GATResult 
00097 filestream_adaptor_FireReadEvent(GATContext context, 
00098   GATMonitorable_Impl monitorable, GATObject_const source, char const *name);
00099   
00100 static GATResult 
00101 filestream_adaptor_FireWriteEvent(GATContext context, 
00102   GATMonitorable_Impl monitorable, GATObject_const source, char const *name);
00103   
00104 static GATResult 
00105 filestream_adaptor_FireSeekEvent(GATContext context, 
00106   GATMonitorable_Impl monitorable, GATObject_const source, char const *name);
00107   
00108 static GATResult 
00109 filestream_adaptor_FireCloseEvent(GATContext context, 
00110   GATMonitorable_Impl monitorable, GATObject_const source, char const *name);
00111       
00112 /* File scope variables */
00113 static GATStaticMetric metric_data[] = {
00114   /* filestream.read event */
00115   { 
00116     "filestream.read",              /* name */
00117     GATMeasurementType_EventLike,   /* type */
00118     GATType_String,                 /* data type */
00119     "",                             /* unit */
00120     0,                              /* parameter count */
00121     0                               /* parameters */
00122   },
00123   /* filestream.write event */
00124   { 
00125     "filestream.write",             /* name */
00126     GATMeasurementType_EventLike,   /* type */
00127     GATType_String,                 /* data type */
00128     "",                             /* unit */
00129     0,                              /* parameter count */
00130     0                               /* parameters */
00131   },
00132   /* filestream.seek event */
00133   { 
00134     "filestream.seek",              /* name */
00135     GATMeasurementType_EventLike,   /* type */
00136     GATType_String,                 /* data type */
00137     "",                             /* unit */
00138     0,                              /* parameter count */
00139     0                               /* parameters */
00140   },
00141   /* filestream.close event */
00142   { 
00143     "filestream.close",             /* name */
00144     GATMeasurementType_EventLike,   /* type */
00145     GATType_String,                 /* data type */
00146     "",                             /* unit */
00147     0,                              /* parameter count */
00148     0                               /* parameters */
00149   },
00150 };
00151 
00152 /* symbolic constants for the metric positions inside the metric_data array */
00153 #define METRIC_FILESTREAM_READ   0
00154 #define METRIC_FILESTREAM_WRITE  1
00155 #define METRIC_FILESTREAM_SEEK   2
00156 #define METRIC_FILESTREAM_CLOSE  3
00157 
00158 
00159 /* External functions */
00160 
00161 /** filestream_adaptor_register
00162  *  Registers all CPIs this adaptor provides.
00163  *  This function is invoked by the loader in the GATEngine when
00164  *  an instance of this adaptor is loaded.  Each instance has its
00165  *  own private configuration table.
00166  *
00167  *  For every CPI provided the adapter has to hand all the corresponding 
00168  *  function pointers to the engine to allow to be called back under certain
00169  *  circumstances. Additionally the adaptor may allocate some private data for
00170  *  every loaded instance. This data is handed back to the adaptor as the first
00171  *  parameter to each of the subsequently called functions.
00172  *
00173  *  @param registry The registry the adaptor should register its CPIs with.
00174  *  @param system_config The system configuration table.
00175  *  @param instance_config The configuration table for this instance.
00176  *  @param token An arbitrary token used by the loader to identify this adaptor 
00177  *        instance
00178  *
00179  *  @return An error code.
00180  */
00181 GATResult 
00182 filestream_adaptor_register(GATContext error_context, GATRegistry registry, 
00183   GATTable_const system_config, GATTable_const instance_config, void *token)
00184 {
00185   GATResult retcode = GAT_MEMORYFAILURE;
00186 
00187   if (!GATVERSION_ISCOMPATIBLE())
00188   {
00189     retcode = GAT_UNKNOWN_VERSION;
00190   }
00191   else
00192   {
00193     GATFileStreamCPI cpi = NULL;
00194     GATFileStreamCPI_Data cpidata;
00195     
00196     memset(&cpidata, 0, sizeof(GATFileStreamCPI_Data));
00197       
00198     /*
00199     *  provide the appropriate callback functions
00200     */
00201       
00202     /* adaptor instance data */
00203     cpidata.data = NULL;
00204     cpidata.destroy = filestream_adaptor_FileStreamCPI_Destroy;
00205     
00206     /*  Lifetime control and basic GATObject functionality support for every
00207     *  object instance created by the client.
00208     */
00209     cpidata.create_instance = filestream_adaptor_FileStreamCPI_CreateInstance;
00210     cpidata.destroy_instance = filestream_adaptor_FileStreamCPI_DestroyInstance;
00211     cpidata.clone_instance = filestream_adaptor_FileStreamCPI_CloneInstance;
00212     cpidata.equals_instance = filestream_adaptor_FileStreamCPI_EqualsInstance;
00213 
00214     /* streamable support */
00215     cpidata.read = filestream_adaptor_FileStreamCPI_Read;
00216     cpidata.write = filestream_adaptor_FileStreamCPI_Write;
00217     cpidata.seek = filestream_adaptor_FileStreamCPI_Seek;
00218     cpidata.close = filestream_adaptor_FileStreamCPI_Close;
00219     
00220     /* monitoring support */
00221     cpidata.get_metrics = filestream_adaptor_FileStreamCPI_GetMetrics;
00222     cpidata.get_metric_event = filestream_adaptor_FileStreamCPI_GetMetricEvent;
00223 
00224     /* Create a GATFileStreamCPI object. */
00225     cpi = GATFileStreamCPI_Create(GATFILESTREAMCPI_VERSION, &cpidata);
00226     if(NULL != cpi)
00227     {
00228       /* Need to pass preferences to allow matching
00229       * of a user's preferences with what this adaptor does.
00230       */
00231       GATPreferences preferences = GATPreferences_Create();
00232       if(NULL != preferences)
00233       {
00234         /* at least the Name preference should be defined */
00235         GATPreferences_Add(preferences, "Name", "filestream_adaptor");
00236         GATPreferences_Add(preferences, "Security", "none");
00237         GATPreferences_Add(preferences, "Local", "true");
00238         
00239         retcode = GATRegistry_AddGATFileStreamCPI(registry, cpi, token, 
00240           preferences);
00241         
00242         GATPreferences_Destroy(&preferences);
00243       }
00244     }
00245     
00246     if (GAT_SUCCESS != retcode)
00247     {
00248       GATFileStreamCPI_Destroy(&cpi);
00249     }
00250   }
00251   return retcode;
00252 }
00253 
00254 /* Local functions */
00255 
00256 /** filestream_adaptor_FileStreamCPI_Destroy
00257  *  Destroy the adaptor-provided data object on GATFileStreamCPI destruction.
00258  *  When the GATFileStreamCPI object created in this adaptor's _register
00259  *  function is destroyed, this function is invoked to allow the
00260  *  adaptor to cleanup.
00261  *
00262  *  @param data Adaptor-provided data object.
00263  */
00264 static void 
00265 filestream_adaptor_FileStreamCPI_Destroy(void *data)
00266 {
00267   /* nothing to do here (no internal data allocated) */
00268 }
00269 
00270 /** filestream_adaptor_FileStreamCPI_CreateInstance
00271  *  Create a new CPI object instance.
00272  *  Adaptor implementation of create instance capability.
00273  *
00274  * @param adaptor_data Adaptor-provided data object.
00275  * @param data The pointer to the data structure containing at least 
00276  *        the constructor provided data items and a member instance_data, which 
00277  *        may be used by the adaptor to store CPI instance specific data.
00278  * 
00279  * @return An error code.
00280  */
00281 GATResult 
00282 filestream_adaptor_FileStreamCPI_CreateInstance(void *adaptor_data, 
00283   GATFileStreamCPI_Instance *data)
00284 {
00285   if (NULL != data)
00286   {
00287     GAT_USES_STATUS(data->context, "filestream_adaptor_FileStreamCPI_CreateInstance");
00288     char *location = GATLocation_ToString(data->location);
00289     
00290     if (NULL != location)
00291     {
00292       FILE *file = NULL;
00293       if (GATFileStreamMode_Read == data->mode)
00294       {
00295         file = fopen(location, "r");
00296       } 
00297       else if (GATFileStreamMode_Write == data->mode)
00298       {
00299         file = fopen(location, "w");
00300       } 
00301       else if (GATFileStreamMode_Append == data->mode)
00302       {
00303         file = fopen(location, "a");
00304       } 
00305       else 
00306       {
00307         file = fopen(location, "r+");
00308       }
00309       
00310       if (NULL != file)
00311       {
00312         data->instance_data = (void *) file;
00313       }
00314       else
00315       {
00316         GAT_CREATE_STATUS(GAT_FILEOPEN_ERROR);
00317       }
00318       free(location);
00319     }
00320     else
00321     {
00322       GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00323     }
00324     
00325     return GAT_RETURN_STATUS();
00326   }
00327   return GAT_INVALID_HANDLE;
00328 }
00329 
00330 /** filestream_adaptor_FileStreamCPI_DestroyInstance
00331  *  Destroy a CPI object instance.
00332  *  Adaptor implementation of destroy instance capability.
00333  *
00334  * @param data Adaptor-provided data object.
00335  * @param instance_data The instance data of the CPI object to destroy.
00336  */
00337 void
00338 filestream_adaptor_FileStreamCPI_DestroyInstance(void *adaptor_data, 
00339   GATFileStreamCPI_Instance *data)
00340 {
00341   if (NULL != data)
00342   {
00343     GAT_USES_STATUS(data->context, 
00344       "filestream_adaptor_FileStreamCPI_DestroyInstance");
00345     
00346     if (NULL != data->instance_data)
00347     {
00348       fclose((FILE *)data->instance_data);
00349       data->instance_data = NULL;
00350     }
00351 
00352     GAT_STORE_STATUS();
00353   }
00354 }
00355 
00356 /** filestream_adaptor_FileStreamCPI_CloneInstance
00357  *  Clone a CPI object instance.
00358  *  Adaptor implementation of the clone instance capability.
00359  *
00360  * @param data Adaptor-provided data object.
00361  * @param instance_data The instance data of this CPI object
00362  * @param new_instance_data The pointer to the variable, where the instance 
00363  *      data of the cloned CPI object is to be returned to.
00364  * 
00365  * @return An error code.
00366  */
00367 GATResult 
00368 filestream_adaptor_FileStreamCPI_CloneInstance(void *adaptor_data, 
00369   GATFileStreamCPI_Instance const *instance_data, 
00370   GATFileStreamCPI_Instance *new_instance_data)
00371 {
00372   if (NULL != instance_data && NULL != new_instance_data)
00373   {
00374     GAT_USES_STATUS(instance_data->instance_data, 
00375       "filestream_adaptor_FileStreamCPI_CloneInstance");
00376     
00377     if (NULL != instance_data->instance_data)
00378     {
00379       new_instance_data->instance_data = instance_data->instance_data;
00380     }
00381     else
00382     {
00383       GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00384     }
00385     
00386     return GAT_RETURN_STATUS();
00387   }
00388   return GAT_INVALID_HANDLE;
00389 }
00390 
00391 /** filestream_adaptor_FileStreamCPI_EqualsInstance
00392  *  Clone a CPI object instance.
00393  *  Adaptor implementation of the clone instance capability.
00394  *
00395  * @param data Adaptor-provided data object.
00396  * @param lhs The instance data of the left CPI object.
00397  * @param lhs The instance data of the right CPI object.
00398  * @param isequal The pointer to the variable, where the result is to be 
00399  *        returned to.
00400  *
00401  * @return An error code.
00402  */
00403 GATResult 
00404 filestream_adaptor_FileStreamCPI_EqualsInstance(void *data, 
00405   GATFileStreamCPI_Instance const *lhs, GATFileStreamCPI_Instance const *rhs, 
00406   GATBool *isequal)
00407 {
00408   if (NULL != lhs && NULL != rhs)
00409   {
00410     GAT_USES_STATUS(lhs->context, 
00411       "filestream_adaptor_FileStreamCPI_EqualsInstance");
00412     
00413     if (NULL != isequal)
00414     {
00415       *isequal = GATFalse;
00416       if (lhs->instance_data == rhs->instance_data)
00417       {
00418         *isequal = GATTrue;
00419       }
00420     }
00421     else
00422     {
00423       GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00424     }
00425     
00426     return GAT_RETURN_STATUS();
00427   }
00428   return GAT_INVALID_HANDLE;
00429 }
00430 
00431 
00432 /* Streamable support */
00433 
00434 /** filestream_adaptor_FileStreamCPI_Read
00435  *  Reads data from a FileStream.
00436  *  Adaptor implementation of FileStream read capability.
00437  *
00438  * @param data Adaptor-provided data object.
00439  * @param instance_data The instance data of this CPI object
00440  * @param buffer The buffer into which data is read
00441  * @param size The size of the buffer
00442  * @param readBytes the number of bytes read
00443  * @return An error code.
00444  */
00445 static GATResult 
00446 filestream_adaptor_FileStreamCPI_Read(void *data, 
00447   GATFileStreamCPI_Instance const *instance_data, void *buffer, 
00448   GATuint32 size, GATuint32 *readBytes)
00449 {
00450   if (NULL != instance_data)
00451   {
00452     GAT_USES_STATUS(instance_data->context, 
00453       "filestream_adaptor_FileStreamCPI_Read");
00454     if ((NULL != buffer) && (NULL != readBytes))
00455     {
00456       *readBytes = (GATuint32) fread(buffer, 1, (size_t) size, 
00457         (FILE *) instance_data->instance_data);
00458 
00459       if (size == *readBytes)
00460       {
00461         GAT_CREATE_STATUS(filestream_adaptor_FireReadEvent(
00462           instance_data->context, instance_data->monitorable, 
00463           instance_data->source, "read"));
00464       }
00465       else
00466       {
00467         GAT_CREATE_STATUS(POSIX_TO_GAT(errno));
00468       }
00469     }
00470     else
00471     {
00472       GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00473     }
00474     return GAT_RETURN_STATUS();
00475   }  
00476   return GAT_INVALID_HANDLE;
00477 }
00478 
00479 /** filestream_adaptor_FileStreamCPI_Write
00480  *  Writes data to a FileStream.
00481  *  Adaptor implementation of FileStream write capability.
00482  *
00483  * @param data Adaptor-provided data object.
00484  * @param instance_data The instance data of this CPI object
00485  * @param buffer The buffer from which data is written
00486  * @param size The size of the buffer
00487  * @param writtenBytes the number of bytes written
00488  * @return An error code.
00489  */
00490 static GATResult 
00491 filestream_adaptor_FileStreamCPI_Write(void *data, 
00492   GATFileStreamCPI_Instance const *instance_data, void const *buffer, 
00493   GATuint32 size, GATuint32 *writtenBytes)
00494 {
00495   if (NULL != instance_data) 
00496   {
00497     GAT_USES_STATUS(instance_data->context, 
00498       "filestream_adaptor_FileStreamCPI_Write");
00499     if ((NULL != buffer) && (NULL != writtenBytes))
00500     {
00501       *writtenBytes = (GATuint32) fwrite (buffer, 1, (size_t) size, 
00502         (FILE *) instance_data->instance_data );
00503       if (size == *writtenBytes)
00504       {
00505         GAT_CREATE_STATUS(filestream_adaptor_FireWriteEvent(
00506           instance_data->context, instance_data->monitorable, 
00507           instance_data->source, "write"));
00508       }
00509       else
00510       {
00511         GAT_CREATE_STATUS(POSIX_TO_GAT(errno));
00512       }
00513     }
00514     else
00515     {
00516       GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00517     }
00518     return GAT_RETURN_STATUS();
00519   }  
00520   return GAT_INVALID_HANDLE;
00521 }
00522 
00523 /** filestream_adaptor_FileStreamCPI_Seek
00524  * Seeks on a FileStream.
00525  * Adaptor implementation of FileStream seek capability.
00526  *
00527  * @param data Adaptor-provided data object.
00528  * @param instance_data The instance data of this CPI object
00529  * @param origin The GATOrigin from whence to seek
00530  * @param offset The offset from the origin which to seek to
00531  * @param new_position The new position of the FileStream
00532  * @return An error code.
00533  */
00534 static GATResult 
00535 filestream_adaptor_FileStreamCPI_Seek(void *data, 
00536   GATFileStreamCPI_Instance const *instance_data, GATOrigin origin, 
00537   GATint32 offset, GATuint32 *new_position)
00538 {
00539   if (NULL != instance_data) 
00540   {
00541     GAT_USES_STATUS(instance_data->context, 
00542       "filestream_adaptor_FileStreamCPI_Seek");
00543     if (NULL != new_position)
00544     {
00545       int wherefrom;
00546       
00547       if (GATOrigin_Set == origin)
00548       {
00549         wherefrom = SEEK_SET;
00550       } 
00551       else if (GATOrigin_Current == origin)
00552       {
00553         wherefrom = SEEK_CUR;
00554       } 
00555       else if (GATOrigin_End == origin)
00556       {
00557         wherefrom = SEEK_END;
00558       }
00559       else
00560       {
00561         GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00562       }
00563       
00564       if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00565       {
00566         if (0 == fseek ((FILE *) instance_data->instance_data, (long) offset, 
00567           wherefrom ))
00568         {
00569           long newPosition = ftell ((FILE *) instance_data->instance_data);
00570           if (-1 != newPosition)
00571           {
00572             if (NULL != new_position)
00573             {
00574               *new_position = (GATuint32) newPosition;
00575               GAT_CREATE_STATUS(filestream_adaptor_FireSeekEvent(
00576                 instance_data->context, instance_data->monitorable, 
00577                 instance_data->source, "seek"));
00578             }
00579             else
00580             { 
00581               GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00582             }
00583           }
00584           else
00585           {
00586             GAT_CREATE_STATUS(POSIX_TO_GAT(errno));
00587           }
00588         }
00589         else
00590         {
00591           GAT_CREATE_STATUS(POSIX_TO_GAT(errno));
00592         }
00593       }
00594     }
00595     return GAT_RETURN_STATUS();
00596   }  
00597   return GAT_INVALID_HANDLE;
00598 }
00599 
00600 /** filestream_adaptor_FileStreamCPI_Close
00601  * Closes a FileStream
00602  * Adaptor implementation of FileStream close capability.
00603  *
00604  * @param data Adaptor-provided data object.
00605  * @param instance_data The instance data of this CPI object
00606  * @return An error code.
00607  */
00608 static GATResult 
00609 filestream_adaptor_FileStreamCPI_Close(void *data, 
00610   GATFileStreamCPI_Instance *instance_data)
00611 {
00612   if (NULL != instance_data)
00613   {
00614     GAT_USES_STATUS(instance_data->context, 
00615       "filestream_adaptor_FileStreamCPI_Close");
00616     if (0 == fclose ((FILE *) instance_data->instance_data))
00617     {
00618       GAT_CREATE_STATUS(filestream_adaptor_FireCloseEvent(
00619         instance_data->context, instance_data->monitorable, 
00620         instance_data->source, "close"));
00621     }
00622     else
00623     {
00624       GAT_CREATE_STATUS(POSIX_TO_GAT(errno));
00625     }
00626     instance_data->instance_data = NULL;
00627     
00628     return GAT_RETURN_STATUS();
00629   }
00630   return GAT_INVALID_HANDLE;
00631 }
00632 
00633 
00634 /* Monitoring support */ 
00635 
00636 /** filestream_adaptor_FileStreamCPI_GetMetrics
00637  *
00638  *  The function filestream_adaptor_FileStreamCPI_GetMetrics should return a 
00639  *  list of GATMetric objects supported by this adaptor. I.e. the adaptor is 
00640  *  capable to fire GATMetricEvents for the returned metrics. This list should 
00641  *  include all the supported metrics, event like and continuous ones.
00642  *
00643  *  @param data Adaptor-provided data object.
00644  *  @param instance_data Instance data for the CPI provider object.
00645  *  @param metrics The pointer to the variable, which receives the returned 
00646  *        list of metrics.
00647  *
00648  *  @return An error code.
00649  */
00650 static GATResult 
00651 filestream_adaptor_FileStreamCPI_GetMetrics(void *data, 
00652   GATFileStreamCPI_Instance const *instance_data, GATList_GATMetric *metrics)
00653 {
00654   return GATMetric_CreateListOfMetrics(metric_data, __countof(metric_data), 
00655     metrics);
00656 }
00657 
00658 /** filestream_adaptor_FileStreamCPI_GetMetricEvent
00659  *
00660  *  The function filestream_adaptor_FileStreamCPI_GetMetricEvent should 
00661  *  return the GATMetricEvent associated with the given continuous metric. This 
00662  *  function gets called for continuous metrics only, since returning the 
00663  *  metric event object to the caller is th only way for the client to get 
00664  *  access to it.
00665  *
00666  *  @param data Adaptor-provided data object.
00667  *  @param instance_data Instance data for the CPI provider object.
00668  *  @param metric The metric instance describing the metric event to return.
00669  *        This metric should be equivalent to one of the metrics returned by
00670  *        our own GetMetrics CPI function (see above). If this is another
00671  *        (not known to us metric), an error should be returned.
00672  *  @param event The pointer to the variable, which receives the metric event 
00673  *        to return.
00674  *
00675  *  @return An error code.
00676  */
00677 static GATResult 
00678 filestream_adaptor_FileStreamCPI_GetMetricEvent(void *data, 
00679   GATFileStreamCPI_Instance const *instance_data, GATMetric metric, 
00680   GATMetricEvent *event)
00681 {
00682   /* this adaptor supports no continuous metrics */
00683   GATResult retval = GAT_SUCCESS;
00684   return retval;
00685 }
00686 
00687 
00688 /** filestream_adaptor_FireReadEvent
00689  *
00690  *  The function filestream_adaptor_FireReadEvent fires a 
00691  *  'filestream read' event to all registered metric listeners.
00692  */
00693 static GATResult 
00694 filestream_adaptor_FireReadEvent(GATContext context, 
00695   GATMonitorable_Impl monitorable, GATObject_const source, char const *name)
00696 {
00697   GAT_USES_STATUS(context, "filestream_adaptor_FireReadEvent");
00698   if (NULL != monitorable && NULL != source && NULL != name)
00699   {
00700     GATMetric metric = NULL;
00701     
00702     GAT_CREATE_STATUS(GATMetric_CreateMetric(
00703       &metric_data[METRIC_FILESTREAM_READ], &metric));
00704     if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00705     {
00706       GATMetricEvent event = GATMetricEvent_Create_EventLike(source, metric, 
00707         (void *)name, (GATuint32)(strlen(name) + 1));
00708         
00709       if (NULL != event)
00710       {
00711         GAT_CREATE_STATUS(GATMonitorable_Impl_FireEvent(monitorable, metric, 
00712           event));
00713       }
00714       else
00715       {
00716         GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00717       }
00718       
00719       GATMetricEvent_Destroy(&event);
00720       GATMetric_Destroy(&metric);
00721     }
00722   }
00723   else
00724   {
00725     GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00726   }
00727   return GAT_RETURN_STATUS();
00728 }
00729 
00730 /** filestream_adaptor_FireWriteEvent
00731  *
00732  *  The function filestream_adaptor_FireWriteEvent fires a 
00733  *  'filestream write' event to all registered metric listeners.
00734  */
00735 static GATResult 
00736 filestream_adaptor_FireWriteEvent(GATContext context, 
00737   GATMonitorable_Impl monitorable, GATObject_const source, char const *name)
00738 {
00739   GAT_USES_STATUS(context, "filestream_adaptor_FireWriteEvent");
00740   if (NULL != monitorable && NULL != source && NULL != name)
00741   {
00742     GATMetric metric = NULL;
00743     
00744     GAT_CREATE_STATUS(GATMetric_CreateMetric(
00745       &metric_data[METRIC_FILESTREAM_WRITE], &metric));
00746     if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00747     {
00748       GATMetricEvent event = GATMetricEvent_Create_EventLike(source, metric, 
00749         (void *)name, (GATuint32)(strlen(name) + 1));
00750         
00751       if (NULL != event)
00752       {
00753         GAT_CREATE_STATUS(GATMonitorable_Impl_FireEvent(monitorable, metric, 
00754           event));
00755       }
00756       else
00757       {
00758         GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00759       }
00760       
00761       GATMetricEvent_Destroy(&event);
00762       GATMetric_Destroy(&metric);
00763     }
00764   }
00765   else
00766   {
00767     GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00768   }
00769   return GAT_RETURN_STATUS();
00770 }
00771 
00772 /** filestream_adaptor_FireSeekEvent
00773  *
00774  *  The function filestream_adaptor_FireSeekEvent fires a 
00775  *  'filestream seek' event to all registered metric listeners.
00776  */
00777 static GATResult 
00778 filestream_adaptor_FireSeekEvent(GATContext context, 
00779   GATMonitorable_Impl monitorable, GATObject_const source, char const *name)
00780 {
00781   GAT_USES_STATUS(context, "filestream_adaptor_FireSeekEvent");
00782   if (NULL != monitorable && NULL != source && NULL != name)
00783   {
00784     GATMetric metric = NULL;
00785     
00786     GAT_CREATE_STATUS(GATMetric_CreateMetric(
00787       &metric_data[METRIC_FILESTREAM_SEEK], &metric));
00788     if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00789     {
00790       GATMetricEvent event = GATMetricEvent_Create_EventLike(source, metric, 
00791         (void *)name, (GATuint32)(strlen(name) + 1));
00792         
00793       if (NULL != event)
00794       {
00795         GAT_CREATE_STATUS(GATMonitorable_Impl_FireEvent(monitorable, metric, 
00796           event));
00797       }
00798       else
00799       {
00800         GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00801       }
00802       
00803       GATMetricEvent_Destroy(&event);
00804       GATMetric_Destroy(&metric);
00805     }
00806   }
00807   else
00808   {
00809     GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00810   }
00811   return GAT_RETURN_STATUS();
00812 }
00813 
00814 /** filestream_adaptor_FireCloseEvent
00815  *
00816  *  The function filestream_adaptor_FireCloseEvent fires a 
00817  *  'filestream close' event to all registered metric listeners.
00818  */
00819 static GATResult 
00820 filestream_adaptor_FireCloseEvent(GATContext context, 
00821   GATMonitorable_Impl monitorable, GATObject_const source, char const *name)
00822 {
00823   GAT_USES_STATUS(context, "filestream_adaptor_FireCloseEvent");
00824   if (NULL != monitorable && NULL != source && NULL != name)
00825   {
00826     GATMetric metric = NULL;
00827     
00828     GAT_CREATE_STATUS(GATMetric_CreateMetric(
00829       &metric_data[METRIC_FILESTREAM_CLOSE], &metric));
00830     if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00831     {
00832       GATMetricEvent event = GATMetricEvent_Create_EventLike(source, metric, 
00833         (void *)name, (GATuint32)(strlen(name) + 1));
00834         
00835       if (NULL != event)
00836       {
00837         GAT_CREATE_STATUS(GATMonitorable_Impl_FireEvent(monitorable, metric, 
00838           event));
00839       }
00840       else
00841       {
00842         GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00843       }
00844       
00845       GATMetricEvent_Destroy(&event);
00846       GATMetric_Destroy(&metric);
00847     }
00848   }
00849   else
00850   {
00851     GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00852   }
00853   return GAT_RETURN_STATUS();
00854 }