GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATFileStreamCPI.c

Go to the documentation of this file.
00001 /** @file GATFileStreamCPI.c
00002  * Main .c for the GATFileStreamCPI class.
00003  * 
00004  * A GATFileStreamCPI encapsulates all the methods that a GATFileStream capability
00005  * provider provides.
00006  * 
00007  * @date $Date: 2004/04/02 12:31:57 $
00008  * 
00009  * @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATFileStreamCPI.c,v 1.5 2004/04/02 12:31:57 hartmutkaiser Exp $
00010  *
00011  *  Copyright (C) Kelly Davis
00012  *  This fileStream is part of the GAT Engine.
00013  *  Contributed by Kelly Davis <kdavis@aei.mpg.de> and
00014  *  Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00015  *
00016  *  Use, modification and distribution is subject to the Gridlab Software
00017  *  License. (See accompanying file GLlicense.txt or copy at
00018  *  http://www.gridlab.org/GLlicense.txt)
00019  */
00020 
00021 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATFileStreamCPI.c,v 1.5 2004/04/02 12:31:57 hartmutkaiser Exp $";
00022 
00023 /* System Header Files */
00024 
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 
00028 /* GAT Header Files */
00029 
00030 #include "GATFileStreamCPI.h"
00031 
00032 /* Macros */
00033 
00034 /* Structures, unions and enums */
00035 
00036 struct GATFileStreamCPI_S
00037 {
00038   /* CPI data (type local data) */
00039   void *data;
00040   GATFileStreamCPI_Adaptor_Destroy destroy;
00041   GATFileStreamCPI_Adaptor_ServiceActions service_actions;
00042 
00043   /* CPI instance data */
00044   GATFileStreamCPI_Adaptor_CreateInstance create_instance;
00045   GATFileStreamCPI_Adaptor_DestroyInstance destroy_instance;
00046   GATFileStreamCPI_Adaptor_CloneInstance clone_instance;
00047   GATFileStreamCPI_Adaptor_EqualsInstance equals_instance;
00048 
00049   /* CPI functionality */
00050   GATFileStreamCPI_Adaptor_Read read;
00051   GATFileStreamCPI_Adaptor_Write write;
00052   GATFileStreamCPI_Adaptor_Seek seek;
00053   GATFileStreamCPI_Adaptor_Close close;
00054   
00055   /* CPI monitoring support */
00056   GATFileStreamCPI_Adaptor_GetMetrics get_metrics;
00057   GATFileStreamCPI_Adaptor_GetMetricEvent get_metric_event;
00058 };
00059 
00060 /* Static function prototypes */
00061 static int GATFileStreamCPI_IsValidData_V1(GATFileStreamCPI_Data *data);
00062 
00063 /* File scope variables */
00064 
00065 /* External functions */
00066 
00067 /** GATFileStreamCPI_Create
00068  *  The  GATFileStreamCPI constructor.
00069  *  This is the constructor for GATFileStreamCPI objects.
00070  *  
00071  *  @param version Version of the GATFileStreamCPI_Data structure
00072  *  @param data Pointer to adaptor CPI instance data structure.
00073  *
00074  * @return A new GATFileStreamCPI
00075  */
00076 GATFileStreamCPI GATFileStreamCPI_Create(unsigned long int version, GATFileStreamCPI_Data *data)
00077 {
00078   GATFileStreamCPI new_cpi = NULL;
00079 
00080   if (version <= GATFILESTREAMCPI_VERSION)
00081   {
00082     if (version == GATFILESTREAMCPI_VERSION && 
00083         GATTrue == GATFileStreamCPI_IsValidData_V1(data))
00084     {
00085       new_cpi = (GATFileStreamCPI)malloc(sizeof(struct GATFileStreamCPI_S));
00086       if(NULL != new_cpi)
00087       {
00088         new_cpi->data = data->data;
00089         new_cpi->destroy = data->destroy;
00090         new_cpi->service_actions = data->service_actions;
00091         
00092         new_cpi->destroy_instance = data->destroy_instance;
00093         new_cpi->create_instance = data->create_instance;
00094         new_cpi->equals_instance = data->equals_instance;
00095         new_cpi->clone_instance = data->clone_instance;
00096 
00097         new_cpi->read = data->read;
00098         new_cpi->write = data->write;
00099         new_cpi->seek = data->seek;
00100         new_cpi->close = data->close;
00101         
00102         new_cpi->get_metrics = data->get_metrics;
00103         new_cpi->get_metric_event = data->get_metric_event;
00104       }
00105     }
00106 /*  add functionality for newer versions here
00107     else if (version == GATFILESTREAMCPI_VERSION2 && GATFileStreamCPI_IsValidData_V2(data))
00108     {
00109       ...
00110     }
00111  */
00112     else
00113     {
00114       /* Missing required functions */
00115       /* error_code = GAT_INVALID_PARAMETER; */
00116     }
00117   }
00118   else
00119   {
00120     /* unknown version */
00121     /* error_code = GAT_UNKNOWN_VERSION; */
00122   }
00123   return new_cpi;
00124 }
00125 
00126 /** GATFileStreamCPI_Destroy
00127  *  @brief The GATFileStreamCPI destructor.
00128  *
00129  *  This is the destructor for GATFileStreamCPI objects.
00130  *
00131  *  @param this An old GATFileStreamCPI
00132  */
00133 void GATFileStreamCPI_Destroy(GATFileStreamCPI *cpi)
00134 {
00135   if(NULL != cpi && NULL != *cpi)
00136   {
00137     (*cpi)->destroy((*cpi)->data);
00138     free(*cpi);
00139     *cpi = NULL;
00140   }
00141 }
00142 
00143 /** GATFileStreamCPI_CreateInstance
00144  *  @brief Create a new CPI object instance
00145  *
00146  *  Calls the adaptor to create a new CPI object instance.
00147  *
00148  *  @param this The CPI object.
00149  *  @param instance_data The instance data of the attached CPI object
00150  *
00151  *  @return An error code.
00152  */
00153 GATResult 
00154 GATFileStreamCPI_CreateInstance(GATFileStreamCPI cpi, GATFileStreamCPI_Instance *data)
00155 {
00156   return cpi->create_instance(cpi->data, data);
00157 }
00158 
00159 /** GATFileStreamCPI_DestroyInstance
00160  *  @brief Create a new CPI object instance
00161  *
00162  *  Calls the adaptor to destroy a CPI object instance.
00163  *
00164  *  @param this The CPI object.
00165  *  @param instance_data The instance data of the attached CPI object
00166  */
00167 void 
00168 GATFileStreamCPI_DestroyInstance(GATFileStreamCPI cpi, GATFileStreamCPI_Instance *data)
00169 {
00170   cpi->destroy_instance(cpi->data, data);
00171 }
00172 
00173 /** GATFileStreamCPI_EqualsInstance
00174  *  @brief Compares two CPI object instances.
00175  *
00176  *  Calls the adaptor to compare two CPI object instances.
00177  *
00178  *  @param this The CPI object.
00179  *  @param lhs The instance data of the left CPI object
00180  *  @param rhs The instance data of the right CPI object
00181  *  @param isequal The pointer to the variable, where the result is to be 
00182  *        returned to.
00183  *
00184  *  @return An error code.
00185  */
00186 GATResult 
00187 GATFileStreamCPI_EqualsInstance(GATFileStreamCPI cpi, GATFileStreamCPI_Instance const *lhs, 
00188   GATFileStreamCPI_Instance const *rhs, GATBool *isequal)
00189 {
00190   return cpi->equals_instance(cpi->data, lhs, rhs, isequal);
00191 }
00192 
00193 /** GATFileStreamCPI_CloneInstance
00194  *  @brief Clones a CPI object instance.
00195  *
00196  *  Calls the adaptor to clone a CPI object instance.
00197  *
00198  *  @param this The CPI object.
00199  *  @param instance_data The instance data of the CPI object to clone.
00200  *  @param rhs The new instance data is to be returned here.
00201  *
00202  *  @return An error code.
00203  */
00204 GATResult 
00205 GATFileStreamCPI_CloneInstance(GATFileStreamCPI cpi, 
00206   GATFileStreamCPI_Instance const *data, GATFileStreamCPI_Instance *new_data) 
00207 {
00208   return cpi->clone_instance(cpi->data, data, new_data);
00209 }
00210 
00211 /** GATFileStreamCPI_Read
00212  *  @brief Read from this fileStream.
00213  *
00214  *  Calls the adaptor to read from this fileStream.
00215  *
00216  *  @param cpi The CPI object.
00217  *  @param data The instance data of the attached CPI object
00218  *  @param buffer The buffer to read into
00219  *  @param size Size of data to read
00220  *  @param read_bytes Number of bytes read
00221  *
00222  *  @return An error code.
00223  */
00224 GATResult GATFileStreamCPI_Read(GATFileStreamCPI cpi, GATFileStreamCPI_Instance const *data, void *buffer, GATuint32 size, GATuint32 *read_bytes)
00225 {
00226   return cpi->read(cpi->data, data, buffer, size, read_bytes);
00227 }
00228 
00229 /** GATFileStreamCPI_Write
00230  *  @brief Write to this fileStream.
00231  *
00232  *  Calls the adaptor to write to this fileStream.
00233  *
00234  *  @param cpi The CPI object.
00235  *  @param data The instance data of the attached CPI object
00236  *  @param buffer The buffer to write from
00237  *  @param size Size of data to write
00238  *  @param read_bytes Number of bytes written
00239  *
00240  *  @return An error code.
00241  */
00242 GATResult GATFileStreamCPI_Write(GATFileStreamCPI cpi, GATFileStreamCPI_Instance const *data, void const *buffer, GATuint32 size, GATuint32 *written_bytes)
00243 {
00244   return cpi->write(cpi->data, data, buffer, size, written_bytes);
00245 }
00246 
00247 /** GATFileStreamCPI_Seek
00248  *  @brief Seek on this fileStream.
00249  *
00250  *  Calls the adaptor to seek on this fileStream.
00251  *
00252  *  @param cpi The CPI object.
00253  *  @param data The instance data of the attached CPI object
00254  *  @param origin Where to seek from
00255  *  @param offset Offset of seek
00256  *  @param new_position New position
00257  *
00258  *  @return An error code.
00259  */
00260 GATResult 
00261 GATFileStreamCPI_Seek(GATFileStreamCPI cpi, GATFileStreamCPI_Instance const *data, 
00262   GATOrigin origin, GATint32 offset, GATuint32 *new_position)
00263 {
00264   return cpi->seek(cpi->data, data, origin, offset, new_position);
00265 }
00266 
00267 /** GATFileStreamCPI_Close
00268  *  @brief Closes this fileStream.
00269  *
00270  *  Calls the adaptor to close this fileStream.
00271  *
00272  *  @param cpi The CPI object.
00273  *  @param data The instance data of the attached CPI object
00274  *
00275  *  @return An error code.
00276  */
00277 GATResult 
00278 GATFileStreamCPI_Close(GATFileStreamCPI cpi, GATFileStreamCPI_Instance *data)
00279 {
00280   return cpi->close(cpi->data, data);
00281 }
00282 
00283 /** GATFileStreamCPI_GetMetrics
00284  *
00285  *  The function GATFileStreamCPI_GetMetrics returns the list of metrics supported
00286  *  by this adaptor.
00287  *
00288  *  @param this The CPI object.
00289  *  @param instance_data The instance data of the attached CPI object
00290  *  @param The pointer to the variable, which receives the resulting list of
00291  *        metrics.
00292  *
00293  *  @return An error code.
00294  */
00295 GATResult 
00296 GATFileStreamCPI_GetMetrics(GATFileStreamCPI cpi, GATFileStreamCPI_Instance const *data,
00297   GATList_GATMetric *metrics)
00298 {
00299   return cpi->get_metrics(cpi->data, data, metrics);
00300 }
00301 
00302 /** GATFileStreamCPI_GetMetricEvent
00303  *
00304  *  The function GATFileStreamCPI_GetMetricEvent returns the metric event, which is 
00305  *  associated with the given metric.
00306  *
00307  *  @param this The CPI object.
00308  *  @param instance_data The instance data of the attached CPI object
00309  *  @param metric The continuous metric, for which the metric event is to be 
00310  *        returned. 
00311  *  @param event The pointer to the variable, which receives the resulting
00312  *        metric event.
00313  *
00314  *  @return An error code.
00315  */
00316 GATResult
00317 GATFileStreamCPI_GetMetricEvent(GATFileStreamCPI cpi, GATFileStreamCPI_Instance const *data,
00318   GATMetric metric, GATMetricEvent *event)
00319 {
00320   return cpi->get_metric_event(cpi->data, data, metric, event);
00321 }
00322 
00323 /* Local functions */
00324 static int 
00325 GATFileStreamCPI_IsValidData_V1(GATFileStreamCPI_Data *data)
00326 {
00327   return (
00328       NULL != data->destroy && 
00329 //      NULL != data->service_actions &&
00330             
00331       NULL != data->destroy_instance && 
00332       NULL != data->create_instance && 
00333       NULL != data->clone_instance && 
00334       NULL != data->equals_instance &&  
00335       
00336       NULL != data->read && 
00337       NULL != data->write && 
00338       NULL != data->seek && 
00339       NULL != data->close && 
00340       
00341       NULL != data->get_metrics &&
00342       NULL != data->get_metric_event
00343     ) ? 1 : 0;
00344 }