DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
RestApi.c
См. документацию.
1
3
4
5// -------------------------------------------------------------------------
6// states, (result + error) codes
7// defined in C++
9{
10 EREST_EMPTY, // not initialized
11 EREST_PENDING, // awaiting processing
12 EREST_FEEDING, // awaiting incoming data
13 EREST_SUCCESS, // result and/ or data are ready (success), awaiting data processing to be finished (no longer blocking queue processing)
14 EREST_PROCESSED, // finished (either successfully or with failure) and eill be removed ASAP
15
16 EREST_ERROR, // (state >= EREST_ERROR) == error happened
17 EREST_ERROR_CLIENTERROR, // (EREST_ERROR == EREST_ERROR_CLIENTERROR)
23};
24
25// -------------------------------------------------------------------------
26// options
27// defined in C++
29{
30 ERESTOPTION_UNKNOWN, // invalid option
31
32 ERESTOPTION_READOPERATION, // read operation timeout (default 10sec)
33 ERESTOPTION_CONNECTION, // connection timeout (default 10sec)
34 // note: limit for timeout is between <3 .. 120> seconds, you cannot exceed this value
35};
36
37
38
39// -------------------------------------------------------------------------
40// object to be used from script for result binding
41//
42// [Example:]
43//
44// RestCallback cbx1 = new RestCallback;
45// RestContext ctx = GetRestApi().GetRestContext("http://somethingsomewhere.com/path/");
46// ctx.GET(cbx1,"RequestPath?Argument=Something");
47//
48// Event are then called upon RestCallback()
49//
51{
55 void OnError( int errorCode )
56 {
57 // override this with your implementation
58 Print(" !!! OnError() ");
59 };
60
64 void OnTimeout()
65 {
66 // override this with your implementation
67 Print(" !!! OnTimeout() ");
68 };
69
73 void OnSuccess( string data, int dataSize )
74 {
75 // override this with your implementation
76 Print(" !!! OnSuccess() size=" + dataSize );
77 if( dataSize > 0 )
78 Print(data); // !!! NOTE: Print() will not output string longer than 1024b, check your dataSize !!!
79 };
80
84 void OnFileCreated( string fileName, int dataSize )
85 {
86 // override this with your implementation
87 Print(" !!! OnFileCreated() file=" + fileName + " size=" + dataSize );
88 };
89
90};
91
92
93// -------------------------------------------------------------------------
94// context API and request API
96{
97 private void RestContext() {}
98 private void ~RestContext() {}
99
103 proto native int GET( RestCallback cb, string request );
104
108 proto native string GET_now( string request );
109
113 proto native int FILE( RestCallback cb, string request, string filename );
114
118 proto native int FILE_now( string request, string filename );
119
123 proto native int POST( RestCallback cb, string request, string data );
124
128 proto native string POST_now( string request, string data );
129
133 proto native void reset();
134
141 proto native void SetHeader( string value );
142};
143
144
145// -------------------------------------------------------------------------
146// RestApi core for context create/ access + debug features
148{
149 private void RestApi() {}
150 private void ~RestApi() {}
151
155 proto native RestContext GetRestContext( string serverURL );
156
160 proto native int GetContextCount();
161
165 proto native void EnableDebug( bool bEnable );
166
170 proto native void DebugList();
171
175 proto native void SetOption( int option, int value );
176
177};
178
179// -------------------------------------------------------------------------
180// RestApi create/ access methods out of Hive initialization
181proto native RestApi CreateRestApi();
182proto native void DestroyRestApi();
183proto native RestApi GetRestApi();
184
proto native RestApi GetRestApi()
proto native void DestroyRestApi()
ERestResultState
Определения RestApi.c:9
@ EREST_FEEDING
Определения RestApi.c:12
@ EREST_ERROR_CLIENTERROR
Определения RestApi.c:17
@ EREST_PROCESSED
Определения RestApi.c:14
@ EREST_ERROR_APPERROR
Определения RestApi.c:19
@ EREST_PENDING
Определения RestApi.c:11
@ EREST_ERROR_SERVERERROR
Определения RestApi.c:18
@ EREST_ERROR_UNKNOWN
Определения RestApi.c:22
@ EREST_ERROR_TIMEOUT
Определения RestApi.c:20
@ EREST_ERROR
Определения RestApi.c:16
@ EREST_EMPTY
Определения RestApi.c:10
@ EREST_SUCCESS
Определения RestApi.c:13
@ EREST_ERROR_NOTIMPLEMENTED
Определения RestApi.c:21
ERestOption
Определения RestApi.c:29
@ ERESTOPTION_READOPERATION
Определения RestApi.c:32
@ ERESTOPTION_UNKNOWN
Определения RestApi.c:30
@ ERESTOPTION_CONNECTION
Определения RestApi.c:33
proto native RestApi CreateRestApi()
TODO doc.
Определения EnScript.c:118
proto native void DebugList()
List of all currently active contexes and processed (pending) requests.
proto native RestContext GetRestContext(string serverURL)
Get new or existing context for http comm GetRestContext("www.server915.com/interface/")
void RestApi()
Определения RestApi.c:149
proto native void EnableDebug(bool bEnable)
Enable debug output to console (disabled by default)
proto native int GetContextCount()
Get count of registered contexes.
proto native void SetOption(int option, int value)
Set specific option (integer)
void ~RestApi()
Определения RestApi.c:150
Определения RestApi.c:148
void OnFileCreated(string fileName, int dataSize)
Called when data arrived and/ or file created successfully.
Определения RestApi.c:84
void OnError(int errorCode)
Called in case request failed (ERestResultState) - Note! May be called multiple times in case of (Ret...
Определения RestApi.c:55
void OnTimeout()
Called in case request timed out or handled improperly (no error, no success, no data)
Определения RestApi.c:64
void OnSuccess(string data, int dataSize)
Called when data arrived and/ or response processed successfully.
Определения RestApi.c:73
Определения RestApi.c:51
proto native int FILE(RestCallback cb, string request, string filename)
Processes GET request and returns result (ERestResultState) and/ or stores data int specified file (t...
proto native string GET_now(string request)
Processes GET request and returns data immediately (thread blocking operation!)
proto native string POST_now(string request, string data)
Processes POST request and returns data immediately (thread blocking operation!)
proto native int GET(RestCallback cb, string request)
Processes GET request and returns result (ERestResultState) and/ or data (timeout,...
proto native int FILE_now(string request, string filename)
Processes GET request and returns result (ERestResultState) and/ stores data int specified file immed...
proto native void SetHeader(string value)
Set Content-Type header (string)
proto native void reset()
Clear all pending requests and buffers.
void ~RestContext()
Определения RestApi.c:98
void RestContext()
Определения RestApi.c:97
proto native int POST(RestCallback cb, string request, string data)
Pushes POST request and returns result (ERestResultState) and/ or data (timeout, error) when finished...
Определения RestApi.c:96
proto void Print(void var)
Prints content of variable to console/log.