- Timestamp:
- 07/13/11 18:38:23 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fad.cc
r11374 r11380 14 14 #include "HeadersFAD.h" 15 15 16 #include "dis.hxx" 17 #include "Dim.h" 18 16 19 using namespace std; 17 20 using namespace FAD; … … 24 27 using ba::ip::tcp; 25 28 29 class tcp_connection; 30 31 class Trigger : public DimCommandHandler 32 { 33 DimCommand fCmd; 34 35 vector<tcp_connection*> vec; 36 37 public: 38 Trigger() : fCmd("FAD/TRIGGER", "C", this) 39 { 40 } 41 42 void Add(tcp_connection *ptr) 43 { 44 vec.push_back(ptr); 45 } 46 47 void Remove(tcp_connection *ptr) 48 { 49 vec.erase(find(vec.begin(), vec.end(), ptr)); 50 } 51 52 void commandHandler(); 53 }; 54 26 55 // ------------------------------------------------------------------------ 27 56 … … 29 58 { 30 59 public: 60 static Trigger fTrigger; 61 31 62 const int fBoardId; 32 63 … … 55 86 // The constructor is prvate to force the obtained pointer to be shared 56 87 tcp_connection(ba::io_service& ioservice, int boardid) : ba::ip::tcp::socket(ioservice), 57 fBoardId(boardid), fRamRoi(kNumChannels), fTriggerSendData(ioservice) 58 { 88 fBoardId(boardid), fRamRoi(kNumChannels), fTriggerSendData(ioservice), 89 fTriggerEnabled(false) 90 { 91 fTrigger.Add(this); 92 } 93 void PostTrigger() 94 { 95 if (fTriggerEnabled) 96 get_io_service().post(boost::bind(&tcp_connection::SendData, this)); 59 97 } 60 98 … … 380 418 ~tcp_connection() 381 419 { 420 fTrigger.Remove(this); 382 421 fSockets.clear(); 383 422 } … … 390 429 } 391 430 }; 431 432 Trigger tcp_connection::fTrigger; 433 434 void Trigger::commandHandler() 435 { 436 for (vector<tcp_connection*>::iterator it=vec.begin(); 437 it!=vec.end(); it++) 438 { 439 (*it)->PostTrigger(); 440 } 441 } 392 442 393 443 … … 482 532 }; 483 533 534 #include "Configuration.h" 535 536 void SetupConfiguration(::Configuration &conf) 537 { 538 const string n = conf.GetName()+".log"; 539 540 po::options_description config("Program options"); 541 config.add_options() 542 ("dns", var<string>("localhost"), "Dim nameserver host name (Overwites DIM_DNS_NODE environment variable)") 543 ("port,p", var<uint16_t>(4000), "") 544 ("num,n", var<uint16_t>(40), "") 545 ; 546 547 po::positional_options_description p; 548 p.add("port", 1); // The first positional options 549 p.add("num", 1); // The second positional options 550 551 conf.AddEnv("dns", "DIM_DNS_NODE"); 552 553 conf.AddOptions(config); 554 conf.SetArgumentPositions(p); 555 } 556 484 557 int main(int argc, const char **argv) 485 558 { 559 ::Configuration conf(argv[0]); 560 561 SetupConfiguration(conf); 562 563 po::variables_map vm; 564 try 565 { 566 vm = conf.Parse(argc, argv); 567 } 568 #if BOOST_VERSION > 104000 569 catch (po::multiple_occurrences &e) 570 { 571 cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl; 572 return -1; 573 } 574 #endif 575 catch (exception& e) 576 { 577 cerr << "Program options invalid due to: " << e.what() << endl; 578 return -1; 579 } 580 581 if (conf.HasVersion() || conf.HasPrint() || conf.HasHelp()) 582 return -1; 583 584 Dim::Setup(conf.Get<string>("dns")); 585 586 DimServer::start("FAD"); 587 486 588 //try 487 589 { 488 590 ba::io_service io_service; 489 591 490 int port = argc>=2 ? lexical_cast<int>(argv[1]) : 5000;491 int n = argc==3 ? lexical_cast<int>(argv[2]) : 1;592 const uint16_t n = conf.Get<uint16_t>("num"); 593 uint16_t port = conf.Get<uint16_t>("port"); 492 594 493 595 vector<shared_ptr<tcp_server>> servers; -
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.