Changeset 11380 for trunk/FACT++/src/ftm.cc
- Timestamp:
- 07/13/11 18:38:23 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/ftm.cc
r10865 r11380 12 12 #include "Converter.h" 13 13 14 #include "Dim.h" 14 15 #include "HeadersFTM.h" 15 16 … … 53 54 void (tcp_connection::*handler)(const bs::error_code&))// const 54 55 { 55 timer.expires_from_now(boost::posix_time:: seconds(seconds));56 timer.expires_from_now(boost::posix_time::milliseconds(seconds)); 56 57 timer.async_wait(boost::bind(handler, shared_from_this(), dummy::error)); 57 58 } … … 61 62 // The constructor is prvate to force the obtained pointer to be shared 62 63 tcp_connection(ba::io_service& ioservice) : ba::ip::tcp::socket(ioservice), 63 fTriggerDynData(ioservice) 64 fTriggerDynData(ioservice), fTriggerSendData(ioservice) 64 65 { 65 66 //deadline_.expires_at(boost::posix_time::pos_infin); … … 156 157 bool fReportsDisabled; 157 158 159 ba::deadline_timer fTriggerSendData; 160 158 161 void SendDynamicData() 159 162 { … … 175 178 fHeader.fType=kDynamicData; // FtuList 176 179 fHeader.fDataSize=sizeof(FTM::DynamicData)/2+1; 177 fHeader.fTriggerCounter = fCounter ++;180 fHeader.fTriggerCounter = fCounter; 178 181 fHeader.fTimeStamp = fTimeStamp++*1000000;//lrint(Time().UnixTime()); 179 182 … … 190 193 fHeader.fType=kStaticData; // FtuList 191 194 fHeader.fDataSize=sizeof(FTM::StaticData)/2+1; 192 fHeader.fTriggerCounter = fCounter ++;195 fHeader.fTriggerCounter = fCounter; 193 196 fHeader.fTimeStamp = fTimeStamp*1000000;//lrint(Time().UnixTime()); 194 197 … … 242 245 fHeader.fType=kFtuList; // FtuList 243 246 fHeader.fDataSize=sizeof(FTM::FtuList)/2+1; 244 fHeader.fTriggerCounter = fCounter ++;247 fHeader.fTriggerCounter = fCounter; 245 248 fHeader.fTimeStamp = fTimeStamp*1000000;//lrint(Time().UnixTime()); 246 249 … … 330 333 fCounter = 0; 331 334 fTimeStamp = 0; 335 fHeader.fTriggerCounter = fCounter; 332 336 333 337 fBufCommand.resize(5); 334 338 AsyncRead(ba::buffer(fBufCommand)); 339 340 AsyncWait(fTriggerSendData, 0, &tcp_connection::TriggerSendData); 335 341 return; 336 342 337 343 case kCmdStopRun: 338 344 fHeader.fState = FTM::kFtmIdle; 345 346 fTriggerSendData.cancel(); 339 347 340 348 fCounter = 0; … … 365 373 fHeader.fType=kRegister; // FtuList 366 374 fHeader.fDataSize=2; 367 fHeader.fTriggerCounter = fCounter++;368 375 fHeader.fTimeStamp = fTimeStamp*1000000;//lrint(Time().UnixTime()); 369 376 … … 430 437 SendDynamicData(); 431 438 432 AsyncWait(fTriggerDynData, 1, &tcp_connection::SendDynData); 439 AsyncWait(fTriggerDynData, 1000, &tcp_connection::SendDynData); 440 } 441 442 void TriggerSendData(const boost::system::error_code &ec) 443 { 444 if (!is_open()) 445 { 446 // For example: Here we could schedule a new accept if we 447 // would not want to allow two connections at the same time. 448 return; 449 } 450 451 if (ec==ba::error::basic_errors::operation_aborted) 452 return; 453 454 // Check whether the deadline has passed. We compare the deadline 455 // against the current time since a new asynchronous operation 456 // may have moved the deadline before this actor had a chance 457 // to run. 458 if (fTriggerSendData.expires_at() > ba::deadline_timer::traits_type::now()) 459 return; 460 461 Dim::SendCommand("FAD/TRIGGER"); 462 fCounter++; 463 464 const uint16_t time = 100*float(rand())/RAND_MAX+50; 465 466 AsyncWait(fTriggerSendData, time, &tcp_connection::TriggerSendData); 433 467 } 434 468 … … 449 483 AsyncRead(ba::buffer(fBufCommand)); 450 484 451 AsyncWait(fTriggerDynData, 1 , &tcp_connection::SendDynData);485 AsyncWait(fTriggerDynData, 1000, &tcp_connection::SendDynData); 452 486 453 487 // AsyncWrite(ba::buffer(ba::const_buffer(&fHeader, sizeof(FTM::Header)))); … … 508 542 }; 509 543 544 #include "Configuration.h" 545 546 void SetupConfiguration(::Configuration &conf) 547 { 548 const string n = conf.GetName()+".log"; 549 550 po::options_description config("Program options"); 551 config.add_options() 552 ("dns", var<string>("localhost"), "Dim nameserver host name (Overwites DIM_DNS_NODE environment variable)") 553 ("port,p", var<uint16_t>(5000), "") 554 ; 555 556 po::positional_options_description p; 557 p.add("port", 1); // The first positional options 558 p.add("num", 1); // The second positional options 559 560 conf.AddEnv("dns", "DIM_DNS_NODE"); 561 562 conf.AddOptions(config); 563 conf.SetArgumentPositions(p); 564 } 565 510 566 int main(int argc, const char **argv) 511 567 { 568 ::Configuration conf(argv[0]); 569 570 SetupConfiguration(conf); 571 572 po::variables_map vm; 573 try 574 { 575 vm = conf.Parse(argc, argv); 576 } 577 #if BOOST_VERSION > 104000 578 catch (po::multiple_occurrences &e) 579 { 580 cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl; 581 return -1; 582 } 583 #endif 584 catch (exception& e) 585 { 586 cerr << "Program options invalid due to: " << e.what() << endl; 587 return -1; 588 } 589 590 if (conf.HasVersion() || conf.HasPrint() || conf.HasHelp()) 591 return -1; 592 593 Dim::Setup(conf.Get<string>("dns")); 594 512 595 //try 513 596 { 514 597 ba::io_service io_service; 515 598 516 Port = argc==2 ? lexical_cast<int>(argv[1]) : 5000;599 Port = conf.Get<uint16_t>("port"); 517 600 518 601 tcp_server server(io_service, Port);
Note:
See TracChangeset
for help on using the changeset viewer.