<h4>5.1 <span class="Heading">Installation of <strong class="pkg">SCSCP</strong> procedures</span></h4>
<p>There may various ways to run <strong class="pkg">SCSCP</strong> server, for example:</p>
<ul>
<li><p>allowing generic services like evaluation of arbitrary <strong class="pkg">OpenMath</strong> code;</p>
</li>
<li><p>offering highly specialized procedures like identification of groups of order 512;</p>
</li>
<li><p>providing access to a database of mathematical objects.</p>
</li>
</ul>
<p>Each of these use cases requires certain control over the level of functionality exposed to the client. To achieve this, before starting <strong class="pkg">SCSCP</strong> service its provider must call the function <code class="func">InstallSCSCPprocedure</code> (<a href="chap5.html#X8031C2F4787E0C1A"><span class="RefLink">5.1-1</span></a>) to make required procedures <q>visible</q> for the client.</p>
<p>Additionally, the service can be made made accessible only for clients running on the same computer, or accessible only through a particular network interface, or generally accessible. This customization is made at the stage of starting the <strong class="pkg">SCSCP</strong> server with the function <code class="func">RunSCSCPserver</code> (<a href="chap5.html#X831C84577884215E"><span class="RefLink">5.2-1</span></a>).</p>
<p>For a string <var class="Arg">procname</var> and a function <var class="Arg">procfunc</var>, <codeclass="func">InstallSCSCPprocedure</code> makes the <var class="Arg">procfunc</var> available as SCSCP procedure under the name <var class="Arg">procname</var>, adding it to the transient <strong class="pkg">OpenMath</strong> content dictionary <code class="code">scscp_transient_1</code> that will exist during the service lifetime.</p>
<p>The second argument <var class="Arg">procfunc</var> may be either a standard or user-defined <strong class="pkg">GAP</strong> function (procedure, operation, etc.).</p>
<p>The rest of arguments are optional and may be used in a number of combinations:</p>
<ul>
<li><p><var class="Arg">description</var> is a string with the description of the procedure. It may be used by the help system. If it is omitted, the procedure will be reported as undocumented.</p>
</li>
<li><p><var class="Arg">narg1</var> is a non-negative integer, specifying the minimal number of arguments, and <var class="Arg">narg2</var> is a non-negative integer or infinity, specifying the maximal number of arguments. If <var class="Arg">narg2</var> is omitted then the maximal number of arguments will be set to <var class="Arg">narg1</var>. If both <var class="Arg">narg1</var> and <var class="Arg">narg2</var> are omitted then the minimal number of arguments will be set to zero and their maximal number will be set to infinity.</p>
</li>
<li><p><var class="Arg">signature</var> is the signature record of the procedure. If the <var class="Arg">signature</var> is given, then the number of arguments must be explicitly specified (by <var class="Arg">narg1</var> with or without <var class="Arg">narg2</var>) at least to zero and infinity respectively (to ensure proper matching of arguments). Note that it is completely acceptable for a symbol from a transient content dictionary to overstate the set of symbols which may occur in its children using the <code class="code">scscp2.symbol_set_all</code> symbol, and to use standard <strong class="pkg">OpenMath</strong> errors to reject requests later at the stage of their evaluation. For example, using such approach, we will define the procedure <code class="code">WS_Factorial</code> accepting not only immediate <code class="code"><OMI></code> objects but anything which could be evaluated to an integer.</p>
<p>. The signature must be either a list of records, where <span class="SimpleMath">i</span>-th record corresponds to the <span class="SimpleMath">i</span>-th argument, or a record itself meaning that it specifies the signature for all arguments. In the latter case the record may be <code class="code">rec( )</code> corresponding to the <code class="code">scscp2.symbol_set_all</code> symbol (this will be assumed by default if the signature will be omitted).</p>
<p>If more detailed description of allowed arguments is needed, the signature record (one for all arguments or a specific one) may have components <code class="code">CDgroups</code>, <code class="code">CDs</code> and <code class="code">Symbols</code>. The first two are lists of names of content dictionary groups and content dictionaries, and the third is a record whose components are names of content dictionaries, containing lists of names of allowed symbols from these dictionaries,for example:</p>
</li>
</ul>
<p>In the following example we define the function <code class="code">WS_Factorial</code> that takes an integers and returns its factorial, using only mandatory arguments of <code class="func">InstallSCSCPprocedure</code>:</p>
<p>In the following example we install the procedure that will accept a list of permutations and return the number in the <strong class="pkg">GAP</strong> Small Groups library of the group they generate (for the sake of simplicity we omit tests of validity of arguments, availability of <code class="code">IdGroup</code> for groups of given order etc.)</p>
<p>After installation, the procedure may be reinstalled, if necessary:</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">InstallSCSCPprocedure( "WS_Factorial", Factorial );</span>
WS_Factorial is already installed. Do you want to reinstall it [y/n]? y
InstallSCSCPprocedure : procedure WS_Factorial reinstalled.
</pre></div>
<p>Finally, some examples of various combinations of optional arguments:</p>
<div class="example"><pre>
InstallSCSCPprocedure( "WS_Phi", Phi, "Euler's totient function, see ?Phi in GAP", 1, 1 );
InstallSCSCPprocedure( "GroupIdentificationService",
IdGroupByGenerators, 1, infinity, rec() );
InstallSCSCPprocedure( "IdGroup512ByCode", IdGroup512ByCode, 1 );
InstallSCSCPprocedure( "WS_IdGroup", IdGroup, "See ?IdGroup in GAP" );
</pre></div>
<p>Note that it is quite acceptable to overstate the signature of the procedure and use only mandatory arguments in a call to <code class="func">InstallSCSCPprocedure</code>, which will be installed then as a procedure that can accept arbitrary number of arguments encoded without any restrictions on <strong class="pkg">OpenMath</strong> symbols used, because anyway the <strong class="pkg">GAP</strong> system will return an error in case of the wrong number or type of arguments, though it might be a good practice to give a way to the client to get more precise procedure description a priori, that is before sending request. See <a href="chap5.html#X789962C579109D8F"><span class="RefLink">5.3</span></a> about utilities for obtaining such information about the <strong class="pkg">SCSCP</strong> service.</p>
<p>Some more examples of installation of SCSCP procedures are given in the file <code class="file">scscp/example/myserver.g</code>.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ OMsymRecord</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>This is the global record from the <strong class="pkg">OpenMath</strong> package used for the conversion from <strong class="pkg">OpenMath</strong> to <strong class="pkg">GAP</strong>. It is extended in the <strong class="pkg">SCSCP</strong> package by adding support for symbols from <code class="code">scscp1</code> and <code class="code">scscp2</code> content dictionaries (<a href="chapBib.html#biBscscp1cd">[FHK+a]</a>, <a href="chapBib.html#biBscscp2cd">[FHK+c]</a>). Additionally, <code class="func">InstallSCSCPprocedure</code> (<a href="chap5.html#X8031C2F4787E0C1A"><span class="RefLink">5.1-1</span></a>) adds to this record a component corresponding to the appropriate transient content dictionary (by default, <code class="code">scscp_transient_1</code>) defining mappings between <strong class="pkg">OpenMath</strong> symbols from this content dictionary and installed <strong class="pkg">SCSCP</strong> procedures.</p>
<p>Will start the <strong class="pkg">SCSCP</strong> server at port given by the integer <var class="Arg">port</var>. The first parameter <var class="Arg">servertype</var> is either <code class="keyw">true</code>, <code class="keyw">false</code> or a string containing the server hostname:</p>
<ul>
<li><p>when <var class="Arg">servertype</var> is <code class="keyw">true</code>, the server will be started in a <q>universal</q> mode and will accept all incoming connections;</p>
</li>
<li><p>when <var class="Arg">servertype</var> is <code class="keyw">false</code>, the server will be started at <code class="file">localhost</code> and will not accept any incoming connections from outside;</p>
</li>
<li><p>when <var class="Arg">servertype</var> is a string, for example, <code class="file">"scscp.gap-system.org"</code>, the server will be accessible only by specified server name (this may be useful to manage accessibility if, for example, the hardware has several network interfaces).</p>
</li>
</ul>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">RunSCSCPserver( "localhost", 26133 );</span>
Ready to accept TCP/IP connections at localhost:26133 ...
Waiting for new client connection at localhost:26133 ...
</pre></div>
<p>Actually, there is more than one way to run <strong class="pkg">GAP</strong> <strong class="pkg">SCSCP</strong> server:</p>
<ul>
<li><p>from the <strong class="pkg">GAP</strong> session as shown in the example above;</p>
</li>
<li><p>starting <strong class="pkg">GAP</strong> as <code class="code">gap myserver.g</code>, where <code class="file">myserver.g</code> is the server configuration file with the last command being the call <code class="func">RunSCSCPserver</code>, which may take its arguments from the configuration file <code class="file">scscp/config.g</code> (an example of such configuration file is given in <code class="file">scscp/example/myserver.g</code> );</p>
</li>
<li><p>start <strong class="pkg">GAP</strong> as a daemon using the script <code class="file">gapd.sh</code> which is supplied in the root directory of the package (for the description of all available options see comments in <code class="file">gapd.sh</code>) and may overwrite parameters from <code class="file">scscp/config.g</code>.</p>
</li>
</ul>
<p>See Section <a href="chap2.html#X878084B083D5217F"><span class="RefLink">2.2</span></a> about configuring files <code class="file">config.g</code> and <code class="file">gapd.sh</code>.</p>
<p>Returns the record with three components containing strings with the name, version and description of the service as specified by the service provider in the <code class="file">scscp/config.g</code> (for details about configuration files, see <a href="chap2.html#X878084B083D5217F"><span class="RefLink">2.2</span></a>).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">GetServiceDescription( "localhost", 26133 );</span>
rec(
description := "Started with the configuration file scscp/example/myserver.g\
on Thu 16 Feb 2017 16:03:56 GMT", service_name := "GAP SCSCP service",
version := "GAP 4.8.6 + SCSCP 2.2.1" )
<p>Returns the record with components corresponding to content dictionaries. The name of each component is the name of the content dictionary, and its the value is either a boolean or a list of strings. In case it's value is a list, it contains names of symbols from the corresponding content dictionary which are allowed to appear as a head symbol (i.e. the first child of the outermost <OMA>) in an SCSCP procedure call to the SCSCP server running at server:port. If it's value is <code class="keyw">true</code>, it means the server allows all symbols from the corresponding content dictionary.</p>
<p>Note that it is acceptable (although not quite desirable) for a server to <q>overstate</q> the set of symbols it accepts and use standard <strong class="pkg">OpenMath</strong> errors to reject requests later.</p>
<p>Checks whether the <strong class="pkg">OpenMath</strong> symbol <var class="Arg">cd</var><code class="code">.</code><var class="Arg">symbol</var>, which may be a symbol from a standard or transient <strong class="pkg">OpenMath</strong> content dictionary, is allowed to appear as <q>head</q> symbol (i.e. the first child of the outermost <code class="code"><OMA></code> in an <strong class="pkg">SCSCP</strong> procedure call to the <strong class="pkg">SCSCP</strong> server running at <var class="Arg">server</var><code class="code">:</code><var class="Arg">port</var>. This enables the client to check whether a particular symbol is allowed without requesting the full list of symbols.</p>
<p>Also, it is acceptable (although not necessarily desirable) for a server to <q>overstate</q> the set of symbols it accepts and use standard <strong class="pkg">OpenMath</strong> errors to reject requests later.</p>
<p>Returns a record with the transient content dictionary <var class="Arg">transient_cd</var> from the <strong class="pkg">SCSCP</strong> server running at <var class="Arg">server</var><code class="code">:</code><var class="Arg">port</var>. Names of components of this record correspond to symbols from the <code class="code">meta</code> content dictionary.</p>
<p>By default, the name of the transient content dictionary for the <strong class="pkg">GAP</strong> <strong class="pkg">SCSCP</strong> server is <code class="code">scscp_transient_1</code>. Other systems may use transient content dictionaries with another names, which, however, must always begin with <code class="code">scscp_transient_</code> and may be guessed from the output of <code class="func">GetAllowedHeads</code> (<a href="chap5.html#X7F387F3681775177"><span class="RefLink">5.3-2</span></a>).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">GetTransientCD( "scscp_transient_1", "localhost", 26133 );</span>
rec( CDDate := "2017-02-08",
CDDefinitions :=
[ rec( Description := "Size is currently undocumented.", Name := "Size" ),
rec( Description := "Length is currently undocumented.",
Name := "Length" ),
rec( Description := "NrConjugacyClasses is currently undocumented.",
Name := "NrConjugacyClasses" ),
...
rec( Description := "MatrixGroup is currently undocumented.",
Name := "MatrixGroup" ) ], CDName := "scscp_transient_1",
CDReviewDate := "2017-02-08", CDRevision := "0", CDStatus := "private",
CDVersion := "0",
Description := "This is a transient CD for the GAP SCSCP service" )
<p>Returns a record with the signature of the <strong class="pkg">OpenMath</strong> symbol <var class="Arg">transientcd</var><code class="code">.</code><var class="Arg">symbol</var> from a transient <strong class="pkg">OpenMath</strong> content dictionary. This record contains components corresponding to the <strong class="pkg">OpenMath</strong> symbol whose signature is described, the minimal and maximal number of its children (that is, of its arguments), and symbols which may be used in the <strong class="pkg">OpenMath</strong> encoding of its children. Note that it is acceptable for a symbol from a transient content dictionary to overstate the set of symbols which may occur in its children using the <code class="code">scscp2.symbol_set_all</code> symbol, and use standard <strong class="pkg">OpenMath</strong> errors to reject requests later, like in the example below: using such approach, the procedure <code class="code">WS_Factorial</code> is defined to accept not only immediate <code class="code"><OMI></code> objects but anything which could be evaluated to an integer.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">GetSignature("scscp_transient_1","WS_Factorial","localhost",26133);</span>
rec( maxarg := 1, minarg := 1,
symbol := rec( cd := "scscp_transient_1", name := "WS_Factorial" ),
symbolargs := rec( cd := "scscp2", name := "symbol_set_all" ) )
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.