SetDiagnosticSetting.cpp
Go to the documentation of this file.00001
00002
00003 #include <fesa-core/Server/SetDiagnosticSetting.h>
00004
00005 #include <fesa-core/Server/RequestEvent.h>
00006 #include <fesa-core/DataStore/GlobalDevice.h>
00007 #include <fesa-core/Diagnostic/DiagnosticUtils.h>
00008 #include <fesa-core/Diagnostic/Diagnostics.h>
00009
00010 #include <cmw-rda/Data.h>
00011 #include <cmw-log/Logger.h>
00012 #include <cmw-log/FilterLogger.h>
00013 #include <cmw-log/AppenderManager.h>
00014 #include <cmw-log/LogException.h>
00015 #include <cmw-log-stomp/StompAppenderBuilder.h>
00016
00017
00018 namespace
00019 {
00020
00021 const std::string serverActionTopic = fesa::DiagnosticUtils::setActionProfilingStr;
00022 const std::string appenderName = "DiagStompLogs";
00023 const std::string socketType = "udp";
00024 const std::string domain = "FESA";
00025 const std::string subDomain = "TEST";
00026 const std::string source = "TEST";
00027 CMW::Log::Appender* diagStompAppender = NULL;
00028 CMW::Log::Logger& logger = CMW::Log::LoggerFactory::getLogger("FESA.FWK.fesa-core.Server.SetDiagnosticSetting");
00029
00030 }
00031
00032
00033 namespace fesa
00034 {
00035
00036 SetDiagnosticSetting::SetDiagnosticSetting(ServerActionConfig& serverActCfg, const AbstractServiceLocator* serviceLocator, const std::map<std::string, const AbstractServiceLocator*> serviceLocatorRelatedClasses) :
00037 AbstractServerAction(serverActCfg, serviceLocator, serviceLocatorRelatedClasses)
00038 {
00039 }
00040
00041
00042 SetDiagnosticSetting::~SetDiagnosticSetting()
00043 {
00044 }
00045
00046
00047 bool SetDiagnosticSetting::needFilter()
00048 {
00049 return false;
00050 }
00051
00052
00053 void SetDiagnosticSetting::execute(RequestEvent* event, AbstractDevice& device, const rdaData& filter,
00054 rdaData& data, IOType ioType, RequestType requestType)
00055 {
00056 const boost::shared_ptr<Diagnostics>& diagnostics = AbstractEquipment::getInstance()->getDiagnostics();
00057 const DiagnosticUtils::DiagnosticTopics& frameworkTopics = diagnostics->getTopics(DiagnosticUtils::framework);
00058 const DiagnosticUtils::DiagnosticTopics& userTopics = diagnostics->getTopics(DiagnosticUtils::user);
00059 DiagnosticUtils::DiagnosticMessage diagMsg;
00060 diagMsg.side = DiagnosticUtils::framework;
00061 diagMsg.source = DiagnosticUtils::server;
00062 diagMsg.name = getName();
00063 diagMsg.action = DiagnosticUtils::start;
00064 diagnostics->log(serverActionTopic, diagMsg);
00065 GlobalDevice& globalDevice = static_cast<GlobalDevice&>(device);
00066 MultiplexingContext* context = event->getMultiplexingContext();
00067 bool enabled = false;
00068 if (data.contains("enableDiagMode"))
00069 {
00070 enabled = data.extractBoolean("enableDiagMode");
00071 }
00072
00073 if (enabled == false)
00074 {
00075 const bool diagEnabled = globalDevice.enableDiagMode.get(context);
00076 if (diagEnabled == true)
00077 {
00078 for (DiagnosticUtils::DiagnosticTopics::const_iterator iter = frameworkTopics.begin(); iter != frameworkTopics.end(); ++iter)
00079 {
00080 const std::string topicName = iter->second;
00081 diagnostics->disable(DiagnosticUtils::framework, topicName);
00082 }
00083 for (DiagnosticUtils::DiagnosticTopics::const_iterator iter = userTopics.begin(); iter != userTopics.end(); ++iter)
00084 {
00085 const std::string topicName = iter->second;
00086 diagnostics->disable(DiagnosticUtils::user, topicName);
00087 }
00088 CMW::Log::AppenderManager::unregisterAppender(appenderName);
00089 delete diagStompAppender;
00090 diagStompAppender = NULL;
00091 }
00092 globalDevice.enableDiagMode.set(false, context);
00093 return;
00094 }
00095 globalDevice.enableDiagMode.set(true, context);
00096 if (data.contains("hostName") && data.contains("portNumber"))
00097 {
00098 const std::string host = data.getString("hostName");
00099 const int32_t port = static_cast<int32_t>(data.extractInt("portNumber"));
00100 globalDevice.hostName.set(host.c_str(), context);
00101 globalDevice.portNumber.set(port, context);
00102
00103
00104
00105 CMW::Log::FilterLogger::Filters loggerFilters;
00106 loggerFilters.push_back("FESA.DIAG.FWK");
00107 loggerFilters.push_back("FESA.DIAG.USR");
00108 CMW::LogStomp::StompAppenderBuilder builder(appenderName);
00109 builder.setSocketType(socketType);
00110 builder.setHost(host);
00111 builder.setPort(port);
00112 builder.setDomain(domain);
00113 builder.setSubdomain(subDomain);
00114 builder.setSource(source);
00115 builder.setConnectionConfirmation(false);
00116 builder.addFilter(boost::shared_ptr<CMW::Log::FilterLogger>(new CMW::Log::FilterLogger(loggerFilters)));
00117 diagStompAppender = builder.build();
00118 try
00119 {
00120 CMW::Log::AppenderManager::registerAppender(diagStompAppender);
00121 }
00122 catch (CMW::Log::LogException& error)
00123 {
00124 LOG_ERROR_IF(logger, error.what());
00125 }
00126 }
00127 if (data.contains("fwkTopic"))
00128 {
00129 const int32_t fwkTopic = static_cast<int32_t>(data.extractInt("fwkTopic"));
00130 globalDevice.fwkTopic.set(fwkTopic, context);
00131 for (DiagnosticUtils::DiagnosticTopics::const_iterator iter = frameworkTopics.begin(); iter != frameworkTopics.end(); ++iter)
00132 {
00133 const int32_t mask = iter->first;
00134 const std::string topicName = iter->second;
00135 const bool enabled = fwkTopic & mask;
00136 if(logger.isLoggable(CMW::Log::Level::LL_TRACE))
00137 {
00138 std::ostringstream msg;
00139 msg << "fwkTopic: " << fwkTopic << "; mask: " << mask << "; topicName: " << topicName << "; enabled: " << enabled << "; loggerName: FESA.DIAG.FWK." << topicName;
00140 LOG_TRACE_IF(logger, msg.str());
00141 }
00142 if (enabled == true)
00143 {
00144 diagnostics->enable(DiagnosticUtils::framework, topicName);
00145 }
00146 else
00147 {
00148 diagnostics->disable(DiagnosticUtils::framework, topicName);
00149 }
00150 }
00151 }
00152 if (data.contains("customTopic"))
00153 {
00154 const int32_t customTopic = static_cast<int32_t>(data.extractInt("customTopic"));
00155 globalDevice.customTopic.set(customTopic, context);
00156 for (DiagnosticUtils::DiagnosticTopics::const_iterator iter = userTopics.begin(); iter != userTopics.end(); ++iter)
00157 {
00158 const int32_t mask = iter->first;
00159 const std::string topicName = iter->second;
00160 const bool enabled = customTopic & mask;
00161 if (logger.isLoggable(CMW::Log::Level::LL_TRACE))
00162 {
00163 std::ostringstream msg;
00164 msg << "customTopic: " << customTopic << "; mask: " << mask << "; topicName: " << topicName
00165 << "; enabled: " << enabled << "; loggerName: FESA.DIAG.USR." << topicName;
00166 LOG_TRACE_IF(logger, msg.str());
00167 }
00168 if (enabled == true)
00169 {
00170 diagnostics->enable(DiagnosticUtils::user, topicName);
00171 }
00172 else
00173 {
00174 diagnostics->disable(DiagnosticUtils::user, topicName);
00175 }
00176 }
00177 }
00178 if (data.contains("traceDevices"))
00179 {
00180 const std::string traceDevices = data.getString("traceDevices");
00181 globalDevice.traceDevices.set(traceDevices.c_str(), context);
00182 }
00183 if (data.contains("bypassActions"))
00184 {
00185 const std::string bypassActions = data.getString("bypassActions");
00186 globalDevice.bypassActions.set(bypassActions.c_str(), context);
00187 std::vector<std::string> actions;
00188 CMW::Util::StringUtils::tokenize(bypassActions, actions, ",");
00189 std::vector<std::string>::const_iterator iter;
00190 for (iter = actions.begin(); iter < actions.end(); ++iter)
00191 {
00192 diagnostics->disable(DiagnosticUtils::framework, DiagnosticUtils::getActionProfilingStr + "." + *iter);
00193 diagnostics->disable(DiagnosticUtils::framework, DiagnosticUtils::setActionProfilingStr + "." + *iter);
00194 diagnostics->disable(DiagnosticUtils::framework, DiagnosticUtils::rtActionProfilingStr + "." + *iter);
00195 diagnostics->disable(DiagnosticUtils::framework, DiagnosticUtils::getActionTrackingStr + "." + *iter);
00196 diagnostics->disable(DiagnosticUtils::framework, DiagnosticUtils::setActionTrackingStr + "." + *iter);
00197 diagnostics->disable(DiagnosticUtils::framework, DiagnosticUtils::rtActionTrackingStr + "." + *iter);
00198 }
00199 }
00200 diagMsg.action = DiagnosticUtils::stop;
00201 diagnostics->log(serverActionTopic, diagMsg);
00202 }
00203
00204 void SetDiagnosticSetting::performCommit(MultiplexingContext& context, AbstractDevice* device)
00205 {
00206 }
00207
00208 void SetDiagnosticSetting::performRollback(MultiplexingContext& context, AbstractDevice* transactionDevice)
00209 {
00210 }
00211 }