static void MyAgentEventCallback(sml.smlAgentEventId eventID, IntPtr callbackData, IntPtr kernelPtr, String agentName) { // Retrieve the original object reference from the GCHandle which is used to pass the value safely to and from C++ (unsafe/unmanaged) code. sml.Kernel kernel = (sml.Kernel)((GCHandle)kernelPtr).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; // This callback returns the name of the agent as a string, to avoid having SWIG have to lookup the C# agent object // and pass that back. We do something similar in Java for the same reasons. sml.Agent agent = kernel.GetAgent(agentName); if (agent == null) { throw new Exception("Error looking up agent in callback"); } System.Console.Out.WriteLine(eventID + " agent " + agentName + " with user data " + userData); }
static String MyTestRhsFunction(sml.smlRhsEventId eventID, IntPtr callbackData, IntPtr kernelPtr, String agentName, String functionName, String argument) { // Retrieve the original object reference from the GCHandle which is used to pass the value safely to and from C++ (unsafe/unmanaged) code. sml.Kernel kernel = (sml.Kernel)((GCHandle)kernelPtr).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; // This callback returns the name of the agent as a string, to avoid having SWIG have to lookup the C# agent object // and pass that back. We do something similar in Java for the same reasons. sml.Agent agent = kernel.GetAgent(agentName); if (agent == null) { throw new Exception("Error looking up agent in callback"); } System.Console.Out.WriteLine(eventID + " agent " + agentName + " function " + functionName + " arg " + argument); // This is the result of the RHS function and can be placed into working memory as the result of the call // (whether this happens or not depends on how the RHS function is used in the production rule). return("result"); }