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 logicalfile adaptor.
00003  * 
00004  * Test adaptor to check the GATLogicalFile API. Provides a simple
00005  * file GATLogicalFileCPI implementation.
00006  * 
00007  * @date Sun Oct 5 2003
00008  * 
00009  * @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/logicalfile/adaptor.c,v 1.20 2004/04/22 10:25:05 hartmutkaiser Exp $
00010  *
00011  *  Copyright (C) Hartmut Kaiser
00012  *  This file is part of the GAT Engine.
00013  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] 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/logicalfile/adaptor.c,v 1.20 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 
00027 #include <sys/wait.h>
00028 #include <sys/stat.h>
00029 
00030 /* GAT Header Files */
00031 #include <GATCPI.h>
00032 #include "GATUtil.h"
00033 
00034 #include "logical_filestore.h"
00035 
00036 /* Macros */
00037 #define __countof(x) (sizeof(x)/sizeof(x[0]))
00038 
00039 /* Structures, unions and enums */
00040 
00041 /* Static function prototypes */
00042 static void 
00043 logicalfile_adaptor_LogicalFileCPI_Destroy(void *data);
00044 
00045 /* instance specific functions */
00046 static GATResult
00047 logicalfile_adaptor_LogicalFileCPI_ServiceActions(void *data, 
00048   GATLogicalFileCPI_Instance *instance_data, GATTimePeriod_const timeout /* = 0 */);
00049   
00050 GATResult 
00051 logicalfile_adaptor_LogicalFileCPI_CreateInstance(void *adaptor_data, 
00052   GATLogicalFileCPI_Instance *data);
00053 
00054 void 
00055 logicalfile_adaptor_LogicalFileCPI_DestroyInstance(void *adaptor_data, 
00056   GATLogicalFileCPI_Instance *data);
00057 
00058 GATResult 
00059 logicalfile_adaptor_LogicalFileCPI_CloneInstance(void *adaptor_data, 
00060   GATLogicalFileCPI_Instance const *data, 
00061   GATLogicalFileCPI_Instance *new_data);
00062 
00063 GATResult 
00064 logicalfile_adaptor_LogicalFileCPI_EqualsInstance(void *adaptor_data, 
00065   GATLogicalFileCPI_Instance const *lhs, GATLogicalFileCPI_Instance const *rhs, 
00066   GATBool *isequal);
00067 
00068 /* Execute a GATLogicalFile add file operation */
00069 static GATResult 
00070 logicalfile_adaptor_LogicalFileCPI_AddFile(void *adaptor_data, 
00071   GATLogicalFileCPI_Instance *data, GATFile_const target);
00072 
00073 /* Execute a GATLogicalFile remove file operation */
00074 static GATResult 
00075 logicalfile_adaptor_LogicalFileCPI_RemoveFile(void *adaptor_data, 
00076   GATLogicalFileCPI_Instance *data, GATFile_const target);
00077 
00078 /* Execute a GATLogicalFile replicate file operation */
00079 static GATResult 
00080 logicalfile_adaptor_LogicalFileCPI_Replicate(void *adaptor_data, 
00081   GATLogicalFileCPI_Instance const *data, GATLocation_const target);
00082 
00083 /* Execute a GATLogicalFile get files operation */
00084 static GATResult 
00085 logicalfile_adaptor_LogicalFileCPI_GetFiles(void *adaptor_data, 
00086   GATLogicalFileCPI_Instance const *data, GATList_GATFile *target);
00087 
00088 /* Execute a GATLogicalFile remove operation */
00089 static GATResult 
00090 logicalfile_adaptor_LogicalFileCPI_Remove(void *adaptor_data, 
00091   GATLogicalFileCPI_Instance const *data);
00092 
00093 /* Serialisation functions */
00094 static GATResult 
00095 logicalfile_adaptor_LogicalFileCPI_Serialise(void *data, 
00096   GATLogicalFileCPI_Instance const *instance_data, GATObject stream,
00097   GATBool clear_dirty);
00098   
00099 static GATResult 
00100 logicalfile_adaptor_LogicalFileCPI_DeSerialise(void *data, 
00101   GATObject stream, GATLogicalFileCPI_Instance *instance_data);
00102   
00103 /* Execute a GATLogicalFile get_metrics operation */
00104 static GATResult 
00105 logicalfile_adaptor_LogicalFileCPI_GetMetrics(void *data, 
00106   GATLogicalFileCPI_Instance const *instance_data, GATList_GATMetric *metrics);
00107 
00108 /* Execute a GATLogicalFile get_metric_event operation */
00109 static GATResult 
00110 logicalfile_adaptor_LogicalFileCPI_GetMetricEvent(void *data, 
00111   GATLogicalFileCPI_Instance const *instance_data, GATMetric metric, 
00112     GATMetricEvent *event);
00113     
00114 /* local helper functions */
00115 static GATResult 
00116 logicalfile_adaptor_FireReplicatedEvent(GATMonitorable_Impl monitorable, 
00117   GATObject_const source, char const *name);
00118   
00119 
00120 /* File scope variables */
00121 static GATStaticMetric metric_data[] = {
00122   /* fileops.file_copied event */
00123   { 
00124     "logicalfile.file_replicated",  /* name */
00125     GATMeasurementType_EventLike,   /* type */
00126     GATType_String,                 /* data type */
00127     "",                             /* unit */
00128     0,                              /* parameter count */
00129     0                               /* parameters */
00130   },
00131 };
00132 
00133 /* symbolic constants for the metric positions inside the metric_data array */
00134 #define METRIC_FILE_REPLICATED  0
00135 
00136 
00137 /* External functions */
00138 
00139 /** logicalfile_adaptor_register
00140  *  Registers all CPIs this adaptor provides.
00141  *  This function is invoked by the loader in the GATEngine when
00142  *  an instance of this adaptor is loaded.  Each instance has its
00143  *  own private configuration table.
00144  *
00145  *  For every CPI provided the adapter has to hand all the corresponding 
00146  *  function pointers to the engine to allow to be called back under certain
00147  *  circumstances. Additionally the adaptor may allocate some private data for
00148  *  every loaded instance. This data is handed back to the adaptor as the first
00149  *  parameter to each of the subsequently called functions.
00150  *
00151  *  @param registry The registry the adaptor should register its CPIs with.
00152  *  @param system_config The system configuration table.
00153  *  @param instance_config The configuration table for this instance.
00154  *  @param token An arbitrary token used by the loader to identify this adaptor 
00155  *        instance
00156  *
00157  *  @return An error code.
00158  */
00159 GATResult 
00160 logicalfile_adaptor_register(GATContext error_context, GATRegistry registry, 
00161   GATTable_const system_config, GATTable_const instance_config, void *token)
00162 {
00163   GATResult retcode = GAT_MEMORYFAILURE;
00164 
00165   if (!GATVERSION_ISCOMPATIBLE())
00166   {
00167     retcode = GAT_UNKNOWN_VERSION;
00168   }
00169   else
00170   {
00171     GATLogicalFileCPI cpi = NULL;
00172     GATLogicalFileCPI_Data cpidata;
00173     
00174     memset(&cpidata, 0, sizeof(GATLogicalFileCPI_Data));
00175       
00176     /*
00177     *  provide the appropriate callback functions
00178     */
00179       
00180     /* adaptor instance data */
00181     cpidata.data = NULL;
00182     cpidata.destroy = logicalfile_adaptor_LogicalFileCPI_Destroy;
00183     
00184     /*  Lifetime control and basic GATObject functionality support for every
00185     *  object instance created by the client.
00186     */
00187     cpidata.service_actions = logicalfile_adaptor_LogicalFileCPI_ServiceActions;
00188     cpidata.create_instance = logicalfile_adaptor_LogicalFileCPI_CreateInstance;
00189     cpidata.destroy_instance = logicalfile_adaptor_LogicalFileCPI_DestroyInstance;
00190     cpidata.clone_instance = logicalfile_adaptor_LogicalFileCPI_CloneInstance;
00191     cpidata.equals_instance = logicalfile_adaptor_LogicalFileCPI_EqualsInstance;
00192 
00193     /* serialisation support for the provided instance data */
00194     cpidata.serialise = logicalfile_adaptor_LogicalFileCPI_Serialise;
00195     cpidata.deserialise = logicalfile_adaptor_LogicalFileCPI_DeSerialise;
00196 
00197     /* the CPI specific functionality */
00198     cpidata.add = logicalfile_adaptor_LogicalFileCPI_AddFile;
00199     cpidata.removefile = logicalfile_adaptor_LogicalFileCPI_RemoveFile;
00200     cpidata.replicate = logicalfile_adaptor_LogicalFileCPI_Replicate;
00201     cpidata.getfiles = logicalfile_adaptor_LogicalFileCPI_GetFiles;
00202     cpidata.remove = logicalfile_adaptor_LogicalFileCPI_Remove;
00203     
00204     /* monitoring support */
00205     cpidata.get_metrics = logicalfile_adaptor_LogicalFileCPI_GetMetrics;
00206     cpidata.get_metric_event = logicalfile_adaptor_LogicalFileCPI_GetMetricEvent;
00207 
00208     /* Create a GATLogicalFileCPI object. */
00209     cpi = GATLogicalFileCPI_Create(GATLOGICALFILECPI_VERSION, &cpidata);
00210     if(NULL != cpi)
00211     {
00212       /* Need to pass preferences to allow matching
00213       * of a user's preferences with what this adaptor does.
00214       */
00215       GATPreferences preferences = GATPreferences_Create();
00216       if(NULL != preferences)
00217       {
00218         /* at least the Name preference should be defined */
00219         GATPreferences_Add(preferences, "Name", "logicalfile_adaptor");
00220         GATPreferences_Add(preferences, "Security", "none");
00221         GATPreferences_Add(preferences, "Local", "true");
00222         
00223         retcode = GATRegistry_AddGATLogicalFileCPI(registry, cpi, token, 
00224           preferences);
00225         
00226         GATPreferences_Destroy(&preferences);
00227       }
00228     }
00229     
00230     if (GAT_SUCCESS != retcode)
00231     {
00232       GATLogicalFileCPI_Destroy(&cpi);
00233     }
00234   }
00235   return retcode;
00236 }
00237 
00238 /* Local functions */
00239 
00240 /** logicalfile_adaptor_LogicalFileCPI_Destroy
00241  *  Destroy the adaptor-provided data object on GATLogicalFileCPI destruction.
00242  *  When the GATLogicalFileCPI object created in this adaptor's _register
00243  *  function is destroyed, this function is invoked to allow the
00244  *  adaptor to cleanup.
00245  *
00246  *  @param data Adaptor-provided data object.
00247  */
00248 static void 
00249 logicalfile_adaptor_LogicalFileCPI_Destroy(void *data)
00250 {
00251   /* nothing to do here (no internal data allocated) */
00252 }
00253 
00254 /** logicalfile_adaptor_LogicalFileCPI_ServiceActions
00255  *  
00256  *  The function logicalfile_adaptor_LogicalFileCPI_ServiceActions is called, whenever
00257  *  the client calls GATContext_ServiceActions. This function is called for 
00258  *  every created object.
00259  *  This function should be used to update all instance specific data, which 
00260  *  may have been changed asynchronously or to fire pending events.
00261  *
00262  *  @param data Adaptor-provided data object.
00263  *  @param instance_data The instance data of this CPI object
00264  *  @param timeout This may be a 0 timeout to indicate no timeout at all, or
00265  *        a specific time length.
00266  *
00267  *  @return An error code.
00268  */
00269 static GATResult
00270 logicalfile_adaptor_LogicalFileCPI_ServiceActions(void *data, 
00271   GATLogicalFileCPI_Instance *instance_data, GATTimePeriod_const timeout)
00272 {
00273   return GAT_NOTIMPL;
00274 }
00275 
00276 /** logicalfile_adaptor_LogicalFileCPI_CreateInstance
00277  *  Create a new CPI object instance.
00278  *  Adaptor implementation of create instance capability.
00279  *
00280  * @param adaptor_data Adaptor-provided data object.
00281  * @param data The pointer to the data structure containing at least 
00282  *        the constructor provided data items and a member instance_data, which 
00283  *        may be used by the adaptor to store CPI instance specific data.
00284  * 
00285  * @return An error code.
00286  */
00287 GATResult 
00288 logicalfile_adaptor_LogicalFileCPI_CreateInstance(void *adaptor_data, 
00289   GATLogicalFileCPI_Instance *data)
00290 {
00291   GATResult retval = GAT_INVALID_PARAMETER;
00292   if (NULL != data)
00293   {
00294     /* this adaptor does not maintain instance data */
00295     data->instance_data = NULL;
00296     retval = GAT_SUCCESS;
00297   }
00298   return retval;
00299 }
00300 
00301 /** logicalfile_adaptor_LogicalFileCPI_DestroyInstance
00302  *  Destroy a CPI object instance.
00303  *  Adaptor implementation of destroy instance capability.
00304  *
00305  * @param data Adaptor-provided data object.
00306  * @param instance_data The instance data of the CPI object to destroy.
00307  */
00308 void
00309 logicalfile_adaptor_LogicalFileCPI_DestroyInstance(void *adaptor_data, 
00310   GATLogicalFileCPI_Instance *data)
00311 {
00312   /* this adaptor does not maintain instance data */
00313   assert(NULL == data || NULL == data->instance_data);
00314 }
00315 
00316 /** logicalfile_adaptor_LogicalFileCPI_CloneInstance
00317  *  Clone a CPI object instance.
00318  *  Adaptor implementation of the clone instance capability.
00319  *
00320  * @param data Adaptor-provided data object.
00321  * @param instance_data The instance data of this CPI object
00322  * @param new_instance_data The pointer to the variable, where the instance 
00323  *      data of the cloned CPI object is to be returned to.
00324  * 
00325  * @return An error code.
00326  */
00327 GATResult 
00328 logicalfile_adaptor_LogicalFileCPI_CloneInstance(void *adaptor_data, 
00329   GATLogicalFileCPI_Instance const *instance_data, 
00330   GATLogicalFileCPI_Instance *new_instance_data)
00331 {
00332   /* this adaptor does not maintain instance data */
00333   assert(NULL != new_instance_data);
00334   new_instance_data->instance_data = NULL;
00335   return GAT_SUCCESS;
00336 }
00337 
00338 /** logicalfile_adaptor_LogicalFileCPI_EqualsInstance
00339  *  Clone a CPI object instance.
00340  *  Adaptor implementation of the clone instance capability.
00341  *
00342  * @param data Adaptor-provided data object.
00343  * @param lhs The instance data of the left CPI object.
00344  * @param lhs The instance data of the right CPI object.
00345  * @param isequal The pointer to the variable, where the result is to be 
00346  *        returned to.
00347  *
00348  * @return An error code.
00349  */
00350 GATResult 
00351 logicalfile_adaptor_LogicalFileCPI_EqualsInstance(void *data, 
00352   GATLogicalFileCPI_Instance const *lhs, GATLogicalFileCPI_Instance const *rhs, 
00353   GATBool *isequal)
00354 {
00355   /* this adaptor does not maintain instance data */
00356   GATResult retval = GAT_INVALID_HANDLE;
00357   if (NULL != isequal)
00358   {
00359     *isequal = GATTrue;
00360     retval = GAT_SUCCESS;
00361   }
00362   return retval;
00363 }
00364 
00365 /** logicalfile_adaptor_LogicalFileCPI_AddFile
00366  *  Add a file to the logical file store.
00367  *  Adaptor implementation of logical file add capability.
00368  *
00369  * @param data Adaptor-provided data object.
00370  * @param context a GATContext
00371  * @param target File to add to the logical file collection.
00372  * 
00373  * @return An error code.
00374  */
00375 static GATResult 
00376 logicalfile_adaptor_LogicalFileCPI_AddFile(void *adaptor_data, 
00377   GATLogicalFileCPI_Instance *data, GATFile_const target)
00378 {
00379   GATResult retcode = GAT_FAIL;
00380   char const *name = GATLocation_ToString(data->location);
00381   logical_filestore store = logical_filestore_create(data->context, 
00382     name, data->mode);
00383 
00384   free((char *)name);
00385   if (NULL != store)
00386   {
00387     retcode = logical_filestore_addfile(data->context, store, target);
00388     logical_filestore_destroy(data->context, &store);  /* flush to disk and destroy object */
00389   }
00390   return retcode;
00391 }
00392 
00393 /** logicalfile_adaptor_LogicalFileCPI_RemoveFile
00394  *  Remove a file from the logical file store.
00395  *  Adaptor implementation of logical file remove capability.
00396  *
00397  * @param data Adaptor-provided data object.
00398  * @param instance_data The instance data of this CPI object
00399  * @param target File to remove from the collection.
00400  * 
00401  * @return An error code.
00402  */
00403 static GATResult 
00404 logicalfile_adaptor_LogicalFileCPI_RemoveFile(void *adaptor_data, 
00405   GATLogicalFileCPI_Instance *data, GATFile_const target)
00406 {
00407   GATResult retcode = GAT_FAIL;
00408   char const *name = GATLocation_ToString(data->location);
00409   logical_filestore store = logical_filestore_create(data->context, 
00410     name, data->mode);
00411 
00412   free((char *)name);
00413   if (NULL != store)
00414   {
00415     retcode = logical_filestore_removefile(data->context, store, target);
00416     logical_filestore_destroy(data->context, &store);  /* flush to disk and destroy object */
00417   }
00418   return retcode;
00419 }
00420 
00421 /** static GATResult logicalfile_adaptor_LogicalFileCPI_Remove
00422  *  Remove the logical file store.
00423  *  Adaptor implementation of logical file store remove capability.
00424  *
00425  * @param data Adaptor-provided data object.
00426  * @param instance_data The instance data of this CPI object
00427  * 
00428  * @return An error code.
00429  */
00430 static GATResult 
00431 logicalfile_adaptor_LogicalFileCPI_Remove(void *adaptor_data, 
00432   GATLogicalFileCPI_Instance const *data)
00433 {
00434   GATResult retcode = GAT_FAIL;
00435   char const *name = GATLocation_ToString(data->location);
00436   logical_filestore store = logical_filestore_create(data->context, 
00437     name, data->mode);
00438 
00439   free((char *)name);
00440   if (NULL != store)
00441   {
00442     retcode = logical_filestore_remove(store);
00443     logical_filestore_destroy(data->context, &store);  /* flush to disk and destroy object */
00444   }
00445   return retcode;
00446 }
00447 
00448 /** logicalfile_adaptor_LogicalFileCPI_Replicate
00449  *  Replicates the logical file store to a file at the given location.
00450  *  Adaptor implementation of logical file replicate capability.
00451  *
00452  * @param data Adaptor-provided data object.
00453  * @param instance_data The instance data of this CPI object
00454  * @param target Location of the file, where the logical file store is to be 
00455  *      replicated to.
00456  * 
00457  * @return An error code.
00458  */
00459 static GATResult 
00460 logicalfile_adaptor_LogicalFileCPI_Replicate(void *adaptor_data, 
00461   GATLogicalFileCPI_Instance const *data, GATLocation_const target)
00462 {
00463   GATResult retcode = GAT_FAIL;
00464   char const *name = GATLocation_ToString(data->location);
00465   logical_filestore store = logical_filestore_create(data->context, 
00466     name, data->mode);
00467 
00468   free((char *)name);
00469   if (NULL != store)
00470   {
00471     retcode = logical_filestore_replicate(data->context, store, target);
00472     logical_filestore_destroy(data->context, &store);  /* flush to disk and destroy object */
00473 
00474     if (GAT_SUCCESS == retcode)
00475     {
00476       /* fire the file_copied event */
00477       char *source = GATLocation_ToString(target);
00478       retcode = logicalfile_adaptor_FireReplicatedEvent(data->monitorable, 
00479         data->source, source);
00480       free(source);
00481     }
00482   }
00483   return retcode;
00484 }
00485 
00486 /** logicalfile_adaptor_LogicalFileCPI_GetFiles
00487  *  Get the list of physical files contained in the given logical file store.
00488  *  Adaptor implementation of logical file get files capability.
00489  *
00490  * @param data Adaptor-provided data object.
00491  * @param instance_data The instance data of this CPI object
00492  * @param target A pointer to the location, where the returned list of files is 
00493  *      to be placed to.
00494  * 
00495  * @return An error code.
00496  */
00497 static GATResult 
00498 logicalfile_adaptor_LogicalFileCPI_GetFiles(void *adaptor_data, 
00499   GATLogicalFileCPI_Instance const *data, GATList_GATFile *target)
00500 {
00501   GAT_USES_STATUS(data->context, "logicalfile_adaptor_LogicalFileCPI_GetFiles");
00502 
00503   if (NULL == target)
00504   {
00505     GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00506   }
00507   else
00508   {
00509     char const *name = GATLocation_ToString(data->location);
00510     logical_filestore store = logical_filestore_create(data->context, 
00511       name, data->mode);
00512 
00513     free((char *)name);
00514     *target = NULL;
00515     if (NULL != store)
00516     {
00517       GAT_CREATE_STATUS(logical_filestore_getfiles(data->context, store, target));
00518       logical_filestore_destroy(data->context, &store);  
00519       //retcode = (NULL != *target) ? GAT_SUCCESS : GAT_MEMORYFAILURE;
00520     }else{
00521       GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00522     }
00523   }
00524   return GAT_RETURN_STATUS();
00525 }
00526 
00527 /* Serialisation support */
00528 
00529 /** logicalfile_adaptor_LogicalFileCPI_Serialise
00530  *
00531  *  The function logicalfile_adaptor_LogicalFileCPI_Serialise is called by the 
00532  *  GAT engine, whenever the client requested a Serialise operation on the 
00533  *  corresponding GATLogicalFile object. The function should serialise into the 
00534  *  given stream all the instance specific data of the object.
00535  *
00536  *  @param data Adaptor-provided data object.
00537  *  @param instance_data The instance data of this CPI object.
00538  *  @param stream The GATSTream object to use for serialisation of the instance 
00539  *        data.
00540  *  @param clear_dirty This flag defines, whether the dirty flag of saved 
00541  *        dependent objects is to be cleared.
00542  *
00543  *  @return An error code
00544  */
00545 static GATResult 
00546 logicalfile_adaptor_LogicalFileCPI_Serialise(void *data, 
00547   GATLogicalFileCPI_Instance const *instance_data, GATObject stream,
00548   GATBool clear_dirty)
00549 {
00550   /* this adaptor does not maintain instance data */
00551   GATResult retval = GAT_SUCCESS;
00552   return retval;
00553 }
00554 
00555 /** logicalfile_adaptor_LogicalFileCPI_DeSerialise
00556  *
00557  *  The function logicalfile_adaptor_LogicalFileCPI_DeSerialise is called by 
00558  *  the GATEngine, whenever the client requested a DeSerialise operation for
00559  *  a GATLogicalFile object. The function should deserialise all the instance 
00560  *  specific data of the object from the given stream.
00561  *
00562  *  @param data Adaptor-provided data object.
00563  *  @param stream The GATSTream object to use for de-serialisation of the 
00564  *        instance data.
00565  *  @param instance_data The instance data of this CPI object.
00566  *
00567  *  @return An error code
00568  */
00569 static GATResult 
00570 logicalfile_adaptor_LogicalFileCPI_DeSerialise(void *data, 
00571   GATObject stream, GATLogicalFileCPI_Instance *instance_data)
00572 {
00573   /* this adaptor does not maintain instance data */
00574   GATResult retval = GAT_SUCCESS;
00575   if (instance_data)
00576   {
00577     instance_data->instance_data = NULL;
00578   }
00579   return retval;
00580 }
00581 
00582 
00583 /* Monitoring support */ 
00584 
00585 /** logicalfile_adaptor_LogicalFileCPI_GetMetrics
00586  *
00587  *  The function logicalfile_adaptor_LogicalFileCPI_GetMetrics should return a 
00588  *  list of GATMetric objects supported by this adaptor. I.e. the adaptor is 
00589  *  capable to fire GATMetricEvents for the returned metrics. This list should 
00590  *  include all the supported metrics, event like and continuous ones.
00591  *
00592  *  @param data Adaptor-provided data object.
00593  *  @param instance_data Instance data for the CPI provider object.
00594  *  @param metrics The pointer to the variable, which receives the returned 
00595  *        list of metrics.
00596  *
00597  *  @return An error code.
00598  */
00599 static GATResult 
00600 logicalfile_adaptor_LogicalFileCPI_GetMetrics(void *data, 
00601   GATLogicalFileCPI_Instance const *instance_data, GATList_GATMetric *metrics)
00602 {
00603   return GATMetric_CreateListOfMetrics(metric_data, __countof(metric_data), 
00604     metrics);
00605 }
00606 
00607 /** logicalfile_adaptor_LogicalFileCPI_GetMetricEvent
00608  *
00609  *  The function logicalfile_adaptor_LogicalFileCPI_GetMetricEvent should 
00610  *  return the GATMetricEvent associated with the given continuous metric. This 
00611  *  function gets called for continuous metrics only, since returning the 
00612  *  metric event object to the caller is th only way for the client to get 
00613  *  access to it.
00614  *
00615  *  @param data Adaptor-provided data object.
00616  *  @param instance_data Instance data for the CPI provider object.
00617  *  @param metric The metric instance describing the metric event to return.
00618  *        This metric should be equivalent to one of the metrics returned by
00619  *        our own GetMetrics CPI function (see above). If this is another
00620  *        (not known to us metric), an error should be returned.
00621  *  @param event The pointer to the variable, which receives the metric event 
00622  *        to return.
00623  *
00624  *  @return An error code.
00625  */
00626 static GATResult 
00627 logicalfile_adaptor_LogicalFileCPI_GetMetricEvent(void *data, 
00628   GATLogicalFileCPI_Instance const *instance_data, GATMetric metric, 
00629   GATMetricEvent *event)
00630 {
00631   /* this adaptor supports no continuous metrics */
00632   GATResult retval = GAT_SUCCESS;
00633   return retval;
00634 }
00635 
00636 
00637 /** logicalfile_adaptor_FireReplicatedEvent
00638  *
00639  *  The function logicalfile_adaptor_FireReplicatedEvent fires a 
00640  *  'file replicated' event to all registered metric listeners.
00641  */
00642 static GATResult 
00643 logicalfile_adaptor_FireReplicatedEvent(GATMonitorable_Impl monitorable, 
00644   GATObject_const source, char const *name)
00645 {
00646   GATResult retval = GAT_INVALID_PARAMETER;
00647   if (NULL != monitorable && NULL != source && NULL != name)
00648   {
00649     GATMetric metric = NULL;
00650     
00651     retval = GATMetric_CreateMetric(&metric_data[METRIC_FILE_REPLICATED], &metric);
00652     if (GAT_SUCCESS == retval)
00653     {
00654       GATMetricEvent event = GATMetricEvent_Create_EventLike(source, metric, 
00655         (void *)name, (GATuint32)(strlen(name) + 1));
00656         
00657       if (NULL != event)
00658       {
00659         retval = GATMonitorable_Impl_FireEvent(monitorable, metric, event);
00660       }
00661       else
00662       {
00663         retval = GAT_MEMORYFAILURE;
00664       }
00665       
00666       GATMetricEvent_Destroy(&event);
00667       GATMetric_Destroy(&metric);
00668     }
00669   }
00670   return retval;
00671 }
00672