GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATSoftwareDescription.c

Go to the documentation of this file.
00001 /** @file GATSoftwareDescription.c
00002  *  Source file for the GATSoftwareDescription class.
00003  *
00004  *  An instance of this class is a description of a piece of software 
00005  *  (component) which is to be submitted as a job. It currently takes a table 
00006  *  describing this piece of software’s attributes to any underlying job 
00007  *  submission system.
00008  *
00009  *  @date Wed Oct 22 2003
00010  *
00011  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATSoftwareDescription.c,v 1.9 2004/04/02 12:31:58 hartmutkaiser Exp $
00012  *
00013  *  Copyright (C) Hartmut Kaiser
00014  *  This file is part of the GAT Engine.
00015  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00016  *
00017  *  Use, modification and distribution is subject to the Gridlab Software
00018  *  License. (See accompanying file GLlicense.txt or copy at
00019  *  http://www.gridlab.org/GLlicense.txt)
00020  */
00021  
00022 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATSoftwareDescription.c,v 1.9 2004/04/02 12:31:58 hartmutkaiser Exp $";
00023  
00024 /* System Header Files */
00025 #include <stdlib.h>
00026 #include <string.h>
00027 
00028 /* GAT Header Files */
00029 #include "GATInternal.h"
00030 #include "GATErrors.h"
00031 #include "GATType.h"
00032 #include "GATSoftwareDescription.h"
00033 #include "GATXdsWrapper.h"
00034 
00035 /* define the vtable types */
00036 GATOBJECT_DEFINE_VTABLE(GATSoftwareDescription);
00037 GATSERIALISABLE_DEFINE_VTABLE(GATSoftwareDescription);
00038 
00039 /* define the converters to/from GATObject */
00040 GATOBJECT_DEFINE_CONVERTERS(GATSoftwareDescription)
00041 
00042 /* Macros */
00043 
00044 /* Structures, unions and enums */
00045 struct GATSoftwareDescription_S {
00046   GATSoftwareDescription_vtable *GATObject__vtable;
00047   GATSoftwareDescription_ISerialisable_vtable *GATSerialisable__vtable;
00048 
00049   GATTable attributes;
00050   GATBool isdirty;
00051 };
00052 
00053 /* Static function prototypes */
00054 static int
00055 GATSoftwareDescription_DeSerialise_Create(GATContext context, GATObject stream, 
00056   GATTable_const attributes, GATSoftwareDescription *new_object);
00057 
00058 /* File scope variables */
00059 GATSoftwareDescription_vtable GATSoftwareDescription__vtable = {
00060   GATSoftwareDescription_GetType,
00061   GATSoftwareDescription_Destroy,
00062   GATSoftwareDescription_Equals,
00063   GATSoftwareDescription_Clone,
00064   GATSoftwareDescription_GetInterface
00065 };
00066 
00067 static GATSoftwareDescription_ISerialisable_vtable 
00068   GATSoftwareDescription_ISerialisable__vtable = 
00069 {
00070   GATSoftwareDescription_Serialise,
00071   GATSoftwareDescription_DeSerialise,
00072   GATSoftwareDescription_GetIsDirty,
00073 };
00074 
00075 /* External functions */
00076 
00077 /** GATSoftwareDescription_Register_GATSerialisable
00078  *  The GATSoftwareDescription_Register_GATSerialisable function registers the serialization
00079  *  vtable with the GAT engine to allow generic object creation.
00080  *  This function is called by the GAT engine, there is no need to use it 
00081  *  directly.
00082  */
00083 GATResult GATSoftwareDescription_Register_GATSerialisable(void)
00084 {
00085   return GATObject_Register_GATSerialisable(GATType_GATSoftwareDescription, 
00086     &GATSoftwareDescription_ISerialisable__vtable);
00087 }
00088 
00089 /** GATSoftwareDescription_Create
00090  *  @brief Create a new GATSoftwareDescription object
00091  *
00092  *  The function @c GATSoftwareDescription_Create creates a new 
00093  *  GATSoftwareDescription object
00094  *
00095  *  @param attributes The attributes to initially use while initialising the 
00096  *        new GATSoftwareDescription. This parameter may be ommitted (zero).
00097  *
00098  *  @return Returns a handle to the newly created GATSoftwareDescription object.
00099  *        Returns 0 (zero) if an error occurs.
00100  */
00101 GATSoftwareDescription 
00102 GATSoftwareDescription_Create(GATTable_const attributes)
00103 {
00104   GATResult err_code = GAT_MEMORYFAILURE;
00105   GATSoftwareDescription retval = (GATSoftwareDescription) malloc(
00106     sizeof(struct GATSoftwareDescription_S));
00107       
00108   if (NULL != retval)
00109   {
00110     memset(retval, 0, sizeof(struct GATSoftwareDescription_S));
00111     retval->GATObject__vtable = &GATSoftwareDescription__vtable;
00112     retval->GATSerialisable__vtable = &GATSoftwareDescription_ISerialisable__vtable;
00113     retval->isdirty = GATFalse;
00114     
00115     if (NULL != attributes)
00116     {
00117       err_code = GATTable_Clone(attributes, &retval->attributes);
00118     }
00119     else
00120     {
00121       retval->attributes = GATTable_Create();
00122       if (NULL != retval->attributes)
00123       {
00124         err_code = GAT_SUCCESS;
00125       }
00126     }
00127   }
00128   
00129   /* error handling */
00130   if (GAT_SUCCESS != err_code)
00131   {
00132     /* FIXME: GATStatus(err_code) */
00133     if (NULL != retval)
00134     {
00135       GATSoftwareDescription_Destroy(&retval);
00136     }
00137   }
00138   return retval;
00139 }
00140 
00141 /** void GATSoftwareDescription_Destroy(GATSoftwareDescription *resource)
00142  *
00143  *  The function GATSoftwareDescription_Destroy is the destructor used to
00144  *  free all the memory allocated by an GATSoftwareDescription instance.
00145  *
00146  *  @param description The pointer to the GATSoftwareDescription to destroy
00147  */
00148 void
00149 GATSoftwareDescription_Destroy(GATSoftwareDescription *object)
00150 {
00151   if (NULL != object && NULL != *object)
00152   {
00153     GATTable_Destroy(&(*object)->attributes);
00154     free(*object);
00155     *object = NULL;
00156   }
00157 }
00158 
00159 /** GATSoftwareDescription_Equals
00160  *  @brief Compare two GATSoftwareDescription objects
00161  *
00162  *  The function @c GATSoftwareDescription_Equals compares two objects of the
00163  *  @c GATSoftwareDescription type.
00164  *
00165  *  @param lhs The first list to compare
00166  *  @param rhs The second list to compare
00167  *  @param isequal The pointer to the location, where the outcome of the 
00168  *        function has to be stored.
00169  *
00170  *  @return An error code.
00171  */
00172 GATResult
00173 GATSoftwareDescription_Equals(GATSoftwareDescription_const lhs,
00174   GATSoftwareDescription_const rhs, GATBool *isequal)
00175 {
00176   GATResult retval = GAT_INVALID_HANDLE;
00177 
00178   *isequal = GATFalse;
00179   if (NULL != lhs && NULL != rhs)
00180   {
00181     retval = GAT_INVALID_PARAMETER;
00182     if (NULL != isequal)
00183     {
00184       retval = GATTable_Equals(lhs->attributes, rhs->attributes, isequal);
00185     }
00186   }
00187   return retval;
00188 }
00189 
00190 /** GATSoftwareDescription_Clone
00191  *  @brief Clone the given GATSoftwareDescription
00192  *
00193  *  The function @c GATSoftwareDescription_Clone generates a (deep) copy of 
00194  *  the given GATSoftwareDescription. 
00195  *
00196  *  @param description The object to clone
00197  *  @param new_object The pointer, through which the result is to be 
00198  *        returned.
00199  *
00200  *  @return An error type.
00201  */
00202 GATResult
00203 GATSoftwareDescription_Clone(GATSoftwareDescription_const object, 
00204   GATSoftwareDescription *new_object)
00205 {
00206   GATResult retval = GAT_INVALID_PARAMETER;
00207   
00208   if (NULL != new_object)
00209   {
00210     *new_object = GATSoftwareDescription_Create(object->attributes);
00211     if (NULL == *new_object)
00212     {
00213       retval = GAT_MEMORYFAILURE;
00214     }
00215     else
00216     {
00217       retval = GAT_SUCCESS;
00218     }
00219   }
00220   return retval;
00221 }
00222 
00223 /** int GATSoftwareDescription_GetType(GATResourceDescription_const resource)
00224  *  @brief Return the type of the GATResourceDescription
00225  *
00226  *  The function @c GATSoftwareDescription_GetType always returns 
00227  *  @c #GATType_GATSoftwareDescription. 
00228  *
00229  *  @param object The object to inspect
00230  *
00231  *  @return Returns always @c #GATType_GATSoftwareDescription. 
00232  */
00233 GATType
00234 GATSoftwareDescription_GetType(GATSoftwareDescription_const description)
00235 {
00236   GAT_UNUSED_PARAMETER(description);
00237   return GATType_GATSoftwareDescription;
00238 }
00239 
00240 /** GATResult GATSoftwareDescription_GetInterface(GATSoftwareDescription_const file, GATInterface iftype, void const **ifp)
00241  *  @brief Get an interface supported by a GATObject
00242  *
00243  *  The function GATSoftwareDescription_GetInterface allows to get a pointer to an 
00244  *  additional interface supported by this GATSoftwareDescription.
00245  *
00246  *  @param object The object to be asked for the new interface.
00247  *  @param iftype The interface the object is to be asked for.
00248  *  @param ifp The pointer, through which the result is to be returned.
00249  *
00250  *  @return An error type.
00251  */
00252 GATResult 
00253 GATSoftwareDescription_GetInterface(GATSoftwareDescription_const object, 
00254   GATInterface iftype, void const **ifp)
00255 {
00256   GATResult retval = GAT_INVALID_PARAMETER;
00257 
00258   if (NULL != ifp)
00259   {
00260     *ifp = NULL;
00261     if (GATInterface_ISerialisable == iftype)
00262     {
00263       *ifp = (void const *) &object->GATSerialisable__vtable;
00264       retval = GAT_SUCCESS;
00265     }
00266     else
00267     {
00268       retval = GAT_NO_INTERFACE;
00269     }
00270   }
00271   return retval;
00272 }
00273 
00274 
00275 /* GATSoftwareDescription API */
00276 
00277 /** GATSoftwareDescription_GetAttributes
00278  *  @brief Access the stored set of attributes 
00279  *
00280  *  The function @c GATSoftwareDescription_getAttributes allows to access the
00281  *  attributes stored insoide the given GATSoftwareDescription instance.
00282  */
00283 GATTable_const
00284 GATSoftwareDescription_GetAttributes(GATSoftwareDescription_const object)
00285 {
00286   GATTable retval = NULL;
00287   if (NULL != object)
00288   {
00289     retval = object->attributes;
00290   }
00291   return retval;
00292 }
00293   
00294 /** GATSoftwareDescription_internal_GetAttributesRef
00295  *  @brief Access the stored set of attributes 
00296  *
00297  *  The function @c GATSoftwareDescription_internal_GetAttributesRef allows to 
00298  *  access the attributes stored inside the given GATSoftwareDescription 
00299  *  instance.
00300  *
00301  *  @param object The software description to query for its attributes table.
00302  *  @param attr The pointer to a variable, which receives the reslting 
00303  *        attributes table.
00304  *
00305  *  @return An error code.
00306  */
00307 GATResult
00308 GATSoftwareDescription_internal_GetAttributesRef(
00309   GATSoftwareDescription_const object, GATTable *attr)
00310 {
00311   GATResult retval = GAT_INVALID_HANDLE;
00312   if (NULL != object)
00313   {
00314     if (NULL != attr)
00315     {
00316       *attr = object->attributes;
00317       retval = GAT_SUCCESS;
00318     }
00319     else
00320     {
00321       retval = GAT_INVALID_PARAMETER;
00322     }
00323   }
00324   return retval;
00325 }
00326 
00327 /* Change the stored set of attributes */
00328 GATResult 
00329 GATSoftwareDescription_SetAttributes(GATSoftwareDescription object, 
00330   GATTable_const attributes)
00331 {
00332   GATResult result = GAT_INVALID_HANDLE;
00333   if (NULL != object)
00334   {
00335     GATTable new_attributes = NULL;
00336     
00337     result = GATTable_Clone(attributes, &new_attributes);
00338     if (GAT_SUCCESS != result || NULL == new_attributes)
00339     {
00340       GATTable_Destroy(&new_attributes);
00341       result = GAT_MEMORYFAILURE;
00342     }
00343     else
00344     {
00345       GATTable_Destroy(&object->attributes);
00346       object->attributes = new_attributes;
00347       result = GAT_SUCCESS;
00348     }
00349   }
00350   return result;
00351 }
00352 
00353 
00354 /* GATAdvertiseable API */
00355 
00356 /** GATResult GATSoftwareDescription_Serialise(GATSoftwareDescription object, GATObject stream, GATBool clear_dirty)
00357  *  @brief Serialise a GATSoftwareDescription object
00358  *
00359  *  The function GATSoftwareDescription_Serialise serialises the given  
00360  *  GATSoftwareDescription object into the given stream. 
00361  *
00362  *  @param object The GATSoftwareDescription object to serialise.
00363  *  @param stream The stream interface to use for the serialisation.
00364  *  @param clear_dirty If the clear_dirty parameter is set to GATTrue, the 
00365  *        internal dirty flag of this object is to be reset (no used here)
00366  *
00367  *  @return An error code.
00368  */
00369 GATResult 
00370 GATSoftwareDescription_Serialise(GATSoftwareDescription object, 
00371   GATObject stream, GATBool clear_dirty)
00372 {
00373   GATResult retval = GAT_INVALID_HANDLE;
00374   if (NULL != object)
00375   {
00376     retval = GATXds_SerialiseObject(GATSoftwareDescription_ToGATObject(object), stream, 
00377       clear_dirty, 0, "uint32 object",
00378       GATSOFTWAREDESCRIPTION_VERSION1, object->attributes, clear_dirty);
00379 
00380     if (GAT_SUCCEEDED(retval) && clear_dirty)
00381     {
00382       object->isdirty = GATFalse;
00383     }
00384   }
00385   return retval;
00386 }
00387 
00388 /** GATSoftwareDescription_VersionCallback
00389  *
00390  *  The function GATSoftwareDescription_VersionCallback is used as a callback function
00391  *  during the de-serialisation of a GATSoftwareDescription. It should be 
00392  *  provided to test, whether the de-serialised version matches the expected 
00393  *  version.
00394  *
00395  *  @param version The version number, which was de-serialised from the stream.
00396  *
00397  *  @return This function should return GATTrue, if the version matches the 
00398  *        expected value (version is valid), GATFalse otherwise.
00399  *
00400  *  @remark This function is called from the GAT engine, there is no need to 
00401  *        call it directly.
00402  */
00403 static GATBool
00404 GATSoftwareDescription_VersionCallback(GATuint32 version)
00405 {
00406   GATBool retval = GATFalse;
00407   if ((version & ~GATSOFTWAREDESCRIPTION_MINOR_MASK) <= GATSOFTWAREDESCRIPTION_LASTVERSION)
00408   {
00409     retval = GATTrue;
00410   }
00411   return retval;
00412 }
00413 
00414 /** GATSoftwareDescription_DeSerialiseCallback
00415  *
00416  *  The function GATSoftwareDescription_DeSerialiseCallback is used as a 
00417  *  callback function during the de-serialisation of a GATSoftwareDescription. 
00418  *  It should be provided for the instantiation of the new 
00419  *  GATSoftwareDescription object based on the already de-serialised 
00420  *  data items and the de-serialisation of the associated CPI provider data for 
00421  *  the given object.
00422  *
00423  *  @param context The GAT context to be used for object construction.
00424  *  @param stream The stream interface to use for the serialisation.
00425  *  @param object The pointer to the variable, which should receive the newly 
00426  *        constructed object.
00427  *  @param version The version of the saved data read from the input stream.
00428  *  @param args This parameter is the pointer to the va_list containing 
00429  *        pointers to the already de-serialised data items accordingly to the
00430  *        format string, provided during the call to the 
00431  *        GATSoftwareDescription_DeSerialise function.
00432  *
00433  *  @return An error code.
00434  *
00435  *  @remark This function is called from the GAT engine, there is no need to 
00436  *        call it directly.
00437  */
00438 static GATResult 
00439 GATSoftwareDescription_DeSerialiseCallback(GATContext context, GATObject stream, 
00440   GATObject *new_object, GATuint32 version, va_list args)
00441 {
00442   /* the version was eaten already */
00443 
00444   GATSoftwareDescription object = NULL;
00445   GATTable *attributes = va_arg(args, GATTable *);
00446   
00447   /* construct the new object */
00448   GATResult retval = GATSoftwareDescription_DeSerialise_Create(context, stream, 
00449     *attributes, &object);
00450   if (GAT_SUCCESS == retval)
00451   {
00452     if (NULL != object)
00453     {
00454       *new_object = GATSoftwareDescription_ToGATObject(object);
00455     }
00456     else
00457     {
00458       GATSoftwareDescription_Destroy(&object);
00459       retval = GAT_INVALID_PARAMETER;
00460     }
00461   }
00462   return retval;
00463 }
00464 
00465 /** GATSoftwareDescription GATSoftwareDescription_DeSerialise(GATContext context, GATObject stream, GATBool clear_dirty)
00466  *  @brief De-serialise a GATSoftwareDescription object
00467  *
00468  *  The function GATSoftwareDescription_DeSerialise de-serialises a streamed 
00469  *  GATSoftwareDescription object from the given stream  It constructs a new 
00470  *  instance of the de-serialised object.
00471  *
00472  *  @param context The GAT context to be used for object construction.
00473  *  @param stream The stream interface to use for the serialisation.
00474  *  @param result The pointer to a variable, which receives the status code of
00475  *        the operation.
00476  *
00477  *  @return The newly constructed GATSoftwareDescription object.
00478  */
00479 GATSoftwareDescription 
00480 GATSoftwareDescription_DeSerialise(GATContext context, GATObject stream, 
00481   GATResult *result)
00482 {
00483   GAT_USES_STATUS(context, "GATSoftwareDescription_DeSerialise");
00484   GATObject object = NULL;     /* the new object will be created here */
00485   
00486   /* we must provide all instance data items to be de-serialised for this
00487      GATSoftwareDescription object accordingly to the provided format string */
00488   GATuint32 version = 0;
00489   GATTable attributes = NULL;
00490   
00491   /* read the data */
00492   GAT_CREATE_STATUS(GATXds_DeSerialiseObject(context, stream, 
00493     GATSoftwareDescription_DeSerialiseCallback, 
00494     GATSoftwareDescription_VersionCallback, &object, 
00495     "uint32 object", &version, &attributes));
00496 
00497   GATTable_Destroy(&attributes);
00498 
00499   if (NULL != result)
00500   { 
00501     *result = GAT_CURRENT_STATUS();
00502   }
00503   else
00504   {
00505     GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00506   }
00507   GAT_STORE_STATUS();
00508   return GATObject_ToGATSoftwareDescription(object);
00509 }
00510 
00511 /** GATSoftwareDescription_GetIsDirty
00512  *  
00513  *  The function GATSoftwareDescription_GetIsDirty retrieves the status of the 
00514  *  dirty flag of this GATSoftwareDescription object.
00515  *
00516  *  @param file The GATSoftwareDescription object to inspect for its dirty status.
00517  *  @param isdirty The pointer to a variable, which receives the dirty status.
00518  *
00519  *  @return An error code.
00520  */
00521 GATResult 
00522 GATSoftwareDescription_GetIsDirty(GATSoftwareDescription_const object, 
00523   GATBool *isdirty)
00524 {
00525   GATResult retval = GAT_INVALID_HANDLE;
00526   if (NULL != object)
00527   {
00528     if (NULL != isdirty)
00529     {
00530       *isdirty = object->isdirty;
00531       retval = GAT_SUCCESS;
00532     }
00533     else
00534     {
00535       retval = GAT_INVALID_PARAMETER;
00536     }
00537   }  
00538   return retval;
00539 }
00540 
00541 
00542 /* Local functions */
00543 
00544 /** GATSoftwareDescription_DeSerialise_Create
00545  *
00546  *  The function GATSoftwareDescription_DeSerialise_Create creates a new GATSoftwareDescription object.
00547  *
00548  *  @param context The GAT context to use for creation of the GATSoftwareDescription object.
00549  *  @param stream The object from which the adaptor should read the streamed
00550  *        instance data.
00551  *  @param attributes The attributes to use for inittialisation of the newly
00552  *        created GATSoftwareDescription
00553  *  @param new_object The pointer to the variable, which should receive the 
00554  *        newly constructed GATSoftwareDescription object.
00555  *
00556  *  @return An error code.
00557  */
00558 static GATResult 
00559 GATSoftwareDescription_DeSerialise_Create(GATContext context, GATObject stream, 
00560   GATTable_const attributes, GATSoftwareDescription *object)
00561 {
00562   GAT_USES_STATUS(context, "GATSoftwareDescription_DeSerialise_Create");
00563   GATSoftwareDescription new_object = 
00564     (GATSoftwareDescription) malloc(sizeof(struct GATSoftwareDescription_S));
00565 
00566   if(NULL != new_object)
00567   {
00568     memset(new_object, 0, sizeof(struct GATSoftwareDescription_S));
00569     new_object->GATObject__vtable = &GATSoftwareDescription__vtable;
00570     new_object->GATSerialisable__vtable = &GATSoftwareDescription_ISerialisable__vtable;
00571     
00572     new_object->isdirty = GATFalse;
00573     GAT_CREATE_STATUS(GATTable_Clone(attributes, &new_object->attributes));
00574   }
00575   else
00576   {
00577     GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00578   }
00579   
00580   if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00581   {
00582     if (NULL != new_object)
00583     {
00584       *object = new_object;
00585     }
00586     else
00587     {
00588       GATSoftwareDescription_Destroy(&new_object);
00589       GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00590     }
00591   }
00592   else
00593   {
00594     GATSoftwareDescription_Destroy(&new_object);
00595   }
00596   return GAT_RETURN_STATUS();
00597 }
00598