123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- /* -*- C++ -*- */
- /****************************************************************************
- ** Copyright (c) quickfixengine.org All rights reserved.
- **
- ** This file is part of the QuickFIX FIX Engine
- **
- ** This file may be distributed under the terms of the quickfixengine.org
- ** license as defined by quickfixengine.org and appearing in the file
- ** LICENSE included in the packaging of this file.
- **
- ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- **
- ** See http://www.quickfixengine.org/LICENSE for licensing information.
- **
- ** Contact ask@quickfixengine.org if any conditions of this licensing are
- ** not clear to you.
- **
- ****************************************************************************/
- #ifdef _MSC_VER
- #pragma warning( disable : 4503 4355 4786 )
- #endif
- #include "Application.h"
- #include "quickfix/Session.h"
- #include <iostream>
- #include "ufx_security_interface.h"
- void Application::sendMsg(int id, SessionID *sid, Message *msg, const Message *constmsg) {
- //std::cout << SignalSyncIsStart(sync) << std::endl;
- if (SignalSyncIsStart(sync) == 0) {
- return;
- }
- callbacks[id].app = this;
- callbacks[id].id = id;
- callbacks[id].sid = sid;
- callbacks[id].msg = msg;
- callbacks[id].constmsg = constmsg;
- try {
- SignalSyncSend(sync, id, &callbacks[id]);
- SignalSyncDone(sync, id);
- } catch (std::exception &e) {
- std::cout << e.what() << std::endl;
- }
- //std::cout << "msg end: " << id << std::endl;
- }
- void Application::onLogon( const FIX::SessionID& sessionID )
- {
- SessionID *sid = WarpSessionID(&sessionID);
- sendMsg(1, sid, NULL, NULL);
- }
- void Application::onLogout( const FIX::SessionID& sessionID )
- {
- SessionID *sid = WarpSessionID(&sessionID);
- sendMsg(2, sid, NULL, NULL);
- }
- void Application::onCreate( const FIX::SessionID& sessionID) {
- //std::cout << "Application::onCreate" << std::endl;
- sessionId = WarpSessionID(&sessionID);
- }
- void Application::toAdmin( FIX::Message& message, const FIX::SessionID& sessionID) {
- const FIX::Dictionary& session_settings = settings.get(sessionID);
- senderCompID = session_settings.getString("SenderCompID");
- targetCompID = session_settings.getString("TargetCompID");
- if (FIX::MsgType_Logon == message.getHeader().getField(FIX::FIELD::MsgType)) {
- message.setField(FIX::EncryptMethod(0));
- message.setField(FIX::HeartBtInt(30));
- FIX::Username username;
- FIX::Password password;
- if (session_settings.has("Username")) {
- username = session_settings.getString("Username");
- }
- if (session_settings.has("Password")) {
- password = session_settings.getString("Password");
- }
- message.setField(FIX::Password(password));
- message.setField(FIX::Username(username));
- message.setField(FIX::ResetSeqNumFlag(FIX::ResetSeqNumFlag_NO));
- }
- std::cout << message << std::endl;
- SessionID *sid = WarpSessionID(&sessionID);
- Message *msg = WarpMessage(&message);
- std::cout << MessageToStr(msg) << std::endl;
-
- sendMsg(4, sid, msg, NULL);
-
- }
- void Application::fromAdmin( const FIX::Message& message, const FIX::SessionID& sessionID)
- throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::RejectLogon ) {
- SessionID *sid = WarpSessionID(&sessionID);
- const Message *msg = WarpConstMessage(&message);
- sendMsg(5, sid, NULL, msg);
- }
- void Application::fromApp(const FIX::Message& message, const FIX::SessionID& sessionID)
- throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::UnsupportedMessageType ) {
- SessionID *sid = WarpSessionID(&sessionID);
- const Message *msg = WarpConstMessage(&message);
- sendMsg(6, sid, NULL, msg);
- }
- void Application::toApp( FIX::Message& message, const FIX::SessionID& sessionID ) throw( FIX::DoNotSend )
- {
- std::cout <<"toApp:" << message << std::endl;
- try
- {
- FIX::PossDupFlag possDupFlag;
- message.getHeader().getField( possDupFlag );
- if ( possDupFlag ) throw FIX::DoNotSend();
- SessionID *sid = WarpSessionID(&sessionID);
- Message *msg = WarpMessage(&message);
- sendMsg(7, sid, msg, NULL);
- } catch (FIX::FieldNotFound&) {
- }
- }
- static void process(void *data) {
- MsgCallBack *cb = (MsgCallBack *)data;
- //std::cout << "call: " << cb->id << std::endl;
- if (cb->id == 1) {
- cb->app->IApp->onLogon(cb->app->Trade, cb->sid);
- } else if (cb->id == 2) {
- cb->app->IApp->onLogout(cb->app->Trade, cb->sid);
- } else if (cb->id == 4) {
- if (cb->msg == NULL) {
- std::cout << "message error: " << cb->id << std::endl;
- return;
- }
- cb->app->IApp->toAdmin(cb->app->Trade, cb->msg, cb->sid);
- } else if (cb->id == 5) {
- if (cb->constmsg == NULL) {
- std::cout << "message error: " << cb->id << std::endl;
- return;
- }
- cb->app->IApp->fromAdmin(cb->app->Trade, cb->constmsg, cb->sid);
- } else if (cb->id == 6) {
- if (cb->constmsg == NULL) {
- std::cout << "message error: " << cb->id << std::endl;
- return;
- }
- cb->app->IApp->fromApp(cb->app->Trade, cb->constmsg, cb->sid);
- } else if (cb->id == 7) {
- if (cb->msg == NULL) {
- std::cout << "message error: " << cb->id << std::endl;
- return;
- }
- cb->app->IApp->toApp(cb->app->Trade, cb->msg, cb->sid);
- }
- //std::cout << "call end: " << cb->id << std::endl;
- }
- int Application::run() {
- std::cout << "sync start" << std::endl;
- SignalSyncStart(sync);
- while (true) {
- int ret = SignalSyncProcess(sync, process);
- if (ret != 1) {
- return ret;
- }
- }
- }
|