2012-11-19 54 views
0

如何硬編碼啓動器和接受器的設置,以便我不需要外部設置文件?如何硬編碼設置

這是我到目前爲止已經試過:

FIX::SessionSettings serverSettings; 
FIX::Dictionary serverDictionary; 

serverDictionary.setString("BeginString", "FIX.4.4"); 
serverDictionary.setString("UseDataDictionary", "Y"); 
serverDictionary.setString("DataDictionary", "../../../spec/FIX.4.4.xml"); 
serverDictionary.setString("SenderCompID", "SRVR"); 
serverDictionary.setString("TargetCompID", "CLNT"); 
serverDictionary.setString("SocketAcceptHost", "localhost"); 
serverDictionary.setLong("SocketAcceptPort", 2024); 

FIX::SessionID serverSessionID; 
serverSettings.set(serverSessionID, serverDictionary); 

Server server; // Extends FIX::Application 

FIX::FileStoreFactory serverStoreFactory("server/fileStore/"); 
FIX::FileLogFactory serverLogFactory("server/logs/"); 

FIX::SocketAcceptor acceptor(server, serverStoreFactory, serverSettings, serverLogFactory); 

我覺得我在正確的道路上,但我得到這個錯誤:Configuration failed: BeginString must be FIX.4.0 to FIX.4.4 or FIXT.1.1

任何想法?

+0

我沒有看到使用設置文件的好處。你真的需要以編程方式設置設置嗎? –

+0

是的,我願意。這些是我的要求。 – Qsiris

回答

1

它與「FIX.4.4」的值無關,它與setString的定義是一樣的;

無效詞典::了setString(常量的std :: string &鍵,常量的std :: string &值)

它正在通過參考這些字符串和你傳遞它是由釋放的一個臨時變量時間setString嘗試訪問該值。既然你不能改變你需要做的功能定義,

std::string key = "current key"; 
std::string value = "current value"; 
serverDictionary.setString(key, value); 

所有setString調用爲了這個工作。至少對我來說,這會阻止我走這條路。

+0

4.4是可接受的值。它適用於我使用外部設置文件。 – Qsiris

+0

@ ovidiub13如果你可以從文件中讀取它並且工作,在調用'serverDictionary.setString(「BeginString」,「FIX.4.4」)之前設置一個斷點;'並檢查你傳遞的值在哪裏「FIX .4.4「是。無論那個價值是什麼,你需要通過的代替「FIX.4.4」。 – evanmcdonnal

+0

我試過了。值集合是正確的。問題是:這是設置設置的正確方法嗎? – Qsiris

1

經過艱苦的鬥爭,我終於成功地做到了這一點。以下是硬編碼接受器中設置的功能代碼,也可應用於啓動器中:

try { 
    FIX::SessionSettings serverSettings; 
    FIX::Dictionary serverDictionary; 

    serverDictionary.setString("ConnectionType", "acceptor"); 
    serverDictionary.setString("DataDictionary", "FIX.4.4.xml"); 
    serverDictionary.setString("StartTime", "00:00:00"); 
    serverDictionary.setString("EndTime", "00:00:00"); 
    serverDictionary.setString("SocketAcceptHost", "localhost"); 
    serverDictionary.setString("SocketAcceptPort", "2024"); 

    FIX::SessionID serverSessionID("FIX.4.4", "SRVR", "CLNT"); 
    serverSettings.set(serverSessionID, serverDictionary); 

    Server server; 
    FIX::FileStoreFactory serverStoreFactory("server/fileStore/"); 
    FIX::FileLogFactory serverLogFactory("server/logs/"); 
    FIX::SocketAcceptor acceptor(server, serverStoreFactory, serverSettings, serverLogFactory); 
    acceptor.start(); 
    // do something 
    acceptor.stop(); 

    return 0; 
} catch (FIX::ConfigError& e) { 
    std::cout << e.what() << std::endl; 
    return 1; 
}