GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

reservation.c

Go to the documentation of this file.
00001 /** @file reservation.c
00002  *  Source file for the sample Reservation CPI provider.
00003  *
00004  *  @date Thu Oct 23 2003
00005  *
00006  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/resourcebroker/reservation.c,v 1.7 2004/04/26 15:45:00 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/adaptors/resourcebroker/reservation.c,v 1.7 2004/04/26 15:45:00 hartmutkaiser Exp $";
00018  
00019 /* System Header Files */
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include <string.h>
00023 
00024 /* GAT Header Files */
00025 #include "GATCPI.h"
00026 #include "GATUtil.h"
00027 
00028 /* Macros */
00029 
00030 /* Structures, unions and enums */
00031 
00032 /* Static function prototypes */
00033 static void
00034 resourcebroker_adaptor_GATReservationCPI_Destroy(void *data);
00035 
00036 /* instance specific functions */
00037 static GATResult
00038 resourcebroker_adaptor_GATReservationCPI_ServiceActions(void *data, 
00039   GATReservationCPI_Instance *instance_data, GATTimePeriod_const timeout);
00040 
00041 GATResult resourcebroker_adaptor_GATReservationCPI_CreateInstance(void *data, 
00042   GATReservationCPI_Instance *instance_data);
00043 
00044 void resourcebroker_adaptor_GATReservationCPI_DestroyInstance(void *data, 
00045   GATReservationCPI_Instance *instance_data);
00046 
00047 GATResult resourcebroker_adaptor_GATReservationCPI_CloneInstance(void *data, 
00048   GATReservationCPI_Instance const *instance_data, 
00049   GATReservationCPI_Instance *new_instance_data);
00050 
00051 GATResult resourcebroker_adaptor_GATReservationCPI_EqualsInstance(void *data, 
00052   GATReservationCPI_Instance const *lhs, GATReservationCPI_Instance const *rhs, 
00053   GATBool *isequal);
00054 
00055 
00056 /* CPI API functionality */
00057 static GATResult
00058 resourcebroker_adaptor_ReservationCPI_Cancel(void *data, 
00059   GATReservationCPI_Instance *instance_data);
00060 
00061 static GATResult
00062 resourcebroker_adaptor_ReservationCPI_GetResource(void *data, 
00063   GATReservationCPI_Instance const *instance_data, GATResource_const *resource);
00064 
00065 
00066 /* File scope variables */
00067 
00068 /* External functions */
00069 
00070 /* Register the CPI to implement */
00071 GATResult resourcebroker_adaptor_Register_GATReservationCPI(
00072   GATContext error_context, GATRegistry registry, 
00073   GATTable_const system_config, GATTable_const instance_config, void *token)
00074 {
00075   GAT_USES_STATUS(error_context, 
00076     "resourcebroker_adaptor_Register_GATReservationCPI");
00077   
00078   GATReservationCPI cpi = NULL;
00079   GATReservationCPI_Data cpidata;
00080 
00081   {
00082     memset(&cpidata, 0, sizeof(GATReservationCPI_Data));
00083       
00084     /*
00085      *  provide the appropriate callback functions
00086      */
00087     cpidata.data = NULL;   /* no adaptor instance data */
00088     cpidata.destroy = resourcebroker_adaptor_GATReservationCPI_Destroy;
00089     
00090     /* instance data handling */
00091     cpidata.service_actions = resourcebroker_adaptor_GATReservationCPI_ServiceActions;
00092     cpidata.create_instance = resourcebroker_adaptor_GATReservationCPI_CreateInstance;
00093     cpidata.destroy_instance = resourcebroker_adaptor_GATReservationCPI_DestroyInstance;
00094     cpidata.clone_instance = resourcebroker_adaptor_GATReservationCPI_CloneInstance;
00095     cpidata.equals_instance = resourcebroker_adaptor_GATReservationCPI_EqualsInstance;
00096   
00097     /* CPI specific API functions */
00098     cpidata.cancel = resourcebroker_adaptor_ReservationCPI_Cancel;
00099     cpidata.get_resource = resourcebroker_adaptor_ReservationCPI_GetResource;
00100   
00101     /* Create a GATReservationCPI object. */
00102     cpi = GATReservationCPI_Create(GATRESERVATIONCPI_VERSION, &cpidata);
00103     if(NULL != cpi)
00104     {
00105       /* Need to pass preferences to allow matching
00106        * of a user's preferences with what this adaptor does.
00107        */
00108       GATPreferences preferences = GATPreferences_Create();
00109       if(NULL != preferences)
00110       {
00111         GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Name", 
00112           "resourcebroker_adaptor"));
00113         GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Security", "none"));
00114         GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Local", "true"));
00115         
00116         GAT_CREATE_STATUS(GATRegistry_AddGATReservationCPI(registry, cpi, token, 
00117           preferences));
00118         
00119         GATPreferences_Destroy(&preferences);
00120       }
00121       else
00122       {
00123         GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00124       }
00125     }
00126     else
00127     {
00128       GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00129     }
00130   }
00131 
00132   if (GAT_FAILED(GAT_CURRENT_STATUS()))
00133   {
00134     GATReservationCPI_Destroy(&cpi);
00135   }
00136 
00137   return GAT_RETURN_STATUS();
00138 }
00139 
00140 /* Local functions */
00141 
00142 static void
00143 resourcebroker_adaptor_GATReservationCPI_Destroy(void *data)
00144 {
00145   /* nothing to do here (no internal data allocated) */
00146 }
00147 
00148 
00149 /* instance specific functions */
00150 
00151 /** resourcebroker_adaptor_GATReservationCPI_ServiceActions
00152  *  
00153  *  The function resourcebroker_adaptor_GATReservationCPI_ServiceActions is called, whenever
00154  *  the client calls GATContext_ServiceActions. This function is called for 
00155  *  every created object.
00156  *  This function should be used to update all instance specific data, which 
00157  *  may have been changed asynchronously or to fire pending events.
00158  *
00159  *  @param data Adaptor-provided data object.
00160  *  @param instance_data The instance data of this CPI object
00161  *  @param timeout This may be a 0 timeout to indicate no timeout at all, or
00162  *        a specific time length.
00163  *
00164  *  @return An error code.
00165  */
00166 static GATResult
00167 resourcebroker_adaptor_GATReservationCPI_ServiceActions(void *data, 
00168   GATReservationCPI_Instance *instance_data, GATTimePeriod_const timeout)
00169 {
00170   return GAT_NOTIMPL;
00171 }
00172 
00173 /** resourcebroker_adaptor_GATReservationCPI_CreateInstance
00174  *  Create a new CPI object instance.
00175  *  Adaptor implementation of create instance capability.
00176  *
00177  * @param data Adaptor-provided data object.
00178  * @param context The GATContext for this CPI instance
00179  * @param target The location of the file in question.
00180  * @param new_instance_data The pointer to the variable, where the instance 
00181  *      data of this CPI object is to be returned to.
00182  * 
00183  * @return An error code.
00184  */
00185 GATResult 
00186 resourcebroker_adaptor_GATReservationCPI_CreateInstance(void *data, 
00187   GATReservationCPI_Instance *new_instance_data)
00188 {
00189   GATResult retval = GAT_INVALID_PARAMETER;
00190   if (NULL != new_instance_data)
00191   {
00192     new_instance_data->instance_data = NULL;     /* no instance data */
00193     retval = GAT_SUCCESS;
00194   }
00195   return retval;
00196 }
00197 
00198 /** resourcebroker_adaptor_GATReservationCPI_DestroyInstance
00199  *  Destroy a CPI object instance.
00200  *  Adaptor implementation of destroy instance capability.
00201  *
00202  * @param data Adaptor-provided data object.
00203  * @param instance_data The instance data of the CPI object to destroy.
00204  */
00205 void
00206 resourcebroker_adaptor_GATReservationCPI_DestroyInstance(void *data, 
00207   GATReservationCPI_Instance *instance_data)
00208 {
00209   assert(NULL == instance_data->instance_data);  /* no instance data */
00210 }
00211 
00212 /** resourcebroker_adaptor_GATReservationCPI_CloneInstance
00213  *  Clone a CPI object instance.
00214  *  Adaptor implementation of the clone instance capability.
00215  *
00216  * @param data Adaptor-provided data object.
00217  * @param instance_data The instance data of this CPI object
00218  * @param new_instance_data The pointer to the variable, where the instance 
00219  *      data of the cloned CPI object is to be returned to.
00220  * 
00221  * @return An error code.
00222  */
00223 GATResult 
00224 resourcebroker_adaptor_GATReservationCPI_CloneInstance(void *data, 
00225   GATReservationCPI_Instance const *instance_data, 
00226   GATReservationCPI_Instance *new_instance_data)
00227 {
00228   if (new_instance_data)
00229   {
00230     new_instance_data->instance_data = NULL;     /* no instance data */
00231   }
00232   return GAT_SUCCESS;
00233 }
00234 
00235 /** resourcebroker_adaptor_GATReservationCPI_EqualsInstance
00236  *  Clone a CPI object instance.
00237  *  Adaptor implementation of the clone instance capability.
00238  *
00239  * @param data Adaptor-provided data object.
00240  * @param lhs The instance data of the left CPI object.
00241  * @param lhs The instance data of the right CPI object.
00242  * @param isequal The pointer to the variable, where the result is to be 
00243  *        returned to.
00244  *
00245  * @return An error code.
00246  */
00247 GATResult 
00248 resourcebroker_adaptor_GATReservationCPI_EqualsInstance(void *data, 
00249   GATReservationCPI_Instance const *lhs, 
00250   GATReservationCPI_Instance const *rhs, GATBool *isequal)
00251 {
00252   GATResult retval = GAT_INVALID_PARAMETER;
00253   if (NULL != isequal)
00254   {
00255     *isequal = GATTrue;
00256     retval = GAT_SUCCESS;
00257   }
00258   return retval;
00259 }
00260 
00261 
00262 /* CPI specific API functions */
00263 
00264 static GATResult
00265 resourcebroker_adaptor_ReservationCPI_Cancel(void *data, 
00266   GATReservationCPI_Instance *instance_data)
00267 {
00268   GATResult retval = GAT_NOTIMPL;
00269   return retval;
00270 }
00271 
00272 static GATResult
00273 resourcebroker_adaptor_ReservationCPI_GetResource(void *data, 
00274   GATReservationCPI_Instance const *instance_data, GATResource_const *resource)
00275 {
00276   GATResult retval = GAT_NOTIMPL;
00277   return retval;
00278 }
00279