//
//  Device.h
//  Device Explorer
//
//  Created by otusweb on Fri May 10 2002.
//  Copyright (c) 2002 Texas Instruments Incorporated. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "DeviceFolder.h"

/*"Key for the dictionary that is returned when asking for the information on a device"*/
extern NSString *TIDeviceInfoBatteryState;
extern NSString *TIDeviceInfoProductID;
extern NSString *TIDeviceInfoBaseVersion;
extern NSString *TIDeviceInfoBootVersion;
extern NSString *TIDeviceInfoBatteryStateString;
extern NSString *TIDeviceInfoHardwareVersion;
extern NSString *TIDeviceInfoLanguagePrimary;
extern NSString *TIDeviceInfoLanguageSub;
extern NSString *TIDeviceInfoProductIDString;

/*"Key for clock information dictionary"*/
extern NSString *TIClockDate;
extern NSString *TIClock1224Type;
extern NSString *TIClockOnOff;
extern NSString *TIClockDateFormat;
// :sreid:20050321 
extern NSString *TIClockDateFormatStrings;

/*"Key for status dictionary"*/
extern NSString *TIDeviceStatusOperationEventType;
extern NSString *TIDeviceStatusTotalTransfered;
extern NSString *TIDeviceStatusTotal;
extern NSString *TIDeviceStatusTransfered;
extern NSString *TIDeviceStatusSize;
extern NSString *TIDeviceStatusClassOfTransferedItem;
extern NSString *TIDeviceStatusNameOfTransferedFile;

/*"Result key"*/
extern NSString *target;

/*"properties"*/
extern NSString *TIDeviceScreenshotProperty;
extern NSString *TIDeviceGreenishScreenshotProperty;
extern NSString *TIDeviceClockProperty;
extern NSString *TIDeviceUserLoginNameProperty;
extern NSString *TIDeviceLoginStatusProperty;
extern NSString *TIDeviceIoStatusProperty;
extern NSString *TIDeviceDefaultFolderNameProperty;
extern NSString *TIDeviceObjectClass;
extern NSString *TIDeviceNativeNameProperty;
extern NSString *TIDeviceDisplayNameProperty;
extern NSString *TIDeviceIDListValueProperty;
extern NSString *TIDeviceModelProperty;
extern NSString *TIDeviceIdentityProperty;
extern NSString *TIDeviceFamilyProperty;
extern NSString *TIDeviceDirectoryProperty;
extern NSString *TIDeviceBatteryProperty;
extern NSString *TIDeviceCableNameProperty;
extern NSString *TIDeviceFeaturesProperty;
extern NSString *TIDeviceDeviceUserNameProperty;
extern NSString *TIDeviceDirectoryFilterProperty;
extern NSString *TIDeviceStoreModelNameProperty;
extern NSString *TIDeviceCertificateMemoryProperty;
extern NSString *TIDeviceProductInformationProperty;
extern NSString *TIDeviceProductConnectionProperty;

/*"connnection types"*/
extern NSString *TIDeviceConnectionUSBCable;
extern NSString *TIDeviceConnectionDirectUSB;
extern NSString *TIDeviceConnectionNavigator;

/*"special file type"*/
extern NSString *TIScreenshotFileType;
extern NSString *TIColorScreenshotFileType;
extern NSString *TIColorImageFileType;
extern NSString *TIColorPictureFileType;
extern NSString *TIClockFileType;
extern NSString *TIProductFileType;
extern NSString *TIProductIDlist;

/*"features"*/
extern NSString *TIProductIsOnHomeScreenFeature;
extern NSString *TIRDISupportFeature;
extern NSString *TIFlashFeature;
extern NSString *TIZeroRdcFeature;
extern NSString *TIRDCFeature;
extern NSString *TIDirectoryFilterFeatureFeature;
extern NSString *TIBusyFeature;
extern NSString *TIProductCodeLoadedFeature;
extern NSString *TIArchiveFeature;
extern NSString *TIClockFeature;
extern NSString *TIScreenFeature;
extern NSString *TILoginFeature;
extern NSString *TISupportFolderFeature;
extern NSString *TISupportDeleteFeature;

/*"notification name"*/
extern NSString *TINotificationDeviceBusyStateChanged;
extern NSString *TINotificationDeviceDoneLoadingContent;
extern NSString *TINotificationDeviceContentChanged;
extern NSString *TINotificationDeviceRefreshIsComplete;

/*"non human readable Device Kind"*/
extern NSString *TINHRTI73Kind;
extern NSString *TINHRTI82Kind;
extern NSString *TINHRTI83Kind;
extern NSString *TINHRTI83pKind;
extern NSString *TINHRTI83pSEKind;
extern NSString *TINHRTI85Kind;
extern NSString *TINHRTI86Kind;
extern NSString *TINHRTI89Kind;
extern NSString *TINHRTI92Kind;
extern NSString *TINHRTI92pKind;
extern NSString *TINHRTIV200Kind;
extern NSString *TINHRCBLKind;
extern NSString *TINHRCBRKind;
extern NSString *TINHRCBR2Kind;
extern NSString *TINHRCBL2pKind;
extern NSString *TINHRLabProKind;
extern NSString *TINHRPresenterKind;


enum TIClockState
{
    clockOff = 0,
    clockOn,
    clockUnknown
};
typedef enum TIClockState TIClockState;

