Changeset dd7c44 for src/Observer/Observable.cpp
- Timestamp:
- Oct 30, 2015, 11:43:20 AM (10 years ago)
- Children:
- 6e2f3b
- Parents:
- 1f96ec
- git-author:
- Frederik Heber <heber@…> (07/10/15 09:44:07)
- git-committer:
- Frederik Heber <heber@…> (10/30/15 11:43:20)
- File:
-
- 1 edited
-
src/Observer/Observable.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Observer/Observable.cpp
r1f96ec rdd7c44 335 335 Notification_ptr Observable::getChannel(size_t no) const 336 336 { 337 boost::recursive_mutex::scoped_lock lock(GlobalObservableInfo::getInstance().getObservablesMapMutex()); 338 const ChannelMap::const_iterator iter = NotificationChannels.find(const_cast<Observable *>(this)); 339 const bool status = iter != NotificationChannels.end(); 340 Channels *OurChannel = NULL; 341 if (status) 342 OurChannel = iter->second; 343 ASSERT(status, 344 "Observable::getChannel() - we do not have a channel "+toString(no)+" in NotificationChannels."); 345 ASSERT(OurChannel != NULL, 346 "Observable::getChannel() - observable has no channels."); 347 return OurChannel->getChannel(no); 337 return getNotificationChannel(this, no); 348 338 } 349 339 … … 361 351 } 362 352 { 363 const ChannelMap::const_iterator iter = 364 NotificationChannels.find(const_cast<Observable *>(this)); 365 // if not present, then we have zero observers 366 if (iter != NotificationChannels.end()) 367 for (Channels::NotificationTypetoRefMap::const_iterator channeliter = iter->second->ChannelMap.begin(); 368 channeliter != iter->second->ChannelMap.end(); 353 boost::recursive_mutex::scoped_lock lock(GlobalObservableInfo::getInstance().getObservablesMapMutex()); 354 const Channels *OurChannels = getNotificationChannels(this); 355 if (OurChannels != NULL) 356 for (Channels::NotificationTypetoRefMap::const_iterator channeliter = OurChannels->ChannelMap.begin(); 357 channeliter != OurChannels->ChannelMap.end(); 369 358 ++channeliter) 370 359 ObserverCount += (channeliter->second)->getNumberOfObservers(); … … 396 385 397 386 if (!_channels.empty()) { 398 boost::recursive_mutex::scoped_lock lock(GlobalObservableInfo::getInstance().getObservablesMapMutex());399 387 Channels *OurChannel = new Channels; 400 NotificationChannels.insert( std::make_pair(static_cast<Observable *>(this), OurChannel) );401 388 // add instance for each notification type 402 389 for (channels_t::const_iterator iter = _channels.begin(); 403 390 iter != _channels.end(); ++iter) 404 391 OurChannel->addChannel(*iter); 392 insertNotificationChannel( std::make_pair(static_cast<Observable *>(this), OurChannel) ); 405 393 } 406 394 } … … 436 424 437 425 // also kill instance in static Channels map if present 438 { 439 boost::recursive_mutex::scoped_lock lock(GlobalObservableInfo::getInstance().getObservablesMapMutex()); 440 ChannelMap::iterator iter = NotificationChannels.find(static_cast<Observable *>(this)); 441 if (iter != NotificationChannels.end()) { 442 iter->second->subjectKilled(static_cast<Observable *>(this)); 443 delete iter->second; 444 NotificationChannels.erase(iter); 445 } 446 } 426 eraseNotificationChannel(this); 447 427 } 448 428 … … 453 433 return channels; 454 434 } 435 436 void Observable::insertNotificationChannel(std::pair<Observable*, Channels *> _pair) 437 { 438 boost::recursive_mutex::scoped_lock lock(GlobalObservableInfo::getInstance().getObservablesMapMutex()); 439 NotificationChannels.insert(_pair); 440 } 441 442 void Observable::eraseNotificationChannel(Observable * const _target) 443 { 444 boost::recursive_mutex::scoped_lock lock(GlobalObservableInfo::getInstance().getObservablesMapMutex()); 445 ChannelMap::iterator iter = NotificationChannels.find(static_cast<Observable *>(_target)); 446 if (iter != NotificationChannels.end()) { 447 iter->second->subjectKilled(static_cast<Observable *>(_target)); 448 delete iter->second; 449 NotificationChannels.erase(iter); 450 } 451 } 452 453 bool Observable::isNotificationChannelPresent(const Observable * const _target) 454 { 455 boost::recursive_mutex::scoped_lock lock(GlobalObservableInfo::getInstance().getObservablesMapMutex()); 456 ChannelMap::const_iterator iter = 457 NotificationChannels.find(const_cast<Observable * const>(_target)); 458 return iter != NotificationChannels.end(); 459 } 460 461 462 const Channels* Observable::getNotificationChannels(const Observable * const _target) 463 { 464 boost::recursive_mutex::scoped_lock lock(GlobalObservableInfo::getInstance().getObservablesMapMutex()); 465 ChannelMap::const_iterator iter = 466 NotificationChannels.find(const_cast<Observable * const>(_target)); 467 if (iter != NotificationChannels.end()) 468 return iter->second; 469 else 470 return NULL; 471 } 472 473 Notification_ptr Observable::getNotificationChannel(const Observable * const _target, const size_t _no) 474 { 475 boost::recursive_mutex::scoped_lock lock(GlobalObservableInfo::getInstance().getObservablesMapMutex()); 476 ChannelMap::const_iterator iter = 477 NotificationChannels.find(const_cast<Observable * const>(_target)); 478 ASSERT(iter != NotificationChannels.end(), 479 "Observable::getNotificationChannel() - could not find channel for target " 480 +toString(_target)+"."); 481 return iter->second->getChannel(_no); 482 }
Note:
See TracChangeset
for help on using the changeset viewer.
