GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATEndpointCPI.c

Go to the documentation of this file.
00001 /** @file GATEndpointCPI.c
00002  * Main .c for the GATEndpointCPI class.
00003  * 
00004  * A GATEndpointCPI encapsulates all the methods that a GATEndpoint capability
00005  * provider provides.
00006  * 
00007  * @date $Date: 2004/04/02 12:31:57 $
00008  * 
00009  * @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATEndpointCPI.c,v 1.8 2004/04/02 12:31:57 hartmutkaiser Exp $
00010  *
00011  *  Copyright (C) Kelly Davis
00012  *  This endpoint is part of the GAT Engine.
00013  *  Contributed by Kelly Davis <kdavis@aei.mpg.de> and
00014  *  Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00015  *
00016  *  Use, modification and distribution is subject to the Gridlab Software
00017  *  License. (See accompanying file GLlicense.txt or copy at
00018  *  http://www.gridlab.org/GLlicense.txt)
00019  */
00020 
00021 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATEndpointCPI.c,v 1.8 2004/04/02 12:31:57 hartmutkaiser Exp $";
00022 
00023 /* System Header Files */
00024 
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 
00028 /* GAT Header Files */
00029 
00030 #include "GATEndpointCPI.h"
00031 
00032 /* Macros */
00033 
00034 /* Structures, unions and enums */
00035 
00036 struct GATEndpointCPI_S
00037 {
00038   /* CPI data (type local data) */
00039   void *data;
00040   GATEndpointCPI_Adaptor_Destroy destroy;
00041   GATEndPointCPI_Adaptor_ServiceActions service_actions;
00042 
00043   /* CPI instance data */
00044   GATEndpointCPI_Adaptor_CreateInstance create_instance;
00045   GATEndpointCPI_Adaptor_DestroyInstance destroy_instance;
00046   GATEndpointCPI_Adaptor_CloneInstance clone_instance;
00047   GATEndpointCPI_Adaptor_EqualsInstance equals_instance;
00048 
00049   /* CPI serialisation */
00050   GATEndpointCPI_Adaptor_Serialise serialise;
00051   GATEndpointCPI_Adaptor_DeSerialise deserialise;
00052   
00053   /* CPI functionality */
00054   GATEndpointCPI_Adaptor_Connect connect;
00055   GATEndpointCPI_Adaptor_Listen listen;
00056   GATEndpointCPI_Adaptor_AddGATPipeListener addPipeListener;
00057   
00058   /* CPI monitoring support */
00059   GATEndpointCPI_Adaptor_GetMetrics get_metrics;
00060   GATEndpointCPI_Adaptor_GetMetricEvent get_metric_event;
00061 };
00062 
00063 /* Static function prototypes */
00064 static GATBool GATEndpointCPI_IsValidData_V1(GATEndpointCPI_Data *data);
00065 
00066 /* File scope variables */
00067 
00068 /* External functions */
00069 
00070 /** GATEndpointCPI_Create
00071  *  The  GATEndpointCPI constructor.
00072  *  This is the constructor for GATEndpointCPI objects.
00073  *  
00074  *  @param version Version of the GATEndpointCPI_Data structure
00075  *  @param data Pointer to adaptor CPI instance data structure.
00076  *
00077  * @return A new GATEndpointCPI
00078  */
00079 GATEndpointCPI GATEndpointCPI_Create(unsigned long int version, GATEndpointCPI_Data *data)
00080 {
00081   GATEndpointCPI new_cpi = NULL;
00082 
00083   if (version <= GATENDPOINTCPI_VERSION)
00084   {
00085     if (version == GATENDPOINTCPI_VERSION && 
00086         GATTrue == GATEndpointCPI_IsValidData_V1(data))
00087     {
00088       new_cpi = (GATEndpointCPI)malloc(sizeof(struct GATEndpointCPI_S));
00089       if(NULL != new_cpi)
00090       {
00091         new_cpi->data = data->data;
00092         new_cpi->destroy = data->destroy;
00093         new_cpi->service_actions = data->service_actions;
00094         
00095         new_cpi->destroy_instance = data->destroy_instance;
00096         new_cpi->create_instance = data->create_instance;
00097         new_cpi->equals_instance = data->equals_instance;
00098         new_cpi->clone_instance = data->clone_instance;
00099 
00100         new_cpi->serialise = data->serialise;
00101         new_cpi->deserialise = data->deserialise;
00102 
00103         new_cpi->connect = data->connect;
00104         new_cpi->listen = data->listen;
00105         new_cpi->addPipeListener = data->addPipeListener;
00106         
00107         new_cpi->get_metrics = data->get_metrics;
00108         new_cpi->get_metric_event = data->get_metric_event;
00109       }
00110     }
00111 /*  add functionality for newer versions here
00112     else if (version == GATENDPOINTCPI_VERSION2 && GATEndpointCPI_IsValidData_V2(data))
00113     {
00114       ...
00115     }
00116  */
00117     else
00118     {
00119       /* Missing required functions */
00120       /* error_code = GAT_INVALID_PARAMETER; */
00121     }
00122   }
00123   else
00124   {
00125     /* unknown version */
00126     /* error_code = GAT_UNKNOWN_VERSION; */
00127   }
00128   return new_cpi;
00129 }
00130 
00131 /** GATEndpointCPI_Destroy
00132  *  @brief The GATEndpointCPI destructor.
00133  *
00134  *  This is the destructor for GATEndpointCPI objects.
00135  *
00136  *  @param this An old GATEndpointCPI
00137  */
00138 void GATEndpointCPI_Destroy(GATEndpointCPI *cpi)
00139 {
00140   if(NULL != cpi && NULL != *cpi)
00141   {
00142     (*cpi)->destroy((*cpi)->data);
00143     free(*cpi);
00144     *cpi = NULL;
00145   }
00146 }
00147 
00148 /** GATEndpointCPI_CreateInstance
00149  *  @brief Create a new CPI object instance
00150  *
00151  *  Calls the adaptor to create a new CPI object instance.
00152  *
00153  *  @param this The CPI object.
00154  *  @param instance_data The instance data of the attached CPI object
00155  *
00156  *  @return An error code.
00157  */
00158 GATResult 
00159 GATEndpointCPI_CreateInstance(GATEndpointCPI cpi, GATEndpointCPI_Instance *data)
00160 {
00161   return cpi->create_instance(cpi->data, data);
00162 }
00163 
00164 /** GATEndpointCPI_DestroyInstance
00165  *  @brief Create a new CPI object instance
00166  *
00167  *  Calls the adaptor to destroy a CPI object instance.
00168  *
00169  *  @param this The CPI object.
00170  *  @param instance_data The instance data of the attached CPI object
00171  */
00172 void 
00173 GATEndpointCPI_DestroyInstance(GATEndpointCPI cpi, GATEndpointCPI_Instance *data)
00174 {
00175   cpi->destroy_instance(cpi->data, data);
00176 }
00177 
00178 /** GATEndpointCPI_EqualsInstance
00179  *  @brief Compares two CPI object instances.
00180  *
00181  *  Calls the adaptor to compare two CPI object instances.
00182  *
00183  *  @param this The CPI object.
00184  *  @param lhs The instance data of the left CPI object
00185  *  @param rhs The instance data of the right CPI object
00186  *  @param isequal The pointer to the variable, where the result is to be 
00187  *        returned to.
00188  *
00189  *  @return An error code.
00190  */
00191 GATResult 
00192 GATEndpointCPI_EqualsInstance(GATEndpointCPI cpi, GATEndpointCPI_Instance const *lhs, 
00193   GATEndpointCPI_Instance const *rhs, GATBool *isequal)
00194 {
00195   return cpi->equals_instance(cpi->data, lhs, rhs, isequal);
00196 }
00197 
00198 /** GATEndpointCPI_CloneInstance
00199  *  @brief Clones a CPI object instance.
00200  *
00201  *  Calls the adaptor to clone a CPI object instance.
00202  *
00203  *  @param this The CPI object.
00204  *  @param instance_data The instance data of the CPI object to clone.
00205  *  @param rhs The new instance data is to be returned here.
00206  *
00207  *  @return An error code.
00208  */
00209 GATResult 
00210 GATEndpointCPI_CloneInstance(GATEndpointCPI cpi, 
00211   GATEndpointCPI_Instance const *data, GATEndpointCPI_Instance *new_data) 
00212 {
00213   return cpi->clone_instance(cpi->data, data, new_data);
00214 }
00215 
00216 /** GATEndpointCPI_Serialise
00217  *  @brief Serialise the instance data.
00218  *
00219  *  Calls the adaptor to serialise the instance data.
00220  *
00221  *  @param this The CPI object.
00222  *  @param instance_data The instance data of the attached CPI object
00223  *  @param stream The stream to use be used for serialisation.
00224  *  @param clear_dirty If the clear_dirty parameter is set to GATTrue, the 
00225  *        internal dirty flag of this object is to be reset.
00226  *
00227  *  @return An error code.
00228  */
00229 GATResult 
00230 GATEndpointCPI_Serialise(GATEndpointCPI cpi, 
00231   GATEndpointCPI_Instance const *data, GATObject stream, GATBool clear_dirty)
00232 {
00233   return cpi->serialise(cpi->data, data, stream, clear_dirty);
00234 }
00235   
00236 /** GATEndpointCPI_DeSerialise
00237  *  @brief De-serialise the instance data
00238  *
00239  *  Call the adaptor to de-serialise the instance data.
00240  *
00241  *  @param context The GAT context to be used for object construction.
00242  *  @param stream The stream interface to use for the serialisation.
00243  *  @param instance_data The pointer to a variable, which contains the client 
00244  *        data of the new object. The member instance data of this object 
00245  *        may receive the pointer to the new instance data of the CPI object.
00246  *
00247  *  @return An error code.
00248  */
00249 GATResult 
00250 GATEndpointCPI_DeSerialise(GATEndpointCPI cpi,
00251   GATObject stream, GATEndpointCPI_Instance *data)
00252 {
00253   return cpi->deserialise(cpi->data, stream, data);
00254 }
00255   
00256 /** GATEndpointCPI_Connect
00257  *  @brief Connect a client's endpoint.
00258  *
00259  *  Calls the adaptor to connect a client's endpoint.
00260  *
00261  *  @param this The CPI object.
00262  *  @param instance_data The instance data of the attached CPI object
00263  *  @param peep The connected GATPipe
00264  *
00265  *  @return An error code.
00266  */
00267 GATResult GATEndpointCPI_Connect(GATEndpointCPI cpi, GATEndpointCPI_Instance const *data, GATPipe *peep)
00268 {
00269   return cpi->connect(cpi->data, data, peep);
00270 }
00271 
00272 /** GATEndpointCPI_Listen
00273  *  @brief Connect a server's endpoint.
00274  *
00275  *  Calls the adaptor to connect a server's endpoint.
00276  *
00277  *  @param this The CPI object.
00278  *  @param instance_data The instance data of the attached CPI object
00279  *  @param peep The connected GATPipe
00280  *
00281  *  @return An error code.
00282  */
00283 GATResult GATEndpointCPI_Listen(GATEndpointCPI cpi, GATEndpointCPI_Instance const *data, GATPipe *peep)
00284 {
00285   return cpi->listen(cpi->data, data, peep);
00286 }
00287 
00288 /** GATEndpointCPI_AddGATPipeListener
00289  *  @brief Add a GATPipeListener to this endpoint.
00290  *
00291  *  Calls the adaptor to add a GATPipeListener to this endpoint.
00292  *
00293  *  @param this The CPI object.
00294  *  @param instance_data The instance data of the attached CPI object
00295  *  @param pipeListener The to be added GATPipeListener
00296  *  @param listenerData Callback data
00297  *
00298  *  @return An error code.
00299  */
00300 GATResult GATEndpointCPI_AddGATPipeListener(GATEndpointCPI cpi, GATEndpointCPI_Instance const *data, GATPipeListener pipeListener, void *listenerData)
00301 {
00302   return cpi->addPipeListener(cpi->data, data, pipeListener, listenerData);
00303 }
00304 
00305 /** GATEndpointCPI_GetMetrics
00306  *
00307  *  The function GATEndpointCPI_GetMetrics returns the list of metrics supported
00308  *  by this adaptor.
00309  *
00310  *  @param this The CPI object.
00311  *  @param instance_data The instance data of the attached CPI object
00312  *  @param The pointer to the variable, which receives the resulting list of
00313  *        metrics.
00314  *
00315  *  @return An error code.
00316  */
00317 GATResult 
00318 GATEndpointCPI_GetMetrics(GATEndpointCPI cpi, GATEndpointCPI_Instance const *data,
00319   GATList_GATMetric *metrics)
00320 {
00321   return cpi->get_metrics(cpi->data, data, metrics);
00322 }
00323 
00324 /** GATEndpointCPI_GetMetricEvent
00325  *
00326  *  The function GATEndpointCPI_GetMetricEvent returns the metric event, which is 
00327  *  associated with the given metric.
00328  *
00329  *  @param this The CPI object.
00330  *  @param instance_data The instance data of the attached CPI object
00331  *  @param metric The continuous metric, for which the metric event is to be 
00332  *        returned. 
00333  *  @param event The pointer to the variable, which receives the resulting
00334  *        metric event.
00335  *
00336  *  @return An error code.
00337  */
00338 GATResult
00339 GATEndpointCPI_GetMetricEvent(GATEndpointCPI cpi, GATEndpointCPI_Instance const *data,
00340   GATMetric metric, GATMetricEvent *event)
00341 {
00342   return cpi->get_metric_event(cpi->data, data, metric, event);
00343 }
00344 
00345 /* Local functions */
00346 static GATBool 
00347 GATEndpointCPI_IsValidData_V1(GATEndpointCPI_Data *data)
00348 {
00349   return (
00350       NULL != data->destroy && 
00351 //      NULL != data->service_actions &&
00352             
00353       NULL != data->destroy_instance && 
00354       NULL != data->create_instance && 
00355       NULL != data->clone_instance && 
00356       NULL != data->equals_instance &&  
00357       
00358       NULL != data->serialise && 
00359       NULL != data->deserialise && 
00360            
00361       NULL != data->connect && 
00362       NULL != data->listen && 
00363       NULL != data->addPipeListener && 
00364       
00365       NULL != data->get_metrics &&
00366       NULL != data->get_metric_event
00367     ) ? GATTrue : GATFalse;
00368 }