enum TIDeviceConnectionType
{
    TISilverLink = 0,
    TIDirectUSB,
    TINavigator
};
typedef enum TIDeviceConnectionType TIDeviceConnectionType;

enum TISendKeyScreenOptionValue
{
    noScreen = 0,
    whiteBackgroundScreen,
    greenBackgroundScreen
};
typedef enum TISendKeyScreenOptionValue TISendKeyScreenOptionValue;

enum TIDeviceError
{
    deviceNotLoadedLowBattery = 1,
    deviceNotLoadedAlreadyExisted,
    deviceNotLoadedInvalidConnectionID,
    deviceNotLoadedInconsistentIdentityAndModel,
    deviceNotLoadedFailedToReturnProperties,
    DeviceNotLoadedComManagerDead
};
typedef enum TIDeviceError TIDeviceError;

@interface TIDevice : TIDeviceFolder <NSCopying>	/*"TIDeviceObject"*/
{
    @private
    NSString *_connectionID;	/*"the unique identifier of a calculator"*/
    NSString *familly;		/*"give the familly of the device. (look at the com manager dictionary for the values)"*/
    NSString *nonHumanReadableFamilly;	/*"give the familly of the device. (look at the com manager dictionary for the values)"*/
    NSString *hubAddress;	/*"give the IP adress of the hub to which the device is connected if it is connected to a hub"*/
    NSDictionary *ioStatus;
    NSArray *features; 		/*"the feature list the device returns"*/
    BOOL _isBusy;		/*"true whenever there are communication with the com manager"*/
    BOOL isTransferingFiles;	/*"true when an operation that can be mesured is going on (saving and sending files)"*/
    BOOL isGettingIOStatus;
    BOOL isLoggingIn;
    BOOL isRefreshing;
    BOOL contentLoaded;
    NSLock *ioStatusLock;
    SInt32 busyCount;
    SInt32 transferingFileCount;
	TIDeviceConnectionType deviceConnectionType;
}

/*"initialisation"*/
+ (TIDevice*) deviceWithPropertyRecord: (NSAppleEventDescriptor *) inPropertyRecord
                           container: (TIDeviceFolder*) inContainer;
- (id) initWithNonHumanReadableKind: (NSString*)nonHumanReadableKind
                       connectionID: (NSString*)inConnectionID
                          container: (TIDeviceFolder*) inContainer
                               name: (NSString*)inName
                       internalName: (NSString*)inInternalName
                               size: (NSNumber*)inSize
             nonHumanReadableFamily: (NSString*)inNonHumanReadableFamily
                         hubAddress: (NSString*)inHubAddress
					 connectionType: (TIDeviceConnectionType) inConnectionType;

    /*"accessors"*/
- (NSString *) connectionID;
- (BOOL)isGettingIOStatus;
- (void)setIsGettingIOStatus:(BOOL)inFlag;
- (BOOL) isBusy;
- (NSString *) familly;
- (NSString *) hubAddress;
- (NSDictionary *) ioStatus;
- (BOOL) isTransferingFiles;
- (BOOL) isLoggingIn;
- (BOOL) isUSBDevice;
- (NSArray*) features;
- (NSString*) nonHumanReadableFamilly;
- (void) setIsTransferingFiles:(BOOL)newIsTransferingFiles;
- (void)setNonHumanReadableKind:(NSString *)newNonHumanReadableKind;
- (BOOL) deviceStillPluggedin;
- (BOOL) isRefreshing;
- (BOOL) hasOS;
- (TIDeviceConnectionType) deviceConnectionType;



    /*"accessors to data stored on the device"*/
- (NSImage*) screen;
- (NSImage*) screenWithGreenBackground: (BOOL) wantGreenBackground;
- (NSDictionary*) productInformation;
- (NSDictionary*) clock;
- (NSNumber*) setClock: (NSDictionary*) inClockData;
- (void) setName:(NSString*) inName;

    /*"Action send to the devices"*/
- (void) loadContent;
- (void) refreshDevices;
- (void) reaquireDevices;

- (void) sendKey: (NSInteger)inKeyCode gettingScreen: (TISendKeyScreenOptionValue) inScreenReturnOption callingCompletionOn: (id) target;
- (NSImage*) sendKeyInCurrentThread: (NSInteger)inKeyCode gettingScreen: (TISendKeyScreenOptionValue) inScreenReturnOption errorNumber: (NSInteger*) outErrorNumber;
@end

@interface NSObject (TIDeviceDelegate)
/*"Delegate methods, called for callback to asynchronous operations"*/
- (void) device: (TIDevice*)sender doneLoadingContent:(TIDeviceError) result;
- (void) device: (TIDevice*)sender doneSendingReaquire:(TIDeviceError) inResult;
- (void) device: (TIDevice*)sender doneRefreshing:(TIDeviceError) inResult;
@end

@interface NSObject (TIDeviceCompletionRoutine)
/*"Completion methods, called for callback to asynchronous operations"*/
- (void) device: (TIDevice*)sender loggedInWithName: (NSString*) name error: (NSNumber*) errorNumber;
- (void) device: (TIDevice*)sender doneSendingKey:(SInt32)key withError: (OSStatus) errorNumber andScreen: (NSImage*) inImage;
@end
