CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
2
4 Message exchange by SCSCP
3
4
To ensure the message exchange as required by SCSCP specification, the SCSCP
5
package extends the global record OMsymRecord from the OpenMath package with
6
new entries to support scscp1 and scscp2 content dictionaries ([FHK+a],
7
[FHK+c]), and also service-dependent transient private content dictionaries
8
(see Chapter 5 for details about transient content dictionaries). It also
9
overwrites some OpenMath functions by their extended (but backwards
10
compatible) versions, and adds some new OpenMath-related functions to send
11
and receive SCSCP messages, documented below.
12
13
Note that functions documented in this chapter belong to the middle-level
14
interface, and the user may find it more convenient to use functions
15
developed on top of them and explained in next chapters.
16
17
18
4.1 Communication with the SCSCP server
19
20
4.1-1 StartSCSCPsession
21
22
StartSCSCPsession( stream )  function
23
Returns: string
24
25
Initialises SCSCP session and negotiates with the server about the version
26
of the protocol. Returns the string with the service_id (which may be used
27
later as a part of the call identifier) or causes an error message if can
28
not perform these tasks.
29
30
 Example 
31

32
gap> s := InputOutputTCPStream("localhost",26133);
33
< input/output TCP stream to localhost:26133 >
34
gap> StartSCSCPsession(s);
35
"localhost:26133:5541"
36
gap> CloseStream( s );
37

38

39
40
After the call to StartSCSCPsession the SCSCP server is ready to accept
41
procedure calls.
42
43
4.1-2 OMPutProcedureCall
44
45
OMPutProcedureCall( stream, proc_name, objrec )  function
46
Returns: nothing
47
48
Takes a stream stream, the string proc_name and a record objrec, and writes
49
to stream an OpenMath object procedure_call for the procedure proc_name with
50
arguments given by the list objrec.object and procedure call options (which
51
should be encoded as OpenMath attributes) given in the list
52
objrec.attributes.
53
54
This function accepts options cd and debuglevel.
55
56
cd:="cdname" may be used to specify the name of the content dictionary if
57
the procedure is actually a standard OpenMath symbol. Note that the server
58
may reject such a call if it accepts only calls of procedures from the
59
transient content dictionary, see InstallSCSCPprocedure (5.1-1) for
60
explanation). If the cdname is not specified, scscp_transient_1 content
61
dictionary will be assumed by default. The value of the debuglevel option is
62
an integer. If it is non-zero, the procedure_completed message will carry on
63
also some additional information about the call, for example, runtime and
64
memory used.
65
66
 Example 
67

68
gap> t:="";; stream:=OutputTextString(t,true);;
69
gap> OMPutProcedureCall( stream, "WS_Factorial", rec( object:= [ 5 ], 
70
>  attributes:=[ [ "call_id", "user007" ], 
71
>  ["option_runtime",1000],
72
>  ["option_min_memory",1024], 
73
>  ["option_max_memory",2048],
74
>  ["option_debuglevel",1], 
75
>  ["option_return_object"] ] ) );;
76
gap> Print(t);
77
<?scscp start ?>
78
<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
79
 <OMATTR>
80
 <OMATP>
81
 <OMS cd="scscp1" name="call_id"/>
82
 <OMSTR>user007</OMSTR>
83
 <OMS cd="scscp1" name="option_runtime"/>
84
 <OMI>1000</OMI>
85
 <OMS cd="scscp1" name="option_min_memory"/>
86
 <OMI>1024</OMI>
87
 <OMS cd="scscp1" name="option_max_memory"/>
88
 <OMI>2048</OMI>
89
 <OMS cd="scscp1" name="option_debuglevel"/>
90
 <OMI>1</OMI>
91
 <OMS cd="scscp1" name="option_return_object"/>
92
 <OMSTR></OMSTR>
93
 </OMATP>
94
 <OMA>
95
 <OMS cd="scscp1" name="procedure_call"/>
96
 <OMA>
97
 <OMS cd="scscp_transient_1" name="WS_Factorial"/>
98
 <OMI>5</OMI>
99
 </OMA>
100
 </OMA>
101
 </OMATTR>
102
</OMOBJ>
103
<?scscp end ?>
104

105

106
107
4.1-3 SCSCPwait
108
109
SCSCPwait( stream[, timeout] )  function
110
Returns: nothing
111
112
This function may be used by the SCSCP client to wait (using IO_select (IO:
113
IO_select)) until the result of the procedure call will be available from
114
stream. By default the timeout is one hour, to specify another value give it
115
as the optional second argument in seconds. See the end of this chapter for
116
the example.
117
118
4.1-4 OMGetObjectWithAttributes
119
120
OMGetObjectWithAttributes( stream )  function
121
Returns: record with components object and attributes, or fail
122
123
This function is similar to the function OMGetObject from the OpenMath
124
package, and the main difference is that it is able to understand OpenMath
125
attribution pairs. It retrieves exactly one OpenMath object from the stream
126
stream, and stores it in the object component of the returned record. If the
127
OpenMath object has no attributes, the attributes component of the returned
128
record will be an empty list, otherwise it will contain pairs
129
[attribute_name,attribute_value], where attribute_name is a string, and
130
attribute_value is a GAP object, whose type is determined by the kind of an
131
attribute. Only attributes, defined by the SCSCP are allowed, otherwise an
132
error message will be displayed.
133
134
If the procedure was not successful, the function returns fail instead of an
135
error message like the function OMGetObject (OpenMath: OMGetObject) does.
136
Returning fail is useful when OMGetObjectWithAttributes is used inside
137
accept-evaluate-return loop.
138
139
As an example, the file scscp/tst/omdemo.om contains some OpenMath objects,
140
including those from the SCSCP Specification [FHK+b]. We can retrieve them
141
from this file, preliminary installing some SCSCP procedures using the
142
function InstallSCSCPprocedure (5.1-1):
143
144
 Example 
