00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/src/GATPipeCPI.c,v 1.6 2004/04/02 12:31:58 hartmutkaiser Exp $";
00022
00023
00024
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027
00028
00029
00030 #include "GATPipeCPI.h"
00031
00032
00033
00034
00035
00036 struct GATPipeCPI_S
00037 {
00038
00039 void *data;
00040 GATPipeCPI_Adaptor_Destroy destroy;
00041 GATPipeCPI_Adaptor_ServiceActions service_actions;
00042
00043
00044 GATPipeCPI_Adaptor_CreateInstance create_instance;
00045 GATPipeCPI_Adaptor_DestroyInstance destroy_instance;
00046 GATPipeCPI_Adaptor_CloneInstance clone_instance;
00047 GATPipeCPI_Adaptor_EqualsInstance equals_instance;
00048
00049
00050 GATPipeCPI_Adaptor_Read read;
00051 GATPipeCPI_Adaptor_Write write;
00052 GATPipeCPI_Adaptor_Seek seek;
00053 GATPipeCPI_Adaptor_Close close;
00054
00055
00056 GATPipeCPI_Adaptor_GetMetrics get_metrics;
00057 GATPipeCPI_Adaptor_GetMetricEvent get_metric_event;
00058 };
00059
00060
00061 static int GATPipeCPI_IsValidData_V1(GATPipeCPI_Data *data);
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 GATPipeCPI GATPipeCPI_Create(unsigned long int version, GATPipeCPI_Data *data)
00077 {
00078 GATPipeCPI new_cpi = NULL;
00079
00080 if (version <= GATPIPECPI_VERSION)
00081 {
00082 if (version == GATPIPECPI_VERSION && GATPipeCPI_IsValidData_V1(data))
00083 {
00084 new_cpi = (GATPipeCPI)malloc(sizeof(struct GATPipeCPI_S));
00085 if(NULL != new_cpi)
00086 {
00087 new_cpi->data = data->data;
00088 new_cpi->destroy = data->destroy;
00089 new_cpi->service_actions = data->service_actions;
00090
00091 new_cpi->destroy_instance = data->destroy_instance;
00092 new_cpi->create_instance = data->create_instance;
00093 new_cpi->equals_instance = data->equals_instance;
00094 new_cpi->clone_instance = data->clone_instance;
00095
00096 new_cpi->read = data->read;
00097 new_cpi->write = data->write;
00098 new_cpi->seek = data->seek;
00099 new_cpi->close = data->close;
00100
00101 new_cpi->get_metrics = data->get_metrics;
00102 new_cpi->get_metric_event = data->get_metric_event;
00103 }
00104 }
00105
00106
00107
00108
00109
00110
00111 else
00112 {
00113
00114
00115 }
00116 }
00117 else
00118 {
00119
00120
00121 }
00122 return new_cpi;
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132 void GATPipeCPI_Destroy(GATPipeCPI *cpi)
00133 {
00134 if(NULL != cpi && NULL != *cpi)
00135 {
00136 (*cpi)->destroy((*cpi)->data);
00137 free(*cpi);
00138 *cpi = NULL;
00139 }
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 GATResult
00153 GATPipeCPI_CreateInstance(GATPipeCPI cpi, GATPipeCPI_Instance *data, void *information)
00154 {
00155 return cpi->create_instance(cpi->data, data, information);
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 void
00167 GATPipeCPI_DestroyInstance(GATPipeCPI cpi, GATPipeCPI_Instance *data)
00168 {
00169 cpi->destroy_instance(cpi->data, data);
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 GATResult
00186 GATPipeCPI_EqualsInstance(GATPipeCPI cpi, GATPipeCPI_Instance const *lhs,
00187 GATPipeCPI_Instance const *rhs, GATBool *isequal)
00188 {
00189 return cpi->equals_instance(cpi->data, lhs, rhs, isequal);
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 GATResult
00204 GATPipeCPI_CloneInstance(GATPipeCPI cpi,
00205 GATPipeCPI_Instance const *data, GATPipeCPI_Instance *new_data)
00206 {
00207 return cpi->clone_instance(cpi->data, data, new_data);
00208 }
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 GATResult GATPipeCPI_Read(GATPipeCPI cpi, GATPipeCPI_Instance const *data, void *buffer, GATuint32 size, GATuint32 *read_bytes)
00224 {
00225 return cpi->read(cpi->data, data, buffer, size, read_bytes);
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 GATResult GATPipeCPI_Write(GATPipeCPI cpi, GATPipeCPI_Instance const *data, void const *buffer, GATuint32 size, GATuint32 *written_bytes)
00242 {
00243 return cpi->write(cpi->data, data, buffer, size, written_bytes);
00244 }
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 GATResult GATPipeCPI_Seek(GATPipeCPI cpi, GATPipeCPI_Instance const *data, GATOrigin origin, GATint32 offset, GATuint32 *new_position)
00260 {
00261 return cpi->seek(cpi->data, data, origin, offset, new_position);
00262 }
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 GATResult GATPipeCPI_Close(GATPipeCPI cpi, GATPipeCPI_Instance const *data)
00275 {
00276 return cpi->close(cpi->data, data);
00277 }
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 GATResult
00292 GATPipeCPI_GetMetrics(GATPipeCPI cpi, GATPipeCPI_Instance const *data,
00293 GATList_GATMetric *metrics)
00294 {
00295 return cpi->get_metrics(cpi->data, data, metrics);
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 GATResult
00313 GATPipeCPI_GetMetricEvent(GATPipeCPI cpi, GATPipeCPI_Instance const *data,
00314 GATMetric metric, GATMetricEvent *event)
00315 {
00316 return cpi->get_metric_event(cpi->data, data, metric, event);
00317 }
00318
00319
00320 static int
00321 GATPipeCPI_IsValidData_V1(GATPipeCPI_Data *data)
00322 {
00323 return (
00324 NULL != data->destroy &&
00325
00326
00327 NULL != data->destroy_instance &&
00328 NULL != data->create_instance &&
00329 NULL != data->clone_instance &&
00330 NULL != data->equals_instance &&
00331
00332 NULL != data->read &&
00333 NULL != data->write &&
00334 NULL != data->seek &&
00335 NULL != data->close &&
00336
00337 NULL != data->get_metrics &&
00338 NULL != data->get_metric_event
00339 ) ? 1 : 0;
00340 }