00001 // Copyright CERN 2012 - Developed in collaboration with GSI 00002 00003 #include <fesa-core/Diagnostic/Diagnostics.h> 00004 00005 #include <fesa-core/Diagnostic/AbstractUserDiagnostics.h> 00006 #include <fesa-core/Utilities/Thread.h> 00007 00008 #include <iostream> 00009 00010 00011 namespace fesa 00012 { 00013 00014 Diagnostics::Diagnostics(const FrameworkDiagnostics& frameworkDiagnostics, const boost::shared_ptr<AbstractUserDiagnostics>& userDiagnostics) : 00015 frameworkDiagnostics_(frameworkDiagnostics), 00016 userDiagnostics_(userDiagnostics) 00017 { 00018 } 00019 00020 00021 Diagnostics::~Diagnostics() 00022 { 00023 } 00024 00025 00026 const DiagnosticUtils::DiagnosticTopics& 00027 Diagnostics::getTopics(DiagnosticUtils::Side side) const 00028 { 00029 switch (side) 00030 { 00031 case DiagnosticUtils::framework: 00032 return frameworkDiagnostics_.getTopics(); 00033 case DiagnosticUtils::user: 00034 return userDiagnostics_.get()->getTopics(); 00035 default: 00036 assert(false); 00037 } 00038 } 00039 00040 00041 void 00042 Diagnostics::log(const std::string& topic, DiagnosticUtils::DiagnosticMessage& diagMsg) 00043 { 00044 // diagMsg.thread = Thread::getThreadName(pthread_self()); 00045 std::string extendedTopic(topic); 00046 if (diagMsg.name.empty() == false) 00047 { 00048 extendedTopic.append("." + diagMsg.name); 00049 } 00050 switch (diagMsg.side) 00051 { 00052 case DiagnosticUtils::framework: 00053 frameworkDiagnostics_.log(extendedTopic, diagMsg); 00054 break; 00055 case DiagnosticUtils::user: 00056 userDiagnostics_->log(extendedTopic, diagMsg); 00057 break; 00058 default: 00059 assert(false); 00060 } 00061 } 00062 00063 00064 void 00065 Diagnostics::enable(DiagnosticUtils::Side side, const std::string& topic) const 00066 { 00067 switch (side) 00068 { 00069 case DiagnosticUtils::framework: 00070 frameworkDiagnostics_.enable(topic); 00071 break; 00072 case DiagnosticUtils::user: 00073 return userDiagnostics_.get()->enable(topic); 00074 break; 00075 default: 00076 assert(false); 00077 } 00078 } 00079 00080 00081 void 00082 Diagnostics::disable(DiagnosticUtils::Side side, const std::string& topic) const 00083 { 00084 switch (side) 00085 { 00086 case DiagnosticUtils::framework: 00087 frameworkDiagnostics_.disable(topic); 00088 break; 00089 case DiagnosticUtils::user: 00090 return userDiagnostics_.get()->disable(topic); 00091 break; 00092 default: 00093 assert(false); 00094 } 00095 } 00096 00097 } // fesa