This repository has been archived by the owner on Apr 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
development_javascript_Rpc.html
230 lines (180 loc) · 6.7 KB
/
development_javascript_Rpc.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mobile Widgets</title>
<link rel="stylesheet" href="style/style.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
<script type="text/javascript" src="js/StructureElts.js"></script>
<script type="text/javascript" src="js/Structure.js"></script>
<script type="text/javascript" src="js/DocElements.js"></script>
</head>
<body>
<script type="text/javascript">
<!--
idCurrentPage = "development_javascript_Rcp";
beginPage();
//-->
</script>
<h1 class="title">Rcp Javascript library</h1>
<script type="text/javascript">
<!--
addIndex();
//-->
</script>
<script type="text/javascript">addTitle("Description", 1);</script>
<p>
The Rpc class allows to make calls to an JSON-RPC server.
</p>
<p>
The server address is given by the "PFS" Jad property and cannot be modified. The
API automatically adds the "JSON-RPC" path to the "PFS" property to access the
JSON-RPC service.
</p>
<p>
If multiple connections are made simultaneously, then will be queued and done
one after the
</p>
<p class="note Warning">
<b>Warning</b>:<br/>
This API uses "opaque" references that must be passed from one call to another
and must be freed at the end of the operation by calling Rpc.getResult(ref) or
Rpc.cancel(ref). The number of references is limited so all references must
always be freed.
</p>
<p class="note Warning">
<b>Warning</b>:<br/>
Do not use the synchronous mode of the JSON-RPC request. This will freeze your
application during all the request and parsing.
</p>
<p>
This API is only supported on Mobile Widgets version of the MeMo, and should now
only be used to support data provided by the Rpc API.<br/>
It is not supproted by Tiny Mobile Widgets version.
</p>
<br/>
<script type="text/javascript">addTitle("Since", 1);</script>
<h2>1.4.0</h2>
<br/>
<script type="text/javascript">addTitle("Methods", 1);</script>
<p>
<b>ref call (true, string methodCall, [arg1, arg2, ..., argN])</b>:<br/>
Make a asynchronous JSON-RPC request to the server and return a reference to
this request.
</p>
<ul>
<li>methodCall must define the method to call on the server side (e.g.
"Weather.getForcast").</li>
<li>arg1, arg2, ..., argN are the optional parameters to pass to the method. These
arguments can be either a string, an integer, a float or a reference to an
array or collection of the Array API.</li>
</ul>
<p>
<b>result call (false, string methodCall, [arg1, arg2, ..., argN])</b>:<br/>
<b><span class="highlight">DEPRECATED</span></b> Make a synchronous JSON-RPC request.
</p>
<p>
<b>void cancel (ref)</b>:<br/>
Cancel the asynchronous request referenced by ref. Calling this methods frees
the reference ref.
</p>
<p>
<b>result getResult (ref)</b>:<br/>
Retrieve the result of the asynchronous request referenced by ref. The result is
either a string, an integer, a float or a reference to an array or collection of
the Array API, or -1 on error. Calling this methods frees the reference ref.
</p>
<p>
<b>void addCallback (ref, event, callback, [arg1, arg2, ..., argN])</b>:<br/>
Add a callback to an asynchronous request referenced by ref. This allows to
monitor the progress and completion of an asynchronous request.
</p>
<ul>
<li>event can be one of Rpc.ON_SUCESS, Rpc.ON_ERROR, Rpc.ON_PROGRESS,
Rpc.ON_START, Rpc.ALL_STATES.</li>
<li>callback : name of the function to call when the event occurs on the request.</li>
<li>arg1 arg2, ..., argN : operational parameters to pass to the callback.</li>
</ul>
<p>
The callback will then have the following signature : function callback (ref,
[arg1, arg2, ..., argN][, progress], time).
</p>
<p>
<b>void clean ()</b>:<br/>
Cancel all queued requests and free all data associated to this API.
</p>
<br/>
<script type="text/javascript">addTitle("Constants", 1);</script>
<p>
<b>ON_SUCCESS</b>:<br/>
To use as the event argument for addCallback.<br/>
The callback will be called if the asynchronous request is successful.
</p>
<p>
<b>ON_ERROR</b>:<br/>
To use as the event argument for addCallback.<br/>
The callback will be called if the asynchronous request triggers an error.
</p>
<p>
<b>ON_START</b>:<br/>
To use as the event argument for addCallback.<br/>
The callback will be called when the asynchronous request starts.
</p>
<p>
<b>ON_PROGRESS</b>:<br/>
To use as the event argument for addCallback.<br/>
The callback will then be called during the download the events on the
asynchronous request with an additional progress parameter (ranging from 0 to 100).
</p>
<p>
<b>ALL_STATES</b>:<br/>
<b><span class="highlight">DEPRECATED</span></b> To use as the event argument for addCallback.<br/>
The callback will be called for all the events on the asynchronous request with
an additional event parameter.<br/>
The additional parameter is an integer with values 0=UNKNOWN, 1=QUEUED, 2=START,
4=SUCCESS, 8=ERROR.
</p>
<br/>
<script type="text/javascript">addTitle("Examples", 1);</script>
<p>
This is an example for a imaginary weather forecast service.
</p>
<textarea rows="15" cols="80" readonly="readonly" wrap="off">
function testRpc () {
var ref = Rpc.call (true, 'Weather.getForecast', 'Rennes');
Rpc.addCallback (ref, Rpc.ON_SUCCESS, onSuccess, 'Weather for Rennes', 'this is a test', 'a third arg');
Rpc.addCallback (ref, Rpc.ON_ERROR, onError, 'Rennes');
Rpc.addCallback (ref, Rpc.ON_PROGRESS, onProgress, 'Rennes');
}
function onSuccess (ref, arg1, arg2, arg3) {
var forecastResult = Rpc.getResult (ref); // retreive collection from the server and free the request reference
// Parse and display forecast
var forecast = Array.getElement(forecastResult, 'forecast');
Browser.print ('Weather on monday : '+Array.getElement (forecast, 'monday'));
Browser.print ('Weather on sunday : '+Array.getElement (forecast, 'sunday'));
Array.free (forecast);
Array.free (forecastResult);
}
function onError (ref, arg1) {
Browser.print ('Could not request forecast for city '+arg1);
}
function onProgress (ref, arg1, progress) {
Browser.print ('Downloading forecast for city '+arg1+': '+(progress/100.0)+'%');
}
</textarea>
<br/>
<script type="text/javascript">
<!--
//Display navigation bar (bottom of page) with next/previous pages.
addBackPageNavigator('widgets_development_javascript_ref', '');
//-->
</script>
<script type="text/javascript">
<!--
endPage();
//-->
</script>
</body>
</html>