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 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
|
###########################################################################
##
#W utils.g The SCSCP package Alexander Konovalov
#W Steve Linton
##
###########################################################################
###########################################################################
##
## DateISO8601
##
## <#GAPDoc Label="DateISO8601">
## <ManSection>
## <Func Name="DateISO8601" Arg=""/>
## <Returns>
## string
## </Returns>
## <Description>
## Returns the current date in the ISO-8601 YYYY-MM-DD format.
## This is an internal function of the package which is used
## by the &SCSCP; server to generate the transient content
## dictionary, accordingly to the definition of the &OpenMath;
## symbol <C>meta.CDDate</C>.
## <Log>
## <![CDATA[
## gap> DateISO8601();
## "2017-02-05"
## ]]>
## </Log>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
BindGlobal( "DateISO8601", function()
local s, date;
s := IO_Popen("date", [ "+%y-%m-%d" ],"r");
date := IO_ReadLine(s);
IO_Close(s);
return Concatenation( "20", date{[ 1 .. Length(date)-1 ]} );
end);
###########################################################################
##
## CurrentTimestamp
##
## <#GAPDoc Label="CurrentTimestamp">
## <ManSection>
## <Func Name="CurrentTimestamp" Arg="" />
## <Returns>
## string
## </Returns>
## <Description>
## Returns the result of the call to <File>date</File>.
## This is an internal function of the package which is
## used to add the timestamp to the &SCSCP; service description.
## <Log>
## <![CDATA[
## gap> CurrentTimestamp();
## "Tue 30 Jan 2017 11:19:38 BST"
## ]]>
## </Log>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
BindGlobal( "CurrentTimestamp", function()
local s, date;
s := IO_Popen("date", [ ], "r");
date := IO_ReadLine(s);
IO_Close(s);
return date{[ 1 .. Length(date)-1 ]};
end);
###########################################################################
##
## Hostname
##
## <#GAPDoc Label="Hostname">
## <ManSection>
## <Func Name="Hostname" Arg=""/>
## <Returns>
## string
## </Returns>
## <Description>
## Returns the result of the call to <File>hostname</File>. This function
## may be used in the configuration file <File>scscp/config.g</File>
## to specify that the default hostname which will be used by the &SCSCP;
## server will be detected automatically using <File>hostname</File>.
## <Log>
## <![CDATA[
## gap> Hostname();
## "scscp.gap-system.org"
## ]]>
## </Log>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
BindGlobal( "Hostname", function()
local s, hostname;
s := IO_Popen("hostname",[],"r");
hostname := IO_ReadLine(s);
IO_Close(s);
return hostname{[ 1 .. Length(hostname)-1 ]};;
end);
###########################################################################
##
## MemoryUsageByGAPinKbytes
##
## <#GAPDoc Label="MemoryUsageByGAPinKbytes">
## <ManSection>
## <Func Name="MemoryUsageByGAPinKbytes" Arg=""/>
## <Returns>
## integer
## </Returns>
## <Description>
## Returns the current volume of the memory used by &GAP; in kylobytes.
## This is equivalent to calling <File>ps -p <PID> -o vsz</File>, where
## <C><PID></C> is the process ID of the &GAP; process. This is an
## internal function of the package which is used by the &SCSCP; server to
## report its memory usage in the <C>info_memory</C> attribute when being
## called with the option <C>debuglevel=2</C> (see options in
## <Ref Func="EvaluateBySCSCP" /> and <Ref Func="NewProcess" />).
## <Log>
## <![CDATA[
## gap> MemoryUsageByGAPinKbytes();
## 649848
## ]]>
## </Log>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
BindGlobal( "MemoryUsageByGAPinKbytes", function()
local s, mem;
s := IO_Popen( "ps", [ "-p", String( IO_getpid() ), "-o", "vsz" ], "r");
IO_ReadLine(s);
mem := IO_ReadLine(s);
IO_Close(s);
RemoveCharacters( mem, " \n" );
return Int(mem);
end);
###########################################################################
##
## LastReceivedCallID
##
## <#GAPDoc Label="LastReceivedCallID">
## <ManSection>
## <Func Name="LastReceivedCallID" Arg=""/>
## <Returns>
## string
## </Returns>
## <Description>
## Returns the call ID contained in the most recently received message.
## It may contain some useful debugging information; in particular, the
## call ID for the &GAP; &SCSCP; client and server contains colon-separated
## server name, port number, process ID and a random string.
## <Log>
## <![CDATA[
## gap> LastReceivedCallID();
## "scscp.gap-system.org:26133:77372:choDZBgA"
## ]]>
## </Log>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
BindGlobal( "LastReceivedCallID", function()
return OMTempVars.OMATTR.content[2].content[1].content;
end);
###########################################################################
##
## IO_PickleToString
##
## <#GAPDoc Label="IO_PickleToString">
## <ManSection>
## <Func Name="IO_PickleToString" Arg="obj"/>
## <Returns>
## string containing "pickled" object
## </Returns>
## <Description>
## This function "pickles" or "serialises" the object <A>obj</A> using the
## operation <Ref BookName="IO" Oper="IO_Pickle" /> from the &IO; package,
## and writes it to a string, from which it could be later restored using
## <Ref Func="IO_UnpickleFromString" />. This provides a way to design
## &SCSCP; procedures which transmit &GAP; objects in the "pickled" format
## as &OpenMath; strings, which may be useful for objects which may be
## "pickled" by the &IO; package but can not be converted to &OpenMath;
## or for which the "pickled" representation is more compact or can be
## encoded/decoded much faster.
## <P/>
## See <Ref BookName="IO" Oper="IO_Pickle" /> and <Ref
## BookName="IO" Oper="IO_Unpickle" /> for more details.
## <Example>
## <![CDATA[
## gap> f := IO_PickleToString( GF( 125 ) );
## "FFIEINTG\>15INTG\>13FAIL"
## ]]>
## </Example>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
BindGlobal( "IO_PickleToString", function( obj )
local rb, wb, s;
rb:="";
wb:="";
s:=IO_WrapFD(-1,rb,wb);
IO_Pickle( s, obj );
IO_Close( s );
return wb;
end);
###########################################################################
##
## IO_UnpickleFromString
##
## <#GAPDoc Label="IO_UnpickleFromString">
## <ManSection>
## <Func Name="IO_UnpickleFromString" Arg="s"/>
## <Returns>
## "unpickled" GAP object
## </Returns>
## <Description>
## This function "unpickles" the string <A>s</A> which was
## created using the function <Ref Func="IO_PickleToString" />,
## using the operation <Ref BookName="IO" Oper="IO_Unpickle" />
## from the &IO; package. See <Ref Func="IO_PickleToString" />
## for more details and suggestions about its usage.
## <Example>
## <![CDATA[
## gap> IO_UnpickleFromString( f );
## GF(5^3)
## gap> f = IO_UnpickleFromString( IO_PickleToString( f ) );
## true
## ]]>
## </Example>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
BindGlobal( "IO_UnpickleFromString", function( str )
local rb, wb, s, r;
rb:=str;
wb:="";
s:=IO_WrapFD(-1,rb,wb);
r:=IO_Unpickle( s );
IO_Close( s );
return r;
end);
##########################################################################
##
## SwitchSCSCPmodeToBinary
##
## <#GAPDoc Label="SwitchSCSCPmodeToBinary">
## <ManSection>
## <Func Name="SwitchSCSCPmodeToBinary" Arg=""/>
## <Func Name="SwitchSCSCPmodeToXML" Arg=""/>
## <Returns>
## nothing
## </Returns>
## <Description>
## The &OpenMath; package supports both binary and XML encodings for
## &OpenMath;. To switch between them, use
## <Ref Func="SwitchSCSCPmodeToBinary"/> and
## <Ref Func="SwitchSCSCPmodeToXML"/>.
## When the package is loaded, the mode is initially set to XML.
## On the clients's side, you can change the mode back and forth as
## many times as you wish during the same &SCSCP; session. The server
## will autodetect the mode and will response in the same format, so
## one does not need to set the mode on the server's side.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
BindGlobal( "SwitchSCSCPmodeToBinary", function( )
IN_SCSCP_BINARY_MODE := true;
end);
BindGlobal( "SwitchSCSCPmodeToXML", function( )
IN_SCSCP_BINARY_MODE := false;
end);
###########################################################################
##
#E
##
|