GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATReservationCPI.c

Go to the documentation of this file.
00001 /** @file GATReservationCPI.c
00002  *  Source file for the GATReservationCPI class.
00003  *
00004  *  @date Thu Oct 23 2003
00005  *
00006  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATReservationCPI.c,v 1.5 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/GATReservationCPI.c,v 1.5 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 "GATReservationCPI.h"
00026 
00027 /* Macros */
00028 
00029 /* Structures, unions and enums */
00030 struct GATReservationCPI_S
00031 {
00032   /* CPI data (type local data) */
00033   void *data;
00034   GATReservationCPI_Adaptor_Destroy destroy;
00035   GATReservationCPI_Adaptor_ServiceActions service_actions;
00036 
00037   /* CPI instance data */
00038   GATReservationCPI_Adaptor_CreateInstance create_instance;
00039   GATReservationCPI_Adaptor_DestroyInstance destroy_instance;
00040   GATReservationCPI_Adaptor_CloneInstance clone_instance;
00041   GATReservationCPI_Adaptor_EqualsInstance equals_instance;
00042 
00043   /* CPI functionality */
00044   GATReservationCPI_Adaptor_Cancel cancel;
00045   GATReservationCPI_Adaptor_GetResource get_resource;
00046 };
00047 
00048 /* Static function prototypes */
00049 static GATBool 
00050   GATReservationCPI_IsValidData_V1(GATReservationCPI_Data *data);
00051 
00052 /* File scope variables */
00053 
00054 /* External functions */
00055 /** GATReservationCPI_Create
00056  *  The  GATReservationCPI constructor.
00057  *  new_cpi is the constructor for GATReservationCPI objects.
00058  *  
00059  *  @param version Version of the GATReservationCPI_Data structure
00060  *  @param data Pointer to adaptor CPI instance data structure.
00061  *
00062  * @return A new GATReservationCPI
00063  */
00064 GATReservationCPI GATReservationCPI_Create(unsigned long int version,
00065   GATReservationCPI_Data *data)
00066 {
00067   GATReservationCPI new_cpi = NULL;
00068 
00069   if (version <= GATRESERVATIONCPI_VERSION)
00070   {
00071     if (version == GATRESERVATIONCPI_VERSION && 
00072         GATTrue == GATReservationCPI_IsValidData_V1(data))
00073     {
00074       new_cpi = (GATReservationCPI)malloc(sizeof(struct GATReservationCPI_S));
00075       if(NULL != new_cpi)
00076       {
00077         new_cpi->data = data->data;
00078         new_cpi->destroy = data->destroy;
00079         new_cpi->service_actions = data->service_actions;
00080         
00081         new_cpi->destroy_instance = data->destroy_instance;
00082         new_cpi->create_instance = data->create_instance;
00083         new_cpi->equals_instance = data->equals_instance;
00084         new_cpi->clone_instance = data->clone_instance;
00085 
00086         new_cpi->cancel = data->cancel;
00087         new_cpi->get_resource = data->get_resource;
00088       }
00089     }
00090 /*  add functionality for newer versions here
00091     else if (version == GATRESERVATIONCPI_VERSION2 && 
00092       GATReservationCPI_IsValidData_V2(data))
00093     {
00094       ...
00095     }
00096  */
00097     else
00098     {
00099       /* Missing required functions */
00100       /* error_code = GAT_INVALID_PARAMETER; */
00101       new_cpi = NULL;
00102     }
00103   }
00104   else
00105   {
00106     /* unknown version */
00107     /* error_code = GAT_UNKNOWN_VERSION; */
00108     new_cpi = NULL;
00109   }
00110   return new_cpi;
00111 }
00112 
00113 /** GATReservationCPI_Destroy
00114  *  @brief The GATReservationCPI destructor.
00115  *
00116  *  This is the destructor for GATReservationCPI objects.
00117  *
00118  *  @param this An old GATReservationCPI
00119  */
00120 void GATReservationCPI_Destroy(GATReservationCPI *object)
00121 {
00122   if(NULL != object && NULL != *object)
00123   {
00124     /* call the adapter supplied destroy function */
00125     (*object)->destroy((*object)->data);
00126     free(*object);
00127     *object = NULL;
00128   }
00129 }
00130 
00131 /** GATReservationCPI_CreateInstance
00132  *  @brief Create a new CPI object instance
00133  *
00134  *  Calls the adaptor to create a new CPI object instance.
00135  *
00136  *  @param this The CPI object.
00137  *  @param context a GATContext
00138  *  @param instance_data The instance data of the attached CPI object
00139  *
00140  *  @return An error code.
00141  */
00142 GATResult 
00143 GATReservationCPI_CreateInstance(GATReservationCPI cpi, 
00144   GATReservationCPI_Instance *instance_data)
00145 {
00146   return cpi->create_instance(cpi->data, instance_data);
00147 }
00148 
00149 /** GATReservationCPI_DestroyInstance
00150  *  @brief Create a new CPI object instance
00151  *
00152  *  Calls the adaptor to destroy a CPI object instance.
00153  *
00154  *  @param this The CPI object.
00155  *  @param instance_data The instance data of the attached CPI object
00156  */
00157 void 
00158 GATReservationCPI_DestroyInstance(GATReservationCPI cpi, 
00159   GATReservationCPI_Instance *instance_data)
00160 {
00161   cpi->destroy_instance(cpi->data, instance_data);
00162 }
00163 
00164 /** GATReservationCPI_EqualsInstance
00165  *  @brief Compares two CPI object instances.
00166  *
00167  *  Calls the adaptor to compare two CPI object instances.
00168  *
00169  *  @param this The CPI object.
00170  *  @param lhs The instance data of the left CPI object
00171  *  @param rhs The instance data of the right CPI object
00172  *  @param isequal The pointer to the variable, where the result is to be 
00173  *        returned to.
00174  *
00175  *  @return An error code.
00176  */
00177 GATResult 
00178 GATReservationCPI_EqualsInstance(GATReservationCPI cpi, 
00179   GATReservationCPI_Instance const *lhs, GATReservationCPI_Instance const *rhs, 
00180   GATBool *isequal)
00181 {
00182   return cpi->equals_instance(cpi->data, lhs, rhs, isequal);
00183 }
00184 
00185 /** GATReservationCPI_CloneInstance
00186  *  @brief Clones a CPI object instance.
00187  *
00188  *  Calls the adaptor to clone a CPI object instance.
00189  *
00190  *  @param this The CPI object.
00191  *  @param instance_data The instance data of the CPI object to clone.
00192  *  @param rhs The new instance data is to be returned here.
00193  *
00194  *  @return An error code.
00195  */
00196 GATResult 
00197 GATReservationCPI_CloneInstance(GATReservationCPI cpi, 
00198   GATReservationCPI_Instance const *instance_data, 
00199   GATReservationCPI_Instance *new_instance_data) 
00200 {
00201   return cpi->clone_instance(cpi->data, instance_data, new_instance_data);
00202 }
00203 
00204 /** GATReservationCPI_Cancel
00205  *  @brief Cancel this reservation
00206  *
00207  *  Call the adaptor to cancel a reservation.
00208  *
00209  *  @param reservation The reservation to cancel.
00210  *  @param instance_data The instance data of the CPI object to clone.
00211  *  @param unique_name The unique name of this reservation.
00212  *
00213  *  @return An error code. 
00214  */
00215 GATResult 
00216 GATReservationCPI_Cancel(GATReservationCPI reservation, 
00217   GATReservationCPI_Instance *instance_data)
00218 {
00219   return reservation->cancel(reservation->data, instance_data);
00220 }
00221 
00222 /** GATReservationCPI_GetResource
00223  *  @brief Get the associated resource of this reservation.
00224  *
00225  *  Call the adaptor to get the associated resource.
00226  *
00227  *  @param reservation The reservation to cancel.
00228  *  @param instance_data The instance data of the CPI object to clone.
00229  *  @param unique_name The unique name of this reservation.
00230  *  @param resource The pointer to the variable, where the resulting resource
00231  *        should be returned.
00232  *
00233  *  @return An error code. 
00234  */
00235 GATResult 
00236 GATReservationCPI_GetResource(GATReservationCPI reservation, 
00237   GATReservationCPI_Instance const *instance_data, GATResource_const *resource)
00238 {
00239   return reservation->get_resource(reservation->data, instance_data, resource);
00240 }
00241   
00242 /* Local functions */
00243 static GATBool
00244 GATReservationCPI_IsValidData_V1(GATReservationCPI_Data *data)
00245 {
00246   return (
00247       NULL != data->destroy &&
00248 //      NULL != data->service_actions &&
00249       
00250       NULL != data->create_instance && 
00251       NULL != data->destroy_instance &&
00252       NULL != data->clone_instance &&
00253       NULL != data->equals_instance &&
00254 
00255       NULL != data->cancel &&
00256       NULL != data->get_resource 
00257     ) ? GATTrue : GATFalse;
00258 }