コード例 #1
0
        static void MyOutputEventCallback(IntPtr callbackData, IntPtr agentPtr, String commandName, IntPtr outputWME)
        {
            // Retrieve the original object reference from the GCHandle which is used to pass the value safely to and from C++ (unsafe/unmanaged) code.
            sml.Agent agent = (sml.Agent)((GCHandle)agentPtr).Target;

            // Retrieve arbitrary data from callback data object (note data here can be null, but the wrapper object callbackData won't be so this call is safe)
            // This field's usage is up to the user and passed in during registation call and passed back here.  Can be used to provide context.
            Object userData = (Object)((GCHandle)callbackData).Target;

            // Retrieve the wme.  We don't own this object, so to keep it we'd need to copy it (or its contents).
            // This way when C# deallocated the object the underlying C++ object isn't deleted either (which is correct as the corresponding C++ code
            // doesn't pass ownership in the equivalent callback either).
            sml.WMElement wme = (sml.WMElement)((GCHandle)outputWME).Target;

            String id  = wme.GetIdentifier().GetIdentifierSymbol();
            String att = wme.GetAttribute();
            String val = wme.GetValueAsString();

            System.Console.Out.WriteLine("Output received under ^move attribute for agent " + agent.GetAgentName() + " output wme " + id + " ^" + att + " " + val);
        }
コード例 #2
0
        static void MyOutputNotificationCallback(IntPtr callbackData, IntPtr agentPtr)
        {
            // Retrieve the original object reference from the GCHandle which is used to pass the value safely to and from C++ (unsafe/unmanaged) code.
            sml.Agent agent = (sml.Agent)((GCHandle)agentPtr).Target;

            // Retrieve arbitrary data from callback data object (note data here can be null, but the wrapper object callbackData won't be so this call is safe)
            // This field's usage is up to the user and passed in during registation call and passed back here.  Can be used to provide context.
            Object userData = (Object)((GCHandle)callbackData).Target;

            System.Console.Out.WriteLine("Agent " + agent.GetAgentName() + " has just received some output");

            for (int i = 0; i < agent.GetNumberOutputLinkChanges(); i++)
            {
                sml.WMElement wme = agent.GetOutputLinkChange(i);
                System.Console.Out.WriteLine("Output wme was " + wme.GetIdentifier().GetIdentifierSymbol() + " ^" + wme.GetAttribute() + " " + wme.GetValueAsString());
            }
        }