00001 #include "otsdaq-core/ConfigurationPluginDataFormats/MessageFacilityConfiguration.h"
00002 #include "otsdaq-core/Macros/ConfigurationPluginMacros.h"
00003 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
00004
00005 #include <iostream>
00006 #include <fstream>
00007 #include <stdio.h>
00008 using namespace ots;
00009
00010 #define MF_CFG_FILE std::string(getenv("USER_DATA")) + "/MessageFacilityConfigurations/MessageFacilityGen.fcl"
00011 #define QT_CFG_FILE std::string(getenv("USER_DATA")) + "/MessageFacilityConfigurations/QTMessageViewerGen.fcl"
00012 #define QUIET_CFG_FILE std::string(getenv("USER_DATA")) + "/MessageFacilityConfigurations/QuietForwarderGen.cfg"
00013 #define USE_WEB_BOOL_FILE std::string(getenv("USER_DATA")) + "/MessageFacilityConfigurations/UseWebConsole.bool"
00014 #define USE_QT_BOOL_FILE std::string(getenv("USER_DATA")) + "/MessageFacilityConfigurations/UseQTViewer.bool"
00015
00016
00017 #define COL_NAME "UID"
00018 #define COL_STATUS ViewColumnInfo::COL_NAME_STATUS
00019 #define COL_ENABLE_FWD "EnableUDPForwarding"
00020
00021 #define COL_USE_WEB "ForwardToWebConsoleGUI"
00022 #define COL_WEB_IP "WebConsoleForwardingIPAddress"
00023 #define COL_WEB_PORT0 "WebConsoleForwardingPort0"
00024 #define COL_WEB_PORT1 "WebConsoleForwardingPort1"
00025
00026 #define COL_USE_QT "ForwardToQTViewerGUI"
00027 #define COL_QT_IP "QTViewerForwardingIPAddress"
00028 #define COL_QT_PORT "QTViewerForwardingPort"
00029
00030
00031
00032 MessageFacilityConfiguration::MessageFacilityConfiguration(void) :
00033 ConfigurationBase("MessageFacilityConfiguration")
00034 {
00036
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 }
00063
00064 MessageFacilityConfiguration::~MessageFacilityConfiguration(void)
00065 {}
00066
00067 void MessageFacilityConfiguration::init(ConfigurationManager *configManager)
00068 {
00069
00070
00071
00072
00073 bool status,enableFwd,useWeb,useQT;
00074 int fwdPort;
00075 std::string fwdIP;
00076
00077 auto childrenMap = configManager->__SELF_NODE__.getChildren();
00078
00079
00080
00081 std::fstream fs;
00082 fs.open(MF_CFG_FILE, std::fstream::out | std::fstream::trunc);
00083 if(fs.fail())
00084 {
00085 __SS__ << "Failed to open Message Facility configuration file: " << MF_CFG_FILE << std::endl;
00086 throw std::runtime_error(ss.str());
00087 }
00088
00089
00090
00091 for(auto &child:childrenMap)
00092 {
00093 child.second.getNode(COL_STATUS ).getValue(status);
00094
00095 if(!status) continue;
00096
00097 child.second.getNode(COL_ENABLE_FWD ).getValue(enableFwd);
00098
00099 child.second.getNode(COL_USE_WEB ).getValue(useWeb);
00100 child.second.getNode(COL_USE_QT ).getValue(useQT);
00101
00102 if(useWeb && useQT)
00103 {
00104 fs.close();
00105 __SS__ << "Illegal Message Facility configuration: " <<
00106 "Can only enable Web Console or QT Viewer, not both." << std::endl;
00107 throw std::runtime_error(ss.str());
00108 }
00109
00110 std::fstream bfs;
00111
00112 bfs.open(USE_WEB_BOOL_FILE, std::fstream::out | std::fstream::trunc);
00113 if(bfs.fail())
00114 {
00115 fs.close();
00116 __SS__ << "Failed to open boolean Use of Web Console configuration file: " <<
00117 USE_WEB_BOOL_FILE << std::endl;
00118 throw std::runtime_error(ss.str());
00119 }
00120 bfs << (useWeb?1:0);
00121 bfs.close();
00122
00123
00124 bfs.open(USE_QT_BOOL_FILE, std::fstream::out | std::fstream::trunc);
00125 if(bfs.fail())
00126 {
00127 fs.close();
00128 __SS__ << "Failed to open boolean Use of QT Viewer configuration file: " <<
00129 USE_QT_BOOL_FILE << std::endl;
00130 throw std::runtime_error(ss.str());
00131 }
00132 bfs << (useQT?1:0);
00133 bfs.close();
00134
00135 if(enableFwd)
00136 {
00137
00138
00139 if(useWeb)
00140 {
00141
00142
00143 child.second.getNode(COL_WEB_PORT0 ).getValue(fwdPort);
00144 child.second.getNode(COL_WEB_IP ).getValue(fwdIP);
00145
00146 fs << "udp: {\n";
00147 fs << "\t" << "type: UDP\n";
00148 fs << "\t" << "threshold: DEBUG\n";
00149 fs << "\t" << "port: " << fwdPort << "\n";
00150 fs << "\t" << "host: \"" << fwdIP << "\"\n";
00151 fs << "}\n";
00152
00153
00154 std::fstream qtfs;
00155 qtfs.open(QUIET_CFG_FILE, std::fstream::out | std::fstream::trunc);
00156 if(qtfs.fail())
00157 {
00158 fs.close();
00159 __SS__ << "Failed to open Web Console's 'Quiet Forwarder' configuration file: " <<
00160 QUIET_CFG_FILE << std::endl;
00161 throw std::runtime_error(ss.str());
00162 }
00163 qtfs << "RECEIVE_PORT \t " << fwdPort << "\n";
00164 child.second.getNode(COL_WEB_PORT1 ).getValue(fwdPort);
00165 qtfs << "DESTINATION_PORT \t " << fwdPort << "\n";
00166 qtfs << "DESTINATION_IP \t " << fwdIP << "\n";
00167 qtfs.close();
00168 }
00169
00170
00171 if(useQT)
00172 {
00173
00174
00175 child.second.getNode(COL_QT_PORT ).getValue(fwdPort);
00176 child.second.getNode(COL_QT_IP ).getValue(fwdIP);
00177
00178 fs << "udp: {\n";
00179 fs << "\t" << "type: UDP\n";
00180 fs << "\t" << "threshold: DEBUG\n";
00181 fs << "\t" << "port: " << fwdPort << "\n";
00182 fs << "\t" << "host: \"" << fwdIP << "\"\n";
00183 fs << "}\n";
00184
00185
00186 std::fstream qtfs;
00187 qtfs.open(QT_CFG_FILE, std::fstream::out | std::fstream::trunc);
00188 if(qtfs.fail())
00189 {
00190 fs.close();
00191 __SS__ << "Failed to open QT Message Viewer configuration file: " <<
00192 QT_CFG_FILE << std::endl;
00193 throw std::runtime_error(ss.str());
00194 }
00195 qtfs << "receivers: \n{\n";
00196 qtfs << "\t" << "syslog: \n{\n";
00197 qtfs << "\t\t" << "receiverType: " << "\"UDP\"" << "\n";
00198 qtfs << "\t\t" << "port: " << fwdPort << "\n";
00199 qtfs << "\t}\n";
00200 qtfs << "}\n";
00201 qtfs << "\n";
00202 qtfs << "threshold: " << "DEBUG" << "\n";
00203 qtfs.close();
00204 }
00205 }
00206 else
00207 {
00208 __COUT__ << "Using cout-only MesageFacility configuration." << std::endl;
00209 fs << "console: {\n";
00210 fs << "\t" << "type: \"cout\"\n";
00211 fs << "\t" << "threshold: \"DEBUG\"\n";
00212 fs << "\t" << "noTimeStamps: true\n";
00213 fs << "\t" << "noLineBreaks: true\n";
00214 fs << "}\n";
00215 }
00216
00217 break;
00218 }
00219
00220
00221 fs.close();
00222 }
00223
00224 DEFINE_OTS_CONFIGURATION(MessageFacilityConfiguration)