00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/resourcebroker/resource.c,v 1.11 2004/04/27 11:34:50 hartmutkaiser Exp $";
00021
00022
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026
00027
00028 #include "GATCPI.h"
00029
00030 #include "GATResourceCPIInstanceData.h"
00031
00032
00033
00034
00035
00036
00037 static void
00038 resourcebroker_adaptor_GATResourceCPI_Destroy(void *data);
00039
00040
00041 static GATResult
00042 resourcebroker_adaptor_GATResourceCPI_ServiceActions(void *data,
00043 GATResourceCPI_Instance *instance_data, GATTimePeriod_const timeout);
00044
00045 static GATResult
00046 resourcebroker_adaptor_GATResourceCPI_CreateInstance(
00047 void *data, GATResourceCPI_Instance *instance_data,
00048 void *initialisation_data);
00049
00050 static void
00051 resourcebroker_adaptor_GATResourceCPI_DestroyInstance(
00052 void *data, GATResourceCPI_Instance *instance_data);
00053
00054 static GATResult
00055 resourcebroker_adaptor_GATResourceCPI_CloneInstance(
00056 void *data, GATResourceCPI_Instance const *instance_data,
00057 GATResourceCPI_Instance *new_instance_data);
00058
00059 static GATResult
00060 resourcebroker_adaptor_GATResourceCPI_EqualsInstance(
00061 void *data, GATResourceCPI_Instance const *lhs,
00062 GATResourceCPI_Instance const *rhs, GATBool *isequal);
00063
00064
00065 static GATResult
00066 resourcebroker_adaptor_GATResourceCPI_GetMetrics(
00067 void *data, GATResourceCPI_Instance const *instance_data,
00068 GATList_GATMetric *metrics);
00069 static GATResult
00070 resourcebroker_adaptor_GATResourceCPI_GetMetricEvent(
00071 void *data, GATResourceCPI_Instance const *instance_data,
00072 GATMetric metric, GATMetricEvent *event);
00073
00074
00075 static GATResult
00076 resourcebroker_adaptor_GATResourceCPI_Serialise(
00077 void *data, GATResourceCPI_Instance const *instance_data,
00078 GATObject stream, GATBool clear_dirty);
00079 static GATResult
00080 resourcebroker_adaptor_GATResourceCPI_DeSerialise(
00081 void *data, GATObject stream,
00082 GATResourceCPI_Instance *instance_data);
00083
00084
00085 static GATResult
00086 resourcebroker_adaptor_GATResourceCPI_GetResourceDescription(
00087 void *data, GATResourceCPI_Instance const *instance_data,
00088 GATResourceDescription_const *description);
00089 static GATResult
00090 resourcebroker_adaptor_GATResourceCPI_GetReservation(
00091 void *data, GATResourceCPI_Instance const *instance_data,
00092 GATReservation_const *reservation);
00093
00094
00095
00096
00097
00098
00099 GATResult resourcebroker_adaptor_Register_GATResourceCPI(
00100 GATContext error_context, GATRegistry registry,
00101 GATTable_const system_config, GATTable_const instance_config, void *token)
00102 {
00103 GAT_USES_STATUS(error_context, "resourcebroker_adaptor_Register_GATResourceCPI");
00104
00105 GATResourceCPI cpi = NULL;
00106 GATResourceCPI_Data cpidata;
00107
00108 {
00109 memset(&cpidata, 0, sizeof(GATResourceCPI_Data));
00110
00111
00112
00113
00114 cpidata.data = NULL;
00115 cpidata.destroy = resourcebroker_adaptor_GATResourceCPI_Destroy;
00116
00117
00118 cpidata.service_actions = resourcebroker_adaptor_GATResourceCPI_ServiceActions;
00119 cpidata.create_instance = resourcebroker_adaptor_GATResourceCPI_CreateInstance;
00120 cpidata.destroy_instance = resourcebroker_adaptor_GATResourceCPI_DestroyInstance;
00121 cpidata.clone_instance = resourcebroker_adaptor_GATResourceCPI_CloneInstance;
00122 cpidata.equals_instance = resourcebroker_adaptor_GATResourceCPI_EqualsInstance;
00123
00124
00125 cpidata.get_metrics = resourcebroker_adaptor_GATResourceCPI_GetMetrics;
00126 cpidata.get_metric_event = resourcebroker_adaptor_GATResourceCPI_GetMetricEvent;
00127
00128
00129 cpidata.serialise = resourcebroker_adaptor_GATResourceCPI_Serialise;
00130 cpidata.deserialise = resourcebroker_adaptor_GATResourceCPI_DeSerialise;
00131
00132
00133 cpidata.get_resource_description = resourcebroker_adaptor_GATResourceCPI_GetResourceDescription;
00134 cpidata.get_reservation = resourcebroker_adaptor_GATResourceCPI_GetReservation;
00135
00136
00137 cpi = GATResourceCPI_Create(GATRESOURCECPI_VERSION, &cpidata);
00138 if(NULL != cpi)
00139 {
00140
00141
00142
00143 GATPreferences preferences = GATPreferences_Create();
00144 if(NULL != preferences)
00145 {
00146 GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Name",
00147 "resourcebroker_adaptor"));
00148 GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Security", "none"));
00149 GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Local", "true"));
00150
00151 GAT_CREATE_STATUS(GATRegistry_AddGATResourceCPI(registry, cpi, token,
00152 preferences));
00153
00154 GATPreferences_Destroy(&preferences);
00155 }
00156 else
00157 {
00158 GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00159 }
00160 }
00161 else
00162 {
00163 GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00164 }
00165 }
00166
00167 if (GAT_FAILED(GAT_CURRENT_STATUS()))
00168 {
00169 GATResourceCPI_Destroy(&cpi);
00170 }
00171
00172 return GAT_RETURN_STATUS();
00173 }
00174
00175
00176
00177 static void
00178 resourcebroker_adaptor_GATResourceCPI_Destroy(void *data)
00179 {
00180
00181 assert(NULL == data);
00182 }
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 static GATResult
00203 resourcebroker_adaptor_GATResourceCPI_ServiceActions(void *data,
00204 GATResourceCPI_Instance *instance_data, GATTimePeriod_const timeout)
00205 {
00206 return GAT_NOTIMPL;
00207 }
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 static GATResult
00222 resourcebroker_adaptor_GATResourceCPI_CreateInstance(void *data,
00223 GATResourceCPI_Instance *new_instance_data, void *initialisation_data)
00224 {
00225 if (NULL != new_instance_data)
00226 {
00227 GAT_USES_STATUS(new_instance_data->context,
00228 "resourcebroker_adaptor_GATResourceCPI_CreateInstance");
00229
00230 GAT_CREATE_STATUS(GATResourceCPIInstance_Data_Clone(
00231 (GATResourceCPIInstance_Data *) initialisation_data,
00232 (GATResourceCPIInstance_Data **) &new_instance_data->instance_data));
00233
00234 return GAT_RETURN_STATUS();
00235 }
00236 return GAT_INVALID_HANDLE;
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246 static void
00247 resourcebroker_adaptor_GATResourceCPI_DestroyInstance(void *data,
00248 GATResourceCPI_Instance *instance_data)
00249 {
00250 if (NULL != instance_data)
00251 {
00252 GATResourceCPIInstance_Data_Destroy(
00253 (GATResourceCPIInstance_Data **)&instance_data->instance_data);
00254 }
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 static GATResult
00269 resourcebroker_adaptor_GATResourceCPI_CloneInstance(
00270 void *data, GATResourceCPI_Instance const *instance_data,
00271 GATResourceCPI_Instance *new_instance_data)
00272 {
00273 if (NULL != instance_data)
00274 {
00275 GAT_USES_STATUS(instance_data->context,
00276 "resourcebroker_adaptor_GATResourceCPI_CloneInstance");
00277
00278 if (NULL != instance_data && NULL != new_instance_data)
00279 {
00280 GAT_CREATE_STATUS(GATResourceCPIInstance_Data_Clone(
00281 (GATResourceCPIInstance_Data const *) instance_data->instance_data,
00282 (GATResourceCPIInstance_Data **) &new_instance_data->instance_data));
00283 }
00284 else
00285 {
00286 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00287 }
00288 return GAT_RETURN_STATUS();
00289 }
00290 return GAT_INVALID_HANDLE;
00291 }
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 static GATResult
00306 resourcebroker_adaptor_GATResourceCPI_EqualsInstance(
00307 void *data, GATResourceCPI_Instance const *lhs,
00308 GATResourceCPI_Instance const *rhs, GATBool *isequal)
00309 {
00310 if (NULL != lhs)
00311 {
00312 GAT_USES_STATUS(lhs->context,
00313 "resourcebroker_adaptor_GATResourceCPI_CloneInstance");
00314
00315 if (NULL != rhs)
00316 {
00317 GAT_CREATE_STATUS(GATResourceCPIInstance_Data_Equals(
00318 (GATResourceCPIInstance_Data const *) lhs->instance_data,
00319 (GATResourceCPIInstance_Data *) rhs->instance_data, isequal));
00320 }
00321 else
00322 {
00323 GAT_CREATE_STATUS(GAT_INVALID_HANDLE);
00324 }
00325
00326 return GAT_RETURN_STATUS();
00327 }
00328 return GAT_INVALID_HANDLE;
00329 }
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348 static GATResult
00349 resourcebroker_adaptor_GATResourceCPI_GetMetrics(void *data,
00350 GATResourceCPI_Instance const *instance_data, GATList_GATMetric *metrics)
00351 {
00352
00353 GATResult retval = GAT_NOTIMPL;
00354 return retval;
00355 }
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376 static GATResult
00377 resourcebroker_adaptor_GATResourceCPI_GetMetricEvent(void *data,
00378 GATResourceCPI_Instance const *instance_data, GATMetric metric,
00379 GATMetricEvent *event)
00380 {
00381 GATResult retval = GAT_NOTIMPL;
00382 return retval;
00383 }
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402 static GATResult
00403 resourcebroker_adaptor_GATResourceCPI_Serialise(void *data,
00404 GATResourceCPI_Instance const *instance_data, GATObject stream,
00405 GATBool clear_dirty)
00406 {
00407 if (NULL != instance_data)
00408 {
00409 GAT_USES_STATUS(instance_data->context,
00410 "resourcebroker_adaptor_GATResourceCPI_Serialise");
00411
00412 GAT_CREATE_STATUS(GATResourceCPIInstance_Data_Serialize(
00413 (GATResourceCPIInstance_Data const *)instance_data->instance_data, stream,
00414 clear_dirty));
00415
00416 return GAT_RETURN_STATUS();
00417 }
00418 return GAT_INVALID_HANDLE;
00419 }
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435 static GATResult
00436 resourcebroker_adaptor_GATResourceCPI_DeSerialise(void *data,
00437 GATObject stream, GATResourceCPI_Instance *instance_data)
00438 {
00439 if (NULL != instance_data)
00440 {
00441 GAT_USES_STATUS(instance_data->context,
00442 "resourcebroker_adaptor_GATResourceCPI_DeSerialise");
00443
00444 GAT_CREATE_STATUS(GATResourceCPIInstance_Data_DeSerialize(
00445 instance_data->context, stream,
00446 (GATResourceCPIInstance_Data **)&instance_data->instance_data));
00447
00448 return GAT_RETURN_STATUS();
00449 }
00450 return GAT_INVALID_HANDLE;
00451 }
00452
00453
00454
00455
00456
00457
00458
00459
00460 static GATResult
00461 resourcebroker_adaptor_GATResourceCPI_GetResourceDescription(
00462 void *data, GATResourceCPI_Instance const *instance_data,
00463 GATResourceDescription_const *description)
00464 {
00465 if (NULL != instance_data)
00466 {
00467 GAT_USES_STATUS(instance_data->context,
00468 "resourcebroker_adaptor_GATResourceCPI_GetResourceDescription");
00469
00470 GAT_CREATE_STATUS(GATResourceCPIInstance_Data_GetResourceDescription(
00471 (GATResourceCPIInstance_Data const *)instance_data->instance_data,
00472 description));
00473
00474 return GAT_RETURN_STATUS();
00475 }
00476 return GAT_INVALID_HANDLE;
00477 }
00478
00479 static GATResult
00480 resourcebroker_adaptor_GATResourceCPI_GetReservation(
00481 void *data, GATResourceCPI_Instance const *instance_data,
00482 GATReservation_const *reservation)
00483 {
00484 GATResult retval = GAT_NOTIMPL;
00485 return retval;
00486 }
00487