Run (Daemon function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 18: Line 18:
<p>Because <var class="term">objectObj</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>
<p>Because <var class="term">objectObj</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>
<tr><th><var>Info</var></th>
<tr><th><var>Info</var></th>
<td>An optional, but <var>[[Methods#Named parameters|Name-Required]]</var>, 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 class="term">Info</var> must be deep copyable, as described in: [[Copying objects|"Copying objects"]]. The object set to <var class="term">Info</var> is the object passed by the daemon thread using <var>[[ReturnInfoObject (Daemon subroutine)|ReturnInfoObject]]</var>.
<td>An optional, but <var>[[Methods#Named parameters|name required]]</var>, 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 class="term">Info</var> must be deep copyable, as described in: [[Copying objects|"Copying objects"]]. The object set to <var class="term">Info</var> is the object passed by the daemon thread using <var>[[ReturnInfoObject (Daemon subroutine)|ReturnInfoObject]]</var>.
<p>Because <var class="term">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. This parameter is only available in <var class="product">[[Sirius Mods|Sirius Mods]]</var> Version 6.8 and later.</p>
<p>Because <var class="term">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. This parameter is only available in <var class="product">[[Sirius Mods|Sirius Mods]]</var> Version 6.8 and later.</p>
<p>For an example of how to use this parameter, see the bottom of the "Usage Notes," below.</p></td></tr>
<p>For an example of how to use this parameter, see the bottom of the "Usage Notes," below.</p></td></tr>

Revision as of 19:37, 4 May 2011

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 previously defined Daemon object.
commands A string or Stringlist that is the required command, or the set of commands, to be executed by the daemon.
inputObj The input 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: "Copying objects". The passed object can be retrieved by the daemon thread using GetInputObject.
outputObj The output 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: "Copying objects". The object set to "Copying objects" is the object passed by the daemon thread using ReturnObject

Because objectObj 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, but 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, as described in: "Copying objects". 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. 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.

Exceptions

This function can throw the following exceptions:

DaemonLost
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.

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 Run invocation requires an additional argument (represented in the Run method syntax by outputObj), compatible with the ReturnObject argument. "A Daemon example" shows the passing of input and output objects between a master and daemon.

Example

  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,,%sorted) for each record in %Sorted 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