GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATPipeCPI.c

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