GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATJobCPI.c

Go to the documentation of this file.
00001 /** @file GATJobCPI.c
00002  *  Source file for the GATJobCPI class.
00003  *
00004  *  @date Sat Oct 25 2003
00005  *
00006  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATJobCPI.c,v 1.9 2004/04/02 12:31:57 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/GATJobCPI.c,v 1.9 2004/04/02 12:31:57 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 "GATMonitorable.h"
00026 #include "GATJobCPI.h"
00027 
00028 /* Macros */
00029 
00030 /* Structures, unions and enums */
00031 struct GATJobCPI_S
00032 {
00033   /* CPI data (type local data) */
00034   void *data;
00035   GATJobCPI_Adaptor_Destroy destroy;
00036   GATJobCPI_Adaptor_ServiceActions service_actions;
00037 
00038   /* CPI instance data */
00039   GATJobCPI_Adaptor_CreateInstance create_instance;
00040   GATJobCPI_Adaptor_DestroyInstance destroy_instance;
00041   GATJobCPI_Adaptor_CloneInstance clone_instance;
00042   GATJobCPI_Adaptor_EqualsInstance equals_instance;
00043 
00044   /* CPI functionality */
00045   GATJobCPI_Adaptor_UnSchedule unschedule;
00046   GATJobCPI_Adaptor_Checkpoint checkpoint;
00047   GATJobCPI_Adaptor_CloneJob clonejob;
00048   GATJobCPI_Adaptor_Migrate migratejob;
00049   GATJobCPI_Adaptor_Stop stopjob;
00050   GATJobCPI_Adaptor_GetJobDescription get_jobdescription;
00051   GATJobCPI_Adaptor_GetInfo get_jobinfo;
00052   GATJobCPI_Adaptor_GetJobID get_jobid;
00053   GATJobCPI_Adaptor_GetStatus get_status;
00054   
00055   /* CPI monitoring support */
00056   GATJobCPI_Adaptor_GetMetrics get_metrics;
00057   GATJobCPI_Adaptor_GetMetricEvent get_metric_event;
00058 
00059   /* CPI serialisation */
00060   GATJobCPI_Adaptor_Serialise serialise;
00061   GATJobCPI_Adaptor_DeSerialise deserialise;
00062 };
00063 
00064 /* Static function prototypes */
00065 static GATBool 
00066   GATJobCPI_IsValidData_V1(GATJobCPI_Data *data);
00067 
00068 /* File scope variables */
00069 
00070 /* External functions */
00071 
00072 /** GATJobCPI_Create
00073  *  The  GATJobCPI constructor.
00074  *  new_cpi is the constructor for GATJobCPI objects.
00075  *  
00076  *  @param version Version of the GATJobCPI_Data structure
00077  *  @param data Pointer to adaptor CPI instance data structure.
00078  *
00079  * @return A new GATJobCPI
00080  */
00081 GATJobCPI GATJobCPI_Create(unsigned long int version,
00082   GATJobCPI_Data *data)
00083 {
00084   GATJobCPI new_cpi = NULL;
00085 
00086   if (version <= GATJOBCPI_VERSION)
00087   {
00088     if (version == GATJOBCPI_VERSION && 
00089         GATTrue == GATJobCPI_IsValidData_V1(data))
00090     {
00091       new_cpi = (GATJobCPI)malloc(sizeof(*new_cpi));
00092       if(NULL != new_cpi)
00093       {
00094         new_cpi->data = data->data;
00095         new_cpi->destroy = data->destroy;
00096         new_cpi->service_actions = data->service_actions;
00097         
00098         new_cpi->destroy_instance = data->destroy_instance;
00099         new_cpi->create_instance = data->create_instance;
00100         new_cpi->equals_instance = data->equals_instance;
00101         new_cpi->clone_instance = data->clone_instance;
00102         
00103         new_cpi->unschedule = data->unschedule;
00104         new_cpi->checkpoint = data->checkpoint;
00105         new_cpi->clonejob = data->clonejob;
00106         new_cpi->migratejob = data->migratejob;
00107         new_cpi->stopjob = data->stopjob;
00108         new_cpi->get_jobdescription = data->get_jobdescription;
00109         new_cpi->get_jobinfo = data->get_jobinfo;
00110         new_cpi->get_jobid = data->get_jobid;
00111         new_cpi->get_status = data->get_status;
00112 
00113         new_cpi->get_metrics = data->get_metrics;
00114         new_cpi->get_metric_event = data->get_metric_event;
00115 
00116         new_cpi->serialise = data->serialise;
00117         new_cpi->deserialise = data->deserialise;
00118       }
00119     }
00120 /*  add functionality for newer versions here
00121     else if (version == GATJOBCPI_VERSION2 && 
00122       GATJobCPI_IsValidData_V2(data))
00123     {
00124       ...
00125     }
00126  */
00127     else
00128     {
00129       /* Missing required functions */
00130       /* error_code = GAT_INVALID_PARAMETER; */
00131       new_cpi = NULL;
00132     }
00133   }
00134   else
00135   {
00136     /* unknown version */
00137     /* error_code = GAT_UNKNOWN_VERSION; */
00138     new_cpi = NULL;
00139   }
00140   return new_cpi;
00141 }
00142 
00143 /** GATJobCPI_Destroy
00144  *  @brief The GATJobCPI destructor.
00145  *
00146  *  This is the destructor for GATJobCPI objects.
00147  *
00148  *  @param this An old GATJobCPI
00149  */
00150 void GATJobCPI_Destroy(GATJobCPI *object)
00151 {
00152   if(NULL != object && NULL != *object)
00153   {
00154     /* call the adapter supplied destroy function */
00155     (*object)->destroy((*object)->data);
00156     free(*object);
00157     *object = NULL;
00158   }
00159 }
00160 
00161 /** GATJobCPI_CreateInstance
00162  *  @brief Create a new CPI object instance
00163  *
00164  *  Calls the adaptor to create a new CPI object instance.
00165  *
00166  *  @param this The CPI object.
00167  *  @param context a GATContext
00168  *  @param instance_data The instance data of the attached CPI object
00169  *
00170  *  @return An error code.
00171  */
00172 GATResult 
00173 GATJobCPI_CreateInstance(GATJobCPI cpi, 
00174   GATJobCPI_Instance *instance_data, void *initialisation_data)
00175 {
00176   return cpi->create_instance(cpi->data, instance_data, initialisation_data);
00177 }
00178 
00179 /** GATJobCPI_DestroyInstance
00180  *  @brief Create a new CPI object instance
00181  *
00182  *  Calls the adaptor to destroy a CPI object instance.
00183  *
00184  *  @param this The CPI object.
00185  *  @param instance_data The instance data of the attached CPI object
00186  */
00187 void 
00188 GATJobCPI_DestroyInstance(GATJobCPI cpi, 
00189   GATJobCPI_Instance *instance_data)
00190 {
00191   cpi->destroy_instance(cpi->data, instance_data);
00192 }
00193 
00194 /** GATJobCPI_EqualsInstance
00195  *  @brief Compares two CPI object instances.
00196  *
00197  *  Calls the adaptor to compare two CPI object instances.
00198  *
00199  *  @param this The CPI object.
00200  *  @param lhs The instance data of the left CPI object
00201  *  @param rhs The instance data of the right CPI object
00202  *  @param isequal The pointer to the variable, where the result is to be 
00203  *        returned to.
00204  *
00205  *  @return An error code.
00206  */
00207 GATResult 
00208 GATJobCPI_EqualsInstance(GATJobCPI cpi, 
00209   GATJobCPI_Instance const *lhs, GATJobCPI_Instance const *rhs, 
00210   GATBool *isequal)
00211 {
00212   return cpi->equals_instance(cpi->data, lhs, rhs, isequal);
00213 }
00214 
00215 /** GATJobCPI_CloneInstance
00216  *  @brief Clones a CPI object instance.
00217  *
00218  *  Calls the adaptor to clone a CPI object instance.
00219  *
00220  *  @param this The CPI object.
00221  *  @param instance_data The instance data of the CPI object to clone.
00222  *  @param new_instance_data The new instance data is to be returned here.
00223  *
00224  *  @return An error code.
00225  */
00226 GATResult 
00227 GATJobCPI_CloneInstance(GATJobCPI cpi, 
00228   GATJobCPI_Instance const *instance_data,
00229   GATJobCPI_Instance *new_instance_data) 
00230 {
00231   return cpi->clone_instance(cpi->data, instance_data, new_instance_data);
00232 }
00233 
00234   
00235 /** GATJobCPI_GetMetrics
00236  *
00237  *  The function GATJobCPI_GetMetrics returns the list of metrics supported
00238  *  by this adaptor.
00239  *
00240  *  @param cpi The CPI object.
00241  *  @param instance_data The instance data of the attached CPI object
00242  *  @param The pointer to the variable, which receives the resulting list of
00243  *        metrics.
00244  *
00245  *  @return An error code.
00246  */
00247 GATResult 
00248 GATJobCPI_GetMetrics(GATJobCPI cpi, GATJobCPI_Instance const *data,
00249   GATList_GATMetric *metrics)
00250 {
00251   return cpi->get_metrics(cpi->data, data, metrics);
00252 }
00253 
00254 /** GATJobCPI_GetMetricEvent
00255  *
00256  *  The function GATJobCPI_GetMetricEvent returns the metric event, which is 
00257  *  associated with the given metric.
00258  *
00259  *  @param cpi The CPI object.
00260  *  @param instance_data The instance data of the attached CPI object
00261  *  @param metric The continuous metric, for which the metric event is to be 
00262  *        returned. 
00263  *  @param event The pointer to the variable, which receives the resulting
00264  *        metric event.
00265  *
00266  *  @return An error code.
00267  */
00268 GATResult
00269 GATJobCPI_GetMetricEvent(GATJobCPI cpi, GATJobCPI_Instance const *data,
00270   GATMetric metric, GATMetricEvent *event)
00271 {
00272   return cpi->get_metric_event(cpi->data, data, metric, event);
00273 }
00274 
00275 
00276 /** GATJobCPI_Serialise
00277  *  @brief Serialise the instance data.
00278  *
00279  *  Calls the adaptor to serialise the instance data.
00280  *
00281  *  @param this The CPI object.
00282  *  @param instance_data The instance data of the attached CPI object
00283  *  @param stream The stream to use be used for serialisation.
00284  *  @param clear_dirty If the clear_dirty parameter is set to GATTrue, the 
00285  *        internal dirty flag of this object is to be reset.
00286  *
00287  *  @return An error code.
00288  */
00289 GATResult 
00290 GATJobCPI_Serialise(GATJobCPI cpi, 
00291   GATJobCPI_Instance const *data, GATObject stream, GATBool clear_dirty)
00292 {
00293   return cpi->serialise(cpi->data, data, stream, clear_dirty);
00294 }
00295   
00296 /** GATJobCPI_DeSerialise
00297  *  @brief De-serialise the instance data
00298  *
00299  *  Call the adaptor to de-serialise the instance data.
00300  *
00301  *  @param context The GAT context to be used for object construction.
00302  *  @param stream The stream interface to use for the serialisation.
00303  *  @param instance_data The pointer to a variable, which contains the client 
00304  *        data of the new object. The member instance data of this object 
00305  *        may receive the pointer to the new instance data of the CPI object.
00306  *
00307  *  @return An error code.
00308  */
00309 GATResult 
00310 GATJobCPI_DeSerialise(GATJobCPI cpi,
00311   GATObject stream, GATJobCPI_Instance *data)
00312 {
00313   return cpi->deserialise(cpi->data, stream, data);
00314 }
00315   
00316 /* CPI specific API functions */
00317 
00318 /*
00319  *  
00320  */
00321 GATResult 
00322 GATJobCPI_UnSchedule(GATJobCPI cpi, GATJobCPI_Instance const *data)
00323 {
00324   return cpi->unschedule(cpi->data, data);
00325 }
00326 
00327 /*
00328  *  
00329  */
00330 GATResult 
00331 GATJobCPI_Checkpoint(GATJobCPI cpi, GATJobCPI_Instance const *data)
00332 {
00333   return cpi->checkpoint(cpi->data, data);
00334 }
00335 
00336 /*
00337  *  
00338  */
00339 GATResult 
00340 GATJobCPI_CloneJob(GATJobCPI cpi, GATJobCPI_Instance const *data,
00341   GATHardwareResource_const hr, GATJob *cloned_job)
00342 {
00343   return cpi->clonejob(cpi->data, data, hr, cloned_job);
00344 }
00345 
00346 /*
00347  *  
00348  */
00349 GATResult 
00350 GATJobCPI_Migrate(GATJobCPI cpi, GATJobCPI_Instance const *data,
00351   GATHardwareResource_const hr, GATJob *migrated_job)
00352 {
00353   return cpi->migratejob(cpi->data, data, hr, migrated_job);
00354 }
00355 
00356 /*
00357  *  
00358  */
00359 GATResult 
00360 GATJobCPI_Stop(GATJobCPI cpi, GATJobCPI_Instance const *data)
00361 {
00362   return cpi->stopjob(cpi->data, data);
00363 }
00364 
00365 /*
00366  *  
00367  */
00368 GATResult 
00369 GATJobCPI_GetJobDescription(GATJobCPI cpi, GATJobCPI_Instance const *data,
00370   GATJobDescription_const *jd)
00371 {
00372   return cpi->get_jobdescription(cpi->data, data, jd);
00373 }
00374 
00375 /*
00376  *  
00377  */
00378 GATResult 
00379 GATJobCPI_GetInfo(GATJobCPI cpi, GATJobCPI_Instance const *data,
00380   GATTable_const *jobinfo)
00381 {
00382   return cpi->get_jobinfo(cpi->data, data, jobinfo);
00383 }
00384 
00385 /*
00386  *  
00387  */
00388 GATResult 
00389 GATJobCPI_GetJobID(GATJobCPI cpi, GATJobCPI_Instance const *data,
00390   GATJobID_const *jobid)
00391 {
00392   return cpi->get_jobid(cpi->data, data, jobid);
00393 }
00394 
00395 /*
00396  *  
00397  */
00398 GATResult 
00399 GATJobCPI_GetStatus(GATJobCPI cpi, GATJobCPI_Instance const *data,
00400   GATStatus_const *jobstatus)
00401 {
00402   return cpi->get_status(cpi->data, data, jobstatus);
00403 }
00404 
00405 
00406 /* Local functions */
00407 static GATBool 
00408 GATJobCPI_IsValidData_V1(GATJobCPI_Data *data)
00409 {
00410   return (
00411       NULL != data->destroy &&
00412 //      NULL != data->service_actions &&
00413       
00414       NULL != data->get_metrics &&
00415       NULL != data->get_metric_event &&
00416 
00417       NULL != data->serialise && 
00418       NULL != data->deserialise && 
00419 
00420       NULL != data->destroy &&
00421 
00422       NULL != data->unschedule &&
00423       NULL != data->checkpoint &&
00424       NULL != data->clonejob &&
00425       NULL != data->migratejob &&
00426       NULL != data->stopjob &&
00427       NULL != data->get_jobdescription &&
00428       NULL != data->get_jobinfo &&
00429       NULL != data->get_jobid &&
00430       NULL != data->get_status &&
00431 
00432       NULL != data->create_instance && 
00433       NULL != data->destroy_instance &&
00434       NULL != data->clone_instance &&
00435       NULL != data->equals_instance 
00436     ) ? GATTrue : GATFalse;
00437 }
00438