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