ArDrone SDK 1.8 added
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ControlEngine / iPhone / Release / ARDroneFTP.h
1 //
2 //  ARDroneFTP.h
3 //  ARDroneEngine
4 //
5 //  Wrapper around utils/ardrone_ftp.c functions
6 //
7 //  Created by Nicolas BRULEZ on 07/04/11.
8 //  Copyright 2011 Parrot. All rights reserved.
9 //
10
11 #import <Foundation/Foundation.h>
12
13 typedef enum ARDFTP_RESULT_e {
14     ARDFTP_FAIL,
15     ARDFTP_BUSY,
16     ARDFTP_SUCCESS,
17     ARDFTP_TIMEOUT,
18     ARDFTP_BADSIZE,
19     ARDFTP_SAMESIZE,
20     ARDFTP_PROGRESS,
21     ARDFTP_ABORT,
22 } ARDFTP_RESULT;
23
24 typedef enum FTP_OPERATION_e {
25     FTP_NONE,
26     FTP_SEND,
27     FTP_GET,
28     FTP_LIST,
29 } FTP_OPERATION;
30
31 /**
32  * Fail / Success test
33  *
34  * ARDFTP_FAILED is not "return !ARDFTP_SUCCEEDED (result);" because ARDFTP_PROGRESS is not a success
35  * nor a failure case
36  */
37
38
39 static inline bool ARDFTP_SUCCEEDED (ARDFTP_RESULT result)
40 {
41     return (ARDFTP_SAMESIZE == result ||
42             ARDFTP_SUCCESS == result) ? 
43     YES : NO;
44 }
45
46 static inline bool ARDFTP_FAILED (ARDFTP_RESULT result)
47 {
48     return (ARDFTP_FAIL == result ||
49             ARDFTP_BUSY == result ||
50             ARDFTP_TIMEOUT == result ||
51             ARDFTP_BADSIZE == result ||
52             ARDFTP_ABORT == result) ?
53     YES : NO;
54 }
55
56 @interface ARDroneFTPCallbackArg : NSObject {
57     ARDFTP_RESULT status;
58     float progress; // Zero if status is not "ARDFTP_PROGRESS"
59     NSString *fileList; // nil if operation is not "FTP_LIST" and status is not "ARDFTP_SUCCESS"
60     FTP_OPERATION operation;
61 }
62 @property (readonly) ARDFTP_RESULT status;
63 @property (readonly) float progress;
64 @property (readonly) FTP_OPERATION operation;
65 @property (nonatomic, readonly) NSString *fileList;
66
67 - (id)initWithStatus:(ARDFTP_RESULT)_status withProgress:(float)_progress withFileList:(char *)_fileList withOperation:(FTP_OPERATION)_operation;
68
69 @end
70
71 @interface ARDroneFTP : NSObject {
72     struct _ftp_s *ftp;
73     id delegate;
74     SEL defaultCallback;
75     SEL currentOpCallback;
76     BOOL isBusy;
77     FTP_OPERATION currentOperation;
78 }
79 @property (readonly) FTP_OPERATION currentOperation;
80 @property (readonly) SEL currentOpCallback;
81 @property (readonly) id delegate;
82 @property (readwrite) BOOL isBusy;
83
84 /* Instanciations of common FTP for AR.Drone */
85 + (id) anonymousUpdateFTPwithDelegate:(id)_delegate withDefaultCallback:(SEL)_callback;
86 + (id) updateFTPwithUser:(NSString *)user withPassword:(NSString *)password withDelegate:(id)_delegate withDefaultCallback:(SEL)_callback;
87 + (id) anonymousStandardFTPwithDelegate:(id)_delegate withDefaultCallback:(SEL)_callback;
88 + (id) standardFTPwithUser:(NSString *)user withPassword:(NSString *)password withDelegate:(id)_delegate withDefaultCallback:(SEL)_callback;
89
90 /* Open FTP */
91 - (id)initAnonymousWithIP:(NSString *)ip withPort:(int)port withDelegate:(id)_delegate withDefaultCallback:(SEL)_callback;
92 - (id)initWithIP:(NSString *)ip withPort:(int)port withUser:(NSString *)user withPassword:(NSString *)password withDelegate:(id)_delegate withDefaultCallback:(SEL)_callback;
93 /* Change delegate/callback */
94 - (void)setDelegate:(id)_delegate;
95 - (void)setDefaultCallback:(SEL)_callback;
96 /* Close FTP */
97 - (void)close;
98
99 /* Dummy command to keep ftp connexion alive ... return NO if connexion was closed by server */
100 - (bool)keepConnexionAlive;
101
102 /* NOTE : Default callback refers to the callback defined in init... or setDefaultCallback functions */
103
104 /* Send file */
105 - (ARDFTP_RESULT)sendLocalFile:(NSString *)local toDistantFile:(NSString *)distant withResume:(BOOL)resume; // Default callback
106 - (ARDFTP_RESULT)sendLocalFile:(NSString *)local toDistantFile:(NSString *)distant withResume:(BOOL)resume withCallback:(SEL)_callback; // Specified callback
107 - (ARDFTP_RESULT)sendSynchronouslyLocalFile:(NSString *)local toDistantFile:(NSString *)distant withResume:(BOOL)resume; // Blocking call until completion
108 /* Get file */
109 - (ARDFTP_RESULT)getDistantFile:(NSString *)distant toLocalFile:(NSString *)local withResume:(BOOL)resume; // Default callback
110 - (ARDFTP_RESULT)getDistantFile:(NSString *)distant toLocalFile:(NSString *)local withResume:(BOOL)resume withCallback:(SEL)_callback; // Specified callback
111 - (ARDFTP_RESULT)getSynchronouslyDistantFile:(NSString *)distant toLocalFile:(NSString *)local withResume:(BOOL)resume; // Blocking call until completion
112 /* List current directory */
113 - (ARDFTP_RESULT)listCurrentDirectory; // Default callback
114 - (ARDFTP_RESULT)listCurrentDirectoryWithCallback:(SEL)_callback; // Specified callback
115 - (ARDFTP_RESULT)listCurrentDirectoryIn:(NSString **)result; // Blocking call, result is set in *result
116
117 /* Remove file */
118 - (ARDFTP_RESULT)removeDistantFile:(NSString *)distant;
119 /* Rename file/directory (Both functions are the same) */
120 - (ARDFTP_RESULT)renameDistantFileFrom:(NSString *)origin to:(NSString *)dest;
121 - (ARDFTP_RESULT)renameDistantDirectoryFrom:(NSString *)origin to:(NSString *)dest;
122 /* Change working directory */
123 - (ARDFTP_RESULT)changeDirectoryTo:(NSString *)nextDir;
124 /* Get working directory */
125 - (ARDFTP_RESULT)getWorkingDirectoryTo:(NSString **)result;
126 /* Create directory */
127 - (ARDFTP_RESULT)createDirectoryNamed:(NSString *)dirName;
128 /* Remove directory */
129 - (ARDFTP_RESULT)removeDirectoryNamed:(NSString *)dirName;
130
131 /* Abort current operation */
132 - (ARDFTP_RESULT)abortCurrentOperation;
133
134 /* Check if instance is available */
135 - (BOOL)isBusy;
136
137 @end