GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATResourceCPI.c

Go to the documentation of this file.
00001 /** @file GATResourceCPI.c
00002  *  Source file for the GATResourceCPI class.
00003  *
00004  *  @date Sat Oct 25 2003
00005  *
00006  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATResourceCPI.c,v 1.9 2004/04/02 12:31:58 hartmutkaiser Exp $
00007  *
00008  *  Copyright (C) Hartmut Kaiser
00009  *  This file is part of the GAT Engine.
00010  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00011  *
00012  *  Use, modification and distribution is subject to the Gridlab Software
00013  *  License. (See accompanying file GLlicense.txt or copy at
00014  *  http://www.gridlab.org/GLlicense.txt)
00015  */
00016  
00017 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATResourceCPI.c,v 1.9 2004/04/02 12:31:58 hartmutkaiser Exp $";
00018  
00019 /* System Header Files */
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 
00023 /* GAT Header Files */
00024 #include "GATErrors.h"
00025 #include "GATResourceCPI.h"
00026 
00027 /* Macros */
00028 
00029 /* Structures, unions and enums */
00030 struct GATResourceCPI_S
00031 {
00032   /* CPI data (type local data) */
00033   void *data;
00034   GATResourceCPI_Adaptor_Destroy destroy;
00035   GATResourceCPI_Adaptor_ServiceActions service_actions;
00036 
00037   /* CPI instance data */
00038   GATResourceCPI_Adaptor_CreateInstance create_instance;
00039   GATResourceCPI_Adaptor_DestroyInstance destroy_instance;
00040   GATResourceCPI_Adaptor_CloneInstance clone_instance;
00041   GATResourceCPI_Adaptor_EqualsInstance equals_instance;
00042 
00043   /* CPI functionality */
00044   GATResourceCPI_Adaptor_GetResourceDescription get_resource_description;
00045   GATResourceCPI_Adaptor_GetReservation get_reservation;
00046   
00047   /* CPI monitoring support */
00048   GATResourceCPI_Adaptor_GetMetrics get_metrics;
00049   GATResourceCPI_Adaptor_GetMetricEvent get_metric_event;
00050 
00051   /* CPI serialisation */
00052   GATResourceCPI_Adaptor_Serialise serialise;
00053   GATResourceCPI_Adaptor_DeSerialise deserialise;
00054 };
00055 
00056 /* Static function prototypes */
00057 static GATBool 
00058   GATResourceCPI_IsValidData_V1(GATResourceCPI_Data *data);
00059 
00060 /* File scope variables */
00061 
00062 /* External functions */
00063 
00064 /** GATResourceCPI_Create
00065  *  The  GATResourceCPI constructor.
00066  *  new_cpi is the constructor for GATResourceCPI objects.
00067  *  
00068  *  @param version Version of the GATResourceCPI_Data structure
00069  *  @param data Pointer to adaptor CPI instance data structure.
00070  *
00071  * @return A new GATResourceCPI
00072  */
00073 GATResourceCPI GATResourceCPI_Create(unsigned long int version,
00074   GATResourceCPI_Data *data)
00075 {
00076   GATResourceCPI new_cpi = NULL;
00077 
00078   if (version <= GATRESOURCECPI_VERSION)
00079   {
00080     if (version == GATRESOURCECPI_VERSION && 
00081         GATTrue == GATResourceCPI_IsValidData_V1(data))
00082     {
00083       new_cpi = (GATResourceCPI)malloc(sizeof(*new_cpi));
00084       if(NULL != new_cpi)
00085       {
00086         new_cpi->data = data->data;
00087         new_cpi->destroy = data->destroy;
00088         new_cpi->service_actions = data->service_actions;
00089         
00090         new_cpi->destroy_instance = data->destroy_instance;
00091         new_cpi->create_instance = data->create_instance;
00092         new_cpi->equals_instance = data->equals_instance;
00093         new_cpi->clone_instance = data->clone_instance;
00094         
00095         new_cpi->get_resource_description = data->get_resource_description;
00096         new_cpi->get_reservation = data->get_reservation;
00097         
00098         new_cpi->get_metrics = data->get_metrics;
00099         new_cpi->get_metric_event = data->get_metric_event;
00100         
00101         new_cpi->serialise = data->serialise;
00102         new_cpi->deserialise = data->deserialise;
00103       }
00104     }
00105 /*  add functionality for newer versions here
00106     else if (version == GATRESOURCECPI_VERSION2 && 
00107       GATResourceCPI_IsValidData_V2(data))
00108     {
00109       ...
00110     }
00111  */
00112     else
00113     {
00114       /* Missing required functions */
00115       /* error_code = GAT_INVALID_PARAMETER; */
00116       new_cpi = NULL;
00117     }
00118   }
00119   else
00120   {
00121     /* unknown version */
00122     /* error_code = GAT_UNKNOWN_VERSION; */
00123     new_cpi = NULL;
00124   }
00125   return new_cpi;
00126 }
00127 
00128 /** GATResourceCPI_Destroy
00129  *  @brief The GATResourceCPI destructor.
00130  *
00131  *  This is the destructor for GATResourceCPI objects.
00132  *
00133  *  @param this An old GATResourceCPI
00134  */
00135 void GATResourceCPI_Destroy(GATResourceCPI *object)
00136 {
00137   if(NULL != object && NULL != *object)
00138   {
00139     /* call the adapter supplied destroy function */
00140     (*object)->destroy((*object)->data);
00141     free(*object);
00142     *object = NULL;
00143   }
00144 }
00145 
00146 /** GATResourceCPI_CreateInstance
00147  *  @brief Create a new CPI object instance
00148  *
00149  *  Calls the adaptor to create a new CPI object instance.
00150  *
00151  *  @param this The CPI object.
00152  *  @param context a GATContext
00153  *  @param instance_data The instance data of the attached CPI object
00154  *
00155  *  @return An error code.
00156  */
00157 GATResult 
00158 GATResourceCPI_CreateInstance(GATResourceCPI cpi, 
00159   GATResourceCPI_Instance *instance_data, void *initialisation_data)
00160 {
00161   return cpi->create_instance(cpi->data, instance_data, initialisation_data);
00162 }
00163 
00164 /** GATResourceCPI_DestroyInstance
00165  *  @brief Create a new CPI object instance
00166  *
00167  *  Calls the adaptor to destroy a CPI object instance.
00168  *
00169  *  @param this The CPI object.
00170  *  @param instance_data The instance data of the attached CPI object
00171  */
00172 void 
00173 GATResourceCPI_DestroyInstance(GATResourceCPI cpi, 
00174   GATResourceCPI_Instance *instance_data)
00175 {
00176   cpi->destroy_instance(cpi->data, instance_data);
00177 }
00178 
00179 /** GATResourceCPI_EqualsInstance
00180  *  @brief Compares two CPI object instances.
00181  *
00182  *  Calls the adaptor to compare two CPI object instances.
00183  *
00184  *  @param this The CPI object.
00185  *  @param lhs The instance data of the left CPI object
00186  *  @param rhs The instance data of the right CPI object
00187  *  @param isequal The pointer to the variable, where the result is to be 
00188  *        returned to.
00189  *
00190  *  @return An error code.
00191  */
00192 GATResult 
00193 GATResourceCPI_EqualsInstance(GATResourceCPI cpi, 
00194   GATResourceCPI_Instance const *lhs, GATResourceCPI_Instance const *rhs, 
00195   GATBool *isequal)
00196 {
00197   return cpi->equals_instance(cpi->data, lhs, rhs, isequal);
00198 }
00199 
00200 /** GATResourceCPI_CloneInstance
00201  *  @brief Clones a CPI object instance.
00202  *
00203  *  Calls the adaptor to clone a CPI object instance.
00204  *
00205  *  @param this The CPI object.
00206  *  @param instance_data The instance data of the CPI object to clone.
00207  *  @param new_instance_data The new instance data is to be returned here.
00208  *
00209  *  @return An error code.
00210  */
00211 GATResult 
00212 GATResourceCPI_CloneInstance(GATResourceCPI cpi, 
00213   GATResourceCPI_Instance const *instance_data,
00214   GATResourceCPI_Instance *new_instance_data) 
00215 {
00216   return cpi->clone_instance(cpi->data, instance_data, new_instance_data);
00217 }
00218 
00219 
00220 /* CPI specific API */
00221 
00222 /** GATResourceCPI_GetResourceDescription
00223  *  @brief Returns the associated resource description.
00224  *
00225  *  The function GATResourceCPI_GetResourceDescription calls the adaptor to 
00226  *  get the resource description associated with this GATResource.
00227  *
00228  *  @param this The CPI object.
00229  *  @param instance_data The instance data of the CPI object.
00230  *  @param description The pointer to the variable, which receives the 
00231  *        resulting resource description.
00232  *
00233  *  @return An error code.
00234  */
00235 GATResult 
00236 GATResourceCPI_GetResourceDescription(GATResourceCPI cpi, 
00237   GATResourceCPI_Instance const *instance_data, 
00238   GATResourceDescription_const *description)
00239 {
00240   return cpi->get_resource_description(cpi->data, instance_data, description);
00241 }
00242 
00243 /** GATResourceCPI_GetReservation
00244  *  @brief Returns the associated reservation.
00245  *  
00246  *  The function GATResourceCPI_GetReservation calls the adaptor to get the
00247  *  reservation associated with this GATResource.
00248  *
00249  *  @param this The CPI object.
00250  *  @param instance_data The instance data of the CPI object.
00251  *  @param reservation The pointer to a variable, which receives the resulting
00252  *        reservation.
00253  *
00254  *  @return An error code.
00255  */
00256 GATResult 
00257 GATResourceCPI_GetReservation(GATResourceCPI cpi, 
00258   GATResourceCPI_Instance const *instance_data, 
00259   GATReservation_const *reservation)
00260 {
00261   return cpi->get_reservation(cpi->data, instance_data, reservation);
00262 }
00263   
00264   
00265 /** GATResourceCPI_GetMetrics
00266  *
00267  *  The function GATResourceCPI_GetMetrics returns the list of metrics supported
00268  *  by this adaptor.
00269  *
00270  *  @param cpi The CPI object.
00271  *  @param instance_data The instance data of the attached CPI object
00272  *  @param The pointer to the variable, which receives the resulting list of
00273  *        metrics.
00274  *
00275  *  @return An error code.
00276  */
00277 GATResult 
00278 GATResourceCPI_GetMetrics(GATResourceCPI cpi, GATResourceCPI_Instance const *data,
00279   GATList_GATMetric *metrics)
00280 {
00281   return cpi->get_metrics(cpi->data, data, metrics);
00282 }
00283 
00284 /** GATResourceCPI_GetMetricEvent
00285  *
00286  *  The function GATResourceCPI_GetMetricEvent returns the metric event, which is 
00287  *  associated with the given metric.
00288  *
00289  *  @param cpi The CPI object.
00290  *  @param instance_data The instance data of the attached CPI object
00291  *  @param metric The continuous metric, for which the metric event is to be 
00292  *        returned. 
00293  *  @param event The pointer to the variable, which receives the resulting
00294  *        metric event.
00295  *
00296  *  @return An error code.
00297  */
00298 GATResult
00299 GATResourceCPI_GetMetricEvent(GATResourceCPI cpi, GATResourceCPI_Instance const *data,
00300   GATMetric metric, GATMetricEvent *event)
00301 {
00302   return cpi->get_metric_event(cpi->data, data, metric, event);
00303 }
00304 
00305 
00306 /** GATResourceCPI_Serialise
00307  *  @brief Serialise the instance data.
00308  *
00309  *  Calls the adaptor to serialise the instance data.
00310  *
00311  *  @param this The CPI object.
00312  *  @param instance_data The instance data of the attached CPI object
00313  *  @param stream The stream to use be used for serialisation.
00314  *
00315  *  @return An error code.
00316  */
00317 GATResult 
00318 GATResourceCPI_Serialise(GATResourceCPI cpi, 
00319   GATResourceCPI_Instance const *data, GATObject stream, GATBool clear_dirty)
00320 {
00321   return cpi->serialise(cpi->data, data, stream, clear_dirty);
00322 }
00323   
00324 /** GATResourceCPI_DeSerialise
00325  *  @brief De-serialise the instance data
00326  *
00327  *  Call the adaptor to de-serialise the instance data.
00328  *
00329  *  @param context The GAT context to be used for object construction.
00330  *  @param stream The stream interface to use for the serialisation.
00331  *  @param instance_data The pointer to a variable, which contains the client 
00332  *        data of the new object. The member instance data of this object 
00333  *        may receive the pointer to the new instance data of the CPI object.
00334  *
00335  *  @return An error code.
00336  */
00337 GATResult 
00338 GATResourceCPI_DeSerialise(GATResourceCPI cpi,
00339   GATObject stream, GATResourceCPI_Instance *data)
00340 {
00341   return cpi->deserialise(cpi->data, stream, data);
00342 }
00343   
00344 
00345 /* Local functions */
00346 static GATBool 
00347 GATResourceCPI_IsValidData_V1(GATResourceCPI_Data *data)
00348 {
00349   return (
00350       NULL != data->get_metrics &&
00351       NULL != data->get_metric_event &&
00352 //      NULL != data->service_actions &&
00353       
00354       NULL != data->serialise && 
00355       NULL != data->deserialise && 
00356 
00357       NULL != data->get_resource_description &&
00358       NULL != data->get_reservation &&
00359       
00360       NULL != data->destroy &&
00361       NULL != data->create_instance && 
00362       NULL != data->destroy_instance &&
00363       NULL != data->clone_instance &&
00364       NULL != data->equals_instance 
00365     ) ? GATTrue : GATFalse;
00366 }