//
//  DCMAssociation.h
//  OsiriX
//
//  Created by Lance Pysher on 12/3/04.
//  Copyright 2004 Macrad, LLC. All rights reserved.
//

/*************
The networking code of the DCMFramework is predominantly a port of the 11/4/04 version of the java pixelmed toolkit by David Clunie.
htt://www.pixelmed.com   
**************/

#import <Cocoa/Cocoa.h>

@class ONTCPSocket;
@class DCMTransferSyntax;
@class DCMReceivedDataHandler;
@interface DCMAssociation : NSObject {
	int timeout;
	NSString *calledAET;
	NSString *callingAET;
	int port;
	NSString *hostname;
	NSArray *presentationContexts;
	int maximumLengthReceived;
	int receivedBufferSize;
	ONTCPSocket *socket;
	BOOL terminate;
	DCMReceivedDataHandler *dataHandler;
	int debugLevel;
	id _delegate;
	NSTimer *ARTIM;
	NSDate *timeStamp;
	
}

+ (int)defaultMaximumLengthReceived;
+ (int) defaultReceiveBufferSize;
+ (int)defaultSendBufferSize;

/*********
	Parameters needed for initiation are:
	@"hostname"					string
	@"port"						NSNumber int
	@"calledAET"				string
	@"callingAET"				string
	@"presentationContexts"		NSArray of  DCMPresentationContexts
*********/
		
+ (id)associationInitiatorWithParameters:(NSDictionary *)params;

/*********
	Parameters needed for acceptance are:
	@"socket"					ONTCPSocket
	@"calledAET"				string
**********/

+ (id)associationResponderWithParameters:(NSDictionary *)params;
+ (id)listenerOnPort:(int)port;
- (id)initResponderWithParameters:(NSDictionary *)params;
- (id)initInitiatorWithParameters:(NSDictionary *)params;
- (void)terminate:(id)sender;
- (void)releaseAssociation;
- (void)abort;
- (void)sendPresentationContextID:(unsigned char)contextID  command:(NSData *)command  data:(NSData *)data;
- (void)waitForARTIMBeforeTransportConnectionClose;
- (void)waitForPDataPDUs:(NSDictionary *)params;
- (void)waitForOnePDataPDU;
- (void)waitForCommandPDataPDUs;
- (void)waitForDataPDataPDUs;
- (void)waitForPDataPDUsUntilHandlerReportsDone;

- (unsigned char)presentationContextIDForAbstractSyntax:(NSString *)abstractSytaxUID;
- (unsigned char)presentationContextIDForAbstractSyntax:(NSString *)abstractSytaxUID transferSyntax:(DCMTransferSyntax *)transferSyntax;
- (DCMTransferSyntax *)transferSyntaxForPresentationContextID:(unsigned char)contextID;

- (NSString *)callingAET;
- (NSString *)calledAET;

- (void)send:(NSData *)data;
- (void)send:(NSData *)data  asCommand:(BOOL)isCommand  presentationContext:(unsigned char)contextID;
- (void)setReceivedDataHandler:(DCMReceivedDataHandler *)handler;

- (void)startARTIM:(NSObject *)object;
- (void)invalidateARTIM:(NSObject *)object;
- (void)timeoutOver:(NSTimer *)timer;

- (NSData *)readData;


- (void)setDelegate: (id)delegate;
- (id)delegate;

//To delegate
- (void)associationAborted;
- (void)associationReleased;


- (ONTCPSocket *)socket;
- (BOOL)isConnected;




@end
