ThreadPriorityConfiguration.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/Core/ThreadPriorityConfiguration.h>
00004 
00005 #include <fesa-core/Core/FesaDefs.h>
00006 #include <fesa-core/Exception/FesaException.h>
00007 #include <fesa-core/Utilities/XMLParser.h>
00008 #include <fesa-core/Utilities/ProcessConfiguration.h>
00009 
00010 #include <cmw-log/Logger.h>
00011 
00012 
00013 namespace
00014 {
00015 
00016 CMW::Log::Logger& startUpTrackingLogger = CMW::Log::LoggerFactory::getLogger("FESA.DIAG.FWK.StartUpTracking");
00017 
00018 } // namespace
00019 
00020 
00021 namespace fesa
00022 {
00023 
00024 ThreadPriorityConfiguration::~ThreadPriorityConfiguration()
00025 {
00026 }
00027 
00028 ThreadPriorityConfigurationFromFile::ThreadPriorityConfigurationFromFile(XMLParser& xmlParser, const ProcessConfiguration* processConfiguration) :
00029     xmlParser_(xmlParser),
00030     processConfiguration_(processConfiguration)
00031 {
00032 }
00033 
00034 ThreadPriorityConfigurationFromFile::~ThreadPriorityConfigurationFromFile()
00035 {
00036 }
00037 
00038 int32_t ThreadPriorityConfigurationFromFile::getPrioCMW() const
00039 {
00040     int32_t prio = 0;
00041 
00042     AttributeXML* attr =  xmlParser_.extractAttribute(threadCmwXMLElementName, priorityAttributeName);
00043     if (attr == 0)
00044     {
00045         if(processConfiguration_->isDefined(PropertyTag::NO_RT_SCHEDULING))
00046             prio = DEFAULT_NICE_PRIO_RDA_SERVER_THREAD;
00047         else
00048             prio = DEFAULT_RT_PRIO_RDA_SERVER_THREAD;
00049 
00050         std::ostringstream stream;
00051         stream << std::endl;
00052         stream << "------------------------------------------ Information -------------------------------------------"  << std::endl;
00053         stream << "You did not specify a prio-value for the RDA-SERVER-THREAD" << std::endl;
00054         stream << "The default priority value of " << prio << " will be used now for this thread!" << std::endl;
00055         stream << "--------------------------------------------------------------------------------------------------"  << std::endl;
00056         LOG_INFO_IF(startUpTrackingLogger, stream.str());
00057     }
00058     else
00059     {
00060         prio = atoi((attr->value_).c_str());
00061         delete attr;  // It is up to the caller of "extractAttribute" to delete the attributeXML object
00062     }
00063 
00064     return prio;
00065 }
00066 
00067 int32_t ThreadPriorityConfigurationFromFile::getPrioPersistence() const
00068 {
00069     int32_t prio = 0;
00070 
00071     AttributeXML* attr =  xmlParser_.extractAttribute(threadPersistenceXMLElementName, priorityAttributeName);
00072     if (attr == 0)
00073     {
00074         if(processConfiguration_->isDefined(PropertyTag::NO_RT_SCHEDULING))
00075             prio = DEFAULT_NICE_PRIO_PERSISTANCE_THREAD;
00076         else
00077             prio = DEFAULT_RT_PRIO_PERSISTANCE_THREAD;
00078 
00079         std::ostringstream stream;
00080         stream << std::endl;
00081         stream << "------------------------------------------ Information -------------------------------------------"  << std::endl;
00082         stream << "You did not specify a prio-value for the PERSISTANCY-THREAD" << std::endl;
00083         stream << "The default priority value of " << prio << " will be used now for this thread!" << std::endl;
00084         stream << "--------------------------------------------------------------------------------------------------"  << std::endl;
00085         LOG_INFO_IF(startUpTrackingLogger, stream.str());
00086     }
00087     else
00088     {
00089         prio = atoi((attr->value_).c_str());
00090         delete attr;  // It is up to the caller of "extractAttribute" to delete the attributeXML object
00091     }
00092 
00093     return prio;
00094 }
00095 
00096 int32_t  ThreadPriorityConfigurationFromFile::getPrioNotificationConsumer() const
00097 {
00098     int32_t prio = 0;
00099     AttributeXML* attr =  xmlParser_.extractAttribute(threadNotificationConsumerXMLElementName, priorityAttributeName);
00100     if (attr == 0)
00101     {
00102         if(processConfiguration_->isDefined(PropertyTag::NO_RT_SCHEDULING))
00103             prio = DEFAULT_NICE_PRIO_CLIENT_NOTIFICATION_THREAD;
00104         else
00105             prio = DEFAULT_RT_PRIO_CLIENT_NOTIFICATION_THREAD;
00106 
00107         std::ostringstream stream;
00108         stream << std::endl;
00109         stream << "------------------------------------------ Information -------------------------------------------"  << std::endl;
00110         stream << "You did not specify a prio-value for the SERVER-NOTIFICATION-THREAD" << std::endl;
00111         stream << "The default priority value of " << prio << " will be used now for this thread!" << std::endl;
00112         stream << "--------------------------------------------------------------------------------------------------"  << std::endl;
00113         LOG_INFO_IF(startUpTrackingLogger, stream.str());
00114     }
00115     else
00116     {
00117         prio = atoi((attr->value_).c_str());
00118         delete attr;  // It is up to the caller of "extractAttribute" to delete the attributeXML object
00119     }
00120 
00121     return prio;
00122 }
00123 
00124 int32_t ThreadPriorityConfigurationFromFile::getPrioRTScheduler(const std::string& name) const
00125 {
00126     int32_t prio = 0;
00127     std::string rtSchedulerName = name + threadRTSchedulerXMLElementName;
00128     AttributeXML* attr =  xmlParser_.extractAttribute(rtSchedulerName, priorityAttributeName);
00129     if (attr == 0)
00130     {
00131         if(processConfiguration_->isDefined(PropertyTag::NO_RT_SCHEDULING))
00132             prio = DEFAULT_NICE_PRIO_CONCURRENCY_LAYER;
00133         else
00134             prio = DEFAULT_RT_PRIO_CONCURRENCY_LAYER;
00135 
00136         std::ostringstream stream;
00137         stream << std::endl;
00138         stream << "------------------------------------------ Information -------------------------------------------"  << std::endl;
00139         stream << "You did not specify a prio-value for the concurrency-layer " << name << std::endl;
00140         stream << "The default priority value of " << prio << " will be used now for the thread of this concurrency-layer!" << std::endl;
00141         stream << "--------------------------------------------------------------------------------------------------"  << std::endl;
00142         LOG_INFO_IF(startUpTrackingLogger, stream.str());
00143     }
00144     else
00145     {
00146         prio = atoi((attr->value_).c_str());
00147         delete attr;  // It is up to the caller of "extractAttribute" to delete the attributeXML object
00148     }
00149 
00150     return prio;
00151 }
00152 
00153 int32_t ThreadPriorityConfigurationFromFile::getPrioEventSource(const std::string& name) const
00154 {
00155     int32_t prio = 0;
00156     std::string eventSourceName = name + threadEventSourceXMLElementName;
00157     AttributeXML* attr =  xmlParser_.extractAttribute(eventSourceName, priorityAttributeName);
00158     if (attr == 0)
00159     {
00160         if(processConfiguration_->isDefined(PropertyTag::NO_RT_SCHEDULING))
00161             prio = DEFAULT_NICE_PRIO_EVENT_SOURCE;
00162         else
00163             prio = DEFAULT_RT_PRIO_EVENT_SOURCE;
00164 
00165         std::ostringstream stream;
00166         stream << std::endl;
00167         stream << "------------------------------------------ Information -------------------------------------------"  << std::endl;
00168         stream << "You did not specify a prio-value for the event-source " << name << std::endl;
00169         stream << "The default priority value of " << prio << " will be used now for the thread of this event-source!" << std::endl;
00170         stream << "--------------------------------------------------------------------------------------------------"  << std::endl;
00171         LOG_INFO_IF(startUpTrackingLogger, stream.str());
00172     }
00173     else
00174     {
00175         prio = atoi((attr->value_).c_str());
00176         delete attr;  // It is up to the caller of "extractAttribute" to delete the attributeXML object
00177     }
00178 
00179     return prio;
00180 }
00181 
00182 int32_t ThreadPriorityConfigurationFromFile::getPrioNotificationthread(const std::string& className, const std::string& notificationThreadKey) const
00183 {
00184     // The xpath is: //prio-management/classes/className/client-notification-threads/notificationThreadKey
00185     int32_t prio = 0;
00186     std::string notificationName =  className + threadClientNotificationXMLElementName + notificationThreadKey;
00187 
00188     //13.12.2012 Alex ... quickfixed in release-trunk for GSI-release (FESA-3245 takes care for complete-fix)
00189     AttributeXML* attr = 0;
00190     //AttributeXML* attr =  xmlParser_.extractAttribute(threadNotificationConsumerXMLElementName, priorityAttributeName);
00191 
00192     if (attr == 0)
00193     {
00194         if(processConfiguration_->isDefined(PropertyTag::NO_RT_SCHEDULING))
00195         {
00196             prio = DEFAULT_NICE_PRIO_CLIENT_NOTIFICATION_THREAD;
00197         }
00198         else
00199         {
00200             prio = DEFAULT_RT_PRIO_CLIENT_NOTIFICATION_THREAD;
00201         }
00202         std::ostringstream stream;
00203         stream << std::endl;
00204         stream << "------------------------------------------ Information -------------------------------------------"  << std::endl;
00205         stream << "You did not specify a prio-value for the " << notificationThreadKey << std::endl;
00206         stream << "The default priority value of " << prio << " will be used now for this thread!" << std::endl;
00207         stream << "--------------------------------------------------------------------------------------------------"  << std::endl;
00208         LOG_INFO_IF(startUpTrackingLogger, stream.str());
00209     }
00210     else
00211     {
00212         prio = atoi((attr->value_).c_str());
00213         delete attr;  // It is up to the caller of "extractAttribute" to delete the attributeXML object
00214     }
00215     return prio;
00216 }
00217 
00218 bool ThreadPriorityConfigurationFromFile::getMaximumPrio(int32_t &maxPrio) const
00219 {
00220     int32_t prio;
00221     //all elements which define a priority-attribute
00222     std::string xpathExpr = "//*[@" + priorityAttributeName + "]";
00223     std::vector<ElementXML*>* elementXMLCol = xmlParser_.extractElementsFromXPath(xpathExpr);
00224 
00225     if (elementXMLCol == NULL )//no prio-element found
00226     {
00227         return false;
00228     }
00229     else
00230     {
00231         std::vector<ElementXML*>::iterator elementIter;
00232         std::vector<AttributeXML*>::iterator atributeIter;
00233         for(elementIter=elementXMLCol->begin();elementIter!=elementXMLCol->end();elementIter++)
00234         {
00235             std::vector<AttributeXML*> attrCol = (*elementIter)->attributeList_;
00236             for (atributeIter = attrCol.begin(); atributeIter != attrCol.end(); atributeIter++)
00237             {
00238                 if((*atributeIter)->name_ == priorityAttributeName)
00239                 {
00240                     prio = atoi( ((*atributeIter)->value_).c_str() );
00241                     if( prio > maxPrio)
00242                         maxPrio = prio;
00243                 }
00244             }
00245         }
00246         delete elementXMLCol;  // It is up to the caller of "extractAttribute" to delete the attributeXML object
00247     }
00248 
00249     return true;
00250 }
00251 
00252 int32_t ThreadPriorityConfigurationFromCCDB::getPrioCMW() const
00253 {
00254     return 0;
00255 }
00256 
00257 int32_t ThreadPriorityConfigurationFromCCDB::getPrioPersistence() const
00258 {
00259     return 0;
00260 }
00261 
00262 int32_t  ThreadPriorityConfigurationFromCCDB::getPrioNotificationConsumer() const
00263 {
00264     return 0;
00265 }
00266 
00267 int32_t ThreadPriorityConfigurationFromCCDB::getPrioRTScheduler(const std::string& name) const
00268 {
00269     return 0;
00270 }
00271 
00272 int32_t ThreadPriorityConfigurationFromCCDB::getPrioEventSource(const std::string& name) const
00273 {
00274     return 0;
00275 }
00276 
00277 int32_t ThreadPriorityConfigurationFromCCDB::getPrioNotificationthread(const std::string& className, const std::string& notificationThreadKey) const
00278 {
00279     return 0;
00280 }
00281 
00282 bool ThreadPriorityConfigurationFromCCDB::getMaximumPrio(int32_t &maxPrio) const
00283 {
00284     return 0;
00285 }
00286 
00287 } // fesa

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1