DayZ 1.24
Loading...
Searching...
No Matches
RestApi.c
Go to the documentation of this file.
1
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// object to be used from script for result binding
40//
41// [Example:]
42//
43// RestCallback cbx1 = new RestCallback;
44// RestContext ctx = GetRestApi().GetRestContext("http://somethingsomewhere.com/path/");
45// ctx.GET(cbx1,"RequestPath?Argument=Something");
46//
47// Event are then called upon RestCallback()
48//
50{
55 {
56 // override this with your implementation
57 Print(" !!! OnError() ");
58 };
59
63 void OnTimeout()
64 {
65 // override this with your implementation
66 Print(" !!! OnTimeout() ");
67 };
68
72 void OnSuccess(string data, int dataSize)
73 {
74 // override this with your implementation
75 Print(" !!! OnSuccess() size=" + dataSize);
76 if (dataSize > 0)
77 Print(data); // !!! NOTE: Print() will not output string longer than 1024b, check your dataSize !!!
78 };
79
84 {
85 // override this with your implementation
86 Print(" !!! OnFileCreated() file=" + fileName + " size=" + dataSize);
87 };
88
89};
90
91
92// -------------------------------------------------------------------------
93// context API and request API
95{
96 private void RestContext() {}
97 private void ~RestContext() {}
98
103
107 proto native string GET_now(string request);
108
113
117 proto native int FILE_now(string request, string filename);
118
123
127 proto native string POST_now(string request, string data);
128
133
141};
142
143
144// -------------------------------------------------------------------------
145// RestApi core for context create/ access + debug features
147{
148 private void RestApi() {}
149 private void ~RestApi() {}
150
155
160
165
170
175
176};
177
178// -------------------------------------------------------------------------
179// RestApi create/ access methods out of Hive initialization
183
proto native RestApi GetRestApi()
proto native void DestroyRestApi()
ERestResultState
Definition RestApi.c:9
@ EREST_FEEDING
Definition RestApi.c:12
@ EREST_ERROR_CLIENTERROR
Definition RestApi.c:17
@ EREST_PROCESSED
Definition RestApi.c:14
@ EREST_ERROR_APPERROR
Definition RestApi.c:19
@ EREST_PENDING
Definition RestApi.c:11
@ EREST_ERROR_SERVERERROR
Definition RestApi.c:18
@ EREST_ERROR_UNKNOWN
Definition RestApi.c:22
@ EREST_ERROR_TIMEOUT
Definition RestApi.c:20
@ EREST_ERROR
Definition RestApi.c:16
@ EREST_EMPTY
Definition RestApi.c:10
@ EREST_SUCCESS
Definition RestApi.c:13
@ EREST_ERROR_NOTIMPLEMENTED
Definition RestApi.c:21
ERestOption
Definition RestApi.c:29
@ ERESTOPTION_READOPERATION
Definition RestApi.c:32
@ ERESTOPTION_UNKNOWN
Definition RestApi.c:30
@ ERESTOPTION_CONNECTION
Definition RestApi.c:33
proto native RestApi CreateRestApi()
TODO doc.
Definition 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()
Definition RestApi.c:148
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()
Definition RestApi.c:149
void OnFileCreated(string fileName, int dataSize)
Called when data arrived and/ or file created successfully.
Definition RestApi.c:83
void OnError(int errorCode)
Called in case request failed (ERestResultState) - Note! May be called multiple times in case of (Ret...
Definition RestApi.c:54
void OnTimeout()
Called in case request timed out or handled improperly (no error, no success, no data)
Definition RestApi.c:63
void OnSuccess(string data, int dataSize)
Called when data arrived and/ or response processed successfully.
Definition RestApi.c:72
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()
Definition RestApi.c:97
void RestContext()
Definition RestApi.c:96
proto native int POST(RestCallback cb, string request, string data)
Pushes POST request and returns result (ERestResultState) and/ or data (timeout, error) when finished...
proto void Print(void var)
Prints content of variable to console/log.