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/src/GATJob.c,v 1.24 2004/05/12 18:56:00 hartmutkaiser Exp $";
00021
00022
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <assert.h>
00026
00027
00028 #include "GAT.h"
00029 #include "GATInternal.h"
00030 #include "GATRegistry.h"
00031 #include "GATJobCPI.h"
00032 #include "GATXdsWrapper.h"
00033 #include "GATMetricEvent.h"
00034
00035
00036 GATOBJECT_DEFINE_VTABLE(GATJob);
00037 GATSERIALISABLE_DEFINE_VTABLE(GATJob);
00038 GATMONITORABLE_DEFINE_VTABLE(GATJob);
00039
00040
00041 GATOBJECT_DEFINE_CONVERTERS(GATJob)
00042
00043
00044
00045
00046 struct GATJob_S {
00047
00048 GATJob_vtable *GATObject__vtable;
00049 GATJob_ISerialisable_vtable *GATSerialisable__vtable;
00050 GATJob_IMonitorable_vtable *GATMonitorable__vtable;
00051
00052
00053 GATJobID gatjobid;
00054
00055 GATJobCPI_Instance data;
00056 GATJobCPI cpi;
00057 GATJobCPIList cpilist;
00058 };
00059
00060
00061 static GATResult
00062 GATJob_DeSerialise_Create(GATContext context, GATObject stream, GATJobID jobid,
00063 GATJobState state, GATJob *new_object);
00064
00065 static GATResult
00066 GATJob_GetCPIInstanceData(GATJob job, void **data);
00067
00068
00069
00070 GATJob_vtable GATJob__vtable = {
00071 GATJob_GetType,
00072 GATJob_Destroy,
00073 GATJob_Equals,
00074 GATJob_Clone,
00075 GATJob_GetInterface,
00076 GATJob_GetCPIInstanceData
00077 };
00078
00079 static GATJob_ISerialisable_vtable
00080 GATJob_ISerialisable__vtable =
00081 {
00082 GATJob_Serialise,
00083 GATJob_DeSerialise,
00084 GATJob_GetIsDirty,
00085 };
00086
00087 static GATJob_IMonitorable_vtable
00088 GATJob_IMonitorable__vtable =
00089 {
00090 GATJob_AddMetricListener,
00091 GATJob_RegisterPolling,
00092 GATJob_RemoveRegisteredMetric,
00093 GATJob_GetMetrics
00094 };
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 GATResult GATJob_Register_GATSerialisable(void)
00105 {
00106 return GATObject_Register_GATSerialisable(GATType_GATJob,
00107 &GATJob_ISerialisable__vtable);
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 GATJob
00131 GATJob_Create(GATContext context, GATPreferences_const preferences, GATJobID jobid,
00132 void *initialisation_data)
00133 {
00134 GAT_STATUS_APIENTRY(context, "GATJob_Create");
00135
00136 GATJob retval = (GATJob) malloc(sizeof(struct GATJob_S));
00137 if (NULL != retval)
00138 {
00139 memset(retval, 0, sizeof(struct GATJob_S));
00140 retval->GATObject__vtable = &GATJob__vtable;
00141 retval->GATSerialisable__vtable = &GATJob_ISerialisable__vtable;
00142 retval->GATMonitorable__vtable = &GATJob_IMonitorable__vtable;
00143
00144 retval->gatjobid = NULL;
00145 retval->data.context = context;
00146 retval->data.isdirty = GATFalse;
00147 retval->data.source = GATJob_ToGATObject_const(retval);
00148 retval->data.state = GATJobState_Initial;
00149
00150 GAT_CREATE_STATUS(GATString_Clone(jobid, &retval->data.jobid));
00151
00152
00153 if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00154 {
00155 GATRegistry_const registry = GATContext_internal_GetRegistry(context);
00156
00157
00158 if (NULL == preferences)
00159 {
00160 preferences = GATContext_GetPreferences(context);
00161 }
00162 retval->cpilist = GATRegistry_FindGATJobCPI(registry, preferences);
00163
00164 if (NULL == retval->cpilist)
00165 {
00166 GAT_CREATE_STATUS(GAT_NO_REGISTERED_CPI);
00167 }
00168 else
00169 {
00170
00171 GATBool found_cpi = GATFalse;
00172 GATJobCPIList current = NULL;
00173 for(current = retval->cpilist; NULL != current; current = current->next)
00174 {
00175 GAT_CREATE_STATUS(GATJobCPI_CreateInstance(current->cpi,
00176 &retval->data, initialisation_data));
00177
00178 if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00179 {
00180 retval->cpi = current->cpi;
00181 found_cpi = GATTrue;
00182 break;
00183 }
00184 }
00185
00186
00187 if (GATFalse == found_cpi)
00188 {
00189 GAT_CREATE_STATUS(GAT_NO_REGISTERED_CPI);
00190 }
00191 else
00192 {
00193
00194
00195 GATList_GATMetric metrics = NULL;
00196 GATResult err_code = GATJobCPI_GetMetrics(retval->cpi,
00197 &retval->data, &metrics);
00198
00199 if (GAT_SUCCEEDED(err_code))
00200 {
00201 retval->data.monitorable = GATMonitorable_Impl_Create(metrics);
00202 if (NULL == retval->data.monitorable)
00203 {
00204 GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00205 }
00206 GATList_GATMetric_Destroy(&metrics);
00207 }
00208 else if (GAT_NOTIMPL == err_code)
00209 {
00210 err_code = GAT_SUCCESS;
00211 }
00212 else
00213 {
00214 GAT_CREATE_STATUS(err_code);
00215 }
00216
00217
00218 if (GAT_SUCCEEDED(err_code))
00219 {
00220 GAT_CREATE_STATUS(GATRegistry_AddGATJobToCPIList(context, retval->cpi,
00221 retval));
00222 }
00223 }
00224 }
00225 }
00226 }
00227 else
00228 {
00229 GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00230 }
00231
00232
00233 if (GAT_FAILED(GAT_CURRENT_STATUS()))
00234 {
00235 GATJob_Destroy(&retval);
00236 }
00237
00238 GAT_STORE_STATUS();
00239 return retval;
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249 void
00250 GATJob_Destroy(GATJob *object)
00251 {
00252 if (NULL != object && NULL != *object)
00253 {
00254 GATString_Destroy(&(*object)->gatjobid);
00255 GATString_Destroy(&(*object)->data.jobid);
00256 GATMonitorable_Impl_Destroy(&(*object)->data.monitorable);
00257 if (NULL != (*object)->cpi)
00258 {
00259 GATRegistry_RemoveGATJobFromCPIList((*object)->data.context,
00260 (*object)->cpi, *object);
00261 GATJobCPI_DestroyInstance((*object)->cpi, &(*object)->data);
00262 }
00263 GATJobCPIList_Destroy((*object)->cpilist);
00264 free(*object);
00265 *object = NULL;
00266 }
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 GATResult
00283 GATJob_Equals(GATJob_const lhs, GATJob_const rhs, GATBool *isequal)
00284 {
00285 if (NULL != lhs && NULL != rhs)
00286 {
00287 GAT_STATUS_APIENTRY(lhs->data.context, "GATJob_Equals");
00288 if (NULL != isequal)
00289 {
00290 if (lhs->data.state != rhs->data.state)
00291 {
00292 *isequal = GATFalse;
00293 }
00294 else
00295 {
00296 GAT_CREATE_STATUS(GATJobCPI_EqualsInstance(lhs->cpi, &lhs->data,
00297 &rhs->data, isequal));
00298 }
00299 }
00300 return GAT_RETURN_STATUS();
00301 }
00302 return GAT_INVALID_HANDLE;
00303 }
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 GATResult
00318 GATJob_Clone(GATJob_const handle, GATJob *new_handle)
00319 {
00320 if (NULL != handle)
00321 {
00322 GAT_STATUS_APIENTRY(handle->data.context, "GATJob_Clone");
00323
00324 if (NULL == new_handle)
00325 {
00326 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00327 }
00328 else
00329 {
00330 struct GATJob_S const *object = handle;
00331 GATJob new_object = (GATJob) malloc(sizeof(struct GATJob_S));
00332
00333 *new_handle = NULL;
00334 if (NULL == new_object)
00335 {
00336 GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00337 }
00338 else
00339 {
00340 memset(new_object, 0, sizeof(struct GATJob_S));
00341 new_object->GATObject__vtable = &GATJob__vtable;
00342 new_object->GATSerialisable__vtable = &GATJob_ISerialisable__vtable;
00343 new_object->GATMonitorable__vtable = &GATJob_IMonitorable__vtable;
00344
00345 new_object->data.context = object->data.context;
00346 new_object->data.isdirty = GATFalse;
00347 new_object->data.source = GATJob_ToGATObject_const(new_object);
00348 new_object->data.state = object->data.state;
00349 new_object->cpilist = GATRegistry_CloneGATJobCPIList(object->cpilist);
00350
00351 if (NULL == new_object->cpilist)
00352 {
00353 GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00354 }
00355 GAT_CREATE_STATUS(GATString_Clone(object->data.jobid,
00356 &new_object->data.jobid));
00357
00358 if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00359 {
00360
00361 GATJobCPIList current = object->cpilist;
00362 GATJobCPIList new_current = new_object->cpilist;
00363
00364 for (; NULL != current;
00365 current = current->next, new_current = new_current->next)
00366 {
00367 if (current->cpi == object->cpi)
00368 {
00369 new_object->cpi = new_current->cpi;
00370 break;
00371 }
00372 }
00373 assert(NULL != new_object->cpi);
00374
00375
00376 GAT_CREATE_STATUS(GATJobCPI_CloneInstance(object->cpi, &object->data,
00377 &new_object->data));
00378
00379
00380 if (NULL != object->data.monitorable)
00381 {
00382 GAT_CREATE_STATUS(GATMonitorable_Impl_Clone(object->data.monitorable,
00383 &new_object->data.monitorable));
00384 }
00385
00386
00387 GAT_CREATE_STATUS(GATRegistry_AddGATJobToCPIList(
00388 new_object->data.context, new_object->cpi, new_object));
00389 }
00390 }
00391
00392
00393 if (GAT_FAILED(GAT_CURRENT_STATUS()))
00394 {
00395 GATJob_Destroy(&new_object);
00396 }
00397 else
00398 {
00399
00400 *new_handle = new_object;
00401 }
00402 }
00403
00404 return GAT_RETURN_STATUS();
00405 }
00406 return GAT_INVALID_HANDLE;
00407 }
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419 GATType
00420 GATJob_GetType(GATJob_const object)
00421 {
00422 GAT_UNUSED_PARAMETER(object);
00423 return GATType_GATJob;
00424 }
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 GATResult
00439 GATJob_GetInterface(GATJob_const object, GATInterface iftype,
00440 void const **ifp)
00441 {
00442 if (NULL != object)
00443 {
00444 GAT_STATUS_APIENTRY(object->data.context, "GATJob_GetInterface");
00445
00446 if (NULL != ifp)
00447 {
00448 if (GATInterface_ISerialisable == iftype ||
00449 GATInterface_IAdvertisable == iftype)
00450 {
00451 *ifp = (void const *) &object->GATSerialisable__vtable;
00452 }
00453 else if (GATInterface_IMonitorable == iftype && NULL != object->data.monitorable)
00454 {
00455 *ifp = (void const *) &object->GATMonitorable__vtable;
00456 }
00457 else
00458 {
00459 *ifp = NULL;
00460 GAT_CREATE_STATUS(GAT_NO_INTERFACE);
00461 }
00462 }
00463
00464 return GAT_RETURN_STATUS();
00465 }
00466 return GAT_INVALID_HANDLE;
00467 }
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491 GATResult
00492 GATJob_AddMetricListener(GATJob object,
00493 GATMetricListener listener, void *listener_data, GATMetric metric,
00494 GATuint32 *cookie)
00495 {
00496 if (NULL != object)
00497 {
00498 GAT_STATUS_APIENTRY(object->data.context, "GATJob_AddMetricListener");
00499
00500 if (NULL != object->data.monitorable)
00501 {
00502 GAT_CREATE_STATUS(GATMonitorable_Impl_AddMetricListener(object->data.monitorable,
00503 listener, listener_data, metric, cookie));
00504 }
00505 else
00506 {
00507
00508 GAT_CREATE_STATUS(GAT_NO_INTERFACE);
00509 }
00510
00511 return GAT_RETURN_STATUS();
00512 }
00513 return GAT_INVALID_HANDLE;
00514 }
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533 GATResult
00534 GATJob_RegisterPolling(GATJob object, GATMetric metric,
00535 GATMetricEvent *event, GATuint32 *cookie)
00536 {
00537 if (NULL != object)
00538 {
00539 GAT_STATUS_APIENTRY(object->data.context, "GATJob_RegisterPolling");
00540
00541 if (NULL != object->data.monitorable)
00542 {
00543 GAT_CREATE_STATUS(GATMonitorable_Impl_RegisterPolling(
00544 object->data.monitorable, metric, 0, cookie));
00545
00546
00547 GAT_CREATE_STATUS(GATJobCPI_GetMetricEvent(object->cpi, &object->data,
00548 metric, event));
00549
00550 if (GAT_FAILED(GAT_CURRENT_STATUS()) && NULL != cookie && 0 != *cookie)
00551 {
00552 GATMonitorable_Impl_RemoveRegisteredMetric(object->data.monitorable,
00553 metric, *cookie);
00554 *cookie = 0;
00555 }
00556 }
00557 else
00558 {
00559
00560 GAT_CREATE_STATUS(GAT_NO_INTERFACE);
00561 }
00562
00563 return GAT_RETURN_STATUS();
00564 }
00565 return GAT_INVALID_HANDLE;
00566 }
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584 GATResult
00585 GATJob_RemoveRegisteredMetric(GATJob object,
00586 GATMetric metric, GATuint32 cookie)
00587 {
00588 if (NULL != object)
00589 {
00590 GAT_STATUS_APIENTRY(object->data.context, "GATJob_RemoveRegisteredMetric");
00591
00592 if (NULL != object->data.monitorable)
00593 {
00594 GAT_CREATE_STATUS(GATMonitorable_Impl_RemoveRegisteredMetric(
00595 object->data.monitorable, metric, cookie));
00596 }
00597 else
00598 {
00599
00600 GAT_CREATE_STATUS(GAT_NO_INTERFACE);
00601 }
00602
00603 return GAT_RETURN_STATUS();
00604 }
00605 return GAT_INVALID_HANDLE;
00606 }
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620 GATResult
00621 GATJob_GetMetrics(GATJob_const object, GATList_GATMetric *metrics)
00622 {
00623 if (NULL != object)
00624 {
00625 GAT_STATUS_APIENTRY(object->data.context, "GATJob_GetMetrics");
00626
00627 if (NULL != object->data.monitorable)
00628 {
00629 GAT_CREATE_STATUS(GATMonitorable_Impl_GetMetrics(object->data.monitorable,
00630 metrics));
00631 }
00632 else
00633 {
00634
00635 GAT_CREATE_STATUS(GAT_NO_INTERFACE);
00636 }
00637
00638 return GAT_RETURN_STATUS();
00639 }
00640 return GAT_INVALID_HANDLE;
00641 }
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664 static GATResult
00665 GATJobCPI_SerialiseCallback(GATObject handle, GATObject stream,
00666 GATBool clear_dirty)
00667 {
00668 GATJob object = GATObject_ToGATJob(handle);
00669 if (NULL != object)
00670 {
00671 GAT_USES_STATUS(object->data.context, "GATJobCPI_SerialiseCallback");
00672
00673 GAT_CREATE_STATUS(GATJobCPI_Serialise(object->cpi, &object->data, stream,
00674 clear_dirty));
00675
00676 if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()) && GATTrue == clear_dirty)
00677 {
00678 object->data.isdirty = GATFalse;
00679 }
00680
00681 return GAT_RETURN_STATUS();
00682 }
00683 return GAT_INVALID_HANDLE;
00684 }
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699 GATResult
00700 GATJob_Serialise(GATJob object, GATObject stream, GATBool clear_dirty)
00701 {
00702 if (NULL != object)
00703 {
00704 GAT_USES_STATUS(object->data.context, "GATJob_Serialise");
00705
00706 GAT_CREATE_STATUS(GATXds_SerialiseObject(GATJob_ToGATObject(object), stream,
00707 clear_dirty, GATJobCPI_SerialiseCallback, "uint32 uint32 string",
00708 GATJOB_VERSION1, (GATuint32) object->data.state, object->data.jobid));
00709
00710 return GAT_RETURN_STATUS();
00711 }
00712 return GAT_INVALID_HANDLE;
00713 }
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729 static GATBool
00730 GATJob_VersionCallback(GATuint32 version)
00731 {
00732 GATBool retval = GATFalse;
00733 if ((version & ~GATJOB_MINOR_MASK) <= GATJOB_LASTVERSION)
00734 {
00735 retval = GATTrue;
00736 }
00737 return retval;
00738 }
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763 static GATResult
00764 GATJob_DeSerialiseCallback(GATContext context, GATObject stream,
00765 GATObject *new_object, GATuint32 version, va_list args)
00766 {
00767 GAT_USES_STATUS(context, "GATJob_DeSerialiseCallback");
00768
00769
00770 GATuint32 *state = va_arg(args, GATuint32 *);
00771 GATJobID *jobid = va_arg(args, GATJobID *);
00772 GATJob object = NULL;
00773
00774
00775 GAT_CREATE_STATUS(GATJob_DeSerialise_Create(context, stream, *jobid,
00776 (GATJobState)*state, &object));
00777
00778 GAT_UNUSED_PARAMETER(version);
00779 if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00780 {
00781 if (NULL != object)
00782 {
00783 *new_object = GATJob_ToGATObject(object);
00784 }
00785 else
00786 {
00787 GATJob_Destroy(&object);
00788 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00789 }
00790 }
00791
00792 return GAT_RETURN_STATUS();
00793 }
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809 GATJob
00810 GATJob_DeSerialise(GATContext context, GATObject stream, GATResult *result)
00811 {
00812 GAT_USES_STATUS(context, "GATJob_DeSerialise");
00813
00814 GATObject object = NULL;
00815 GATJob job = NULL;
00816
00817
00818
00819 GATuint32 version = 0;
00820 GATJobID jobid = NULL;
00821 GATuint32 state = GATJobState_Unknown;
00822
00823
00824 GAT_CREATE_STATUS(GATXds_DeSerialiseObject(context, stream,
00825 GATJob_DeSerialiseCallback, GATJob_VersionCallback, &object,
00826 "uint32 uint32 string", &version, &state, &jobid));
00827
00828 GATString_Destroy(&jobid);
00829
00830 job = GATObject_ToGATJob(object);
00831 if (NULL == job)
00832 {
00833 GAT_CREATE_STATUS(GAT_BAD_OBJECT_CONVERSION);
00834 }
00835
00836 if (GAT_FAILED(GAT_CURRENT_STATUS()))
00837 {
00838 GATObject_Destroy(&object);
00839 job = NULL;
00840 }
00841
00842 if (NULL != result)
00843 {
00844 *result = GAT_CURRENT_STATUS();
00845 }
00846
00847 GAT_STORE_STATUS();
00848 return job;
00849 }
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861 GATResult GATJob_GetIsDirty(GATJob_const object, GATBool *isdirty)
00862 {
00863 if (NULL != object)
00864 {
00865 GAT_STATUS_APIENTRY(object->data.context, "GATJob_GetIsDirty");
00866
00867 if (NULL != isdirty)
00868 {
00869 *isdirty = object->data.isdirty;
00870 }
00871 else
00872 {
00873 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00874 }
00875
00876 return GAT_RETURN_STATUS();
00877 }
00878 return GAT_INVALID_PARAMETER;
00879 }
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901 static GATResult
00902 GATJob_DeSerialise_Create(GATContext context, GATObject stream, GATJobID jobid,
00903 GATJobState state, GATJob *object)
00904 {
00905 GAT_USES_STATUS(context, "GATJob_DeSerialise_Create");
00906
00907 GATJob new_object = (GATJob) malloc(sizeof(struct GATJob_S));
00908
00909 if(NULL != new_object)
00910 {
00911 memset(new_object, 0, sizeof(struct GATJob_S));
00912 new_object->GATObject__vtable = &GATJob__vtable;
00913 new_object->GATSerialisable__vtable = &GATJob_ISerialisable__vtable;
00914 new_object->GATMonitorable__vtable = &GATJob_IMonitorable__vtable;
00915
00916 new_object->data.context = context;
00917 new_object->data.isdirty = GATFalse;
00918 new_object->data.source = GATJob_ToGATObject_const(new_object);
00919 new_object->data.state = state;
00920
00921 GAT_CREATE_STATUS(GATString_Clone(jobid, &new_object->data.jobid));
00922
00923
00924
00925 if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00926 {
00927 GATRegistry_const registry = GATContext_internal_GetRegistry(context);
00928 GATPreferences_const preferences = NULL;
00929
00930
00931 if (NULL == preferences)
00932 {
00933 preferences = GATContext_GetPreferences(context);
00934 }
00935
00936 new_object->cpilist = GATRegistry_FindGATJobCPI(registry, preferences);
00937 if (NULL == new_object->cpilist)
00938 {
00939 GAT_CREATE_STATUS(GAT_NO_REGISTERED_CPI);
00940 }
00941 else
00942 {
00943
00944 GATuint32 offset = 0;
00945 GATBool found_cpi = GATFalse;
00946 GATJobCPIList current = NULL;
00947
00948 GAT_CREATE_STATUS(GATStreamable_Seek(stream, GATOrigin_Current, 0,
00949 &offset));
00950 if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00951 {
00952
00953 for(current = new_object->cpilist; NULL != current; current = current->next)
00954 {
00955
00956 GAT_CREATE_STATUS(GATJobCPI_DeSerialise(current->cpi, stream,
00957 &new_object->data));
00958 if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00959 {
00960 new_object->cpi = current->cpi;
00961 found_cpi = GATTrue;
00962 break;
00963 }
00964
00965
00966 GAT_CREATE_STATUS(GATStreamable_Seek(stream, GATOrigin_Set, offset, 0));
00967 }
00968 }
00969
00970
00971 if (GATFalse == found_cpi)
00972 {
00973 GAT_CREATE_STATUS(GAT_NO_MATCHING_CPI);
00974 }
00975 else
00976 {
00977
00978
00979 GATList_GATMetric metrics = NULL;
00980
00981 GATResult retval = GATJobCPI_GetMetrics(new_object->cpi, &new_object->data,
00982 &metrics);
00983 if (GAT_SUCCEEDED(retval))
00984 {
00985 new_object->data.monitorable = GATMonitorable_Impl_Create(metrics);
00986 if (NULL != new_object->data.monitorable)
00987 {
00988 GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00989 }
00990 GATList_GATMetric_Destroy(&metrics);
00991 }
00992 else if (GAT_NOTIMPL != retval)
00993 {
00994 GAT_CREATE_STATUS(retval);
00995 }
00996 else
00997 {
00998 retval = GAT_SUCCESS;
00999 }
01000
01001 if (GAT_SUCCEEDED(retval))
01002 {
01003 GAT_CREATE_STATUS(GATRegistry_AddGATJobToCPIList(new_object->data.context,
01004 new_object->cpi, new_object));
01005 }
01006 }
01007 }
01008 }
01009 }
01010 else
01011 {
01012 GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
01013 }
01014
01015 if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
01016 {
01017 if (NULL != new_object)
01018 {
01019 *object = new_object;
01020 }
01021 else
01022 {
01023 GATJob_Destroy(&new_object);
01024 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
01025 }
01026 }
01027 else
01028 {
01029 GATJob_Destroy(&new_object);
01030 }
01031
01032 return GAT_RETURN_STATUS();
01033 }
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045 GATResult GATJob_UnSchedule(GATJob_const object)
01046 {
01047 if (NULL != object)
01048 {
01049 GAT_STATUS_APIENTRY(object->data.context, "GATJob_UnSchedule");
01050 GAT_CREATE_STATUS(GATJobCPI_UnSchedule(object->cpi, &object->data));
01051 return GAT_RETURN_STATUS();
01052 }
01053 return GAT_INVALID_HANDLE;
01054 }
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070 GATResult GATJob_Checkpoint(GATJob_const object)
01071 {
01072 if (NULL != object)
01073 {
01074 GAT_STATUS_APIENTRY(object->data.context, "GATJob_Checkpoint");
01075 GAT_CREATE_STATUS(GATJobCPI_Checkpoint(object->cpi, &object->data));
01076 return GAT_RETURN_STATUS();
01077 }
01078 return GAT_INVALID_HANDLE;
01079 }
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096 GATResult GATJob_CloneJob(GATJob_const object, GATHardwareResource_const hr,
01097 GATJob *cloned_job)
01098 {
01099 if (NULL != object)
01100 {
01101 GAT_STATUS_APIENTRY(object->data.context, "GATJob_CloneJob");
01102 GAT_CREATE_STATUS(GATJobCPI_CloneJob(object->cpi, &object->data, hr,
01103 cloned_job));
01104 return GAT_RETURN_STATUS();
01105 }
01106 return GAT_INVALID_HANDLE;
01107 }
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125 GATResult GATJob_Migrate(GATJob_const object, GATHardwareResource_const hr,
01126 GATJob *migrated_job)
01127 {
01128 if (NULL != object)
01129 {
01130 GAT_STATUS_APIENTRY(object->data.context, "GATJob_Migrate");
01131 GAT_CREATE_STATUS(GATJobCPI_Migrate(object->cpi, &object->data, hr,
01132 migrated_job));
01133 return GAT_RETURN_STATUS();
01134 }
01135 return GAT_INVALID_HANDLE;
01136 }
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149 GATResult GATJob_Stop(GATJob object)
01150 {
01151 if (NULL != object)
01152 {
01153 GAT_STATUS_APIENTRY(object->data.context, "GATJob_Stop");
01154 GAT_CREATE_STATUS(GATJobCPI_Stop(object->cpi, &object->data));
01155 return GAT_RETURN_STATUS();
01156 }
01157 return GAT_INVALID_HANDLE;
01158 }
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172 GATResult GATJob_GetJobDescription(GATJob_const object,
01173 GATJobDescription_const *jd)
01174 {
01175 if (NULL != object)
01176 {
01177 GAT_STATUS_APIENTRY(object->data.context, "GATJob_GetJobDescription");
01178 GAT_CREATE_STATUS(GATJobCPI_GetJobDescription(object->cpi, &object->data,
01179 jd));
01180 return GAT_RETURN_STATUS();
01181 }
01182 return GAT_INVALID_HANDLE;
01183 }
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198 GATResult GATJob_GetState(GATJob_const object, GATJobState *state)
01199 {
01200 if (NULL != object)
01201 {
01202 GAT_STATUS_APIENTRY(object->data.context, "GATJob_GetState");
01203
01204 if (NULL != state)
01205 {
01206 *state = object->data.state;
01207 }
01208 else
01209 {
01210 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
01211 }
01212
01213 return GAT_RETURN_STATUS();
01214 }
01215 return GAT_INVALID_HANDLE;
01216 }
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231 GATResult GATJob_GetInfo(GATJob_const object, GATTable_const *jobinfo)
01232 {
01233 if (NULL != object)
01234 {
01235 GAT_STATUS_APIENTRY(object->data.context, "GATJob_GetInfo");
01236 GAT_CREATE_STATUS(GATJobCPI_GetInfo(object->cpi, &object->data, jobinfo));
01237 return GAT_RETURN_STATUS();
01238 }
01239 return GAT_INVALID_HANDLE;
01240 }
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255 GATResult
01256 GATJob_GetJobID(GATJob_const object, GATJobID_const *jobid)
01257 {
01258 if (NULL != object)
01259 {
01260 GAT_STATUS_APIENTRY(object->data.context, "GATJob_GetJobID");
01261
01262 if (NULL != jobid)
01263 {
01264 *jobid = object->gatjobid;
01265 }
01266 else
01267 {
01268 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
01269 }
01270
01271 return GAT_RETURN_STATUS();
01272 }
01273 return GAT_INVALID_HANDLE;
01274 }
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288 GATResult
01289 GATJob_GetNativeID(GATJob_const object, GATJobID_const *jobid)
01290 {
01291 if (NULL != object)
01292 {
01293 GAT_STATUS_APIENTRY(object->data.context, "GATJob_GetNativeID");
01294
01295 if (NULL != jobid)
01296 {
01297 *jobid = object->data.jobid;
01298 }
01299 else
01300 {
01301 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
01302 }
01303
01304 return GAT_RETURN_STATUS();
01305 }
01306 return GAT_INVALID_HANDLE;
01307 }
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321 GATResult GATJob_GetStatus(GATJob_const object, GATStatus_const *jobstatus)
01322 {
01323 if (NULL != object)
01324 {
01325 GAT_STATUS_APIENTRY(object->data.context, "GATJob_GetStatus");
01326 GAT_CREATE_STATUS(GATJobCPI_GetStatus(object->cpi, &object->data,
01327 jobstatus));
01328 return GAT_RETURN_STATUS();
01329 }
01330 return GAT_INVALID_HANDLE;
01331 }
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344 static GATResult
01345 GATJob_GetCPIInstanceData(GATJob job, void **data)
01346 {
01347 if (NULL != job)
01348 {
01349 GAT_USES_STATUS(job->data.context, "GATJob_GetCPIInstanceData");
01350
01351 if (NULL != data)
01352 {
01353 *data = (void *)&job->data;
01354 }
01355 else
01356 {
01357 GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
01358 }
01359
01360 return GAT_RETURN_STATUS();
01361 }
01362 return GAT_INVALID_HANDLE;
01363 }
01364
01365
01366
01367
01368
01369
01370
01371
01372 GATResult
01373 GATJob_internal_SetGATJobId(GATJob job, GATString_const gatjobid)
01374 {
01375 if (NULL != job)
01376 {
01377 GAT_USES_STATUS(job->data.context, "GATJob_internal_SetGATJobId");
01378
01379 if (NULL != job->gatjobid)
01380 {
01381 GATString_Destroy(&job->gatjobid);
01382 }
01383 GAT_CREATE_STATUS(GATString_Clone(gatjobid, &job->gatjobid));
01384
01385 return GAT_RETURN_STATUS();
01386 }
01387 return GAT_INVALID_HANDLE;
01388 }