Run (Daemon function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(35 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Template:Daemon:Run subtitle}}
{{Template:Daemon:Run subtitle}}
<var>Run</var> runs on the daemon thread the command, or set of commands, specified by its first argument, and it returns the terminal output from the command(s).


Run is a member of the [[Daemon class]]
==Syntax==
{{Template:Daemon:Run syntax}}


===Syntax terms===
<table class="syntaxTable">
<tr><th>%sl</th>
<td>If specified, a <var>[[Stringlist class|Stringlist]]</var> object to contain the terminal output from the command, or commands, run on the daemon thread. </td></tr>
 
<tr><th>daemon</th>
<td>A <var>Daemon</var> object expression. </td></tr>
 
<tr><th>commands</th>
<td>A string or <var>Stringlist</var> that is the command, or the set of commands, to be executed by the daemon. </td></tr>
 
<tr><th><var>Input</var></th>
<td>The input object passed to the daemon method object. This optional, [[Methods#Named parameters|name allowed]], argument is passed by deep copy and not by reference, so <var class="term">object</var> must be deep copyable, as described in: [[Copying objects]]. The passed object can be retrieved by the daemon thread using <var>[[GetInputObject (Daemon subroutine)|GetInputObject]]</var>.</td></tr>


This callable method runs on the daemon thread the command or set of commands specified by its first argument, and it returns the terminal output from the command(s).
<tr><th><var>Output</var></th>
<pre>
<td>The output object returned from the daemon method object. This optional, name allowed, argument is passed by deep copy and not by reference, so <var class="term">object</var> must be deep copyable. The object set to <var class="term">object</var> is the object passed by the daemon thread using <var>[[ReturnObject (Daemon subroutine)|ReturnObject]]</var>.
[%strL =] %daem:Run(command, [%inputObj], [%outputObj], -
<p>Because <var class="term">object</var> is an output variable, it cannot itself be contained inside an object: that is, it must be a local or a common %variable. </p></td></tr>
[Info=%infoObj])
</pre>


===Syntax terms===
<tr><th><var>Info</var></th>
<table class="syntaxTable">
<td>An optional, [[Methods#Named parameters|name required]], parameter that indicates a second output object returned from the daemon method object. This optional argument is passed by deep copy and not by reference, so <var>Info</var> must be deep copyable. The object set to <var>Info</var> is the object passed by the daemon thread using <var>[[ReturnInfoObject (Daemon subroutine)|ReturnInfoObject]]</var>.
<tr><th>%strL</th>
<p>Because <var>Info</var> is an output variable, it cannot itself be contained inside an object: that is, it must be a local or a common %variable. </p>
<td>If specified, a Stringlist object that contains the terminal output from the command or commands run on the daemon thread. </td></tr>
<p>For an example of how to use this parameter, see the bottom of [[Run (Daemon function)#Usage notes|Usage Notes]], below.</p></td></tr>
<tr><th>%daem</th>
<td>A previously defined Daemon object. </td></tr>
<tr><th>command</th>
<td>A string or Stringlist that is the required command or the set of commands executed by the daemon. </td></tr>
<tr><th>%inputObj</th>
<td>The object passed to the daemon method object. This optional argument is passed by deep copy and not by reference, so '''%inputObj''' must be deep copyable, as described in :hdref refid=copying.. The passed object can be retrieved by the daemon thread using the GetInputObject method (:hdref refid=getinp.). </td></tr>
<tr><th>%outputObj</th>
<td>The object returned from the daemon method object. This optional argument is passed by deep copy and not by reference, so '''%outputObj''' must be deep copyable, as described in :hdref refid=copying.. The object set to %outputObj is the object passed by the daemon thread using the ReturnObject method (:hdref refid=retnobj.).
  Because '''%outputObj''' is an output variable, it cannot itself be contained inside an object: that is, it must be a local or a common %variable. </td></tr>
<tr><th>Info=%infoObj</th>
<td>An optional, name required parameter that indicates a second output object returned from the daemon method object. This optional argument is passed by deep copy and not by reference, so '''%infoObj''' must be deep copyable, as described in :hdref refid=copying.. The object set to %infoObj is the object passed by the daemon thread using the ReturnInfoObject method (:hdref refid=retnobj.).
  Because '''%infoObj''' is an output variable, it cannot itself be contained inside an object: that is, it must be a local or a common %variable. This parameter is only available in ''[[Sirius Mods]]'' Version 6.8 and later.
  For an example of how to use this parameter, see the bottom of the "Usage Notes," below.</td></tr>
</table>
</table>


==Exceptions==
==Exceptions==
This function can throw the following exception:
<table class="syntaxTable">
<tr><th><var>[[DaemonLost class|DaemonLost]]</var></th>
<td>If the daemon object is lost (probably restarted), a <var>DaemonLost</var> exception is thrown.  </td></tr>
</table>
   
   
This function can throw the following exceptions:<dl>
<dt>DaemonLost
<dd>If the daemon object is lost (probably restarted), a DaemonLost exception is thrown. This exception will only be thrown in ''[[Sirius Mods]]'' Version 7.2 and later. See (:hdref refid=daemlse.).</dl>
==Usage notes==
==Usage notes==
<ul>
<ul>
<li><var>Run</var> sets the output object to Null if the daemon command contains no <var>[[ReturnObject (Daemon subroutine)|ReturnObject]]</var> invocation. Any subsequent master thread references to that object, for example to print it, will cancel the request.
<li>These are example Run calls:
<pre>
%strlist = %daem:run('V UTABLE')
 
%strlist = %daem:run(%list2, %x, %x)
</pre>
<li>The Run method sets the output object to Null if the daemon command contains no ReturnObject (:hdref refid=retnobj.) invocation. Subsequent master thread references to that object, for example to print it, cancel the request.
<li>As any Run method input-object argument, an input "parameter object" is passed by deep copy: the parameter object, all objects contained in that object, all objects contained in those objects, and so on are copied and passed to the sdaemon thread.  


An example of a category of object that may '''not''' be passed to a daemon is a ''[[Janus Sockets]]'' Socket object.
<li>As any Run method input-object argument, an input "parameter object" is passed by deep copy: the parameter object, all objects contained in that object, all objects contained in those objects, and so on are copied and passed to the sdaemon thread.
<li>If a file you want to open on the daemon is already open on the master thread, the Open method (:hdref refid=opndaem.) lets you open the file with the same privileges it had on the master thread.
<p>An example of a category of object that may <b><i>not</i></b> be passed to a daemon is a <var class="product">[[Janus Sockets]]</var> <var>[[Socket class|Socket]]</var> object.</p>
<li>As described in :hdref refid=workdae., Run's Stringlist argument can pass multiple commands to the daemon.


<li>If a file you want to open on the daemon is already open on the master thread, the <var>[[Open (Daemon subroutine)|Open]]</var> method lets you open the file with the same privileges it had on the master thread.


For example, to pass objects of three different classes, as well as float and longstring values to a daemon request, you can create a user class that contains such objects and the appropriate float and longstring values, then pass a "parameter object" of that class, as follows:
<li>As described in [[Daemon class#Working with Daemonobjects|Working with Daemon objects]], <var>Run's</var> <var class="term">commands</var> argument can pass multiple commands to the daemon.
<pre>
<p>For example, to pass objects of three different classes, as well as float and longstring values to a daemon request, you can create a user class that contains such objects and the appropriate float and longstring values, then pass a "parameter object" of that class, as follows:</p>
class Multivar
<p class="code">class Multivar
public
  public
variable a is object a
      variable a is object a
variable b is object b
      variable b is object b
variable c is object c
      variable c is object c
variable y is float
      variable y is float
variable z is longstring
      variable z is longstring
end public
  end public
end class
end class
...
...
%Multi is object Multivar
%multi is object Multivar
%daem is object daemon
%daem is object daemon
...
...
%Multi = new
%multi = new
%Multi:a = %objectA
%multi:a = %objectA
%Multi:b = %objectB
%multi:b = %objectB
%Multi:c = %objectC
%multi:c = %objectC
%Multi:y = 3.1415929
%multi:y = 3.1415929
%Multi:z = %lstrZ
%multi:z = %lstrZ
...
...
%daem:run('I MYPROC', %Multi)
%daem:run('I MYPROC', %Multi)
</pre>
</p>
<p>To make use of the variables passed in the <code>%multi</code> input parameter above:</p>
<ul>
 
<li>The file containing <code>MYPROC</code> must be open on the daemon from an invocation of <var>Run</var> with a <var class="product">Model 204</var> <var>OPEN</var> command argument or from an invocation of <var>[[Open (Daemon subroutine)|Open]]</var>.
<li>The <code>MYPROC</code> procedure must contain an invocation of <var>[[GetInputObject_(Daemon_subroutine)|GetInputObject]]</var>.
</ul>
<p>To return updated values to the master thread above, <code>MYPROC</code> must contain an invocation of <var>[[ReturnObject (Daemon subroutine)|ReturnObject]]</var>, and the <var>Run</var> invocation requires an additional argument (represented in the <var>Run</var> method syntax by the <var>Output</var> argument), compatible with the <var>ReturnObject</var> argument. [[Daemon_class#A_Daemon_example|A Daemon example]] shows the passing of input and output objects between a master and daemon.</p>
</ul>
 
==Examples==
<ol><li>These are simple examples of <var>Run</var> calls:
<p class="code">%strlist = %daem:run('V UTABLE')
 
%strlist = %daem:run(%list2, %x, %x)
</p>
<li>In the following example, a daemon sorts found records, then returns in an object the sorted set of records:
<p class="code">begin
  %findCriteria is string len 255
  %pazuzu is object daemon
  %sSorted is object sortedRecordset in file MYFILE
  %subList is object stringList
  %findCriteria = 'NICKNAME IS LIKE &#39;'SI*&#39;' '
   
   
 
  %subList = new
To make use of the variables passed in the <tt>%Multi</tt> input parameter above:<ul>
  text to %subList
      begin
        %basicSet is object recordSet in file MYFILE
        %sorted is object sortedRecordSet in file MYFILE
        %basicSet = New
        find records to %basicSet
            {%FindCriteria}
        end find
        sort records in %basicSet to %sorted by NICKNAME
        %(daemon):returnObject(%Sorted)
      end
  end text
   
   
<li>The file containing MYPROC must be open on the daemon from an invocation of Run with a ''Model 204'' OPEN command argument or from an invocation of the Open method (:hdref refid=opndaem.).
  %pazuzu = New
<li>The MYPROC procedure must contain an invocation of the GetInputObject method (:hdref refid=getinp.).</ul>
  %pazuzu:run('*LOWER')
  %pazuzu:open('MYFILE')
  %pazuzu:run(%subList,,%sSorted)
   
   
 
  for each record in %sSorted
To return updated values to the master thread above, MYPROC must contain an invocation of ReturnObject (:hdref refid=retnobj.), and the Run method invocation requires an additional argument (represented in the Run method syntax by '''%inputObject'''), compatible with the ReturnObject argument. :hdref refid=quickeg. shows the passing of input and output objects between a master and daemon.
      print '*'
<li>While the optional <tt>Info</tt> object can be used for any kind of output object, its intent is to separate the "true&amp;CQ. output of a daemon request from informational output (return codes, error messages, diagnostics, etc.).  
      pai
 
  end for
 
end
  In the following example, a Stringlist object (presumably containing error messages) is used as the Info output:
</p>
<pre>
<li>While the optional <var>Info</var> object can be used for any kind of output object, its intent is to separate the "true" output of a daemon request from informational output (return codes, error messages, diagnostics, etc.).  In the following example, a <var>Stringlist</var> object (presumably containing error messages) is used as the <var>Info</var> output:
%errors is object stringList
<p class="code">%errors is object stringList
%result is object myClass
%result is object myClass
%daem is object daemon
%daem is object daemon
...
...
%daem:run('MYSUBSYS', , %result, info=%errors)
%daem:run('MYSUBSYS', , %result, info=%errors)
</pre>
</p>
The daemon thread running the request returns the <var>Info</var> object using <var>[[ReturnInfoObject (Daemon subroutine)|ReturnInfoObject]]</var>:
 
<p class="code">%errors is object stringList
 
The daemon thread running the request returns the Info object using the ReturnInfoObject method (:hdref reftxt=ReturnInfoObject refid=retnobj.):
<pre>
%errors is object stringList
...
...
%(daemon):returnInfoObject(%errors)
%(daemon):returnInfoObject(%errors)
</pre>
</p></ol>
</ul>
 
==Example==
 
In the following example, a daemon sorts found records, then returns in an object the sorted set of records:
<pre>
Begin
%FindCriteria is string len 255
%Pazuzu is object Daemon
%Sorted is object SortedRecordset in file MYFILE
%SubList is object stringList
%FindCriteria = 'NICKNAME IS LIKE ''SI*'' '
 
%SubList = new
Text to %SubList
Begin
%BasicSet is object Recordset in file MYFILE
%Sorted is object SortedRecordset in file MYFILE
%BasicSet = New
Find Records to %BasicSet
{%FindCriteria}
End Find
Sort records in %BasicSet to %Sorted by NICKNAME
%(daemon):returnObject(%Sorted)
End
End Text
 
%Pazuzu = New
%Pazuzu:run('*LOWER')
%Pazuzu:open('MYFILE')
%Pazuzu:run(%SubList,,%Sorted)
 
For each record in %Sorted
Print '*'
pai
End For
End
</pre>
 


==See also==
==See also==
{{Template:Daemon:Run footer}}
{{Template:Daemon:Run footer}}

Latest revision as of 10:08, 16 September 2020

Run a set of commands on the Daemon thread (Daemon class)

Run runs on the daemon thread the command, or set of commands, specified by its first argument, and it returns the terminal output from the command(s).

Syntax

[%sl =] daemon:Run( commands, [[Input=] object], [[Output=] object], - [Info= object]) Throws DaemonLost, IncorrectDaemonState

Syntax terms

%sl If specified, a Stringlist object to contain the terminal output from the command, or commands, run on the daemon thread.
daemon A Daemon object expression.
commands A string or Stringlist that is the command, or the set of commands, to be executed by the daemon.
Input The input object passed to the daemon method object. This optional, name allowed, argument is passed by deep copy and not by reference, so object must be deep copyable, as described in: Copying objects. The passed object can be retrieved by the daemon thread using GetInputObject.
Output The output object returned from the daemon method object. This optional, name allowed, argument is passed by deep copy and not by reference, so object must be deep copyable. The object set to object is the object passed by the daemon thread using ReturnObject.

Because object is an output variable, it cannot itself be contained inside an object: that is, it must be a local or a common %variable.

Info An optional, name required, parameter that indicates a second output object returned from the daemon method object. This optional argument is passed by deep copy and not by reference, so Info must be deep copyable. The object set to Info is the object passed by the daemon thread using ReturnInfoObject.

Because Info is an output variable, it cannot itself be contained inside an object: that is, it must be a local or a common %variable.

For an example of how to use this parameter, see the bottom of Usage Notes, below.

Exceptions

This function can throw the following exception:

DaemonLost If the daemon object is lost (probably restarted), a DaemonLost exception is thrown.

Usage notes

  • Run sets the output object to Null if the daemon command contains no ReturnObject invocation. Any subsequent master thread references to that object, for example to print it, will cancel the request.
  • As any Run method input-object argument, an input "parameter object" is passed by deep copy: the parameter object, all objects contained in that object, all objects contained in those objects, and so on are copied and passed to the sdaemon thread.

    An example of a category of object that may not be passed to a daemon is a Janus Sockets Socket object.

  • If a file you want to open on the daemon is already open on the master thread, the Open method lets you open the file with the same privileges it had on the master thread.
  • As described in Working with Daemon objects, Run's commands argument can pass multiple commands to the daemon.

    For example, to pass objects of three different classes, as well as float and longstring values to a daemon request, you can create a user class that contains such objects and the appropriate float and longstring values, then pass a "parameter object" of that class, as follows:

    class Multivar public variable a is object a variable b is object b variable c is object c variable y is float variable z is longstring end public end class ... %multi is object Multivar %daem is object daemon ... %multi = new %multi:a = %objectA %multi:b = %objectB %multi:c = %objectC %multi:y = 3.1415929 %multi:z = %lstrZ ... %daem:run('I MYPROC', %Multi)

    To make use of the variables passed in the %multi input parameter above:

    • The file containing MYPROC must be open on the daemon from an invocation of Run with a Model 204 OPEN command argument or from an invocation of Open.
    • The MYPROC procedure must contain an invocation of GetInputObject.

    To return updated values to the master thread above, MYPROC must contain an invocation of ReturnObject, and the Run invocation requires an additional argument (represented in the Run method syntax by the Output argument), compatible with the ReturnObject argument. A Daemon example shows the passing of input and output objects between a master and daemon.

Examples

  1. These are simple examples of Run calls:

    %strlist = %daem:run('V UTABLE') %strlist = %daem:run(%list2, %x, %x)

  2. In the following example, a daemon sorts found records, then returns in an object the sorted set of records:

    begin %findCriteria is string len 255 %pazuzu is object daemon %sSorted is object sortedRecordset in file MYFILE %subList is object stringList %findCriteria = 'NICKNAME IS LIKE ''SI*'' ' %subList = new text to %subList begin %basicSet is object recordSet in file MYFILE %sorted is object sortedRecordSet in file MYFILE %basicSet = New find records to %basicSet {%FindCriteria} end find sort records in %basicSet to %sorted by NICKNAME  %(daemon):returnObject(%Sorted) end end text %pazuzu = New %pazuzu:run('*LOWER') %pazuzu:open('MYFILE') %pazuzu:run(%subList,,%sSorted) for each record in %sSorted print '*' pai end for end

  3. While the optional Info object can be used for any kind of output object, its intent is to separate the "true" output of a daemon request from informational output (return codes, error messages, diagnostics, etc.). In the following example, a Stringlist object (presumably containing error messages) is used as the Info output:

    %errors is object stringList %result is object myClass %daem is object daemon ... %daem:run('MYSUBSYS', , %result, info=%errors)

    The daemon thread running the request returns the Info object using ReturnInfoObject:

    %errors is object stringList ... %(daemon):returnInfoObject(%errors)

See also