Пример #1
0
int testSendOnThreadedSocket( int count, short port )
{
  std::stringstream stream;
  stream
    << "[DEFAULT]" << std::endl
    << "SocketConnectHost=localhost" << std::endl
    << "SocketConnectPort=" << (unsigned short)port << std::endl
    << "SocketAcceptPort=" << (unsigned short)port << std::endl
    << "SocketReuseAddress=Y" << std::endl
    << "StartTime=00:00:00" << std::endl
    << "EndTime=00:00:00" << std::endl
    << "UseDataDictionary=N" << std::endl
    << "BeginString=FIX.4.2" << std::endl
    << "PersistMessages=N" << std::endl
    << "[SESSION]" << std::endl
    << "ConnectionType=acceptor" << std::endl
    << "SenderCompID=SERVER" << std::endl
    << "TargetCompID=CLIENT" << std::endl
    << "[SESSION]" << std::endl
    << "ConnectionType=initiator" << std::endl
    << "SenderCompID=CLIENT" << std::endl
    << "TargetCompID=SERVER" << std::endl
    << "HeartBtInt=30" << std::endl;

  FIX::ClOrdID clOrdID( "ORDERID" );
  FIX::HandlInst handlInst( '1' );
  FIX::Symbol symbol( "LNUX" );
  FIX::Side side( FIX::Side_BUY );
  FIX::TransactTime transactTime;
  FIX::OrdType ordType( FIX::OrdType_MARKET );
  FIX42::NewOrderSingle message( clOrdID, handlInst, symbol, side, transactTime, ordType );

  FIX::SessionID sessionID( "FIX.4.2", "CLIENT", "SERVER" );

  TestApplication application;
  FIX::MemoryStoreFactory factory;
  FIX::SessionSettings settings( stream );

  FIX::ThreadedSocketAcceptor acceptor( application, factory, settings );
  acceptor.start();

  FIX::ThreadedSocketInitiator initiator( application, factory, settings );
  initiator.start();

  FIX::process_sleep( 1 );

  int start = GetTickCount();
  for ( int i = 0; i <= count; ++i )
    FIX::Session::sendToTarget( message, sessionID );

  while( application.getCount() < count )
    FIX::process_sleep( 0.1 );

  int ticks = GetTickCount() - start;

  initiator.stop();
  acceptor.stop();

  return ticks;
}
Пример #2
0
int main( int argc, char** argv )
{
  if ( argc != 2 )
  {
    std::cout << "usage: " << argv[ 0 ]
    << " FILE." << std::endl;
    return 0;
  }
  std::string file = argv[ 1 ];

  try
  {
    FIX::SessionSettings settings( file );

    MDApplication application;
    FIX::FileStoreFactory storeFactory( settings );
	FIX::FileLogFactory logFactory(settings);
    FIX::SocketInitiator initiator( application, storeFactory, settings, logFactory );

    initiator.start();
    application.run();
    initiator.stop();

    return 0;
  }
  catch ( std::exception & e )
  {
    std::cout << e.what();
    return 1;
  }
}
int sc_main(int argc, char* argv[])
{
  SimpleLTInitiator3 initiator("initiator");
  SimpleLTTarget2 target("target");

  initiator.socket(target.socket);

  sc_core::sc_start();
  sc_core::sc_stop();

  return 0;
}
int sc_main(int argc, char* argv[])
{
  SimpleLTInitiator_ext initiator("initiator1", 10, 0x0);
  adapt_ext2gp<32>       bridge1("bridge1");
  SimpleBusLT<1,1>       bus("bus");
  adapt_gp2ext<32>       bridge2("bridge2");
  SimpleLTTarget_ext     target("target1");

  initiator.socket(bridge1.target_socket);
  bridge1.initiator_socket(bus.target_socket[0]);
  bus.initiator_socket[0](bridge2.target_socket);
  bridge2.initiator_socket(target.socket);

  sc_core::sc_start();
  sc_core::sc_stop();

  return 0;
}
Пример #5
0
int main(int argc, const char** argv)
{
  std::cout << "client started." << std::endl;
  if (argc < 2) {
    std::cout << "usage: ./client <config_file>" << std::endl;
    exit(1);
  }
  std::string fileName = argv[1];
  std::cout << "config_file: " << fileName << std::endl;
  FIX::SessionSettings settings(fileName);
  FIX::FileStoreFactory storeFactory(settings);
  FIXApplication application;
  FIX::SocketInitiator initiator(application, storeFactory, settings);

  initiator.start();

  while (1) {
    sleep(1);
  }

  initiator.stop();
  std::cout << "Bye" << std::endl;
  return 0;
}
Пример #6
0
int main(void)
{
  disable_unused_circuits();
  _delay_ms(50);

#ifdef HAS_CHARGER
  reset_on_power_change();
#endif /* HAS_CHARGER */

  /* Shut off right away if battery is very low. Do not power on NFC module */
  adc_init();
  (void)read_voltage();
  // Read one more time in case first reading is corrupted
  uint8_t voltage = read_voltage();
  adc_disable();
  if (is_battery_dead(voltage)) {
    //beep_n_times_and_wait(4);
    //sleep_forever();
  }

  lcd_init();
  print_idle();

  // Initialize and self-test
  module_power_up();
  led_on();
#ifdef WITH_TARGET
  // We may have come out of target power down mode
  //(void)pasori_wake_up();
#endif

  while (!rcs956_reset()) {};

  if (!eeprom_has_station_info()) {
    beep_n_times_and_wait(3);
    sleep_forever();
  }
  if (is_on_external_power()) {
    play_song_and_wait(melody_start_up_external,
                       sizeof(melody_start_up_external) / sizeof(struct note));
  } else {
    play_song_and_wait(melody_start_up_battery,
                       sizeof(melody_start_up_battery) / sizeof(struct note));
  }
  led_off();
  initiator_set_defaults();
  watchdog_start();

  for (;;) {
    watchdog_reset();
    // initiator exits after polling times out (false) or URL is pushed (true)
    if (initiator(PUSH_URL_LABEL)) {
      lcd_puts(0, "PUSH SLEEP");
      play_url_push_success_song_and_wait();
    }
#ifdef WITH_TARGET
    uint8_t loop;
    // Loop here to not skip watchdog timer
    for (loop = 0; loop < TARGET_MODE_RETRY; loop++) {
      watchdog_reset();
      (void)rcs956_reset();
      enum target_res res = target(PUSH_URL_LABEL_ENGLISH);
      if (res == TGT_COMPLETE) {
        led_off();
        play_url_push_success_song_and_wait();
        break;
      } else if (res == TGT_TIMEOUT || res == TGT_ERROR) {
        break;
      } // loop on TGT_RETRY
    }
    led_off();
    (void)rcs956_reset();
    low_battery_check();
#else /* !WITH_TARGET */
    // Check battery level while RF field is still on
    low_battery_check();
    sleep_after_timeout();
#endif /* WITH_TARGET */

    // Reconfigure Felica module if communication timed out,
    // e.g. due to temporary disconnect.
    if (protocol_errno == TIMEOUT) {
      initiator_set_defaults();
      eeprom_increment_usart_fail();
    }
    protocol_errno = SUCCESS;
  }

  /* NOT REACHABLE */
  return 0;
}
Пример #7
0
int main( int argc, char** argv )
{
	int err = 0;
	std::string argOutputDir; 
	std::string symbolFile;
	std::string configFile;
	std::string password;
	bool printDebug; 
    

    (void) signal(SIGINT, sighandler);
    (void) signal(SIGTERM, sighandler);
    (void) signal(SIGHUP, sighandler);


	try {
		po::options_description desc("Allowed options");
		desc.add_options()
			("help", "produce help message")
			("s", po::value<std::string>(), "<symbol file>")
			("c", po::value<std::string>(), "<config file>")
			("d", "debug info")
		;
		
		po::variables_map vm;        
		po::store(po::parse_command_line(argc, argv, desc), vm);
		po::notify(vm);    

		
		if (vm.count("help")) {
			std::cout << desc << "\n";
			return 1;
		}
		
		if (vm.count("s")) {
			std::cout << "Symbol file: " << vm["s"].as<std::string>() << "\n";
			symbolFile = vm["s"].as<std::string>();
		} else {
			// use default name for symbols file name 
			symbolFile = "symbols.cfg"; 
			std::cout << "Using default symbols file: symbols.cfg\n"; 
		}
		if (vm.count("c")) {
			std::cout << "Config file: " << vm["c"].as<std::string>() << ".\n";
			configFile = vm["c"].as<std::string>();
		} else {
			std::cout << "Config file was not set.\n";
			err++;
		}
		printDebug = vm.count("d") > 0; 
			
	}
	catch(std::exception& e) {
		std::cerr << "EXCEPTION:" << e.what();
		return 1;
	}
	if (err > 0) {
		std::cout << "Usage: validate_symbols --c <config_file> --s <symbol_file> \n";
		std::cout << "Will save files to MIC.validated-symbols";
		return 1;
	}
	
	/* 
 	* @see http://www.boost.org/doc/libs/1_41_0/doc/html/program_options.html
 	*/
	
	std::vector<std::string> symbols = readSymbols(symbolFile);
	try
	{
		FIX::SessionSettings settings(configFile);
                std::set<FIX::SessionID> sessions = settings.getSessions ();
		assert(sessions.size() == 1); 
		FIX::SessionID sessionId = *(sessions.begin()); 
		const FIX::Dictionary& dict = settings.get(sessionId);
		ApplicationConfig config;  
        // MIC code for adding to output filename 
		config.mic_code = dict.has("MIC") ? dict.getString("MIC") : ""; 

        // Username and password settings
		config.username = dict.has("Username") ? dict.getString("Username") : ""; 
		config.password = dict.has("Password") ? dict.getString("Password") : ""; 
		config.sendPasswordInRawDataField = dict.has("SendPasswordInRawData") && 
		    dict.getBool("SendPasswordInRawData");

        // Fix Version string
		config.version = dict.has("FIXVersion") ? (FIXVersion)atoi(dict.getString("FIXVersion").c_str()) : FIX_42;
		std::cout << "Using FIX version: " << config.version << std::endl;

        // Reset sequence numbers? 
		bool bReset = dict.has("ResetSeqNo") ? dict.getBool("ResetSeqNo") : false;
		std::cout << "Resetting sequence numbers: " << bReset << std::endl;

        // Debug settings
		config.printDebug = printDebug; 
        
		Application application(bReset, config);
        papplication = &application;
		application.addSymbols(symbols);
    
        // if user specified an output dir, then put files into date-sorted
        // subdirectories, otherwise put into the default dirs specified in 
        // config file 
        std::string orderBooksOutputDir = ".";
        std::string logOutputDir = dict.has("FileLogPath") ? dict.getString("FileLogPath") : "."; 
        std::string storeOutputDir = dict.has("FileStorePath") ? dict.getString("FileStorePath") : ".";

        if (argOutputDir.length() > 0) { 
            orderBooksOutputDir = argOutputDir; 
            fs::path argPath = fs::path(argOutputDir); 
            if (!fs::exists(argPath)) { fs::create_directories(argPath); }
            
            /* put both order books and message logs in subdirs, 
               but put the store at the root dir 
            */ 
            fs::path logOutputPath = argPath / fs::path("log");  
			if (!fs::exists(logOutputPath)) { fs::create_directory(logOutputPath); } 
			logOutputDir = logOutputPath.string(); 

            fs::path storeOutputPath = argPath / fs::path("store"); 
			if (!fs::exists(storeOutputPath)) { fs::create_directory(storeOutputPath); }
			storeOutputDir = storeOutputPath.string(); 
        }

        
		FIX::FileStoreFactory storeFactory(storeOutputDir);         
		FIX::FileLogFactory logFactory(logOutputDir);

		FIX::SocketInitiator initiator(application, storeFactory, settings, logFactory);
        pinitiator = &initiator;
		std::cout << "Starting initiator" << std::endl; 
		initiator.start();
        //application.run();

		char x;
		while(std::cin >> x) {
            std::cout << " Press 'q' to quit" << std::endl;
			if (x == 'q') {
				break;
			}
		}
		std::cout << "Stopping initiator..." << std::endl;
		initiator.stop();
		return 0;
	}
	catch ( FIX::Exception & e )
	{
		std::cout << e.what();
		return 1;
	}
    
}