1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
|
/*
Project: AdunCore
Copyright (C) 200/ Michael Johnston & Jordi Villa-Freixa
Author: Michael Johnston
This application is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This application is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#ifndef _ADFILESYSTEM_SIMULATIONSTORAGE_
#define _ADFILESYSTEM_SIMULATIONSTORAGE_
#include <Foundation/Foundation.h>
#include "AdunKernel/AdFrameworkFunctions.h"
#include "AdunKernel/AdCoreAdditions.h"
#include "AdunKernel/AdunSimulationData.h"
/**
\ingroup coreDataTypes
The available read/write modes for AdFileSystemSimulationStorage objects
The enum values are defined so (mode & AdSimulationStorageAppendMode),
(mode & AdSimulationStorageReadMode) and (mode & AdSimulationStorageWriteMode)
are all true when mode is AdSimulationStorageUpdateMode.
*/
typedef enum
{
AdSimulationStorageWriteMode = 1, /**< Creates a new store for writing */
AdSimulationStorageReadMode = 2, /**< Allows reading of the data stored */
AdSimulationStorageAppendMode = 5, /**< Allows writing to an already existing store */
AdSimulationStorageUpdateMode = 6, /**< Allows reading and writing to a new or already existing store */
}
AdSimulationStorageMode;
/**
\ingroup coreClasses
Class for managing reading/writing of simulation data on the file system.
Modes - see AdSimulationStorageMode
\todo Expand documentation
\todo Implement AdSimulationStorageUpdateMode
With the implementation of on demand read access to the
frames the previous obstacles to implementing this are no
longer present.
*/
@interface AdFileSystemSimulationStorage: NSObject
{
AdSimulationStorageMode storageMode;
BOOL isAccessible;
BOOL isTemporary;
NSFileManager* fileManager;
NSString* storagePath;
NSError* accessError;
NSError* dataError;
NSString* trajectoryPath;
NSString* trajectoryInfoPath;
NSString* energyPath;
NSString* systemPath;
NSFileHandle* energyHandle;
NSFileHandle* trajectoryHandle;
NSUInteger cacheLimit; //Number of frames to be kept in the cache
int numberTrajectoryCheckpoints; //Number of trajectory checkpoints in the store
int numberTopologyCheckpoints; //Number of topology checkpoints in the store
NSMutableArray* dataPerCheckpoint; //Size of each trajectory checkpoint
id trajectoryInfo;
NSMutableArray* trajectoryCache;
NSMutableArray* cacheFrames;
}
/**
Class method for checking if a valid store exists at location
(which is a path to a directory)
*/
+ (BOOL) storageExistsAtLocation: (NSString*) location;
/**
As initStorageForSimulation:inDirectory:mode:error: except
returns an autoreleased object.
*/
+ (id) storageForSimulation: (AdSimulationData*) simulation
inDirectory: (NSString*) directory
mode: (AdSimulationStorageMode) mode
error: (NSError**) error;
/**
As initSimulationStorageAtPath:mode:error: where the containing directory
of \e path is given by \e directory and the simulation directory
by AdSimulationData::identification() appened with "_Data".
If \e directory is nil then the path is relative to the current directory.
*/
- (id) initStorageForSimulation: (AdSimulationData*) simulation
inDirectory: (NSString*) directory
mode: (AdSimulationStorageMode) mode
error: (NSError**) error;
/**
Designated initialiser.
Creates a AdFileSystemSimulationStorage instance for accessing the simulation data
at path. \e mode specfies the mode of access i.e. read, write, read+write. If the
mode is write then the data store is created if it doesnt exist already.
If the stored data cannot be accessed or created upon return anError points
to an NSError object describing the problem.
*/
- (id) initSimulationStorageAtPath: (NSString*) path
mode: (AdSimulationStorageMode) mode
error: (NSError**) anError;
/**
Creates a AdFileSystemSimulationStorage instance that
provides read only access to the simulation data at path \e path which is stored in the file system.
See initSimulationStorageAtPath:mode:error:() for more.
*/
- (id) initForReadingSimulationDataAtPath: (NSString*) path error: (NSError**) anError;
/**
As initForReadingSimulationDataAtPath:error: with \e anError equal to NULL
*/
- (id) initForReadingSimulationDataAtPath: (NSString*) path;
/**
Returns the unique-id associated with the simulation data
Returns nil if no id can be found. Raises an NSInternalInconsistencyException
if the data store is in AdSimulationStorageWriteMode mode.
*/
- (NSString*) identification;
/**
Returns the amount of data in the store in bytes.
*/
- (unsigned long long) sizeOfStore;
/**
Returns the \e number'th trajectory checkpoint
Raises an NSRangeException if no such checkpoint exists.
Raises an NSInternalInconsistencyException if
if the data store is in AdSimulationStorageWriteMode mode.
*/
- (NSData*) trajectoryCheckpoint: (int) number;
/**
Returns the \e number'th topology checkpoint
Returns nil if no such checkpoint exists.
Raises an NSRangeException if no such checkpoint exists.
Raises an NSInternalInconsistencyException if
if the data store is in AdSimulationStorageWriteMode mode.
*/
- (NSData*) topologyCheckpoint: (int) number;
/**
Returns the number of trajectoryCheckpoints in the store
\note This is only partially implemented. In read mode this
returns the total number of checkpoints however in write
mode this only returns the number of frames written.
\todo If we implement caching this method will no longer
work. Have to replace
*/
- (unsigned int) numberTrajectoryCheckpoints;
/**
Returns the number of topologyCheckpoints in the store
*/
- (unsigned int) numberTopologyCheckpoints;
/**
Returns the energy data for the simulation or
nil if there is none
*/
- (NSData*) energyData;
/**
Returns the system data for the simulation or
nil if there is none.
Raises an NSInternalInconsistencyException if
if the data store is in AdSimulationStorageWriteMode mode
or if there is no system data present. Note this would
imply that isAccessible() returns NO and that an accessError()
returns an NSError object.
*/
- (NSData*) systemData;
/**
Returns the frame data for the simulation of
nil if there is none.
Raises an NSInternalInconsistencyException if
if the data store is in AdSimulationStorageWriteMode mode.
*/
- (NSData*) frameData;
/**
Updates the stores state to reflect any changes
since it was initialised. This method mainly checks to
see if any new trajectory frames have been written.
Only useful with a store in AdSimulationStorageReadMode - does
nothing if the store is in AdSimulationStorageWriteMode.
*/
- (void) update;
/**
Returns YES if the data is accesible.
NO otherwise. i.e. if the dataStorage
was removed for some reason.
*/
- (BOOL) isAccessible;
/**
Returns an NSError object describing the reason
why the data store cannot be accessed.
*/
- (NSError*) accessError;
/**
If there is any problem with the data in the data store this method
return an NSError object describing it otherwise it returns nil.
This differs from problems leading to an access error since it deals
mainly with corrupted data.
\todo
Expand docs on access & data errors
\note Currently an data error will only be detected after loadData has
been called. In the future errors will be detected on instantiation.
*/
- (NSError*) dataError;
/**
Returns the path to the location where the
data is stored.
*/
- (NSString*) storagePath;
/**
Deletes the stored data. Immediately sets isAccesible to NO
If the data is not accesible returns NO. If the data cannot be
deleted because it is write protected it will also return NO however in this case
isAccesible will still return YES.
*/
- (BOOL) destroyStoredData;
/**
Sets weather the object should destroy the stored data when
it is released. Value is NO by default.
*/
- (void) setIsTemporary: (BOOL) value;
/**
Returns YES if the object will destroy the stored data when
it is released, NO otherwise.
*/
- (BOOL) isTemporary;
/**
Returns the storage mode.
*/
- (AdSimulationStorageMode) storageMode;
/**
Adds a frame to the stored trajectory.
Raises an NSInternalInconsistencyException exception if the mode is AdSimulationStorageReadMode.
*/
- (void) addTrajectoryCheckpoint: (NSData*) data;
/**
Removes the last \e number frames from the stored trajectory.
Raises an NSInternalInconsistencyException exception if the mode is AdSimulationStorageReadMode.
Raises an NSRangeException if \e number is greater than the
number of available checkpoints.
*/
- (void) removeTrajectoryCheckpoints: (int) number;
/**
Writes \e data to the storage as energy data.
Any previous energy data is overwritten.
Raises an NSInternalInconsistencyException exception if the mode is AdSimulationStorageReadMode.
*/
- (void) setEnergyData: (NSData*) data;
/**
Writes \e data to the storage as frame data.
Any previous frame data is overwritten.
Raises an NSInternalInconsistencyException exception if the mode is AdSimulationStorageReadMode.
*/
- (void) setFrameData: (NSData*) data;
/**
Write \e data to the storage as system data.
Any previous system data is overwritten.
Raises an NSInternalInconsistencyException exception if the mode is AdSimulationStorageReadMode.
*/
- (void) setSystemData: (NSData*) data;
/**
Adds \e data to the stored topology data.
Raises an NSInternalInconsistencyException exception if the mode is AdSimulationStorageReadMode.
*/
- (void) addTopologyCheckpoint: (NSData*) data;
/**
Removes the last \e number frames from the stored topologies.
Raises an NSInternalInconsistencyException exception if the mode is AdSimulationStorageReadMode.
Raises an NSRangeException if \e number is greater than the
number of available checkpoints.
*/
- (void) removeTopologyCheckpoints: (int) number;
/**
Ensures all data is written to the store.
*/
- (void) synchronizeStore;
@end
#endif
|