/********************************************************************** * Project Name: FixExpress * * 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 * ****************************************#*****************************/ #include #include #include #include #include using namespace std; #include "Common.h" #include "Options.h" #include "Shm.h" #include "Time.h" #include "MsgQueue.h" class FixMsg { public: FixMsg(); ~FixMsg() {}; FixMsg &operator+=(string s); public: string message; }; FixMsg::FixMsg() { message = ""; } FixMsg & FixMsg::operator+=(string s){ message += s; message += soh; return *this; }; int main(int argc, char *argv[]) { int msgType = 1; // Default msg type Options opt(argc, argv); if (opt.getCount() < 4) { cout << "Usage: fix_driver shm mq target script [-m n]\n" << endl; exit(-1); } string shmKey = opt.getArgument(1); string qname = opt.getArgument(2); string site = opt.getArgument(3); string fname = opt.getArgument(4); if (opt.is_present('m')) { string typeStr = opt.getOption('m'); msgType = to_int(typeStr); } ifstream script(fname.c_str()); if (!script) { cout << "Fail to open the script file[" << argv[4] << "].\n" << endl; exit(-1); }; char line[BUF_SIZE]; string str; int p; try { Shm shm(shmKey); MsgQueue queue(qname, msgType); Cell *cell = shm.getCell(site); while (!script.eof()) { script.getline(line, BUF_SIZE); if ((line[0] == Comment) || (strlen(line) == 0)) ; else { FixMsg *fix = new FixMsg(); str = line; while (str.length() > 0) { p = str.find(Delimitor); if (p > 0) { *fix += str.substr(0, p); str = str.substr(p + 1); } else { *fix += str; str = ""; } } queue.write(fix->message, msgType); cell->Out.pend++; delete fix; } cout << line << endl; } } catch (ShmException &me) { cerr << me.what() << "\n" << endl; exit (-1); } catch (MQException &e) { cerr << e.what() << "\n" << endl; exit (-1); }; return 0; }