0

I am working on implementing Initiator side for a broker FIX platform using QuickFix in C++. Their FIX spec provides the list of messages they support; Logon, Heartbeat and other messages.

MessageCracker (Fix 4.2) provides two overloads for same type. For example

virtual void onMessage( ResendRequest&, const FIX::SessionID& ) {}

and

virtual void onMessage( const ResendRequest&, const FIX::SessionID& ) {}

Edit: I have a class that is derived from Application and MessageCracker and it calls crack(FIX::Message&) from within toAdmin() that results in calling onMessage() (the version without const).

My confusion was related to the point that which version of onMessage() I should be overriding? The one with const FIX::Message& or the other?

MaLoad
  • 3
  • 4

2 Answers2

3
virtual void onMessage( const ResendRequest&, const FIX::SessionID& )

The crack passes the const reference, so the above function will be invoked. Moreover you shouldn't be changing the received FIX message, unless you have very specific needs. onMessage is for receiving messages, not sending.

DumbCoder
  • 5,696
  • 3
  • 29
  • 40
2

I understand that first one is for sending and second one is for receiving.

That's totally wrong. Neither are for sending.

To be honest, I'm not sure why both exist, but I'd use the const version, as DumbCoder suggests. There's not really any good reason to modify the received message.

And another note, because your intentions are not clear in your question:
Don't implement OnMessage for admin messages (e.g. Login, Heartbeat, etc.). If you need to react to those (and you probably don't), use the FromAdmin() callback.

Grant Birchmeier
  • 17,809
  • 11
  • 63
  • 98
  • The quickfix page says _toAdmin provides you with a peak at the administrative messages that are being sent from your FIX engine to the counter party. This is normally not useful for an application however it is provided for any logging you may wish to do. Notice that the FIX::Message is not const. This allows you to add fields to an adminstrative message before it is sent out._ The crack version without const call onMessage without const, thats why I assumed the first overload is for modifying Fix message before it is sent out. – MaLoad Apr 10 '14 at 15:00
  • An possible example is may be for logon message. Its possible to use `logon.setField()` to add username and password in `onMessage(Logon&)` before logon is sent out. – MaLoad Apr 10 '14 at 15:03
  • 1
    @MaLoad - onMessage as it's name suggests means only on receiving a message, not sending a message. You use `sendToTarget` to send messages. You are doing something weird. Could you post some example whcih you are doing for us to make sense out of it. – DumbCoder Apr 10 '14 at 15:33
  • Thanks both of you for your replies, I have tried to explain a bit by editing my question. – MaLoad Apr 11 '14 at 08:04
  • 1
    I think we've answered your question. Use the `const` one. `OnMessage()` is not for sending messages (at least, not the message that's in the parameter). If you have other questions, perhaps it's time to make a new question. – Grant Birchmeier Apr 11 '14 at 14:02