GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATJobCPIInstanceData.c

Go to the documentation of this file.
00001 /** @file GATJobCPIInstanceData.c
00002  *  Source file for the GATJobCPIInstance_Data class, which represents the 
00003  *  internal data stored by the JobCPI provider for the resource broker 
00004  *  adaptor.
00005  *
00006  *  @date Tue Dec 09 2003
00007  *
00008  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/resourcebroker/GATJobCPIInstanceData.c,v 1.4 2004/04/02 12:31:57 hartmutkaiser Exp $
00009  *
00010  *  Copyright (C) Hartmut Kaiser
00011  *  This file is part of the GAT Engine.
00012  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00013  *
00014  *  Use, modification and distribution is subject to the Gridlab Software
00015  *  License. (See accompanying file GLlicense.txt or copy at
00016  *  http://www.gridlab.org/GLlicense.txt)
00017  */
00018 
00019 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/resourcebroker/GATJobCPIInstanceData.c,v 1.4 2004/04/02 12:31:57 hartmutkaiser Exp $";
00020  
00021 /* System Header Files */
00022 #include <string.h>
00023 #include <sys/utsname.h>
00024 
00025 /* GAT Header Files */
00026 #include "GATJobCPIInstanceData.h"
00027 
00028 /* Macros */
00029 
00030 /* Structures, unions and enums */
00031 
00032 /* Static function prototypes */
00033 
00034 /* File scope variables */
00035 
00036 /* External functions */
00037 
00038 /** GATJobCPIInstance_Data_Create
00039  *
00040  *  The function GATJobCPIInstance_Data_Create creates a new 
00041  *  instance of the internal CPI instance data.
00042  *
00043  *  @param description The job description used for creating the corresponding
00044  *        GATJob object.
00045  *
00046  *  @return The pointer to the newly created and initialised data structure.
00047  */
00048 GATJobCPIInstance_Data *
00049 GATJobCPIInstance_Data_Create(GATJobDescription_const description, 
00050   GATResource_const resource, GATBool checkpointable)
00051 {
00052   GATJobCPIInstance_Data *retval = 
00053     (GATJobCPIInstance_Data *)malloc(sizeof(struct GATJobCPIInstance_Data));
00054 
00055   if (NULL != retval)
00056   {
00057     memset(retval, 0, sizeof(struct GATJobCPIInstance_Data));
00058     if (GAT_SUCCEEDED(GATJobDescription_Clone(description, &retval->description)))
00059     {
00060       retval->parameters = GATTable_Create();
00061       if (NULL == retval->parameters)
00062       {
00063         GATJobCPIInstance_Data_Destroy(&retval);
00064       }
00065       else
00066       {
00067         /* query for the system information */
00068         struct utsname sysinfo;
00069         GATTime time_now = GATTime_Create(0);
00070         
00071         if (NULL == time_now || uname(&sysinfo) < 0 || 
00072             GAT_FAILED(GATTable_Add_String(retval->parameters, 
00073               "hostname", sysinfo.nodename)) ||
00074             GAT_FAILED(GATTable_Add_GATObject(retval->parameters, 
00075               "scheduletime", GATTime_ToGATObject_const(time_now))) ||
00076             GAT_FAILED(GATTable_Add_int(retval->parameters, 
00077               "checkpointable", checkpointable)))
00078         {
00079           GATJobCPIInstance_Data_Destroy(&retval);
00080         }
00081         else
00082         {
00083           if (GAT_FAILED(GATResource_Clone(resource, &retval->resource)))
00084           {
00085             GATJobCPIInstance_Data_Destroy(&retval);
00086           }
00087         }
00088         
00089         GATTime_Destroy(&time_now);
00090       }
00091     }
00092   }
00093   return retval;
00094 }
00095 
00096 /** GATJobCPIInstance_Data_Destroy
00097  *
00098  *  The function GATJobCPIInstance_Data_Destroy is called to 
00099  *  free all the memory associated with the given instance data item.
00100  *
00101  *  @param instance_data The pointer to a variable holding the old instance 
00102  *        data item, this is set to zero on exit.
00103  */
00104 void 
00105 GATJobCPIInstance_Data_Destroy(
00106   GATJobCPIInstance_Data **instance_data)
00107 {
00108   if (NULL != instance_data && NULL != *instance_data)
00109   {
00110     GATJobDescription_Destroy(&(*instance_data)->description);
00111     GATTable_Destroy(&(*instance_data)->parameters);
00112     GATStatus_Destroy(&(*instance_data)->status);
00113     GATResource_Destroy(&(*instance_data)->resource);
00114     
00115     free(*instance_data);
00116     instance_data = NULL;
00117   }
00118 }
00119 
00120 /** GATJobCPIInstance_Data_Clone
00121  *
00122  *  The function GATJobCPIInstance_Data_Clone is called to make 
00123  *  a copy of the given instance data item.
00124  *
00125  *  @param instance_data The instance data item to copy.
00126  *  @param new_instance_Data The pointer to a variable, which receives the 
00127  *        newly created copy of the instance data item.
00128  *
00129  *  @return An error code.
00130  */
00131 GATResult 
00132 GATJobCPIInstance_Data_Clone(GATJobCPIInstance_Data const *instance_data, 
00133   GATJobCPIInstance_Data **new_instance_data)
00134 {
00135   GATResult retval = GAT_INVALID_PARAMETER;
00136   if (NULL != new_instance_data)
00137   {
00138     GATJobCPIInstance_Data *new_data = 
00139       (GATJobCPIInstance_Data *)malloc(sizeof(struct GATJobCPIInstance_Data));
00140 
00141     if (NULL != new_data)
00142     {
00143       memset(new_data, 0, sizeof(struct GATJobCPIInstance_Data));
00144       if (GAT_SUCCEEDED(retval = GATJobDescription_Clone(
00145             instance_data->description, &new_data->description)) &&
00146           GAT_SUCCEEDED(retval = GATTable_Clone(instance_data->parameters,
00147             &new_data->parameters)) &&
00148           (
00149             NULL == instance_data->status ||
00150             GAT_SUCCEEDED(retval = GATStatus_Clone(instance_data->status,
00151               &new_data->status))
00152           ) &&
00153           (
00154             NULL == instance_data->resource ||
00155             GAT_SUCCEEDED(retval = GATResource_Clone(instance_data->resource,
00156               &new_data->resource))
00157           )
00158         )
00159       {
00160         *new_instance_data = new_data;
00161       }
00162       else
00163       {
00164         GATJobCPIInstance_Data_Destroy(&new_data);
00165       }
00166     }
00167     else
00168     {
00169       retval = GAT_MEMORYFAILURE;
00170     }
00171   }
00172   return retval;
00173 }
00174 
00175 /** GATJobCPIInstance_Data_Equals
00176  *
00177  *  The function GATJobCPIInstance_Data_Equals is called, 
00178  *  whenever the engine needs to compare for equality two different instance 
00179  *  data items.
00180  *
00181  *  @param lhs The first instance data item to compare.
00182  *  @param rhs The second instance data item to compare.
00183  *  @param isequal The pointer to a variable, which receives the result of the
00184  *        compare operation.
00185  *
00186  *  @result An error code.
00187  */
00188 GATResult 
00189 GATJobCPIInstance_Data_Equals(
00190   GATJobCPIInstance_Data const *lhs, 
00191   GATJobCPIInstance_Data const *rhs, GATBool *isequal)
00192 {
00193   GATResult retval = GAT_INVALID_HANDLE;
00194   if (NULL != lhs && NULL != rhs)
00195   {
00196     if (NULL != isequal)
00197     {
00198       retval = GATJobDescription_Equals(lhs->description, rhs->description, 
00199         isequal);
00200       if (GAT_SUCCEEDED(retval) && GATTrue == *isequal)
00201       {
00202         retval = GATTable_Equals(lhs->parameters, rhs->parameters, isequal);
00203       }
00204       if (GAT_SUCCEEDED(retval) && GATTrue == *isequal)
00205       {
00206         if (NULL != lhs->status && NULL != rhs->status)
00207         {
00208           retval = GATStatus_Equals(lhs->status, rhs->status, isequal);
00209         }
00210         else
00211         {
00212           *isequal = (NULL == lhs->status && NULL == rhs->status) ? GATTrue : GATFalse;
00213           retval = GAT_SUCCESS;
00214         }
00215       }
00216       if (GAT_SUCCEEDED(retval) && GATTrue == *isequal)
00217       {
00218         if (NULL != lhs->resource && NULL != rhs->resource)
00219         {
00220           retval = GATResource_Equals(lhs->resource, rhs->resource, isequal);
00221         }
00222         else
00223         {
00224           *isequal = (NULL == lhs->resource && NULL == rhs->resource) ? GATTrue : GATFalse;
00225           retval = GAT_SUCCESS;
00226         }
00227       }
00228     }
00229     else
00230     {
00231       retval = GAT_INVALID_PARAMETER;
00232     }
00233   }
00234   return retval;
00235 }
00236 
00237 /** GATJobCPIInstance_Data_Serialize
00238  *
00239  *  The function GATJobCPIInstance_Data_Serialize is called by the engine, 
00240  *  whenever the instance specific data has to be serialised. The function 
00241  *  should serialise into the given stream all the instance specific data of 
00242  *  the object.
00243  *
00244  *  @param instance_data The instance data item to serialise.
00245  *  @param stream The stream to be used for serialisation of the instance data.
00246  *  @param clear_dirty If the clear_dirty parameter is set to GATTrue, the 
00247  *        internal dirty flag of this object is to be reset.
00248  *
00249  *  @return An error code.
00250  */
00251 GATResult 
00252 GATJobCPIInstance_Data_Serialize(
00253   GATJobCPIInstance_Data const *instance_data, GATObject stream,
00254   GATBool clear_dirty)
00255 {
00256   GATResult retval = GAT_INVALID_HANDLE;
00257   if (NULL != instance_data)
00258   {
00259     retval = GATJobDescription_Serialise(instance_data->description, stream, 
00260       clear_dirty);
00261     if (GAT_SUCCEEDED(retval))
00262     {
00263       retval = GATTable_Serialise(instance_data->parameters, stream, 
00264         clear_dirty);
00265     }
00266     if (GAT_SUCCEEDED(retval) && NULL != instance_data->status)
00267     {
00268       retval = GATuint32_Serialise(GATTrue, stream);
00269       if (GAT_SUCCEEDED(retval))
00270       {
00271         retval = GATStatus_Serialise(instance_data->status, stream, 
00272           clear_dirty);
00273       }
00274     }
00275     else
00276     {
00277       /* no status serialised */
00278       retval = GATuint32_Serialise(GATFalse, stream);
00279     }
00280     if (GAT_SUCCEEDED(retval) && NULL != instance_data->resource)
00281     {
00282       retval = GATuint32_Serialise(GATTrue, stream);
00283       if (GAT_SUCCEEDED(retval))
00284       {
00285         retval = GATResource_Serialise(instance_data->resource, stream, 
00286           clear_dirty);
00287       }
00288     }
00289     else
00290     {
00291       /* no resource serialised */
00292       retval = GATuint32_Serialise(GATFalse, stream);
00293     }
00294   }
00295   return retval;
00296 }
00297   
00298 /** GATJobCPIInstance_Data_DeSerialize
00299  *
00300  *  The function GATJobCPIInstance_Data_DeSerialize is called by the engine, 
00301  *  whenever the client requested a DeSerialise operation for
00302  *  a corresponding object. The function should deserialise all the instance 
00303  *  specific data of the object from the given stream.
00304  *
00305  *  @param context The GATContext to use to instantiate new GAT objects.
00306  *  @param stream The stream to use to get the serialised data from.
00307  *  @param instance_data The pointer to a variable, which receives the new
00308  *        instance data deserialised from the given steam.
00309  *
00310  *  @return An error code.
00311  */
00312 GATResult 
00313 GATJobCPIInstance_Data_DeSerialize(GATContext context, GATObject stream, 
00314   GATJobCPIInstance_Data **instance_data)
00315 {
00316   GATResult retval = GAT_NOTIMPL;
00317   return retval;
00318 }
00319 
00320 
00321