GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATResourceBrokerCPI.c

Go to the documentation of this file.
00001 /** @file GATResourceBrokerCPI.c
00002  *  Source file for the GATResourceBrokerCPI class.
00003  *
00004  *  A GATResourcebrokerCPI encapsulates all the methods that a 
00005  *  GATResourceBroker capability provider provides.
00006  *
00007  *  @date Thu Oct 23 2003
00008  *
00009  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATResourceBrokerCPI.c,v 1.6 2004/04/02 12:31:58 hartmutkaiser Exp $
00010  *
00011  *  Copyright (C) Hartmut Kaiser
00012  *  new_cpi 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/src/GATResourceBrokerCPI.c,v 1.6 2004/04/02 12:31:58 hartmutkaiser Exp $";
00021 
00022 /* System Header Files */
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 
00026 /* GAT Header Files */
00027 #include "GATErrors.h"
00028 #include "GATResource.h"
00029 #include "GATResourceBrokerCPI.h"
00030 
00031 /* Macros */
00032 
00033 /* Structures, unions and enums */
00034 struct GATResourceBrokerCPI_S
00035 {
00036   /* CPI data (type local data) */
00037   void *data;
00038   GATResourceBrokerCPI_Adaptor_Destroy destroy;
00039   GATResourceBrokerCPI_Adaptor_ServiceActions service_actions;
00040 
00041   /* CPI instance data */
00042   GATResourceBrokerCPI_Adaptor_CreateInstance create_instance;
00043   GATResourceBrokerCPI_Adaptor_DestroyInstance destroy_instance;
00044   GATResourceBrokerCPI_Adaptor_CloneInstance clone_instance;
00045   GATResourceBrokerCPI_Adaptor_EqualsInstance equals_instance;
00046 
00047   /* CPI functionality */
00048   GATResourceBrokerCPI_Adaptor_ReserveResource_Description reserve_description;
00049   GATResourceBrokerCPI_Adaptor_ReserveResource reserve;
00050   GATResourceBrokerCPI_Adaptor_FindResources find_resources;
00051   GATResourceBrokerCPI_Adaptor_SubmitJob submit_job;
00052 };
00053 
00054 /* Static function prototypes */
00055 static GATBool 
00056   GATResourceBrokerCPI_IsValidData_V1(GATResourceBrokerCPI_Data *data);
00057 
00058 /* File scope variables */
00059 
00060 /* External functions */
00061 
00062 /** GATResourceBrokerCPI_Create
00063  *  The  GATResourceBrokerCPI constructor.
00064  *  new_cpi is the constructor for GATResourceBrokerCPI objects.
00065  *  
00066  *  @param version Version of the GATResourceBrokerCPI_Data structure
00067  *  @param data Pointer to adaptor CPI instance data structure.
00068  *
00069  * @return A new GATResourceBrokerCPI
00070  */
00071 GATResourceBrokerCPI GATResourceBrokerCPI_Create(unsigned long int version,
00072   GATResourceBrokerCPI_Data *data)
00073 {
00074   GATResourceBrokerCPI new_cpi = NULL;
00075 
00076   if (version <= GATRESOURCEBROKERCPI_VERSION)
00077   {
00078     if (version == GATRESOURCEBROKERCPI_VERSION && 
00079         GATTrue == GATResourceBrokerCPI_IsValidData_V1(data))
00080     {
00081       new_cpi = (GATResourceBrokerCPI)malloc(sizeof(*new_cpi));
00082       if(NULL != new_cpi)
00083       {
00084         new_cpi->data = data->data;
00085         new_cpi->destroy = data->destroy;
00086         new_cpi->service_actions = data->service_actions;
00087         
00088         new_cpi->destroy_instance = data->destroy_instance;
00089         new_cpi->create_instance = data->create_instance;
00090         new_cpi->equals_instance = data->equals_instance;
00091         new_cpi->clone_instance = data->clone_instance;
00092         
00093         new_cpi->reserve_description = data->reserve_description;
00094         new_cpi->reserve = data->reserve;
00095         new_cpi->find_resources = data->find_resources;
00096         new_cpi->submit_job = data->submit_job;
00097       }
00098     }
00099 /*  add functionality for newer versions here
00100     else if (version == GATRESOURCEBROKERCPI_VERSION2 && 
00101       GATResourceBrokerCPI_IsValidData_V2(data))
00102     {
00103       ...
00104     }
00105  */
00106     else
00107     {
00108       /* Missing required functions */
00109       /* error_code = GAT_INVALID_PARAMETER; */
00110       new_cpi = NULL;
00111     }
00112   }
00113   else
00114   {
00115     /* unknown version */
00116     /* error_code = GAT_UNKNOWN_VERSION; */
00117     new_cpi = NULL;
00118   }
00119   return new_cpi;
00120 }
00121 
00122 /** GATResourceBrokerCPI_Destroy
00123  *  @brief The GATResourceBrokerCPI destructor.
00124  *
00125  *  This is the destructor for GATResourceBrokerCPI objects.
00126  *
00127  *  @param this An old GATResourceBrokerCPI
00128  */
00129 void GATResourceBrokerCPI_Destroy(GATResourceBrokerCPI *object)
00130 {
00131   if(NULL != object && NULL != *object)
00132   {
00133     /* call the adapter supplied destroy function */
00134     (*object)->destroy((*object)->data);
00135     free(*object);
00136     *object = NULL;
00137   }
00138 }
00139 
00140 /** GATResourceBrokerCPI_CreateInstance
00141  *  @brief Create a new CPI object instance
00142  *
00143  *  Calls the adaptor to create a new CPI object instance.
00144  *
00145  *  @param this The CPI object.
00146  *  @param context a GATContext
00147  *  @param instance_data The instance data of the attached CPI object
00148  *
00149  *  @return An error code.
00150  */
00151 GATResult 
00152 GATResourceBrokerCPI_CreateInstance(GATResourceBrokerCPI cpi, 
00153   GATResourceBrokerCPI_Instance *instance_data)
00154 {
00155   return cpi->create_instance(cpi->data, instance_data);
00156 }
00157 
00158 /** GATResourceBrokerCPI_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 GATResourceBrokerCPI_DestroyInstance(GATResourceBrokerCPI cpi, 
00168   GATResourceBrokerCPI_Instance *instance_data)
00169 {
00170   cpi->destroy_instance(cpi->data, instance_data);
00171 }
00172 
00173 /** GATResourceBrokerCPI_CloneInstance
00174  *  @brief Clones a CPI object instance.
00175  *
00176  *  Calls the adaptor to clone a CPI object instance.
00177  *
00178  *  @param this The CPI object.
00179  *  @param instance_data The instance data of the CPI object to clone.
00180  *  @param new_instance_data The new instance data is to be returned here.
00181  *
00182  *  @return An error code.
00183  */
00184 GATResult 
00185 GATResourceBrokerCPI_CloneInstance(GATResourceBrokerCPI cpi, 
00186   GATResourceBrokerCPI_Instance const *instance_data,
00187   GATResourceBrokerCPI_Instance *new_instance_data) 
00188 {
00189   return cpi->clone_instance(cpi->data, instance_data, new_instance_data);
00190 }
00191 
00192 /** GATResourceBrokerCPI_EqualsInstance
00193  *  @brief Compares two CPI object instances.
00194  *
00195  *  Calls the adaptor to compare two CPI object instances.
00196  *
00197  *  @param this The CPI object.
00198  *  @param lhs The instance data of the left CPI object
00199  *  @param rhs The instance data of the right CPI object
00200  *  @param isequal The pointer to the variable, where the result is to be 
00201  *        returned to.
00202  *
00203  *  @return An error code.
00204  */
00205 GATResult 
00206 GATResourceBrokerCPI_EqualsInstance(GATResourceBrokerCPI cpi, 
00207   GATResourceBrokerCPI_Instance const *lhs, GATResourceBrokerCPI_Instance const *rhs, 
00208   GATBool *isequal)
00209 {
00210   return cpi->equals_instance(cpi->data, lhs, rhs, isequal);
00211 }
00212 
00213 
00214 /** GATResourceBrokerCPI_ReserveResource_Description
00215  *  @brief Reserve a resource, which mets the description.
00216  *
00217  *  Call the adaptor to allocate a reservation
00218  *
00219  *  @param cpi The ResourceBroker CPI object.
00220  *  @param instance_data The instance data of the CPI object to clone.
00221  *  @param description The ResourceDescription to use to select the appropriate
00222  *        resource.
00223  *  @param time The (optional) time, when the reservation has to start
00224  *  @param duration The (optional) time period for which to reserve the 
00225  *        resource.
00226  *  @param reservation The pointer to the GATReservation variable to use to 
00227  *        return the resulting reservation.
00228  *
00229  *  @return An error value.
00230  */
00231 GATResult 
00232 GATResourceBrokerCPI_ReserveResource_Description(GATResourceBrokerCPI cpi, 
00233   GATResourceBrokerCPI_Instance const *instance_data, 
00234   GATResourceDescription_const description, GATTime_const time, 
00235   GATTimePeriod_const duration, GATReservation *reservation)
00236 {
00237   return cpi->reserve_description(cpi->data, instance_data, description, 
00238     time, duration, reservation);
00239 }
00240 
00241 /** GATResourceBrokerCPI_ReserveResource
00242  *  @brief Reserve a given resource.
00243  *
00244  *  Call the adaptor to allocate a reservation
00245  *
00246  *  @param cpi The ResourceBroker CPI object.
00247  *  @param instance_data The instance data of the CPI object to clone.
00248  *  @param resource The resource to reserve.
00249  *  @param time The (optional) time, when the reservation has to start
00250  *  @param duration The (optional) time period for which to reserve the 
00251  *        resource.
00252  *  @param reservation The pointer to the GATReservation variable to use to 
00253  *        return the resulting reservation.
00254  *
00255  *  @return An error value.
00256  */
00257 GATResult 
00258 GATResourceBrokerCPI_ReserveResource(GATResourceBrokerCPI cpi, 
00259   GATResourceBrokerCPI_Instance const *instance_data, 
00260   GATResource_const resource, GATTime_const time, GATTimePeriod_const duration, 
00261   GATReservation *reservation)
00262 {
00263   return cpi->reserve(cpi->data, instance_data, resource, time, duration, 
00264     reservation);
00265 }
00266 
00267 /** GATResourceBrokerCPI_FindResources
00268  *  @brief Find a list of matching resources.
00269  *
00270  *  Call the adaptor to find a list of resources matching the given resource 
00271  *  description.
00272  *
00273  *  @param cpi The ResourceBroker CPI object.
00274  *  @param instance_data The instance data of the CPI object to clone.
00275  *  @param description The resource description to match.
00276  *  @param resources The pointer to the GATList_GATResource variable to use to 
00277  *        return the resulting list of resources.
00278  *
00279  *  @return An error value.
00280  */
00281 GATResult
00282 GATResourceBrokerCPI_FindResources(GATResourceBrokerCPI cpi,
00283   GATResourceBrokerCPI_Instance const *instance_data, 
00284   GATResourceDescription_const description, GATList_GATResource *resources)
00285 {
00286   return cpi->find_resources(cpi->data, instance_data, description, 
00287     resources);
00288 }
00289 
00290 /** GATResourceBrokerCPI_SubmitJob
00291  *  @brief Submit a new job.
00292  *
00293  *  Call the adaptor to submit a new job to a resource.
00294  *
00295  *  @param cpi The ResourceBroker CPI object.
00296  *  @param instance_data The instance data of the CPI object to clone.
00297  *  @param description The resource description to match.
00298  *  @param resources The pointer to the GATJob variable to use to 
00299  *        return the resulting job.
00300  *
00301  *  @return An error value.
00302  */
00303 GATResult 
00304 GATResourceBrokerCPI_SubmitJob(GATResourceBrokerCPI cpi,
00305   GATResourceBrokerCPI_Instance const *instance_data, 
00306   GATJobDescription_const description, GATJob *job)
00307 {
00308   return cpi->submit_job(cpi->data, instance_data, description, job);
00309 }
00310 
00311 
00312 /* Local functions */
00313 static GATBool 
00314 GATResourceBrokerCPI_IsValidData_V1(GATResourceBrokerCPI_Data *data)
00315 {
00316   return (
00317       NULL != data->destroy &&
00318 //      NULL != data->service_actions &&
00319       
00320       NULL != data->create_instance && 
00321       NULL != data->destroy_instance &&
00322       NULL != data->clone_instance &&
00323       NULL != data->equals_instance &&
00324 
00325       NULL != data->reserve_description &&
00326       NULL != data->reserve &&
00327       NULL != data->find_resources &&
00328       NULL != data->submit_job
00329     ) ? GATTrue : GATFalse;
00330 }
00331