GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATSelfCPI.c

Go to the documentation of this file.
00001 /** @file GATSelfCPI.c
00002  *  Source file for the GATSelfCPI class.
00003  *
00004  *  @date Fri Jan 23 2004
00005  *
00006  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATSelfCPI.c,v 1.6 2004/04/05 11:49:44 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/GATSelfCPI.c,v 1.6 2004/04/05 11:49:44 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 "GATSelfCPI.h"
00026 
00027 /* Macros */
00028 
00029 /* Structures, unions and enums */
00030 struct GATSelfCPI_S
00031 {
00032   /* CPI data (type local data) */
00033   void *data;
00034   GATSelfCPI_Adaptor_Destroy destroy;
00035   
00036   /* CPI instance data */
00037   GATSelfCPI_Adaptor_ServiceActions service_actions;
00038   GATSelfCPI_Adaptor_CreateInstance create_instance;
00039   GATSelfCPI_Adaptor_DestroyInstance destroy_instance;
00040 
00041   /* CPI functionality */
00042   GATSelfCPI_Adaptor_GetJob get_selfjob;
00043   GATSelfCPI_Adaptor_CreateRequestForListener create_requestforlistener;
00044   GATSelfCPI_Adaptor_DestroyRequestForListener destroy_requestforlistener;
00045 };
00046 
00047 /* Static function prototypes */
00048 static GATBool 
00049   GATSelfCPI_IsValidData_V1(GATSelfCPI_Data *data);
00050 
00051 /* File scope variables */
00052 
00053 /* External functions */
00054 
00055 /** GATSelfCPI_Create
00056  *  The  GATSelfCPI constructor.
00057  *  new_cpi is the constructor for GATSelfCPI objects.
00058  *  
00059  *  @param version Version of the GATSelfCPI_Data structure
00060  *  @param data Pointer to adaptor CPI instance data structure.
00061  *
00062  * @return A new GATSelfCPI
00063  */
00064 GATSelfCPI GATSelfCPI_Create(unsigned long int version,
00065   GATSelfCPI_Data *data)
00066 {
00067   GATSelfCPI new_cpi = NULL;
00068 
00069   if (version <= GATSELFCPI_VERSION)
00070   {
00071     if (version == GATSELFCPI_VERSION && 
00072         GATTrue == GATSelfCPI_IsValidData_V1(data))
00073     {
00074       new_cpi = (GATSelfCPI)malloc(sizeof(*new_cpi));
00075       if(NULL != new_cpi)
00076       {
00077         new_cpi->data = data->data;
00078         new_cpi->destroy = data->destroy;
00079 
00080         new_cpi->service_actions = data->service_actions;
00081         new_cpi->destroy_instance = data->destroy_instance;
00082         new_cpi->create_instance = data->create_instance;
00083 
00084         new_cpi->get_selfjob = data->get_selfjob;
00085         new_cpi->create_requestforlistener = data->create_requestforlistener;
00086         new_cpi->destroy_requestforlistener = data->destroy_requestforlistener;
00087       }
00088     }
00089 /*  add functionality for newer versions here
00090     else if (version == GATSELFCPI_VERSION2 && 
00091       GATSelfCPI_IsValidData_V2(data))
00092     {
00093       ...
00094     }
00095  */
00096     else
00097     {
00098       /* Missing required functions */
00099       /* error_code = GAT_INVALID_PARAMETER; */
00100       new_cpi = NULL;
00101     }
00102   }
00103   else
00104   {
00105     /* unknown version */
00106     /* error_code = GAT_UNKNOWN_VERSION; */
00107     new_cpi = NULL;
00108   }
00109   return new_cpi;
00110 }
00111 
00112 /** GATSelfCPI_Destroy
00113  *  @brief The GATSelfCPI destructor.
00114  *
00115  *  This is the destructor for GATSelfCPI objects.
00116  *
00117  *  @param this An old GATSelfCPI
00118  */
00119 void GATSelfCPI_Destroy(GATSelfCPI *object)
00120 {
00121   if(NULL != object && NULL != *object)
00122   {
00123     /* call the adapter supplied destroy function */
00124     (*object)->destroy((*object)->data);
00125     free(*object);
00126     *object = NULL;
00127   }
00128 }
00129 
00130 /* Instance specific functions */
00131 
00132 /** GATSelfCPI_CreateInstance
00133  *  @brief Create a new CPI object instance
00134  *
00135  *  Calls the adaptor to create a new CPI object instance.
00136  *
00137  *  @param this The CPI object.
00138  *  @param context a GATContext
00139  *  @param instance_data The instance data of the attached CPI object
00140  *
00141  *  @return An error code.
00142  */
00143 GATResult 
00144 GATSelfCPI_CreateInstance(GATSelfCPI cpi, 
00145   GATSelfCPI_Instance *instance_data)
00146 {
00147   return cpi->create_instance(cpi->data, instance_data);
00148 }
00149 
00150 /** GATSelfCPI_DestroyInstance
00151  *  @brief Create a new CPI object instance
00152  *
00153  *  Calls the adaptor to destroy a CPI object instance.
00154  *
00155  *  @param this The CPI object.
00156  *  @param instance_data The instance data of the attached CPI object
00157  */
00158 void 
00159 GATSelfCPI_DestroyInstance(GATSelfCPI cpi, 
00160   GATSelfCPI_Instance *instance_data)
00161 {
00162   cpi->destroy_instance(cpi->data, instance_data);
00163 }
00164 
00165 /* CPI specific API */
00166 
00167 /** GATSelfCPI_GetJob
00168  *
00169  *  @param this The CPI object.
00170  *  @param instance_data The instance data of the attached CPI object
00171  *
00172  *  @return An error code.
00173  */
00174 GATResult 
00175 GATSelfCPI_GetJob(GATSelfCPI cpi, GATSelfCPI_Instance *instance_data,
00176   GATContext context, GATJob *job)
00177 {
00178   return cpi->get_selfjob(cpi->data, instance_data, context, job);
00179 }
00180 
00181 /** GATSelfCPI_CreateRequestForListener
00182  *
00183  *  @param this The CPI object.
00184  *  @param instance_data The instance data of the attached CPI object
00185  *
00186  *  @return An error code.
00187  */
00188 GATResult 
00189 GATSelfCPI_CreateRequestForListener(GATSelfCPI cpi, 
00190   GATSelfCPI_Instance *instance_data, GATContext context, 
00191   GATRequestListener listener, void *data, GATRequestType type, 
00192   GATTable_const parameters, const char *name, GATRequest *request)
00193 {
00194   return cpi->create_requestforlistener(cpi->data, instance_data, context, 
00195     listener, data, type, parameters, name, request);
00196 }
00197 
00198 /** GATSelfCPI_DestroyRequestForListener
00199  *
00200  *  @param this The CPI object.
00201  *  @param instance_data The instance data of the attached CPI object
00202  *
00203  *  @return An error code.
00204  */
00205 GATResult 
00206 GATSelfCPI_DestroyRequestForListener(GATSelfCPI cpi, 
00207   GATSelfCPI_Instance *instance_data, GATContext context, GATRequest *request)
00208 {
00209   return cpi->destroy_requestforlistener(cpi->data, instance_data, context, 
00210     request);
00211 }
00212 
00213 
00214 /* Local functions */
00215 
00216 static GATBool 
00217 GATSelfCPI_IsValidData_V1(GATSelfCPI_Data *data)
00218 {
00219   return (
00220       NULL != data->destroy &&
00221 
00222       NULL != data->create_instance && 
00223       NULL != data->destroy_instance &&
00224 
00225       NULL != data->get_selfjob &&
00226       NULL != data->create_requestforlistener &&
00227       NULL != data->destroy_requestforlistener
00228     ) ? GATTrue : GATFalse;
00229 }
00230 
00231