public override void OnError(Connection conn, Message msg, Status status, string event_str) { Status result; GmsecExample myEx = new GmsecExample(); Console.Out.WriteLine("\n-- GMD Message Failure Notification Recieved --"); string tmp; result = msg.GetSubject(out tmp); if (!myEx.checkNoThrow("GetSubject", result)) { return; } Console.Out.WriteLine("GMD failure: " + tmp + " " + status.Get()); //Display recieved GMD Failure Message string xml; result = msg.ToXML(out xml); if (myEx.checkNoThrow("ToXML", result)) { if (xml.Length != 0) { Console.Out.WriteLine(xml); } } }
public override void OnMessage(Connection conn, Message message) { //Check For Request GMSECMsgKindDefs kind; message.GetKind(out kind); if (kind == GMSECMsgKindDefs.REQUEST) { Message reply; Status result; string xml; GmsecExample myEx = new GmsecExample(); //Construct Reply Subject Field msg_fld; message.GetField("COMPONENT", out msg_fld); string comp_name; msg_fld.GetValue(out comp_name); Field id_fld; message.GetField("MSG_ID", out id_fld); string msg_id; id_fld.GetValue(out msg_id); string statusCode = "1"; string subjectReply = "GMSEC.MISSION.SAT_ID.RESP." + comp_name + "." + msg_id + "." + statusCode; //Create Reply result = conn.CreateMessage(subjectReply, GMSECMsgKindDefs.REPLY, out reply); myEx.check("CreateMessage", result); //Add Fields Field fd = new Field(); fd.SetName("COMPONENT"); fd.SetValue("gmrpl_cb"); result = reply.AddField(fd); myEx.check("AddField(COMPONENT)", result); fd.SetName("ANSWER"); fd.SetValue("Sure looks like it"); result = reply.AddField(fd); myEx.check("AddField(ANSWER)", result); //Dump Reply result = reply.ToXML(out xml); myEx.check("ToXML", result); Console.Out.WriteLine("[RequestCallback::OnMessage] Sending Reply:\n" + xml); //Send Reply result = conn.Reply(message, reply); myEx.check("Reply Sent", result); } }
private void OnMessageAux(Connection conn, Message message) { Status result; Field tempField; Message replyMessage; Message logMessage; string subject; GMSECMsgKindDefs msgKind; string tempString; GmsecExample myEx = new GmsecExample(); /* We don't care about anything but request messages */ message.GetKind(out msgKind); if (msgKind != GMSECMsgKindDefs.REQUEST) { return; } /* Obtain the DIRECTIVE-KEYWORD field from the message. It holds the request count. */ message.GetField("DIRECTIVE-KEYWORD", out tempField); tempField.GetValue(out tempString); /* Copy and output the request number which has been placed in the DIRECTIVE-KEYWORD field */ Console.Out.WriteLine("\n\nReceived Request (" + tempString + "): " + DateTime.Now.ToString()); /* Create a generic message container for the directive response message */ result = conn.CreateMessage(out replyMessage); myEx.check("CreateMessage", result); /* Find and load the config file directive response message definition */ result = cfgFile.LookupMessage("DIRECTIVE-RESPONSE", replyMessage); myEx.check("LookupMessage", result); /* Replace the DATA field with the request number we are responding to */ tempField.SetType(GMSECTypeDefs.STRING); tempField.SetName("DATA"); tempField.SetValue(tempString); result = replyMessage.AddField(tempField); myEx.check("AddField", result); /* Replace the TIME-COMPLETE field with the correct time */ tempField.SetType(GMSECTypeDefs.STRING); tempField.SetName("TIME-COMPLETED"); tempField.SetValue(DateTime.Now.ToString()); result = replyMessage.AddField(tempField); myEx.check("AddField", result); /* Set the reply subject to the request message's subject */ message.GetSubject(out subject); replyMessage.SetSubject(subject); /* Send the reply */ result = conn.Reply(message, replyMessage); myEx.check("Replying", result); Console.Out.WriteLine("\nReply Sent (" + tempString + "): " + DateTime.Now.ToString()); /* Create a generic message container for the log message */ result = conn.CreateMessage(out logMessage); myEx.check("CreateMessage", result); /* Find and load the config file log message definition */ result = cfgFile.LookupMessage("LOG-REP", logMessage); myEx.check("LookupMessage", result); /* Fill the log message time */ tempField.SetType(GMSECTypeDefs.STRING); tempField.SetName("EVENT-TIME"); tempField.SetValue(DateTime.Now.ToString()); result = logMessage.AddField(tempField); myEx.check("AddField", result); /* Fill the log message message text */ tempField.SetType(GMSECTypeDefs.STRING); tempField.SetName("MSG-TEXT"); tempField.SetValue(tempString); result = logMessage.AddField(tempField); myEx.check("AddField", result); // Publish the log message result = conn.Publish(logMessage); myEx.check("Publish", result); /* Clean up */ conn.DestroyMessage(logMessage); conn.DestroyMessage(replyMessage); }
private void OnReplyAux(Connection conn, Message reqMsg, Message rplMsg) { Status result; Field tempField; Message logMessage; short tempStatus; string tempString = ""; GmsecExample myEx = new GmsecExample(); //Get the status of the response (successful, failed, etc) act accordingly result = rplMsg.GetField("RESPONSE-STATUS", out tempField); if (!myEx.checkNoThrow("GetField(RESPONSE-STATUS)", result)) { return; } result = tempField.GetValue(out tempStatus); if (!myEx.checkNoThrow("GetValue(RESPONSE-STATUS)", result)) { return; } switch (tempStatus) { case 1: Console.Out.WriteLine("\nAcknowledgement"); break; case 2: Console.Out.WriteLine("\nWorking/keep alive"); break; case 3: //Obtain the DATA field which was filled with what request this reply //was generated from result = rplMsg.GetField("DATA", out tempField); if (!myEx.checkNoThrow("GetField(DATA)", result)) { return; } result = tempField.GetValue(out tempString); if (!myEx.checkNoThrow("GetValue(DATA", result)) { return; } if (tempString.Length != 0) { //Output that we'v received a reply Console.Out.WriteLine("\nReceived Reply (DATA=" + tempString + "): " + DateTime.Now.ToString()); } break; case 4: Console.Out.WriteLine("\nFailed completion"); break; case 5: Console.Out.WriteLine("\nInvalid Request"); break; default: break; } //Create a generic message container for the log message result = conn.CreateMessage(out logMessage); myEx.check("CreateMessage", result); //Find and load the config file logmessage definition result = cfgFile.LookupMessage("LOG-REQ", logMessage); myEx.check("LookupMessage", result); /* Fill the log message time */ tempField.SetType(GMSECTypeDefs.STRING); tempField.SetName("EVENT-TIME"); tempField.SetValue(DateTime.Now.ToString()); result = logMessage.AddField(tempField); myEx.check("AddField", result); /* Fill the log message message text */ tempField.SetType(GMSECTypeDefs.STRING); tempField.SetName("MSG-TEXT"); tempField.SetValue(tempString); result = logMessage.AddField(tempField); myEx.check("AddField(MSG-TEXT)", result); // Publish the log message result = conn.Publish(logMessage); myEx.check("Publish", result); conn.DestroyMessage(logMessage); }