int main ( int argc, char** argv ) { char buf[ 512 ]; for (;;) { ssize_t bytes_read = read( STDIN_FILENO, buf, 512 ); if (bytes_read <= -1) { fprintf( stderr,"passthrough: unable to read from fd %d: %s\n", STDIN_FILENO, strerror(errno) ); exit(1); } if (bytes_read == 0) return 0; { char* rest_of_buf = buf; int bytes_left_to_write = bytes_read; // Loop until we've written all the bytes we read: // while (bytes_left_to_write > 0) { // ssize_t bytes_written = write( STDOUT_FILENO, rest_of_buf, bytes_left_to_write ); if (bytes_written <= -1) { // fprintf( stderr,"passthrough: unable to write to fd %d: %s\n", STDOUT_FILENO, strerror(errno) ); exit(1); } // A sane OS shouldn't put us in a busy-wait loop // by accepting zero bytes, but sane OSes are as // common as unicorns, so: // if (bytes_written == 0) sleep_100ms (); rest_of_buf += bytes_written; bytes_left_to_write -= bytes_written; } } } fprintf( stderr,"passthrough: DONE, exiting with status 13\n" ); exit( 13 ); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { DDS::DomainParticipantFactory_var dpf = DDS::DomainParticipantFactory::_nil(); DDS::DomainParticipant_var participant = DDS::DomainParticipant::_nil(); try { QuantLibAddinCpp::initializeAddin(); QuantLib::Calendar calendar = QuantLib::TARGET(); QuantLib::Date settlementDate(22, QuantLib::September, 2004); settlementDate = calendar.adjust(settlementDate); QuantLib::Integer fixingDays = 2; QuantLib::Date todaysDate = calendar.advance(settlementDate, -fixingDays, QuantLib::Days); QuantLibAddinCpp::qlSettingsSetEvaluationDate( todaysDate.serialNumber(), OH_NULL ); std::cout << "Today: " << todaysDate.weekday() << ", " << todaysDate << std::endl; std::cout << "Settlement date: " << settlementDate.weekday() << ", " << settlementDate << std::endl; // Initialize, and create a DomainParticipant dpf = TheParticipantFactoryWithArgs(argc, argv); qldds_utils::BasicDomainParticipant irs_participant( dpf, IRS_DOMAIN_ID ); irs_participant.createPublisher(); irs_participant.createSubscriber(); std::string term_structure; std::vector<std::string> rate_helpers; ACE_Get_Opt cmd_opts( argc, argv, ":c:n:i:" ); int option; while ( (option = cmd_opts()) != EOF ) { switch( option ) { case 'c' : { std::istringstream f( cmd_opts.opt_arg() ); std::string s; while (std::getline(f, s, '|')) { rate_helpers.push_back(s); } break; } case 'n' : { term_structure = cmd_opts.opt_arg(); break; } } } QuantLibAddinCpp::qlLibor("Libor", "USD", "6M", "", false, false, true); // Topics for Swap Components // Setting up schedule topic DDS::Topic_var schedule_topic = irs_participant.createTopicAndRegisterType < schedule::qlScheduleTypeSupport_var, schedule::qlScheduleTypeSupportImpl > ( SCHEDULE_TOPIC_NAME ); // setting up vanilla swap topic DDS::Topic_var vanilla_swap_topic = irs_participant.createTopicAndRegisterType < vanillaswap::qlVanillaSwapTypeSupport_var, vanillaswap::qlVanillaSwapTypeSupportImpl > ( VANILLA_SWAP_TOPIC_NAME ); // Topics for curve components // setting up deposit rate helper DDS::Topic_var deposit_rate_helper2_topic = irs_participant.createTopicAndRegisterType < ratehelpers::qlDepositRateHelper2TypeSupport_var, ratehelpers::qlDepositRateHelper2TypeSupportImpl > ( DEPOSIT_RATE_HELPER2_TOPIC_NAME ); // setting up FRA Rate helper DDS::Topic_var fra_rate_helper2_topic = irs_participant.createTopicAndRegisterType < ratehelpers::qlFraRateHelper2TypeSupport_var, ratehelpers::qlFraRateHelper2TypeSupportImpl > ( FRA_RATE_HELPER2_TOPIC_NAME ); // setting up Swap Rate helper DDS::Topic_var swap_rate_helper2_topic = irs_participant.createTopicAndRegisterType < ratehelpers::qlSwapRateHelper2TypeSupport_var, ratehelpers::qlSwapRateHelper2TypeSupportImpl > ( SWAP_RATE_HELPER2_TOPIC_NAME ); irs_participant.createDataReaderListener< schedule::qlScheduleDataReaderListenerImpl> ( qldds_lock, schedule_topic ); irs_participant.createDataReaderListener< VanillaSwapDataReaderListenerImpl > ( qldds_lock, vanilla_swap_topic ); irs_participant.createDataReaderListener< DepositRateHelper2DataReaderListenerImpl > ( qldds_lock,deposit_rate_helper2_topic ); irs_participant.createDataReaderListener< FraRateHelper2DataReaderListenerImpl > ( qldds_lock, fra_rate_helper2_topic ); irs_participant.createDataReaderListener< SwapRateHelper2DataReaderListenerImpl > ( qldds_lock, swap_rate_helper2_topic ); // setting up IRS Portfolio. Priced portfolios will be published on this topic DDS::Topic_var irs_portfolio_topic = irs_participant.createTopicAndRegisterType < IRS::PortfolioTypeSupport_var, IRS::PortfolioTypeSupportImpl > ( IRS_PORTFOLIO_TOPIC_NAME ); IRS::PortfolioDataWriter_var irs_portfolio_dw = irs_participant.createDataWriter < IRS::PortfolioDataWriter_var, IRS::PortfolioDataWriter > ( irs_portfolio_topic ); curves.insert( std::pair < std::string, std::vector< std::string > > ( term_structure, rate_helpers ) ); int calculation_performed = 0; while ( calculation_performed < 30 ) { IRS::Portfolio irs_portfolio_out; if ( computeNPVs( term_structure, irs_portfolio_out ) == false ) { ACE_Time_Value sleep_100ms( 0, 100000 ); ACE_OS::sleep( sleep_100ms ); continue; } else { calculation_performed++; ACE_OS::sleep(1); } std::cout << "Calculator ["<< term_structure << "] publishing NPVs for "<< irs_portfolio_out.swaps.length() << " interest rate swaps."<< std::endl; int ret = irs_portfolio_dw->write( irs_portfolio_out, DDS::HANDLE_NIL ); if (ret != DDS::RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: IRS Portfolio write returned %d.\n"), ret)); } } } catch (CORBA::Exception& e) { cerr << "Exception caught in main.cpp:" << endl << e << endl; ACE_OS::exit(1); } TheServiceParticipant->shutdown(); return 0; }