/********************************************************************** * Project Name: Fix Engine * * Program Name: fix_driver.cpp * * Auther : Changpeng Yu * * Date : 03/20/2008 * * * * Copyright @ 2008 FT Computer Solutions * * * * Date Name PNO Description * * ------------------------------------------------------------------- * * 03/20/08 Changpeng Yu Create program module * * 12/20/12 Changpeng Yu Improvement for Release 8 * ****************************************#*****************************/ #include #include #include #include #include #include #include using namespace std; #include "../inc/Common.h" #include "../inc/Shm.h" #include "../inc/MsgQueue.h" #define BUF_SIZE 4096 class FixMsg { public: FixMsg(); ~FixMsg() {}; FixMsg &operator+=(string s); public: string message; }; FixMsg::FixMsg() { message = ""; } FixMsg & FixMsg::operator+=(string s){ message += s + Soh; return *this; }; int main(int argc, char *argv[]) { char buf[BUF_SIZE]; if (argc < 2) { cout << "Usage: fix_sender shm mq site\n" << endl; exit(-1); } string site; if (argc > 2) site = argv[3]; try { string shm_name(argv[1]); Shm shm(shm_name); string mq_name(argv[2]); mq_name += ".o"; MsgQueue queue(mq_name); Cell *cell; if (site.length() == 0) { cell = shm.getCell(0); site = cell->name; } else cell = shm.getCell(site); int msgType = shm.getCellId(site) + 1; while (!cin.eof()) { cin.getline(buf, BUF_SIZE); string line = buf; if ((line.length() == 0) || (line[0] == Comment)) ; else { FixMsg *fix = new FixMsg(); while (line.length() > 0) { int p = line.find(Delimitor); if (p > 0) { *fix += line.substr(0, p); line = line.substr(p + 1); } else { *fix += line; line = ""; } } queue.write(fix->message, WaitMode, msgType); cell->Out.pend++; delete fix; } cout << buf << endl; } } catch (ShmException &me) { cerr << me.what() << "\n" << endl; exit (-1); } catch (MQException &e) { cerr << e.what() << "\n" << endl; exit (-1); }; return 0; }