Possible mistakes:
1) I think you have fromAdmin()
/toAdmin()
backward. toAdmin()
is called on outgoing admin messages, fromAdmin()
is called on incoming. For the Initiator, you must set the fields within the toAdmin()
callback. Your Acceptor will check the user/pass in fromAdmin()
.
2) Are you trying to dynamic_cast
without first checking to see if it was a Logon message? The toAdmin()
callback handles all admin messages; the message could be a Heartbeat, Logon, Logout, etc. That might explain your cast error.
As to what the code should look like, my C++ is rusty, but the basic pattern is this:
void YourMessageCracker::toAdmin( FIX::Message& message, const FIX::SessionID& sessionID)
{
if (FIX::MsgType_Logon == message.getHeader().getField(FIX::FIELD::MsgType))
{
FIX44::Logon& logon_message = dynamic_cast<FIX44::Logon&>(message);
logon_message.setField(FIX::Username("my_username"));
logon_message.setField(FIX::Password("my_password"));
}
}
From there, I think you can see how you'd write a similar fromAdmin()
where you'd get the fields instead of setting them.
The above uses hard-coded user/pass, but you probably want to pull it from the config file. I think your calls to session_settings.getString(str)
are correct for that.
(Please forgive any coding errors. I'm much more fluent in the Java/C# versions of the QF engine, though the basic principles are the same.)
I see that your first web reference uses the FIELD_GET_REF
macro. It may be better than message.getHeader().getField()
, but I'm not familiar with it.
EDIT: I hope you didn't start reading this until I finished my 45 edits of it. I think it's good now.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…