Command Submissions

Purpose of Command Submission Client

This example illustrates a client that submits a command to a host system in response to an attribute change event.

Code

using System;
using Spo.SPDlib;
using System.Windows.Forms;
namespace ExamplesOfAPIUsage
{
    class MyAlertPrgram
    {
        // create a SPD class instance
        static SPD m_spd = new SPD();
        // Additional class member attributes declaration...
        [STAThread]
        static void Main(string[] args)
        {
            // Initialize the API.
            // Application name = "command submission example"
            // No application qualifier.
            m_spd.SPDInitClient("command submission example", null);
            // Register a callback to handle attribute change events.
            // No passback data is specified.
            m_spd.SPDHandleEvent(SPD.SPD_eventType.SPD_attributeChangeEvent, 
               new SPD.SPD_eventCallback(attributeChangeEventCB), null);
            // Client enters event processing
            Application.Run();
        } // function: Main
        // Callback that handles attribute change events
        static void attributeChangeEventCB(SPD.SPD_eventType type, 
           SPD.SPD_event this_event, object passback)
        {
            //////string traceMsg;
            // Handle attribute change events
            if (type == SPD.SPD_eventType.SPD_attributeChangeEvent)
            {
                // Determine if attribute change means a command should be sent.
                // Following is an example to get access to attribute and attribute
                // values for attribute change event report.
                for (int naix = 0; naix < this_event.variableCount; naix++)
                {
                    // Go thru the attribute list and determine if a command should
                    // be send. To get access to attribute and attribute values, do:
                    //    this_event.variableData[naix].attribute == <attr>
                    //    this_event.variableData[naix].attr_value == <value>
                }
                // Send a command to the host that reported the attribute change.  
                // Register callback for command ack.
                m_spd.SPDCommand("host", "who, "who", null, new 
                   SPD.SPD_commandCallback(commandEventCB), null, null, null, null);
            } // attribute change event
            else
            {
                // Process other event types (or error if none registered)
            } // not attribute change event
        } // function: alarmEventCB
        // callback that handles command acknowledgement
        static void commandEventCB(string host_class, string host, string command, 
           object reserveValue, SPD.SPD_commandStatusType status, object passback)
        {
            switch (status)
            {
                case SPD.SPD_commandStatusType.SPD_commandSuccess:
                    // command was submitted
                    break;
                case SPD.SPD_commandStatusType.SPD_unknownHost:
                case SPD.SPD_commandStatusType.SPD_unreachableHost:
                    // something went wrong - command did not make it 
                    break;
            } // end of switch
        } // function: commandEventCB
    }// class: MyProgram
}// namespace: ClientSampleProgram

Data Flow Diagram

This illustration shows the flow of information for the command submission client.