00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATResourceCPI.c,v 1.9 2004/04/02 12:31:58 hartmutkaiser Exp $";
00018
00019
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022
00023
00024 #include "GATErrors.h"
00025 #include "GATResourceCPI.h"
00026
00027
00028
00029
00030 struct GATResourceCPI_S
00031 {
00032
00033 void *data;
00034 GATResourceCPI_Adaptor_Destroy destroy;
00035 GATResourceCPI_Adaptor_ServiceActions service_actions;
00036
00037
00038 GATResourceCPI_Adaptor_CreateInstance create_instance;
00039 GATResourceCPI_Adaptor_DestroyInstance destroy_instance;
00040 GATResourceCPI_Adaptor_CloneInstance clone_instance;
00041 GATResourceCPI_Adaptor_EqualsInstance equals_instance;
00042
00043
00044 GATResourceCPI_Adaptor_GetResourceDescription get_resource_description;
00045 GATResourceCPI_Adaptor_GetReservation get_reservation;
00046
00047
00048 GATResourceCPI_Adaptor_GetMetrics get_metrics;
00049 GATResourceCPI_Adaptor_GetMetricEvent get_metric_event;
00050
00051
00052 GATResourceCPI_Adaptor_Serialise serialise;
00053 GATResourceCPI_Adaptor_DeSerialise deserialise;
00054 };
00055
00056
00057 static GATBool
00058 GATResourceCPI_IsValidData_V1(GATResourceCPI_Data *data);
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 GATResourceCPI GATResourceCPI_Create(unsigned long int version,
00074 GATResourceCPI_Data *data)
00075 {
00076 GATResourceCPI new_cpi = NULL;
00077
00078 if (version <= GATRESOURCECPI_VERSION)
00079 {
00080 if (version == GATRESOURCECPI_VERSION &&
00081 GATTrue == GATResourceCPI_IsValidData_V1(data))
00082 {
00083 new_cpi = (GATResourceCPI)malloc(sizeof(*new_cpi));
00084 if(NULL != new_cpi)
00085 {
00086 new_cpi->data = data->data;
00087 new_cpi->destroy = data->destroy;
00088 new_cpi->service_actions = data->service_actions;
00089
00090 new_cpi->destroy_instance = data->destroy_instance;
00091 new_cpi->create_instance = data->create_instance;
00092 new_cpi->equals_instance = data->equals_instance;
00093 new_cpi->clone_instance = data->clone_instance;
00094
00095 new_cpi->get_resource_description = data->get_resource_description;
00096 new_cpi->get_reservation = data->get_reservation;
00097
00098 new_cpi->get_metrics = data->get_metrics;
00099 new_cpi->get_metric_event = data->get_metric_event;
00100
00101 new_cpi->serialise = data->serialise;
00102 new_cpi->deserialise = data->deserialise;
00103 }
00104 }
00105
00106
00107
00108
00109
00110
00111
00112 else
00113 {
00114
00115
00116 new_cpi = NULL;
00117 }
00118 }
00119 else
00120 {
00121
00122
00123 new_cpi = NULL;
00124 }
00125 return new_cpi;
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135 void GATResourceCPI_Destroy(GATResourceCPI *object)
00136 {
00137 if(NULL != object && NULL != *object)
00138 {
00139
00140 (*object)->destroy((*object)->data);
00141 free(*object);
00142 *object = NULL;
00143 }
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 GATResult
00158 GATResourceCPI_CreateInstance(GATResourceCPI cpi,
00159 GATResourceCPI_Instance *instance_data, void *initialisation_data)
00160 {
00161 return cpi->create_instance(cpi->data, instance_data, initialisation_data);
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 void
00173 GATResourceCPI_DestroyInstance(GATResourceCPI cpi,
00174 GATResourceCPI_Instance *instance_data)
00175 {
00176 cpi->destroy_instance(cpi->data, instance_data);
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 GATResult
00193 GATResourceCPI_EqualsInstance(GATResourceCPI cpi,
00194 GATResourceCPI_Instance const *lhs, GATResourceCPI_Instance const *rhs,
00195 GATBool *isequal)
00196 {
00197 return cpi->equals_instance(cpi->data, lhs, rhs, isequal);
00198 }
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 GATResult
00212 GATResourceCPI_CloneInstance(GATResourceCPI cpi,
00213 GATResourceCPI_Instance const *instance_data,
00214 GATResourceCPI_Instance *new_instance_data)
00215 {
00216 return cpi->clone_instance(cpi->data, instance_data, new_instance_data);
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 GATResult
00236 GATResourceCPI_GetResourceDescription(GATResourceCPI cpi,
00237 GATResourceCPI_Instance const *instance_data,
00238 GATResourceDescription_const *description)
00239 {
00240 return cpi->get_resource_description(cpi->data, instance_data, description);
00241 }
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 GATResult
00257 GATResourceCPI_GetReservation(GATResourceCPI cpi,
00258 GATResourceCPI_Instance const *instance_data,
00259 GATReservation_const *reservation)
00260 {
00261 return cpi->get_reservation(cpi->data, instance_data, reservation);
00262 }
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 GATResult
00278 GATResourceCPI_GetMetrics(GATResourceCPI cpi, GATResourceCPI_Instance const *data,
00279 GATList_GATMetric *metrics)
00280 {
00281 return cpi->get_metrics(cpi->data, data, metrics);
00282 }
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 GATResult
00299 GATResourceCPI_GetMetricEvent(GATResourceCPI cpi, GATResourceCPI_Instance const *data,
00300 GATMetric metric, GATMetricEvent *event)
00301 {
00302 return cpi->get_metric_event(cpi->data, data, metric, event);
00303 }
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 GATResult
00318 GATResourceCPI_Serialise(GATResourceCPI cpi,
00319 GATResourceCPI_Instance const *data, GATObject stream, GATBool clear_dirty)
00320 {
00321 return cpi->serialise(cpi->data, data, stream, clear_dirty);
00322 }
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 GATResult
00338 GATResourceCPI_DeSerialise(GATResourceCPI cpi,
00339 GATObject stream, GATResourceCPI_Instance *data)
00340 {
00341 return cpi->deserialise(cpi->data, stream, data);
00342 }
00343
00344
00345
00346 static GATBool
00347 GATResourceCPI_IsValidData_V1(GATResourceCPI_Data *data)
00348 {
00349 return (
00350 NULL != data->get_metrics &&
00351 NULL != data->get_metric_event &&
00352
00353
00354 NULL != data->serialise &&
00355 NULL != data->deserialise &&
00356
00357 NULL != data->get_resource_description &&
00358 NULL != data->get_reservation &&
00359
00360 NULL != data->destroy &&
00361 NULL != data->create_instance &&
00362 NULL != data->destroy_instance &&
00363 NULL != data->clone_instance &&
00364 NULL != data->equals_instance
00365 ) ? GATTrue : GATFalse;
00366 }