GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

GATAdvertServiceCPI.c

Go to the documentation of this file.
00001 /** @file GATAdvertServiceCPI.c
00002  *  Source file for the GATAdvertServiceCPI class.
00003  *
00004  *  @date Fri Feb 13 2004
00005  *
00006  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATAdvertServiceCPI.c,v 1.5 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/GATAdvertServiceCPI.c,v 1.5 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 "GATAdvertServiceCPI.h"
00026 
00027 /* Macros */
00028 
00029 /* Structures, unions and enums */
00030 struct GATAdvertServiceCPI_S
00031 {
00032   /* CPI data (type local data) */
00033   void *data;
00034   GATAdvertServiceCPI_Adaptor_Destroy destroy;
00035   
00036   /* CPI instance data */
00037   GATAdvertServiceCPI_Adaptor_ServiceActions service_actions;
00038   GATAdvertServiceCPI_Adaptor_CreateInstance create_instance;
00039   GATAdvertServiceCPI_Adaptor_DestroyInstance destroy_instance;
00040   GATAdvertServiceCPI_Adaptor_CloneInstance clone_instance;
00041   GATAdvertServiceCPI_Adaptor_EqualsInstance equals_instance;
00042 
00043   /* CPI functionality */
00044   GATAdvertServiceCPI_Adaptor_Add add_entry;
00045   GATAdvertServiceCPI_Adaptor_Delete delete_entry;
00046   GATAdvertServiceCPI_Adaptor_GetMetaData get_metadata;
00047   GATAdvertServiceCPI_Adaptor_GetAdvertisable get_advertisable;
00048   GATAdvertServiceCPI_Adaptor_Find find_entries; 
00049 
00050   /* CPI monitoring support */
00051   GATAdvertServiceCPI_Adaptor_GetMetrics get_metrics;
00052   GATAdvertServiceCPI_Adaptor_GetMetricEvent get_metric_event;
00053 };
00054 
00055 /* Static function prototypes */
00056 static GATBool 
00057   GATAdvertServiceCPI_IsValidData_V1(GATAdvertServiceCPI_Data *data);
00058 
00059 /* File scope variables */
00060 
00061 /* External functions */
00062 
00063 /** GATAdvertServiceCPI_Create
00064  *  The  GATAdvertServiceCPI constructor.
00065  *  new_cpi is the constructor for GATAdvertServiceCPI objects.
00066  *  
00067  *  @param version Version of the GATAdvertServiceCPI_Data structure
00068  *  @param data Pointer to adaptor CPI instance data structure.
00069  *
00070  * @return A new GATAdvertServiceCPI
00071  */
00072 GATAdvertServiceCPI GATAdvertServiceCPI_Create(unsigned long int version,
00073   GATAdvertServiceCPI_Data *data)
00074 {
00075   GATAdvertServiceCPI new_cpi = NULL;
00076 
00077   if (version <= GATADVERTSERVICECPI_VERSION)
00078   {
00079     if (version == GATADVERTSERVICECPI_VERSION && 
00080         GATTrue == GATAdvertServiceCPI_IsValidData_V1(data))
00081     {
00082       new_cpi = (GATAdvertServiceCPI)malloc(sizeof(*new_cpi));
00083       if(NULL != new_cpi)
00084       {
00085         new_cpi->data = data->data;
00086         new_cpi->destroy = data->destroy;
00087 
00088         new_cpi->service_actions = data->service_actions;
00089         new_cpi->destroy_instance = data->destroy_instance;
00090         new_cpi->create_instance = data->create_instance;
00091         new_cpi->equals_instance = data->equals_instance;
00092         new_cpi->clone_instance = data->clone_instance;
00093         
00094         new_cpi->add_entry = data->add_entry;
00095         new_cpi->delete_entry = data->delete_entry;
00096         new_cpi->get_metadata = data->get_metadata;
00097         new_cpi->get_advertisable = data->get_advertisable;
00098         new_cpi->find_entries = data->find_entries;
00099 
00100         new_cpi->get_metrics = data->get_metrics;
00101         new_cpi->get_metric_event = data->get_metric_event;
00102       }
00103     }
00104 /*  add functionality for newer versions here
00105     else if (version == GATADVERTSERVICECPI_VERSION2 && 
00106       GATAdvertServiceCPI_IsValidData_V2(data))
00107     {
00108       ...
00109     }
00110  */
00111     else
00112     {
00113       /* Missing required functions */
00114       /* error_code = GAT_INVALID_PARAMETER; */
00115       new_cpi = NULL;
00116     }
00117   }
00118   else
00119   {
00120     /* unknown version */
00121     /* error_code = GAT_UNKNOWN_VERSION; */
00122     new_cpi = NULL;
00123   }
00124   return new_cpi;
00125 }
00126 
00127 /** GATAdvertServiceCPI_Destroy
00128  *  @brief The GATAdvertServiceCPI destructor.
00129  *
00130  *  This is the destructor for GATAdvertServiceCPI objects.
00131  *
00132  *  @param this An old GATAdvertServiceCPI
00133  */
00134 void GATAdvertServiceCPI_Destroy(GATAdvertServiceCPI *object)
00135 {
00136   if(NULL != object && NULL != *object)
00137   {
00138     /* call the adapter supplied destroy function */
00139     (*object)->destroy((*object)->data);
00140     free(*object);
00141     *object = NULL;
00142   }
00143 }
00144 
00145 /** GATAdvertServiceCPI_CreateInstance
00146  *  @brief Create a new CPI object instance
00147  *
00148  *  Calls the adaptor to create a new CPI object instance.
00149  *
00150  *  @param this The CPI object.
00151  *  @param context a GATContext
00152  *  @param instance_data The instance data of the attached CPI object
00153  *
00154  *  @return An error code.
00155  */
00156 GATResult 
00157 GATAdvertServiceCPI_CreateInstance(GATAdvertServiceCPI cpi, 
00158   GATAdvertServiceCPI_Instance *instance_data)
00159 {
00160   return cpi->create_instance(cpi->data, instance_data);
00161 }
00162 
00163 /** GATAdvertServiceCPI_DestroyInstance
00164  *  @brief Create a new CPI object instance
00165  *
00166  *  Calls the adaptor to destroy a CPI object instance.
00167  *
00168  *  @param this The CPI object.
00169  *  @param instance_data The instance data of the attached CPI object
00170  */
00171 void 
00172 GATAdvertServiceCPI_DestroyInstance(GATAdvertServiceCPI cpi, 
00173   GATAdvertServiceCPI_Instance *instance_data)
00174 {
00175   cpi->destroy_instance(cpi->data, instance_data);
00176 }
00177 
00178 /** GATAdvertServiceCPI_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 GATAdvertServiceCPI_EqualsInstance(GATAdvertServiceCPI cpi, 
00193   GATAdvertServiceCPI_Instance const *lhs, GATAdvertServiceCPI_Instance const *rhs, 
00194   GATBool *isequal)
00195 {
00196   return cpi->equals_instance(cpi->data, lhs, rhs, isequal);
00197 }
00198 
00199 /** GATAdvertServiceCPI_CloneInstance
00200  *  @brief Clones a CPI object instance.
00201  *
00202  *  Calls the adaptor to clone a CPI object instance.
00203  *
00204  *  @param this The CPI object.
00205  *  @param instance_data The instance data of the CPI object to clone.
00206  *  @param new_instance_data The new instance data is to be returned here.
00207  *
00208  *  @return An error code.
00209  */
00210 GATResult 
00211 GATAdvertServiceCPI_CloneInstance(GATAdvertServiceCPI cpi, 
00212   GATAdvertServiceCPI_Instance const *instance_data,
00213   GATAdvertServiceCPI_Instance *new_instance_data) 
00214 {
00215   return cpi->clone_instance(cpi->data, instance_data, new_instance_data);
00216 }
00217 
00218   
00219 /** GATAdvertServiceCPI_GetMetrics
00220  *
00221  *  The function GATAdvertServiceCPI_GetMetrics returns the list of metrics supported
00222  *  by this adaptor.
00223  *
00224  *  @param cpi The CPI object.
00225  *  @param instance_data The instance data of the attached CPI object
00226  *  @param The pointer to the variable, which receives the resulting list of
00227  *        metrics.
00228  *
00229  *  @return An error code.
00230  */
00231 GATResult 
00232 GATAdvertServiceCPI_GetMetrics(GATAdvertServiceCPI cpi, GATAdvertServiceCPI_Instance const *data,
00233   GATList_GATMetric *metrics)
00234 {
00235   return cpi->get_metrics(cpi->data, data, metrics);
00236 }
00237 
00238 /** GATAdvertServiceCPI_GetMetricEvent
00239  *
00240  *  The function GATAdvertServiceCPI_GetMetricEvent returns the metric event, which is 
00241  *  associated with the given metric.
00242  *
00243  *  @param cpi The CPI object.
00244  *  @param instance_data The instance data of the attached CPI object
00245  *  @param metric The continuous metric, for which the metric event is to be 
00246  *        returned. 
00247  *  @param event The pointer to the variable, which receives the resulting
00248  *        metric event.
00249  *
00250  *  @return An error code.
00251  */
00252 GATResult
00253 GATAdvertServiceCPI_GetMetricEvent(GATAdvertServiceCPI cpi, 
00254   GATAdvertServiceCPI_Instance const *data, GATMetric metric, 
00255   GATMetricEvent *event)
00256 {
00257   return cpi->get_metric_event(cpi->data, data, metric, event);
00258 }
00259 
00260 /** GATAdvertServiceCPI_Add
00261  *  
00262  *  Calls the adaptor to add a new entry to the advert service.
00263  *
00264  *  @param this The CPI object.
00265  *  @param instance_data The instance data of the CPI object to add the entry 
00266  *        to.
00267  *  @param advertisable The advertisable object, which should be stored in the 
00268  *        given advertservice.
00269  *  @param metadata The meta data to rassociate with the newly created entry.
00270  *  @param path The path inside the advert service, where the newly created 
00271  *        entry is to be stored.
00272  *
00273  *  @return An error code.
00274  */
00275 GATResult 
00276 GATAdvertServiceCPI_Add(GATAdvertServiceCPI cpi, 
00277   GATAdvertServiceCPI_Instance *instance_data, GATObject_const advertisable, 
00278   GATTable_const metadata, GATString_const path)
00279 {
00280   return cpi->add_entry(cpi->data, instance_data, advertisable, metadata, path);
00281 }
00282 
00283 /** GATAdvertServiceCPI_Delete
00284  *  
00285  *  Calls the adaptor to delete an entry from the advert service.
00286  *
00287  *  @param this The CPI object.
00288  *  @param instance_data The instance data of the CPI object to delete the entry
00289  *        from.
00290  *  @param path The path of the entry to delete from the given advert service.
00291  *
00292  *  @return An error code.
00293  */
00294 GATResult 
00295 GATAdvertServiceCPI_Delete(GATAdvertServiceCPI cpi, 
00296   GATAdvertServiceCPI_Instance *instance_data, GATString_const path)
00297 {
00298   return cpi->delete_entry(cpi->data, instance_data, path);
00299 }
00300 
00301 /** GATAdvertServiceCPI_GetMetaData
00302  *  
00303  *  Calls the adaptor to retrieve the meta data of a given entry in the advert 
00304  *  service.
00305  *
00306  *  @param this The CPI object.
00307  *  @param instance_data The instance data of the CPI object to get the meta 
00308  *        data for a certain entry from.
00309  *  @param path The path of the entry, for which the meta data should be 
00310  *        retrieved.
00311  *  @param The pointer to a variable, which receives the requested meta data. 
00312  *
00313  *  @return An error code.
00314  */
00315 GATResult 
00316 GATAdvertServiceCPI_GetMetaData(GATAdvertServiceCPI cpi, 
00317   GATAdvertServiceCPI_Instance const *instance_data, GATString_const path, 
00318   GATTable *metadata)
00319 {
00320   return cpi->get_metadata(cpi->data, instance_data, path, metadata);
00321 }
00322 
00323 /** GATAdvertServiceCPI_GetAdvertisable
00324  *  
00325  *  Calls the adaptor to retrieve the advertisable object stored in a given 
00326  *  entry in the advert service.
00327  *
00328  *  @param this The CPI object.
00329  *  @param instance_data The instance data of the CPI object to get the 
00330  *        advertised object for a certain entry from.
00331  *  @param path The path of the entry, for which the stroed advertisable should 
00332  *        be retrieved.
00333  *  @param advertisable The pointer to a variable, which should receive the 
00334  *        requested advertisable object.
00335  *
00336  *  @return An error code.
00337  */
00338 GATResult 
00339 GATAdvertServiceCPI_GetAdvertisable(GATAdvertServiceCPI cpi, 
00340   GATAdvertServiceCPI_Instance const *instance_data, GATString_const path, 
00341   GATObject *advertisable)
00342 {
00343   return cpi->get_advertisable(cpi->data, instance_data, path, advertisable);
00344 }
00345 
00346 /** GATAdvertServiceCPI_Find
00347  *  
00348  *  Calls the adaptor to find a list of matching entries in the advert service.
00349  *
00350  *  @param this The CPI object.
00351  *  @param instance_data The instance data of the CPI object, where to find the 
00352  *        matching entries.
00353  *  @param metadata The meta data search criteria to use for the query.
00354  *  @param paths The pointer to a variable, which should receive the list of
00355  *        paths pointing to matching entries inside the given advert service.
00356  *
00357  *  @return An error code.
00358  */
00359 GATResult 
00360 GATAdvertServiceCPI_Find(GATAdvertServiceCPI cpi, 
00361   GATAdvertServiceCPI_Instance const *instance_data, GATTable_const metadata,
00362   GATList_String *paths)
00363 {
00364   return cpi->find_entries(cpi->data, instance_data, metadata, paths);
00365 }
00366 
00367 
00368 /* Local functions */
00369 static GATBool 
00370 GATAdvertServiceCPI_IsValidData_V1(GATAdvertServiceCPI_Data *data)
00371 {
00372   return (
00373       NULL != data->get_metrics &&
00374       NULL != data->get_metric_event &&
00375 
00376       NULL != data->destroy &&
00377       
00378       NULL != data->add_entry &&
00379       NULL != data->delete_entry &&
00380       NULL != data->get_metadata &&
00381       NULL != data->get_advertisable &&
00382       NULL != data->find_entries &&
00383 
00384       NULL != data->create_instance && 
00385       NULL != data->destroy_instance &&
00386       NULL != data->clone_instance &&
00387       NULL != data->equals_instance 
00388     ) ? GATTrue : GATFalse;
00389 }
00390 
00391