145

146
gap> InstallSCSCPprocedure("WS_Factorial", Factorial );
147
gap> InstallSCSCPprocedure("GroupIdentificationService", IdGroup );
148
gap> InstallSCSCPprocedure("GroupByIdNumber", SmallGroup );
149
gap> InstallSCSCPprocedure( "Length", Length, 1, 1 );
150
gap> test:=Filename( Directory( Concatenation(
151
>  GAPInfo.PackagesInfo.("scscp")[1].InstallationPath,"/tst/" ) ), 
152
>  "omdemo.om" );;
153
gap> stream:=InputTextFile(test);;
154
gap> OMGetObjectWithAttributes(stream); 
155
rec( 
156
 attributes := [ [ "option_return_object", "" ], [ "call_id", "5rc6rtG62" ] ]
157
 , object := 6 )
158
gap> OMGetObjectWithAttributes(stream);
159
rec( attributes := [ ], object := 1 )
160
gap> OMGetObjectWithAttributes(stream);
161
rec( attributes := [ ], object := 120 )
162
gap> OMGetObjectWithAttributes(stream);
163
rec( 
164
 attributes := [ [ "call_id", "alexk_9053" ], [ "option_runtime", 300000 ], 
165
 [ "option_min_memory", 40964 ], [ "option_max_memory", 134217728 ], 
166
 [ "option_debuglevel", 2 ], [ "option_return_object", "" ] ],
167
 object := [ 24, 12 ] )
168
gap> OMGetObjectWithAttributes(stream);
169
rec( 
170
 attributes := [ [ "call_id", "alexk_9053" ], [ "option_return_cookie", "" ] 
171
 ], object := <pc group of size 24 with 4 generators> )
172
gap> OMGetObjectWithAttributes(stream);
173
rec( attributes := [ [ "call_id", "alexk_9053" ], [ "info_runtime", 1234 ], 
174
 [ "info_memory", 134217728 ] ], object := [ 24, 12 ] )
175
gap> CloseStream( stream );
176

177

178
179
180
4.2 Communication with the SCSCP client
181
182
4.2-1 OMPutProcedureCompleted
183
184
OMPutProcedureCompleted( stream, objrec )  function
185
Returns: true
186
187
Takes a stream stream, and a record objrec, and writes to stream an OpenMath
188
object procedure_completed with the result being objrec.object and
189
information messages (as OpenMath attributes) given in the list
190
objrec.attributes.
191
192
 Example 
193

194
gap> t:="";; stream:=OutputTextString(t,true);;
195
gap> OMPutProcedureCompleted( stream, 
196
>  rec(object:=120, 
197
>  attributes:=[ [ "call_id", "user007" ] ] ) );
198
true
199
gap> Print(t);
200
<?scscp start ?>
201
<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
202
 <OMATTR>
203
 <OMATP>
204
 <OMS cd="scscp1" name="call_id"/>
205
 <OMSTR>user007</OMSTR>
206
 </OMATP>
207
 <OMA>
208
 <OMS cd="scscp1" name="procedure_completed"/>
209
 <OMI>120</OMI>
210
 </OMA>
211
 </OMATTR>
212
</OMOBJ>
213
<?scscp end ?>
214

215

216
217
4.2-2 OMPutProcedureTerminated
218
219
OMPutProcedureTerminated( stream, objrec, error_cd, error_type )  function
220
Returns: nothing
221
222
Takes a stream stream, and a record with an error message objrec (for
223
example rec( attributes := [ [ "call_id", "localhost:26133:87643:gcX33cCf" ]
224
], object := "localhost:26133 reports : Rational operations: <divisor> must
225
not be zero") and writes to the stream an OpenMath object
226
procedure_terminated containing an error determined by the symbol error_type
227
from the content dictionary error_cd (for example, error_memory,
228
error_runtime or error_system_specific from the scscp1 content dictionary
229
([FHK+a]).
230
231
This is the internal function of the package which is used only in the code
232
for the SCSCP server to return the error message to the client.
233
234
235
4.3 Example: SCSCP session
236
237
In the following example we start an SCSCP session and perform ten procedure
238
calls in a loop before closing that session. Note that we demonstrate the
239
usage of the session ID sid and the function RandomString from the OpenMath
240
package to produce some unique call identifier. The call ID is a mandatory
241
attribute for any procedure call, however, it is not nesessarily random; for
242
example, it may be just a string with the number of the procedure call.
243
244
 Example 
245

246
gap> stream:=InputOutputTCPStream( "localhost", 26133 );
247
< input/output TCP stream to localhost:26133 >
248
gap> sid := StartSCSCPsession( stream );
249
"localhost:26133:5541"
250
gap> res:=[];
251
[ ]
252
gap> for i in [1..10] do
253
>  OMPutProcedureCall( stream, "WS_Factorial", 
254
>  rec( object := [ i ], 
255
>  attributes := [ [ "call_id", 
256
>  Concatenation( sid, ":", RandomString(8) ) ] ] ) );
257
>  SCSCPwait( stream );
258
>  res[i]:=OMGetObjectWithAttributes( stream ).object;
259
> od;
260
gap> CloseStream(stream);
261
gap> res;
262
[ 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800 ]
263

264

265
266
Also note the usage of SCSCPwait (4.1-3) to wait until the result of the
267
computation will be available from stream.
268
269
In this example we assumed that there is an SCSCP server running at
270
localhost, port 26133. In the next chapter we will explain how to configure
271
and run a GAP SCSCP server and how to interrogate it from a GAP client to
272
learn about its functionality. After that, we will proceed with the SCSCP
273
client functionality for the end-user.
274
275
276