Adun  0.83
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions | Static Public Member Functions
AdIOManager Class Reference

#import <AdunIOManager.h>

List of all members.

Public Member Functions

(BOOL) - processCommandLine:
(AdCoreRunMode- runMode
(BOOL) - restartRequested
(void) - saveResults:
(void) - setSimulationReferences:
(void) - setCore:
(NSMutableArray *) - pluginsPaths
(NSString *) - simulationOutputDirectory
(NSString *) - controllerOutputDirectory
(NSString *) - controllerDirectory
(NSString *) - adunDirectory
(NSDictionary *) - template
(NSDictionary *) - externalObjects
(FILE *) - openFile:usingName:flag:
(FILE *) - getStreamForName:
(void) - closeStreamWithName:
(void) - closeAllStreams
(BOOL) - checkProgramDirectories:
(BOOL) - createSimulationOutputDirectory:
(BOOL) - createControllerOutputDirectory:
(BOOL) - createLogFiles:
(BOOL) - moveLogFilesTo:error:
(BOOL) - connectToServer:
(BOOL) - isConnected
(void) - acceptRequests
(void) - sendControllerResults:
(void) - closeConnection:
(BOOL) - loadData:

Static Public Member Functions

(id) + appIOManager

Detailed Description

AdIOManager manages input and output from the simulation application.

Main Attributes

AdIOManager is a singleton - only one instance exists for each application. This instance can be accessed using the appIOManager (AdIOManager) method.

Note:
Many of AdIOManagers methods are documented in separate categories - use List of all members to see a complete list.
Todo:
See if the differences that arise from the run mode e.g. server, command, can be factored to a delegate class.

Member Function Documentation

- (void) acceptRequests

Causes the AdIOManager instance to indicate to the server that it is ready to process requests. Has no effect if a connection was not created using connectToServer: or the connection attempt failed.

- (NSString *) adunDirectory

Returns the program working directory

+ (id) appIOManager

Returns the applications AdIOManager instance.

- (BOOL) checkProgramDirectories: (NSError **)  error

Checks that the adun/ directory exists and has the correct structure. Uses the value given by the NSUserDefaults key ProgramDirectory for the directory location If it doesnt exist it is created in this location. If the structure of the directory is incorrect i.e. there are missing directories, they structure is corrected. If the program directories can be corrected of fixed this method returns NO and error contains an NSError object that describes the problem.

- (void) closeAllStreams

Closes all the stream created using openFile:usingName:flag:.

- (void) closeConnection: (NSError *)  error

Closes the connection to the local AdServer instance. Has no effect if a connection does not exist.

Parameters:
errorIf the connection is being closed for a reason other than normal termination then this should be an NSError object describing the cause. Otherwise pass nil.
- (void) closeStreamWithName: (NSString*)  name

Closes the stream previously created using openFile:usingName:flag:. name is the name given to the stream when it was created. If no stream called name exists this method does nothing.

- (BOOL) connectToServer: (NSError **)  error

Attempts to connect to the AdServer on the localhost. This allows the server to send commands to the simulation application via the AdCommandInterface protocol.

Parameters:
errorIf an error occurs, upon return contains an NSError object that describes the problem.
Returns:
YES if a connection was made, NO otherwise.
- (NSString *) controllerDirectory

Returns the directory where controller plugins are located.

- (NSString *) controllerOutputDirectory

Returns the directory to which the controller should write its output.

- (BOOL) createControllerOutputDirectory: (NSError **)  error

Creates the controller output directory

- (BOOL) createLogFiles: (NSError **)  error

Creates the program and error log files. Uses the values given by NSUserDefaults keys LogFile and ErrorFile for the file locations. Returns YES on succesful creation. If the log files could not be created returns NO and error contains an NSError object that describes the problem.

- (BOOL) createSimulationOutputDirectory: (NSError **)  error

Creates the simulation output directory

- (NSDictionary*) externalObjects

Returns any external objects retrieved from the server or nil if there are none.

- (FILE *) getStreamForName: (NSString*)  name

Returns the stream associated with name. The stream must have been previously created using openFile:usingName:flag:. If no stream called name exists this method return NULL.

Parameters:
nameThe name associated with the stream when it was created.
Returns:
A pointer to the stream
- (BOOL) isConnected

Returns YES if the receiver is connected to an AdServer instance. NO otherwise.

- (BOOL) loadData: (NSError **)  error

Retrieves and processes the program data as specified by the program arguements. Returns YES if the required data was loaded successfully. Returns NO otherwise. If NO is returned error is set with an NSError object explaining the reason the data could not loaded. If processCommandLine: has not been called this method calls it.

The log files are copied to the simulation output directory if the RedirectOutput default is YES.

- (BOOL) moveLogFilesTo: (NSString *)  dataDirectory
error: (NSError **)  error 

Moves the log files (stdout and stderr) to dataDirectory. This method is used to move the log files to the simulation data directory (if RedirectOutput default is YES) and should not usually be called externally.

- (FILE *) openFile: (NSString*)  file
usingName: (NSString*)  name
flag: (NSString*)  fileFlag 

Creates a stream to file. The mode of the stream is detemined by fileFlag. If file is nil or the stream cannot be created this method return NULL. fileFlag also determines if the file should be created if it does not exist.

Parameters:
fileThe path to the file.
nameThe name to be associated with this stream. For use with getStreamForName() and closeStreamWithName().
flagInidicates this mode for the stream. Value are the same as for the libc function fopen().
Returns:
A pointer to the stream
- (NSMutableArray*) pluginsPaths

Returns paths where controllers may be located

- (BOOL) processCommandLine: (NSError**)  error

Checks that the format of the command line arguements is valid, that all the arguement keys are valid and that required arguement are present. On detecting a problem returns NO and error contains an NSError object detailing the problem encountered.

Note:
This method does not check if that the supplied argument values are valid. This is done by loadData: createOutputDirectories:() and other methods.
- (BOOL) restartRequested

Returns YES if a simulation continuation was requested via the command line arguments. NO otherwise.

- (AdCoreRunMode) runMode

Returns the runMode of the core. AdCoreServerRunMode, AdCoreCommandLineRunMode.

- (void) saveResults: (NSArray*)  anArray

Saves the entries in array to the controller output directory. Each entry must be an AdDataSet instance. If not an NSInvalidArgumentException is raised.

- (void) sendControllerResults: (NSArray *)  anArray

Sends the data sets in array anArray to the server. If the program is not connected to a server this method does nothing.

- (void) setCore: (id)  core

Sets a reference to the AdCore instance of the simulator.

- (void) setSimulationReferences: (NSDictionary*)  inputObjects

Adds references to the objects in inputObjects to the simulation data instance. This method also adds the simulation template to the AdSimulationData objects metadata and sends the simulation data to the server if the receiver is connected to one.

- (NSString *) simulationOutputDirectory

Returns the name of the directory to which simulation output is written.

- (NSDictionary *) template

Returns the template for the simulation or nil if none has been loaded.