GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

advertservice.c

Go to the documentation of this file.
00001 /** @file advertservice.c
00002  *  Source file for the GATAdvertServiceCPI provider class for the 
00003  *  request adaptor.
00004  *
00005  *  TODO: Fill in the description of the new CPI provider here
00006  *
00007  *  @date Thu Mar 18 2004
00008  *
00009  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/advertservice_adaptor/advertservice.c,v 1.13 2004/04/26 15:44:59 hartmutkaiser Exp $
00010  *
00011  *  Copyright (C) Hartmut Kaiser
00012  *  This file is part of the GAT Engine.
00013  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00014  *
00015  *  Use, modification and distribution is subject to the Gridlab Software
00016  *  License. (See accompanying file GLlicense.txt or copy at
00017  *  http://www.gridlab.org/GLlicense.txt)
00018  */
00019 
00020 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/advertservice_adaptor/advertservice.c,v 1.13 2004/04/26 15:44:59 hartmutkaiser Exp $";
00021  
00022 /* System Header Files */
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 
00027 /* GAT Header Files */
00028 #include "GATCPI.h"
00029 #include "GATMemoryStream.h"
00030 #include "GATUtil.h"
00031 
00032 #include "advertservice.h"
00033 #include "advertservice_database.h"  
00034 
00035 /* Macros */
00036 
00037 /* Structures, unions and enums */
00038 
00039 /* Instance data */
00040 typedef struct GATAdvertServiceCPIInstance_Data 
00041 {
00042   int dummy; /* no data yet */
00043 } GATAdvertServiceCPIInstance_Data;
00044 
00045 /* Static function prototypes */
00046 static void
00047 advertservice_adaptor_GATAdvertServiceCPI_Destroy(void *data);
00048 
00049 /* Instance data */
00050 static 
00051   GATAdvertServiceCPIInstance_Data *GATAdvertServiceCPIInstance_Data_Create(void);
00052 static void 
00053   GATAdvertServiceCPIInstance_Data_Destroy(GATAdvertServiceCPIInstance_Data **);
00054 static GATResult 
00055   GATAdvertServiceCPIInstance_Data_Clone(GATAdvertServiceCPIInstance_Data const *, 
00056     GATAdvertServiceCPIInstance_Data **);
00057 static GATResult 
00058   GATAdvertServiceCPIInstance_Data_Equals(
00059     GATAdvertServiceCPIInstance_Data const *, 
00060     GATAdvertServiceCPIInstance_Data const *, GATBool *);
00061 
00062 /* instance specific functions */
00063 static GATResult
00064 advertservice_adaptor_GATAdvertServiceCPI_ServiceActions(void *data, 
00065   GATAdvertServiceCPI_Instance *instance_data, GATTimePeriod_const timeout /* = 0 */);
00066   
00067 static GATResult 
00068   advertservice_adaptor_GATAdvertServiceCPI_CreateInstance(
00069     void *data, GATAdvertServiceCPI_Instance *instance_data);
00070 
00071 static void 
00072   advertservice_adaptor_GATAdvertServiceCPI_DestroyInstance(
00073     void *data, GATAdvertServiceCPI_Instance *instance_data);
00074 
00075 static GATResult 
00076   advertservice_adaptor_GATAdvertServiceCPI_CloneInstance(
00077     void *data, GATAdvertServiceCPI_Instance const *instance_data, 
00078     GATAdvertServiceCPI_Instance *new_instance_data);
00079 
00080 static GATResult 
00081   advertservice_adaptor_GATAdvertServiceCPI_EqualsInstance(
00082     void *data, GATAdvertServiceCPI_Instance const *lhs, 
00083     GATAdvertServiceCPI_Instance const *rhs, GATBool *isequal);
00084 
00085 /* CPI API functionality */
00086 static GATResult 
00087   advertservice_adaptor_GATAdvertServiceCPI_Add(
00088     void *, GATAdvertServiceCPI_Instance *, GATObject_const, GATTable_const, 
00089     GATString_const);
00090 
00091 static GATResult 
00092   advertservice_adaptor_GATAdvertServiceCPI_Delete(
00093     void *, GATAdvertServiceCPI_Instance *, GATString_const);
00094 
00095 static GATResult 
00096   advertservice_adaptor_GATAdvertServiceCPI_GetMetaData(
00097     void *, GATAdvertServiceCPI_Instance const *, GATString_const, GATTable *);
00098 
00099 static GATResult 
00100   advertservice_adaptor_GATAdvertServiceCPI_GetAdvertisable(
00101     void *, GATAdvertServiceCPI_Instance const *, GATString_const, GATObject *);
00102 
00103 static GATResult 
00104   advertservice_adaptor_GATAdvertServiceCPI_Find(
00105     void *, GATAdvertServiceCPI_Instance const *, GATTable_const, 
00106     GATList_String *);
00107 
00108 /* Monitoring support */
00109 static GATResult 
00110 advertservice_adaptor_GATAdvertServiceCPI_GetMetrics(void *data, 
00111   GATAdvertServiceCPI_Instance const *instance_data, GATList_GATMetric *metrics);
00112   
00113 static GATResult 
00114 advertservice_adaptor_GATAdvertServiceCPI_GetMetricEvent(void *data, 
00115   GATAdvertServiceCPI_Instance const *instance_data, GATMetric metric, 
00116   GATMetricEvent *event);
00117   
00118 
00119 /* local functions */  
00120 static GATResult
00121 advertservice_adapter_resolve_path(
00122   GATAdvertServiceCPI_Instance const *instance_data, 
00123   GATString_const path, char **absolute);
00124 
00125 /* File scope variables */
00126 
00127 /* External functions */
00128 
00129 /* Register the CPI to implement */
00130 GATResult 
00131 advertservice_adaptor_Register_GATAdvertServiceCPI(
00132   GATContext error_context, GATRegistry registry, 
00133   GATTable_const system_config, GATTable_const instance_config, void *token)
00134 {
00135   GAT_USES_STATUS(error_context, "advertservice_adaptor_Register_GATAdvertServiceCPI");
00136   
00137   GATAdvertServiceCPI cpi = NULL;
00138   GATAdvertServiceCPI_Data cpidata;
00139   
00140   memset(&cpidata, 0, sizeof(GATAdvertServiceCPI_Data));
00141 
00142   /*
00143    *  provide the appropriate callback functions
00144    */
00145   cpidata.data = NULL;
00146   cpidata.destroy = advertservice_adaptor_GATAdvertServiceCPI_Destroy;
00147   
00148   /* instance data handling */
00149   cpidata.service_actions = advertservice_adaptor_GATAdvertServiceCPI_ServiceActions;
00150   cpidata.create_instance = advertservice_adaptor_GATAdvertServiceCPI_CreateInstance;
00151   cpidata.destroy_instance = advertservice_adaptor_GATAdvertServiceCPI_DestroyInstance;
00152   cpidata.clone_instance = advertservice_adaptor_GATAdvertServiceCPI_CloneInstance;
00153   cpidata.equals_instance = advertservice_adaptor_GATAdvertServiceCPI_EqualsInstance;
00154 
00155   /* CPI specific API functions */
00156   cpidata.add_entry = advertservice_adaptor_GATAdvertServiceCPI_Add;
00157   cpidata.delete_entry = advertservice_adaptor_GATAdvertServiceCPI_Delete;
00158   cpidata.get_metadata = advertservice_adaptor_GATAdvertServiceCPI_GetMetaData;
00159   cpidata.get_advertisable = advertservice_adaptor_GATAdvertServiceCPI_GetAdvertisable;
00160   cpidata.find_entries = advertservice_adaptor_GATAdvertServiceCPI_Find;
00161 
00162   /* monitoring support */
00163   cpidata.get_metrics = advertservice_adaptor_GATAdvertServiceCPI_GetMetrics;
00164   cpidata.get_metric_event = advertservice_adaptor_GATAdvertServiceCPI_GetMetricEvent;
00165   
00166   /* Create a GATAdvertServiceCPI object. */
00167   cpi = GATAdvertServiceCPI_Create(GATADVERTSERVICECPI_VERSION, &cpidata);
00168   if (NULL != cpi)
00169   {
00170     /* Need to pass preferences to allow matching
00171      * of a user's preferences with what this adaptor does.
00172      */
00173     GATPreferences preferences = GATPreferences_Create();
00174     if (NULL != preferences)
00175     {
00176       GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Name", 
00177         "advertservice_adaptor"));
00178       GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Security", "none"));
00179       GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Local", "true"));
00180       
00181       GAT_CREATE_STATUS(GATRegistry_AddGATAdvertServiceCPI(registry, cpi, token, 
00182         preferences));
00183       
00184       GATPreferences_Destroy(&preferences);
00185     }
00186     else
00187     {
00188       GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00189     }
00190   }
00191   else
00192   {
00193     GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00194   }
00195   
00196   if (GAT_FAILED(GAT_CURRENT_STATUS()))
00197   {
00198     GATAdvertServiceCPI_Destroy(&cpi);
00199   }
00200 
00201   return GAT_RETURN_STATUS();
00202 }
00203 
00204 /* Local functions */
00205 
00206 static void
00207 advertservice_adaptor_GATAdvertServiceCPI_Destroy(void *data)
00208 {
00209 }
00210 
00211 
00212 /* instance specific functions */
00213 
00214 /** advertservice_adaptor_GATAdvertServiceCPI_ServiceActions
00215  *  
00216  *  The function advertservice_adaptor_GATAdvertServiceCPI_ServiceActions is called, whenever
00217  *  the client calls GATContext_ServiceActions. This function is called for 
00218  *  every created object.
00219  *  This function should be used to update all instance specific data, which 
00220  *  may have been changed asynchronously or to fire pending events.
00221  *
00222  *  @param data Adaptor-provided data object.
00223  *  @param instance_data The instance data of this CPI object
00224  *  @param timeout This may be a 0 timeout to indicate no timeout at all, or
00225  *        a specific time length.
00226  *
00227  *  @return An error code.
00228  */
00229 static GATResult
00230 advertservice_adaptor_GATAdvertServiceCPI_ServiceActions(void *data, 
00231   GATAdvertServiceCPI_Instance *instance_data, GATTimePeriod_const timeout)
00232 {
00233   return GAT_NOTIMPL;
00234 }
00235   
00236 /** advertservice_adaptor_GATAdvertServiceCPI_CreateInstance
00237  *  Create a new CPI object instance.
00238  *  Adaptor implementation of create instance capability.
00239  *
00240  * @param data Adaptor-provided data object.
00241  * @param context The GATContext for this CPI instance
00242  * @param target The location of the file in question.
00243  * @param new_instance_data The pointer to the variable, where the instance 
00244  *      data of this CPI object is to be returned to.
00245  * 
00246  * @return An error code.
00247  */
00248 static GATResult 
00249 advertservice_adaptor_GATAdvertServiceCPI_CreateInstance(void *data, 
00250   GATAdvertServiceCPI_Instance *new_instance_data)
00251 {
00252   if (NULL != new_instance_data)
00253   {
00254     sqlite *db = NULL;
00255     
00256     GAT_USES_STATUS(new_instance_data->context, 
00257       "advertservice_adaptor_GATAdvertServiceCPI_CreateInstance");
00258 
00259     /* create instance data */
00260     new_instance_data->instance_data = 
00261       GATAdvertServiceCPIInstance_Data_Create();
00262 
00263     GAT_CREATE_STATUS_IF(NULL == new_instance_data->instance_data, GAT_MEMORYFAILURE);
00264 
00265     /* try to initialise the database */
00266     
00267     GAT_CREATE_STATUS(advertservice_db_init(new_instance_data->context, &db));
00268     advertservice_db_close(&db);
00269     
00270     return GAT_RETURN_STATUS();
00271   }
00272   return GAT_INVALID_HANDLE;
00273 }
00274 
00275 /** advertservice_adaptor_GATAdvertServiceCPI_DestroyInstance
00276  *  Destroy a CPI object instance.
00277  *  Adaptor implementation of destroy instance capability.
00278  *
00279  * @param data Adaptor-provided data object.
00280  * @param instance_data The instance data of the CPI object to destroy.
00281  */
00282 static void
00283 advertservice_adaptor_GATAdvertServiceCPI_DestroyInstance(void *data, 
00284   GATAdvertServiceCPI_Instance *instance_data)
00285 {
00286   GATAdvertServiceCPIInstance_Data_Destroy(
00287     (GATAdvertServiceCPIInstance_Data **) &instance_data->instance_data);
00288 }
00289 
00290 /** advertservice_adaptor_GATAdvertServiceCPI_CloneInstance
00291  *  Clone a CPI object instance.
00292  *  Adaptor implementation of the clone instance capability.
00293  *
00294  * @param data Adaptor-provided data object.
00295  * @param instance_data The instance data of this CPI object
00296  * @param new_instance_data The pointer to the variable, where the instance 
00297  *      data of the cloned CPI object is to be returned to.
00298  * 
00299  * @return An error code.
00300  */
00301 static GATResult 
00302 advertservice_adaptor_GATAdvertServiceCPI_CloneInstance(
00303   void *data, GATAdvertServiceCPI_Instance const *instance_data, 
00304   GATAdvertServiceCPI_Instance *new_instance_data)
00305 {
00306   if (NULL != instance_data)
00307   {
00308     GAT_USES_STATUS(instance_data->context, 
00309       "advertservice_adaptor_GATAdvertServiceCPI_CloneInstance");
00310     
00311     if (NULL != new_instance_data)
00312     {
00313       GAT_CREATE_STATUS(GATAdvertServiceCPIInstance_Data_Clone(
00314         (GATAdvertServiceCPIInstance_Data const *)instance_data->instance_data, 
00315         (GATAdvertServiceCPIInstance_Data **)&new_instance_data->instance_data));
00316     }
00317     else
00318     {
00319       GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00320     }
00321     return GAT_RETURN_STATUS();
00322   }
00323   return GAT_INVALID_HANDLE;
00324 }
00325 
00326 /** advertservice_adaptor_GATAdvertServiceCPI_EqualsInstance
00327  *  Clone a CPI object instance.
00328  *  Adaptor implementation of the clone instance capability.
00329  *
00330  * @param data Adaptor-provided data object.
00331  * @param lhs The instance data of the left CPI object.
00332  * @param lhs The instance data of the right CPI object.
00333  * @param isequal The pointer to the variable, where the result is to be 
00334  *        returned to.
00335  *
00336  * @return An error code.
00337  */
00338 static GATResult 
00339 advertservice_adaptor_GATAdvertServiceCPI_EqualsInstance(
00340   void *data, GATAdvertServiceCPI_Instance const *lhs, 
00341   GATAdvertServiceCPI_Instance const *rhs, GATBool *isequal)
00342 {
00343   if (NULL != lhs && NULL != rhs)
00344   {
00345     GAT_USES_STATUS(lhs->context, 
00346       "advertservice_adaptor_GATAdvertServiceCPI_EqualsInstance");
00347 
00348     GAT_CREATE_STATUS(GATAdvertServiceCPIInstance_Data_Equals(
00349       (GATAdvertServiceCPIInstance_Data const *) lhs->instance_data, 
00350       (GATAdvertServiceCPIInstance_Data const *) rhs->instance_data, isequal));
00351 
00352     return GAT_RETURN_STATUS();
00353   }
00354   return GAT_INVALID_HANDLE;
00355 }
00356 
00357 
00358 /* CPI API functionality */
00359 
00360 /** advertservice_adaptor_GATAdvertServiceCPI_Add
00361  *  
00362  *  Add a new entry to the advert service.
00363  *
00364  *  @param data The adaptor instance data.
00365  *  @param instance_data The instance data of the CPI object to add the entry 
00366  *        to.
00367  *  @param advertisable The advertisable object, which should be stored in the 
00368  *        given advertservice.
00369  *  @param metadata The meta data to rassociate with the newly created entry.
00370  *  @param path The path inside the advert service, where the newly created 
00371  *        entry is to be stored.
00372  *
00373  *  @return An error code.
00374  */
00375 static GATResult 
00376 advertservice_adaptor_GATAdvertServiceCPI_Add(
00377   void *data, GATAdvertServiceCPI_Instance *instance_data, 
00378   GATObject_const advertisable, GATTable_const metadata, GATString_const path)
00379 {
00380   if (NULL != instance_data)
00381   {
00382     GAT_USES_STATUS(instance_data->context, 
00383       "advertservice_adaptor_GATAdvertServiceCPI_Add");
00384     sqlite *db = NULL;
00385     char *buffer = NULL;
00386     GATuint32 buffer_size = 0;
00387     char *pathstr = NULL;
00388     GATMemoryStream stream = NULL;
00389     
00390     /* create the memory based stream and stream the advertisable into this */
00391     stream = GATMemoryStream_Create(0, 0, GATFalse);
00392     GAT_CREATE_STATUS_IF(NULL == stream, GAT_MEMORYFAILURE);
00393     GAT_CREATE_STATUS(GATSerialisable_Serialise((GATObject)advertisable, 
00394       GATMemoryStream_ToGATObject(stream), GATFalse));
00395 
00396     /* retrieve the streamed data */
00397     buffer = GATMemoryStream_GetBuffer (stream, &buffer_size, GATFalse);
00398     GAT_CREATE_STATUS_IF(NULL == buffer || 0 == buffer_size, GAT_MEMORYFAILURE);
00399     buffer[buffer_size] = '\0';
00400     
00401     /* retrieve the path, where to store the data */
00402     GAT_CREATE_STATUS(advertservice_adapter_resolve_path(instance_data, path, 
00403       &pathstr));
00404 
00405     /* write the serialised data to the database */
00406     GAT_CREATE_STATUS(advertservice_db_init(instance_data->context, &db));
00407     GAT_CREATE_STATUS(advertservice_db_write_advert_data(
00408       instance_data->context, db, pathstr, buffer, metadata));
00409     advertservice_db_close(&db);
00410 
00411     GATMemoryStream_Destroy(&stream);
00412     free(pathstr);
00413     
00414     return GAT_RETURN_STATUS();
00415   }
00416   return GAT_INVALID_HANDLE;
00417 }
00418 
00419 /** advertservice_adaptor_GATAdvertServiceCPI_Delete
00420  *  
00421  *  Delete an entry from the advert service.
00422  *
00423  *  @param data The adaptor instance data.
00424  *  @param instance_data The instance data of the CPI object to delete the entry
00425  *        from.
00426  *  @param path The path of the entry to delete from the given advert service.
00427  *
00428  *  @return An error code.
00429  */
00430 static GATResult 
00431 advertservice_adaptor_GATAdvertServiceCPI_Delete(
00432   void *data, GATAdvertServiceCPI_Instance *instance_data, 
00433   GATString_const path)
00434 {
00435   if (NULL != instance_data)
00436   {
00437     GAT_USES_STATUS(instance_data->context, 
00438       "advertservice_adaptor_GATAdvertServiceCPI_Delete");
00439     sqlite *db = NULL;
00440     char *pathstr = NULL;
00441     
00442     /* retrieve the path, where to store the data */
00443     GAT_CREATE_STATUS(advertservice_adapter_resolve_path(instance_data, path, 
00444       &pathstr));
00445     
00446     /* delete the given data element */
00447     GAT_CREATE_STATUS(advertservice_db_init(instance_data->context, &db));
00448     GAT_CREATE_STATUS(advertservice_db_delete_advert_data(
00449       instance_data->context, db, pathstr));
00450     advertservice_db_close(&db);
00451 
00452     free(pathstr);
00453     return GAT_RETURN_STATUS();
00454   }
00455   return GAT_INVALID_HANDLE;
00456 }
00457 
00458 /** advertservice_adaptor_GATAdvertServiceCPI_GetMetaData
00459  *  
00460  *  Retrieve the meta data of a given entry in the advert service.
00461  *
00462  *  @param data The adaptor instance data.
00463  *  @param instance_data The instance data of the CPI object to get the meta 
00464  *        data for a certain entry from.
00465  *  @param path The path of the entry, for which the meta data should be 
00466  *        retrieved.
00467  *  @param The pointer to a variable, which receives the requested meta data. 
00468  *
00469  *  @return An error code.
00470  */
00471 static GATResult 
00472 advertservice_adaptor_GATAdvertServiceCPI_GetMetaData(
00473   void *data, GATAdvertServiceCPI_Instance const *instance_data, 
00474   GATString_const path, GATTable *metadata)
00475 {
00476   if (NULL != instance_data)
00477   {
00478     GAT_USES_STATUS(instance_data->context, 
00479       "advertservice_adaptor_GATAdvertServiceCPI_GetMetaData");
00480     sqlite *db = NULL;
00481     char *pathstr = NULL;
00482 
00483     /* retrieve the path, where to store the data */
00484     GAT_CREATE_STATUS(advertservice_adapter_resolve_path(instance_data, path, 
00485       &pathstr));
00486 
00487     /* retrieve the metadata associated with the given data element */
00488     GAT_CREATE_STATUS(advertservice_db_init(instance_data->context, &db));
00489     GAT_CREATE_STATUS(advertservice_db_get_metadata(
00490       instance_data->context, db, pathstr, metadata));
00491     advertservice_db_close(&db);
00492     
00493     free(pathstr);
00494     return GAT_RETURN_STATUS();
00495   }
00496   return GAT_INVALID_HANDLE;
00497 }
00498 
00499 /** advertservice_adaptor_GATAdvertServiceCPI_GetAdvertisable
00500  *  
00501  *  Retrieve the advertisable object stored in a given entry in the advert 
00502  *  service.
00503  *
00504  *  @param data The adaptor instance data.
00505  *  @param instance_data The instance data of the CPI object to get the 
00506  *        advertised object for a certain entry from.
00507  *  @param path The path of the entry, for which the stroed advertisable should 
00508  *        be retrieved.
00509  *  @param advertisable The pointer to a variable, which should receive the 
00510  *        requested advertisable object.
00511  *
00512  *  @return An error code.
00513  */
00514 static GATResult 
00515 advertservice_adaptor_GATAdvertServiceCPI_GetAdvertisable(
00516   void *data, GATAdvertServiceCPI_Instance const *instance_data, 
00517   GATString_const path, GATObject *advertisable)
00518 {
00519   if (NULL != instance_data)
00520   {
00521     GAT_USES_STATUS(instance_data->context, 
00522       "advertservice_adaptor_GATAdvertServiceCPI_GetAdvertisable");
00523     sqlite *db = NULL;
00524     char *pathstr = NULL;
00525     char *data = NULL;
00526     GATMemoryStream stream = NULL;
00527     GATObject object = NULL;
00528     GATResult retval = GAT_SUCCESS;
00529     
00530     /* retrieve the path, where to store the data */
00531     GAT_CREATE_STATUS(advertservice_adapter_resolve_path(instance_data, path, 
00532       &pathstr));
00533 
00534     /* retrieve the metadata associated with the given data element */
00535     GAT_CREATE_STATUS(advertservice_db_init(instance_data->context, &db));
00536     GAT_CREATE_STATUS(advertservice_db_get_advert_data(
00537       instance_data->context, db, pathstr, &data));
00538     advertservice_db_close(&db);
00539 
00540     /* recreate the GATObject from the serialised data */
00541     if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00542     {
00543       stream = GATMemoryStream_Create(data, strlen(data), GATTrue);
00544       GAT_CREATE_STATUS_IF(NULL == stream, GAT_MEMORYFAILURE);
00545     }
00546     
00547     /* deserialise the streamed GAT object */
00548     if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00549     {
00550       object = GATSerialisable_DeSerialise(instance_data->context, 
00551         GATMemoryStream_ToGATObject(stream), &retval);
00552       GAT_CREATE_STATUS_UNCOND(retval);
00553     }
00554     GATMemoryStream_Destroy(&stream);
00555     
00556     /* return the new object */
00557     if (NULL != advertisable)
00558     {
00559       *advertisable = object;
00560     }
00561     else
00562     {
00563       GATObject_Destroy(&object);
00564       GAT_CREATE_STATUS_UNCOND(GAT_INVALID_PARAMETER);
00565     }
00566     
00567     free(pathstr);
00568     return GAT_RETURN_STATUS();
00569   }
00570   return GAT_INVALID_HANDLE;
00571 }
00572 
00573 /** advertservice_adaptor_GATAdvertServiceCPI_Find
00574  *  
00575  *  Find a list of matching entries in the advert service.
00576  *
00577  *  @param data The adaptor instance data.
00578  *  @param instance_data The instance data of the CPI object, where to find the 
00579  *        matching entries.
00580  *  @param metadata The meta data search criteria to use for the query.
00581  *  @param paths The pointer to a variable, which should receive the list of
00582  *        paths pointing to matching entries inside the given advert service.
00583  *
00584  *  @return An error code.
00585  */
00586 static GATResult 
00587 advertservice_adaptor_GATAdvertServiceCPI_Find(
00588   void *data, GATAdvertServiceCPI_Instance const *instance_data, 
00589   GATTable_const metadata, GATList_String *paths)
00590 {
00591   if (NULL != instance_data)
00592   {
00593     GAT_USES_STATUS(instance_data->context, 
00594       "advertservice_adaptor_GATAdvertServiceCPI_GetMetaData");
00595     sqlite *db = NULL;
00596 
00597     /* retrieve the metadata associated with the given data element */
00598     GAT_CREATE_STATUS(advertservice_db_init(instance_data->context, &db));
00599     GAT_CREATE_STATUS(advertservice_db_find(
00600       instance_data->context, db, metadata, paths));
00601     advertservice_db_close(&db);
00602     
00603     return GAT_RETURN_STATUS();
00604   }
00605   return GAT_INVALID_HANDLE;
00606 }
00607 
00608 
00609 /* Monitoring support */ 
00610 
00611 /** advertservice_adaptor_GATAdvertServiceCPI_GetMetrics
00612  *
00613  *  The function advertservice_adaptor_GATAdvertServiceCPI_GetMetrics should return a 
00614  *  list of GATMetric objects supported by this adaptor. I.e. the adaptor is 
00615  *  capable to fire GATMetricEvents for the returned metrics. This list should 
00616  *  include all the supported metrics, event like and continuous ones.
00617  *
00618  *  @param data Adaptor-provided data object.
00619  *  @param instance_data Instance data for the CPI provider object.
00620  *  @param metrics The pointer to the variable, which receives the returned 
00621  *        list of metrics.
00622  *
00623  *  @return An error code.
00624  */
00625 static GATResult 
00626 advertservice_adaptor_GATAdvertServiceCPI_GetMetrics(void *data, 
00627   GATAdvertServiceCPI_Instance const *instance_data, GATList_GATMetric *metrics)
00628 {
00629 //  return GATMetric_CreateListOfMetrics(metric_data, __countof(metric_data), 
00630 //    metrics);
00631   return GAT_NOTIMPL;
00632 }
00633 
00634 /** advertservice_adaptor_GATAdvertServiceCPI_GetMetricEvent
00635  *
00636  *  The function advertservice_adaptor_GATAdvertServiceCPI_GetMetricEvent should 
00637  *  return the GATMetricEvent associated with the given continuous metric. This 
00638  *  function gets called for continuous metrics only, since returning the 
00639  *  metric event object to the caller is th only way for the client to get 
00640  *  access to it.
00641  *
00642  *  @param data Adaptor-provided data object.
00643  *  @param instance_data Instance data for the CPI provider object.
00644  *  @param metric The metric instance describing the metric event to return.
00645  *        This metric should be equivalent to one of the metrics returned by
00646  *        our own GetMetrics CPI function (see above). If this is another
00647  *        (not known to us metric), an error should be returned.
00648  *  @param event The pointer to the variable, which receives the metric event 
00649  *        to return.
00650  *
00651  *  @return An error code.
00652  */
00653 static GATResult 
00654 advertservice_adaptor_GATAdvertServiceCPI_GetMetricEvent(void *data, 
00655   GATAdvertServiceCPI_Instance const *instance_data, GATMetric metric, 
00656   GATMetricEvent *event)
00657 {
00658   /* this adaptor supports no continuous metrics */
00659   GATResult retval = GAT_SUCCESS;
00660   return retval;
00661 }
00662 
00663 
00664 /* instance data */
00665 
00666 /** GATAdvertServiceCPIInstance_Data_Create
00667  *
00668  *  The function GATAdvertServiceCPIInstance_Data_Create creates a new 
00669  *  instance of the internal CPI instance data.
00670  *
00671  *  @return The pointer to the newly created and initialised data structure.
00672  */
00673 static GATAdvertServiceCPIInstance_Data *
00674 GATAdvertServiceCPIInstance_Data_Create(void)
00675 {
00676   GATAdvertServiceCPIInstance_Data *retval = 
00677     (GATAdvertServiceCPIInstance_Data *)malloc(
00678       sizeof(struct GATAdvertServiceCPIInstance_Data));
00679 
00680   if (NULL != retval)
00681   {
00682     memset(retval, 0, sizeof(struct GATAdvertServiceCPIInstance_Data));
00683   }
00684   return retval;
00685 }
00686 
00687 /** GATAdvertServiceCPIInstance_Data_Destroy
00688  *
00689  *  The function GATAdvertServiceCPIInstance_Data_Destroy is called to 
00690  *  free all the memory associated with the given instance data item.
00691  *
00692  *  @param instance_data The pointer to a variable holding the old instance 
00693  *        data item, this is set to zero on exit.
00694  */
00695 static void 
00696 GATAdvertServiceCPIInstance_Data_Destroy(
00697   GATAdvertServiceCPIInstance_Data **instance_data)
00698 {
00699   if (NULL != instance_data && NULL != *instance_data)
00700   {
00701     free(*instance_data);
00702     instance_data = NULL;
00703   }
00704 }
00705 
00706 /** GATAdvertServiceCPIInstance_Data_Clone
00707  *
00708  *  The function GATAdvertServiceCPIInstance_Data_Clone is called to make 
00709  *  a copy of the given instance data item.
00710  *
00711  *  @param instance_data The instance data item to copy.
00712  *  @param new_instance_Data The pointer to a variable, which receives the 
00713  *        newly created copy of the instance data item.
00714  *
00715  *  @return An error code.
00716  */
00717 static GATResult 
00718 GATAdvertServiceCPIInstance_Data_Clone(
00719   GATAdvertServiceCPIInstance_Data const *instance_data, 
00720   GATAdvertServiceCPIInstance_Data **new_instance_data)
00721 {
00722   GATResult retval = GAT_INVALID_PARAMETER;
00723   if (NULL != new_instance_data)
00724   {
00725     GATAdvertServiceCPIInstance_Data *new_data = 
00726       (GATAdvertServiceCPIInstance_Data *)malloc(sizeof(struct GATAdvertServiceCPIInstance_Data));
00727 
00728     if (NULL != new_data)
00729     {
00730       *new_instance_data = new_data;
00731       retval = GAT_SUCCESS;
00732     }
00733     else
00734     {
00735       retval = GAT_MEMORYFAILURE;
00736     }
00737   }
00738   return retval;
00739 }
00740 
00741 /** GATAdvertServiceCPIInstance_Data_Equals
00742  *
00743  *  The function GATAdvertServiceCPIInstance_Data_Equals is called, 
00744  *  whenever the engine needs to compare for equality two different instance 
00745  *  data items.
00746  *
00747  *  @param lhs The first instance data item to compare.
00748  *  @param rhs The second instance data item to compare.
00749  *  @param isequal The pointer to a variable, which receives the result of the
00750  *        compare operation.
00751  *
00752  *  @result An error code.
00753  */
00754 static GATResult 
00755 GATAdvertServiceCPIInstance_Data_Equals(
00756   GATAdvertServiceCPIInstance_Data const *lhs, 
00757   GATAdvertServiceCPIInstance_Data const *rhs, GATBool *isequal)
00758 {
00759   *isequal = GATTrue;
00760   return GAT_SUCCESS;
00761 }
00762 
00763 /* Error message handler functions */
00764 /** advertservice_adapter_resolve_path
00765  *  
00766  */
00767 static GATResult
00768 advertservice_adapter_resolve_path(
00769   GATAdvertServiceCPI_Instance const *instance_data, 
00770   GATString_const path, char **absolute_path)
00771 {
00772   char *new_path = NULL;
00773   char const *pwd = GATString_GetBuffer(instance_data->pwd);
00774   char const *pathstr = GATString_GetBuffer(path);
00775   
00776   if (NULL != pwd && NULL != pathstr)
00777   {
00778     int len = strlen(pwd);
00779     if (0 == len)
00780     {
00781       return GAT_INVALID_PARAMETER;
00782     }
00783     
00784     if ('/' != pathstr[0])
00785     {
00786       /* the given path is relative */
00787       GATResult retval = GATUtil_appendstring(&new_path, pwd);
00788       if (GAT_FAILED(retval))
00789       {
00790         return retval;
00791       }
00792       
00793       if ('/' != new_path[len-1])
00794       {
00795         /* make sure the pwd ends with an '/' */
00796         retval = GATUtil_appendstring(&new_path, "/");
00797         if (GAT_FAILED(retval))
00798         {
00799           return retval;
00800         }
00801       }
00802 
00803       /* append the relative part of the path */
00804       retval = GATUtil_appendstring(&new_path, pathstr);
00805       if (GAT_FAILED(retval))
00806       {
00807         return retval;
00808       }
00809     }
00810     else
00811     {
00812       new_path = GATUtil_strdup(pathstr);
00813       if (NULL == new_path)
00814       {
00815         return GAT_MEMORYFAILURE;
00816       }
00817     }
00818   
00819     /* return the complete path */
00820     if (NULL != absolute_path)
00821     {
00822       *absolute_path = new_path;
00823     }
00824     else
00825     {
00826       free(new_path);
00827       return GAT_INVALID_PARAMETER;
00828     }
00829   }
00830   else
00831   {
00832     return GAT_INVALID_PARAMETER;
00833   }
00834   
00835   return GAT_SUCCESS;
00836 }