NotificationThreadFactory.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/RDADeviceServer/NotificationThreadFactory.h>
00004 #include <fesa-core/RDADeviceServer/NotificationThread.h>
00005 
00006 #include <iostream>
00007 
00008 #include <cmw-log/Logger.h>
00009 
00010 namespace
00011 {
00012 CMW::Log::Logger& logger = CMW::Log::LoggerFactory::getLogger("FESA.FWK.fesa-core.RDADeviceServer");
00013 }
00014 
00015 
00016 
00017 namespace fesa
00018 {
00019 
00020 NotificationThreadFactory::NotificationThreadFactory()
00021 {
00022 }
00023 
00024 NotificationThreadFactory::~NotificationThreadFactory()
00025 {
00026 }
00027 
00028 NotificationThread& NotificationThreadFactory::getThread(const std::string& className, const std::string& notificationThreadKey)
00029 {
00030     std::map<std::string, boost::shared_ptr<NotificationThread> >::iterator iter;
00031     // key of the map = className + notificationThreadKey
00032     std::string key = className + notificationThreadKey;
00033     iter = threadPool_.find(key);
00034     if (iter != threadPool_.end()) // Thread was found in the collection
00035     {
00036         return *((*iter).second.get());
00037     }
00038     else // We need to create a new Notification thread for such notificationThreadKey
00039     {
00040         if(logger.isLoggable(CMW::Log::Level::LL_DEBUG))
00041         {
00042             std::ostringstream msg;
00043             msg << "creating new notification thread with key: " << key;
00044             LOG_DEBUG_IF(logger, msg.str());
00045         }
00046         boost::shared_ptr<NotificationThread> thread(new NotificationThread(className, notificationThreadKey));
00047         threadPool_.insert(std::make_pair(key, thread));
00048         return *(thread.get());
00049     }
00050 }
00051 } // fesa

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1