Changeset 14124
- Timestamp:
- 06/08/12 17:09:54 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/StateMachineImp.cc
r14072 r14124 384 384 //! The event names all have the SERVER/ pre-fix removed. 385 385 // 386 const vector<string> StateMachineImp::GetEventNames() const386 const vector<string> StateMachineImp::GetEventNames() 387 387 { 388 388 vector<string> v; … … 391 391 const int len = name.length(); 392 392 393 const lock_guard<mutex> guard(fMutexEvt); 394 393 395 for (vector<EventImp*>::const_iterator i=fListOfEvents.begin(); 394 396 i!=fListOfEvents.end(); i++) … … 413 415 //! if given only the given event is selected 414 416 // 415 void StateMachineImp::PrintListOfEvents(ostream &out, const string &evt) const 416 { 417 void StateMachineImp::PrintListOfEvents(ostream &out, const string &evt) 418 { 419 const lock_guard<mutex> guard(fMutexEvt); 420 417 421 for (vector<EventImp*>::const_iterator c=fListOfEvents.begin(); c!=fListOfEvents.end(); c++) 418 422 if (evt.empty() || GetName()+'/'+evt==(*c)->GetName()) … … 429 433 //! 430 434 // 431 void StateMachineImp::PrintListOfAllowedEvents(ostream &out) const 432 { 435 void StateMachineImp::PrintListOfAllowedEvents(ostream &out) 436 { 437 const lock_guard<mutex> guard(fMutexEvt); 438 433 439 for (vector<EventImp*>::const_iterator c=fListOfEvents.begin(); c!=fListOfEvents.end(); c++) 434 440 if ((*c)->IsStateAllowed(fCurrentState)) … … 444 450 // 445 451 // 446 void StateMachineImp::PrintListOfEvents(const string &str) const452 void StateMachineImp::PrintListOfEvents(const string &str) 447 453 { 448 454 PrintListOfEvents(Out(), str); … … 485 491 //! true if the event was found, false otherwise 486 492 // 487 bool StateMachineImp::HasEvent(const EventImp *cmd) const493 bool StateMachineImp::HasEvent(const EventImp *cmd) 488 494 { 489 495 // Find the event from the list of commands and queue it 496 const lock_guard<mutex> guard(fMutexEvt); 490 497 return find(fListOfEvents.begin(), fListOfEvents.end(), cmd)!=fListOfEvents.end(); 491 498 } … … 500 507 //! true if the event was found, false otherwise 501 508 // 502 EventImp *StateMachineImp::FindEvent(const string &evt) const509 EventImp *StateMachineImp::FindEvent(const string &evt) 503 510 { 504 511 // Find the command from the list of commands and queue it 512 const lock_guard<mutex> guard(fMutexEvt); 505 513 for (vector<EventImp*>::const_iterator c=fListOfEvents.begin(); c!=fListOfEvents.end(); c++) 506 514 if (evt == (*c)->GetName()) … … 546 554 #endif 547 555 556 fMutexEvt.lock(); 548 557 fListOfEvents.push_back(evt); 558 fMutexEvt.unlock(); 549 559 550 560 return *evt; … … 611 621 { 612 622 EventImp *evt = CreateService(name); 623 624 fMutexEvt.lock(); 613 625 fListOfEvents.push_back(evt); 626 fMutexEvt.unlock(); 627 614 628 return *evt; 629 } 630 631 void StateMachineImp::Unsubscribe(EventImp *evt) 632 { 633 const lock_guard<mutex> guard(fMutexEvt); 634 635 auto it = find(fListOfEvents.begin(), fListOfEvents.end(), evt); 636 if (it==fListOfEvents.end()) 637 return; 638 639 fListOfEvents.erase(it); 640 delete evt; 615 641 } 616 642 -
trunk/FACT++/src/StateMachineImp.h
r14008 r14124 41 41 std::queue<Event*> fEventQueue; /// Event queue (fifo) for the received commands 42 42 43 std::mutex fMutex; /// Mutex to ensure thread-safe access to the command fifo 43 std::mutex fMutex; /// Mutex to ensure thread-safe access to the command fifo 44 std::mutex fMutexEvt; /// Mutex to ensure thread-safe access to the command fifo 44 45 45 46 bool fRunning; /// Machine is in main-loop … … 101 102 102 103 EventImp &Subscribe(const std::string &name); 104 void Unsubscribe(EventImp *evt); 103 105 104 106 /// return the current state of the machine … … 128 130 129 131 // Event handling 130 bool HasEvent(const EventImp *cmd) const;131 EventImp *FindEvent(const std::string &evt) const;132 bool HasEvent(const EventImp *cmd); 133 EventImp *FindEvent(const std::string &evt); 132 134 133 135 bool IsQueueEmpty() const { return fEventQueue.size()==0; } 134 136 135 const std::vector<EventImp*> &GetListOfEvents() const { return fListOfEvents; }136 const std::vector<std::string> GetEventNames() const;137 138 void PrintListOfEvents(std::ostream &out, const std::string &evt="") const;139 void PrintListOfEvents(const std::string &str="") const;140 141 void PrintListOfAllowedEvents(std::ostream &out) const;142 void PrintListOfAllowedEvents() const;137 //const std::vector<EventImp*> &GetListOfEvents() const { return fListOfEvents; } 138 const std::vector<std::string> GetEventNames(); 139 140 void PrintListOfEvents(std::ostream &out, const std::string &evt=""); 141 void PrintListOfEvents(const std::string &str=""); 142 143 void PrintListOfAllowedEvents(std::ostream &out); 144 void PrintListOfAllowedEvents(); 143 145 144 146 void PrintListOfStates(std::ostream &out) const;
Note:
See TracChangeset
for help on using the changeset viewer.