GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATResourceCPIInstanceData.c

Go to the documentation of this file.
00001 /** @file GATResourceCPIInstanceData.c
00002  *  Source file for the GATResourceCPIInstance_Data class, which represents the 
00003  *  internal data stored by the ResourceCPI provider for the resource broker 
00004  *  adaptor.
00005  *
00006  *  @date Thu Nov 27 2003
00007  *
00008  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/resourcebroker/GATResourceCPIInstanceData.c,v 1.5 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/GATResourceCPIInstanceData.c,v 1.5 2004/04/02 12:31:57 hartmutkaiser Exp $";
00020 
00021 /* System Header objects */
00022 #include <string.h>
00023 
00024 /* GAT Header objects */
00025 #include "GATResourceCPIInstanceData.h"
00026 
00027 /* Macros */
00028 
00029 /* Structures, unions and enums */
00030 
00031 /* Static function prototypes */
00032 
00033 /* file scope variables */
00034 
00035 /* External functions */
00036 
00037 /** GATResourceCPIInstance_Data_Create
00038  *
00039  *  The function GATResourceCPIInstance_Data_Create creates a new instance of
00040  *  the internal GATResource data.
00041  *
00042  *  @param rd The description of the GATResource to create.
00043  *
00044  *  @return The pointer to the newly created and initialised data structure.
00045  */
00046 GATResourceCPIInstance_Data *
00047 GATResourceCPIInstance_Data_Create(GATResourceDescription_const rd)
00048 {
00049   GATResult retval = GAT_SUCCESS;
00050   GATResourceCPIInstance_Data *result = 
00051     (GATResourceCPIInstance_Data *)malloc(sizeof(struct GATResourceCPIInstance_Data));
00052 
00053   if (NULL != result)
00054   {
00055     GATType type = GATResourceDescription_GetType(rd);
00056     
00057     memset(result, 0, sizeof(struct GATResourceCPIInstance_Data));
00058     retval = GATResourceDescription_Clone(type, rd, &result->rd);
00059     if (GAT_FAILED(retval))
00060     {
00061       free(result);
00062       result = NULL;
00063     }
00064   }
00065   return result;
00066 }
00067 
00068 /** GATResourceCPIInstance_Data_Destroy
00069  *
00070  *  The function GATResourceCPIInstance_Data_Destroy is called to free all the
00071  *  memory associated with the given instance data item.
00072  *
00073  *  @param instance_data The pointer to a variable holding the old instance 
00074  *        data item, this is set to zero on exit.
00075  */
00076 void 
00077 GATResourceCPIInstance_Data_Destroy(
00078   GATResourceCPIInstance_Data **instance_data)
00079 {
00080   if (NULL != instance_data && NULL != *instance_data)
00081   {
00082     GATResourceDescription_Destroy(&(*instance_data)->rd);
00083     free(*instance_data);
00084     *instance_data = NULL;
00085   }
00086 }
00087 
00088 /** GATResourceCPIInstance_Data_Clone
00089  *
00090  *  The function GATResourceCPIInstance_Data_Clone is called to make a copy of 
00091  *  the given instance data item.
00092  *
00093  *  @param instance_data The instance data item to copy.
00094  *  @param new_instance_Data The pointer to a variable, which receives the 
00095  *        newly created copy of the instance data item.
00096  *
00097  *  @return An error code.
00098  */
00099 GATResult 
00100 GATResourceCPIInstance_Data_Clone(
00101   GATResourceCPIInstance_Data const *instance_data, 
00102   GATResourceCPIInstance_Data **new_instance_data)
00103 {
00104   GATResult retval = GAT_INVALID_PARAMETER;
00105   if (NULL != new_instance_data)
00106   {
00107     GATResourceCPIInstance_Data *new_data = 
00108       (GATResourceCPIInstance_Data *)malloc(sizeof(struct GATResourceCPIInstance_Data));
00109 
00110     if (NULL != new_data)
00111     {
00112       GATType type = GATResourceDescription_GetType(instance_data->rd);
00113       
00114       retval = GATResourceDescription_Clone(type, instance_data->rd, 
00115         &new_data->rd);
00116       
00117       if (GAT_FAILED(retval))
00118       {
00119         free(new_data);
00120       }
00121       else
00122       {
00123         *new_instance_data = new_data;
00124       }
00125     }
00126     else
00127     {
00128       retval = GAT_MEMORYFAILURE;
00129     }
00130   }
00131   return retval;
00132 }
00133 
00134 /** GATResourceCPIInstance_Data_Equals
00135  *
00136  *  The function GATResourceCPIInstance_Data_Equals is called, whenever the 
00137  *  engine needs to compare for equality two different instance data items.
00138  *
00139  *  @param lhs The first instance data item to compare.
00140  *  @param rhs The second instance data item to compare.
00141  *  @param isequal The pointer to a variable, which receives the result of the
00142  *        compare operation.
00143  *
00144  *  @result An error code.
00145  */
00146 GATResult 
00147 GATResourceCPIInstance_Data_Equals(
00148   GATResourceCPIInstance_Data const *lhs, 
00149   GATResourceCPIInstance_Data const *rhs, GATBool *isequal)
00150 {
00151   GATResult retval = GAT_INVALID_HANDLE;
00152   if (NULL != lhs && NULL != rhs)
00153   {
00154     retval = GATResourceDescription_Equals(lhs->rd, rhs->rd, isequal);
00155   }
00156   return retval;
00157 }
00158 
00159 /** GATResourceCPIInstance_Data_GetResourceDescription
00160  *
00161  *  The function GATResourceCPIInstance_Data_GetResourceDescription may be used
00162  *  to access the associated resource description of the target resource.
00163  *
00164  *  @param instance_data The instance data item, for which the resource 
00165  *        description is to be retrieved.
00166  *  @param description The pointer to a variable, which receives the resulting 
00167  *        resource description.
00168  *
00169  *  @return An error code.
00170  */
00171 GATResult
00172 GATResourceCPIInstance_Data_GetResourceDescription(
00173   GATResourceCPIInstance_Data const *instance_data, 
00174   GATResourceDescription_const *description)
00175 {
00176   GATResult retval = GAT_INVALID_HANDLE;
00177   if (NULL != instance_data)
00178   {
00179     if (NULL != description)
00180     {
00181       *description = instance_data->rd;
00182       retval = GAT_SUCCESS;
00183     }
00184     else
00185     { 
00186       retval = GAT_INVALID_PARAMETER;
00187     }
00188   }
00189   return retval;
00190 }
00191 
00192 /** GATResourceCPIInstance_Data_Serialize
00193  *
00194  *  The function GATResourceCPIInstance_Data_Serialize is called by the engine, 
00195  *  whenever the instance specific data has to be serialised. The function 
00196  *  should serialise into the given stream all the instance specific data of 
00197  *  the object.
00198  *
00199  *  @param instance_data The instance data item to serialise.
00200  *  @param stream The stream to be used for serialisation of the instance data.
00201  *  @param clear_dirty If the clear_dirty parameter is set to GATTrue, the 
00202  *        internal dirty flag of this object is to be reset.
00203  *
00204  *  @return An error code.
00205  */
00206 GATResult 
00207 GATResourceCPIInstance_Data_Serialize(
00208   GATResourceCPIInstance_Data const *instance_data, GATObject stream, 
00209   GATBool clear_dirty)
00210 {
00211   GATResult retval = GAT_INVALID_HANDLE;
00212   if (NULL != instance_data)
00213   {
00214     retval = GATResourceDescription_Serialise(instance_data->rd, stream, 
00215       clear_dirty);
00216   }
00217   return retval;
00218 }
00219   
00220 /** GATResourceCPIInstance_Data_DeSerialize
00221  *
00222  *  The function GATResourceCPIInstance_Data_DeSerialize is called by the engine, 
00223  *  whenever the client requested a DeSerialise operation for
00224  *  a corresponding object. The function should deserialise all the instance 
00225  *  specific data of the object from the given stream.
00226  *
00227  *  @param context The GATContext to use to instantiate new GAT objects.
00228  *  @param stream The stream to use to get the serialised data from.
00229  *  @param instance_data The pointer to a variable, which receives the new
00230  *        instance data deserialised from the given steam.
00231  *
00232  *  @return An error code.
00233  */
00234 GATResult 
00235 GATResourceCPIInstance_Data_DeSerialize(GATContext context, GATObject stream, 
00236   GATResourceCPIInstance_Data **instance_data)
00237 {
00238   GATResult retval = GAT_INVALID_HANDLE;
00239   if (NULL != instance_data)
00240   {
00241     GATResourceCPIInstance_Data *new_data = 
00242       (GATResourceCPIInstance_Data *)malloc(sizeof(struct GATResourceCPIInstance_Data));
00243 
00244     if (NULL != new_data)
00245     {
00246       memset(new_data, 0, sizeof(struct GATResourceCPIInstance_Data));
00247       new_data->rd = GATResourceDescription_DeSerialise(context, stream, 
00248         &retval);
00249       if (GAT_SUCCEEDED(retval))
00250       {
00251         *instance_data = new_data;
00252       }
00253       else
00254       {
00255         GATResourceCPIInstance_Data_Destroy(&new_data);
00256         *instance_data = NULL;
00257       }
00258     }
00259     else
00260     {
00261       retval = GAT_MEMORYFAILURE;
00262     }
00263   }
00264   return retval;
00265 }