BOOL TerminalStart (PCONINFO con, PCHILDINFO pChildInfo) { sigset_t sa_mask; // We must handle SIGCHLD. // We handle coninfo as a thread-specific data set_coninfo (con); SetSignalHandlers (); sigemptyset (&sa_mask); sigaddset (&sa_mask, SIGCHLD); pthread_sigmask (SIG_UNBLOCK, &sa_mask, NULL); return OpenTerminal (con, pChildInfo); }
int main(int argc, char *argv[]) { UINT32 interval, elapsed, sleep_period; TIMER48 timer; if(!SetSignalHandlers()) exit(1); if(argc > 1) interval = strtoul(argv[1], NULL, 0); else interval = SECOND_MS * 10; if(argc > 2) sleep_period = strtoul(argv[2], NULL, 0); else { sleep_period = interval / 10; if(sleep_period > 100) sleep_period = 100; } printf("Timer interval: %u.%03u, sleep period: %u.%03u\n", interval / 1000, interval % 1000, sleep_period / 1000, sleep_period % 1000); Timer48Start(&timer, interval); printf("timer.upper: %u, timer.lower: %u, timer.interval: %u\n", timer.upper, timer.lower, timer.interval); while(!stop) { elapsed = Timer48MSElapsed(&timer); if(Timer48Expired(&timer)) { printf("\rTimer expired: %u.%03u\n", elapsed / 1000, elapsed % 1000); Timer48Restart(&timer); printf("timer.upper: %u, timer.lower: %u, timer.interval: %u\n", timer.upper, timer.lower, timer.interval); } else { printf("\rElapsed: %u.%03u", elapsed / 1000, elapsed % 1000); MSPause(sleep_period); } } return 0; }
//----------------------------------------------------------------------------- int main(int argc, char *argv[]) { SETTINGS settings; if (argc == 2) { settings.SetConfFile(argv[1]); } if (settings.ReadSettings()) { std::cerr << "Failed to read settings: '" << settings.GetStrError() << "'" << std::endl; Usage(); return -1; } SetSignalHandlers(); PROTO proto(settings.GetServerName(), settings.GetServerPort(), settings.GetLocalPort(), 10); STORE_LOADER storeLoader(settings.GetModulesPath(), settings.GetStoreModuleSettings()); if (storeLoader.Load()) { std::cerr << "Failed to load storage plugin: '" << storeLoader.GetStrError() << "'" << std::endl; return -1; } STORE * dataStore = storeLoader.GetStore(); std::vector<std::string> userList; if (dataStore->GetUsersList(&userList)) { std::cerr << "Failed to get user list: '" << dataStore->GetStrError() << "'" << std::endl; return -1; } std::list<uint32_t> ips; { std::vector<std::string>::const_iterator it; for (it = userList.begin(); it != userList.end(); ++it) { USER_CONF userConf; if (dataStore->RestoreUserConf(&userConf, *it)) { std::cerr << "Failed to read user conf: '" << dataStore->GetStrError() << "'" << std::endl; return -1; } proto.AddUser( USER( *it, userConf.password, userConf.ips[0].ip ) ); ips.push_back(userConf.ips[0].ip); } } if (!proto.Start()) { std::cerr << "Failed to start listening thread: '" << proto.GetStrError() << "'" << std::endl; return -1; } std::list<uint32_t>::const_iterator it; for (it = ips.begin(); it != ips.end(); ++it) { proto.Connect(*it); } std::cout << "Successfully loaded " << proto.UserCount() << " users" << std::endl; running = true; while (running) { struct timespec ts = {0, 200000000}; nanosleep(&ts, NULL); } proto.Stop(); storeLoader.Unload(); return 0; }
//----------------------------------------------------------------------------- int main(int argc, char *argv[]) { SETTINGS_IMPL settings; if (argc == 2) { settings.SetConfFile(argv[1]); } else { // Usage } if (settings.ReadSettings()) { printf("ReadSettingsError\n"); printf("%s\n", settings.GetStrError().c_str()); exit(-1); } settings.Print(); if (settings.GetDaemon()) { switch (fork()) { case -1: exit(1); break; case 0: setsid(); break; default: exit(0); break; } } clnp = new IA_CLIENT_PROT(settings.GetServerName(), settings.GetServerPort(), settings.GetLocalName(), settings.GetLocalPort()); if (!settings.GetNoWeb()) { web = new WEB(); web->SetRefreshPagePeriod(settings.GetRefreshPeriod()); web->SetListenAddr(settings.GetListenWebIP()); web->Start(); } clnp->SetLogin(settings.GetLogin()); clnp->SetPassword(settings.GetPassword()); clnp->SetStatusChangedCb(StatusChanged, NULL); clnp->SetInfoCb(ShowMessage, NULL); clnp->SetErrorCb(ShowError, NULL); clnp->SetDirNameCb(SetDirName, NULL); clnp->SetStatChangedCb(StatUpdate, NULL); clnp->SetReconnect(settings.GetReconnect()); clnp->Start(); SetSignalHandlers(); #ifdef LINUX for (int i = 1; i < argc; i++) memset(argv[i], 0, strlen(argv[i])); if(argc > 1) strcpy(argv[1], "Connecting..."); #endif #ifdef FREEBSD setproctitle("Connecting..."); #endif clnp->Connect(); while (1) { struct timespec ts = {0, 200000000}; nanosleep(&ts, NULL); char state[20]; if (clnp->GetAuthorized()) { if (settings.GetShowPid()) sprintf(state, "On %d", getpid()); else strcpy(state, "Online"); } else { if (settings.GetShowPid()) sprintf(state, "Off %d", getpid()); else strcpy(state, "Offline"); } #ifdef LINUX for (int i = 1; i < argc; i++) memset(argv[i], 0, strlen(argv[i])); if(argc > 1) strcpy(argv[1], state); #endif #ifdef FREEBSD setproctitle(state); #endif #ifdef FREEBSD_5 setproctitle(state); #endif } return 0; }
/** * Entry point */ int main(int argc, char** argv ) { // TODO ([email protected]) put init settings in ctor ApplicationConfig config; config.print_debug = false; config.is_logging = true; SetSignalHandlers(); #ifdef LOG logging_init(createTimestampedLogFilename(PANTHEIOS_FE_PROCESS_IDENTITY).c_str()); #endif if (capk::InitializeZMQPublisher(&g_zmq_context, &g_pub_socket) != 0) { #ifdef LOG pan::log_CRITICAL("Can't init ZMQ - exiting"); #endif return (-1); } // Must call this to use protobufs GOOGLE_PROTOBUF_VERIFY_VERSION; // First read command line if (ReadCommandLineParams(argc, argv, &config) != 0) { #ifdef LOG pan::log_CRITICAL("Aborting due to missing parameters."); #endif return (-1); } // Read the symbols to subscribe to from file std::vector<std::string> symbols = capk::readSymbolsFile(config.symbol_file_name); if (symbols.size() <= 0) { #ifdef LOG pan::log_CRITICAL("No symbols set in:", config.symbol_file_name.c_str()); #endif return (-1); } try { FIX::SessionSettings settings(config.config_file_name); std::set<FIX::SessionID> sessions = settings.getSessions(); assert(sessions.size() == 1); FIX::SessionID sessionId = *(sessions.begin()); const FIX::Dictionary& dict = settings.get(sessionId); // Get additional config settings from FIX config file if (ReadFIXConfig(&config, dict) != 0) { fprintf(stderr, "Can't read local config file - exiting\n"); return (-1); } if (config.venue_config_file_name == "") { // Get config settings from config server if (ReadRemoteConfig(&config) != 0) { fprintf(stderr, "Can't read remote configuration - exiting\n"); return (-1); } } else { // Get config settings from local ini file if (ReadLocalVenueConfig(config.venue_config_file_name, &config) != 0) { fprintf(stderr, "Can't read local venue configuration - exiting\n"); return (-1); } } PrintConfig(&config); // Create the FIX application instance Application application(config); g_papplication = &application; application.addSymbols(symbols); // Create the output directories for orderbooks, log, and store if needed. // Note that actual log directories are created in the location specified // with -o arg each time the program starts // @TODO ([email protected]) Maybe better to put // each log in the dated directory rather than have store and // log on same level as dated tick dirs if (config.root_output_dir.length() > 0) { fs::path argPath = fs::path(config.root_output_dir); if (!fs::exists(argPath)) { fs::create_directories(argPath); } fs::path fix_log_path = argPath / fs::path("log"); if (!fs::exists(fix_log_path)) { fs::create_directory(fix_log_path); } config.fix_log_output_dir = fix_log_path.string(); fs::path store_path = argPath / fs::path("store"); if (!fs::exists(store_path)) { fs::create_directory(store_path); } config.fix_store_output_dir = store_path.string(); } pid_t pid = getpid(); pid_t ppid = getppid(); #ifdef LOG pan::log_DEBUG("pid: ", pan::integer(pid), " ppid: ", pan::integer(ppid)); #endif if (WritePidFile(argv[0], config.mic_string.c_str(), pid, ppid) != 0) { #ifdef LOG pan::log_CRITICAL("Can't write pid file - exiting"); #endif return (-1); } // Set ZMQ parameters in Application if (config.is_publishing) { zmq_bind(g_pub_socket, config.publishing_addr.c_str()); application.setZMQContext(g_zmq_context); application.setZMQSocket(g_pub_socket); } if (config.is_logging) { std::cout << "Logging with FileStoreFactory" << std::endl; FIX::FileStoreFactory fileStoreFactory(config.fix_store_output_dir); FIX::FileLogFactory logFactory(config.fix_log_output_dir); g_pinitiator = new FIX::SocketInitiator(application, fileStoreFactory, settings, logFactory); assert(g_pinitiator); } else { std::cout << "Logging with NullStoreFactory" << std::endl; FIX::NullStoreFactory nullStoreFactory; g_pinitiator = new FIX::SocketInitiator(application, nullStoreFactory, settings); assert(g_pinitiator); } std::cout << "Starting initiator" << std::endl; g_pinitiator->start(); char x; std::cout << "Type 'q' to disconnect and exit" << std::endl; while (std::cin >> x) { if (x == 'q') { break; } } std::cout << "Cleaning up" << std::endl; g_pinitiator->stop(); return 0; } catch(FIX::Exception& e) { std::cerr << e.what(); return 1; } }