$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h" 00002 #include "otsdaq-core/Macros/TablePluginMacros.h" 00003 #include "otsdaq-core/TablePluginDataFormats/MessageFacilityTable.h" 00004 00005 #include <stdio.h> 00006 #include <fstream> // std::fstream 00007 #include <iostream> 00008 using namespace ots; 00009 00010 #define MF_CFG_FILE \ 00011 std::string(getenv("USER_DATA")) + \ 00012 "/MessageFacilityConfigurations/MessageFacilityGen.fcl" 00013 #define QT_CFG_FILE \ 00014 std::string(getenv("USER_DATA")) + \ 00015 "/MessageFacilityConfigurations/QTMessageViewerGen.fcl" 00016 #define QUIET_CFG_FILE \ 00017 std::string(getenv("USER_DATA")) + \ 00018 "/MessageFacilityConfigurations/QuietForwarderGen.cfg" 00019 #define USE_WEB_BOOL_FILE \ 00020 std::string(getenv("USER_DATA")) + \ 00021 "/MessageFacilityConfigurations/" \ 00022 "UseWebConsole.bool" 00023 #define USE_QT_BOOL_FILE \ 00024 std::string(getenv("USER_DATA")) + "/MessageFacilityConfigurations/UseQTViewer.bool" 00025 00026 // MessageFacilityTable Column names 00027 #define COL_NAME "UID" 00028 #define COL_STATUS TableViewColumnInfo::COL_NAME_STATUS 00029 #define COL_ENABLE_FWD "EnableUDPForwarding" 00030 00031 #define COL_USE_WEB "ForwardToWebConsoleGUI" 00032 #define COL_WEB_IP "WebConsoleForwardingIPAddress" 00033 #define COL_WEB_PORT0 "WebConsoleForwardingPort0" 00034 #define COL_WEB_PORT1 "WebConsoleForwardingPort1" 00035 00036 #define COL_USE_QT "ForwardToQTViewerGUI" 00037 #define COL_QT_IP "QTViewerForwardingIPAddress" 00038 #define COL_QT_PORT "QTViewerForwardingPort" 00039 00040 MessageFacilityTable::MessageFacilityTable(void) : TableBase("MessageFacilityTable") 00041 { 00043 // WARNING: the names used in C++ MUST match the Table INFO // 00045 00046 // <?xml version="1.0" encoding="UTF-8" standalone="no" ?> 00047 // <ROOT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 00048 // xsi:noNamespaceSchemaLocation="TableInfo.xsd"> <TABLE 00049 // Name="MessageFacilityTable"> 00050 // <VIEW Name="MESSAGE_FACILITY_TABLE" 00051 // Type="File,Database,DatabaseTest"> 00052 // <COLUMN Type="UID" Name="UID" StorageName="UID" 00053 // DataType="VARCHAR2"/> <COLUMN Type="OnOff" Name="Status" 00054 // StorageName="STATUS" DataType="VARCHAR2"/> 00055 // <COLUMN Type="TrueFalse" Name="EnableUDPForwarding" 00056 // StorageName="ENABLE_UDP_FORWARDING" DataType="VARCHAR2"/> 00057 // <COLUMN Type="YesNo" Name="ForwardToWebConsoleGUI" 00058 // StorageName="FORWARD_TO_WEB_CONSOLE_GUI" DataType="VARCHAR2"/> 00059 // <COLUMN Type="Data" Name="WebConsoleForwardingIPAddress" 00060 // StorageName="WEB_CONSOLE_FORWARDING_IP_ADDRESS" DataType="VARCHAR2"/> 00061 // <COLUMN Type="Data" Name="WebConsoleForwardingPort0" 00062 // StorageName="WEB_CONSOLE_FORWARDING_PORT0" DataType="NUMBER"/> 00063 // <COLUMN Type="Data" Name="WebConsoleForwardingPort1" 00064 // StorageName="WEB_CONSOLE_FORWARDING_PORT1" DataType="NUMBER"/> 00065 // <COLUMN Type="YesNo" Name="ForwardToQTViewerGUI" 00066 // StorageName="FORWARD_TO_QT_VIEWER_GUI" DataType="VARCHAR2"/> 00067 // <COLUMN Type="Data" Name="QTViewerForwardingIPAddress" 00068 // StorageName="QT_VIEWER_FORWARDING_IP_ADDRESS" DataType="VARCHAR2"/> 00069 // <COLUMN Type="Data" Name="QTViewerForwardingPort" 00070 // StorageName="QT_VIEWER_FORWARDING_PORT" DataType="NUMBER"/> 00071 // <COLUMN Type="Comment" Name="CommentDescription" 00072 // StorageName="COMMENT_DESCRIPTION" DataType="VARCHAR2"/> 00073 // <COLUMN Type="Author" Name="Author" StorageName="AUTHOR" 00074 // DataType="VARCHAR2"/> <COLUMN Type="Timestamp" 00075 // Name="RecordInsertionTime" StorageName="RECORD_INSERTION_TIME" 00076 // DataType="TIMESTAMP WITH TIMEZONE"/> 00077 // </VIEW> 00078 // </TABLE> 00079 // </ROOT> 00080 } 00081 00082 MessageFacilityTable::~MessageFacilityTable(void) {} 00083 00084 void MessageFacilityTable::init(ConfigurationManager* configManager) 00085 { 00086 // __COUT__ << "*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*" << std::endl; 00087 // __COUT__ << configManager->__SELF_NODE__ << std::endl; 00088 00089 bool status, enableFwd, useWeb, useQT; 00090 int fwdPort; 00091 std::string fwdIP; 00092 00093 auto childrenMap = configManager->__SELF_NODE__.getChildren(); 00094 00095 // generate MF_CFG_FILE file 00096 std::fstream fs; 00097 fs.open(MF_CFG_FILE, std::fstream::out | std::fstream::trunc); 00098 if(fs.fail()) 00099 { 00100 __SS__ << "Failed to open Message Facility table file: " << MF_CFG_FILE 00101 << std::endl; 00102 __SS_THROW__; 00103 } 00104 else 00105 __COUT__ << "Opened.. " << MF_CFG_FILE << __E__; 00106 00107 // loop through all children just to be same as other tables 00108 // exit loop after first active one 00109 for(auto& child : childrenMap) 00110 { 00111 child.second.getNode(COL_STATUS).getValue(status); 00112 00113 if(!status) 00114 continue; // skip inactive rows 00115 00116 child.second.getNode(COL_ENABLE_FWD).getValue(enableFwd); 00117 00118 child.second.getNode(COL_USE_WEB).getValue(useWeb); 00119 child.second.getNode(COL_USE_QT).getValue(useQT); 00120 00121 if(useWeb && useQT) 00122 { 00123 fs.close(); 00124 __SS__ << "Illegal Message Facility table: " 00125 << "Can only enable Web Console or QT Viewer, not both." << std::endl; 00126 __SS_THROW__; 00127 } 00128 00129 std::fstream bfs; 00130 // output use web bool for StartOTS.sh 00131 bfs.open(USE_WEB_BOOL_FILE, std::fstream::out | std::fstream::trunc); 00132 if(bfs.fail()) 00133 { 00134 fs.close(); 00135 __SS__ << "Failed to open boolean Use of Web Console table file: " 00136 << USE_WEB_BOOL_FILE << std::endl; 00137 __SS_THROW__; 00138 } 00139 bfs << (useWeb ? 1 : 0); 00140 bfs.close(); 00141 00142 // output use web bool for StartOTS.sh 00143 bfs.open(USE_QT_BOOL_FILE, std::fstream::out | std::fstream::trunc); 00144 if(bfs.fail()) 00145 { 00146 fs.close(); 00147 __SS__ << "Failed to open boolean Use of QT Viewer table file: " 00148 << USE_QT_BOOL_FILE << std::endl; 00149 __SS_THROW__; 00150 } 00151 bfs << (useQT ? 1 : 0); 00152 bfs.close(); 00153 00154 if(enableFwd) // write udp forward config 00155 { 00156 // handle using web gui 00157 if(useWeb) 00158 { 00159 __COUT__ << "Forwarding to Web GUI with UDP forward MesageFacility " 00160 "table." 00161 << std::endl; 00162 00163 child.second.getNode(COL_WEB_PORT0).getValue(fwdPort); 00164 child.second.getNode(COL_WEB_IP).getValue(fwdIP); 00165 00166 fs << "udp: {\n"; 00167 fs << "\t" 00168 << "type: UDP\n"; 00169 fs << "\t" 00170 << "threshold: DEBUG\n"; 00171 fs << "\t" 00172 << "port: " << fwdPort << "\n"; 00173 fs << "\t" 00174 << "host: \"" << fwdIP << "\"\n"; 00175 fs << "}\n"; 00176 00177 // output quiet forwarder config file 00178 std::fstream qtfs; 00179 qtfs.open(QUIET_CFG_FILE, std::fstream::out | std::fstream::trunc); 00180 if(qtfs.fail()) 00181 { 00182 fs.close(); 00183 __SS__ << "Failed to open Web Console's 'Quiet Forwarder' " 00184 "table file: " 00185 << QUIET_CFG_FILE << std::endl; 00186 __SS_THROW__; 00187 } 00188 qtfs << "RECEIVE_PORT \t " << fwdPort << "\n"; 00189 child.second.getNode(COL_WEB_PORT1).getValue(fwdPort); 00190 qtfs << "DESTINATION_PORT \t " << fwdPort << "\n"; 00191 qtfs << "DESTINATION_IP \t " << fwdIP << "\n"; 00192 qtfs.close(); 00193 } 00194 00195 // handle using qt viewer 00196 if(useQT) 00197 { 00198 __COUT__ << "Forwarding to Web GUI with UDP forward MesageFacility " 00199 "table." 00200 << std::endl; 00201 00202 child.second.getNode(COL_QT_PORT).getValue(fwdPort); 00203 child.second.getNode(COL_QT_IP).getValue(fwdIP); 00204 00205 fs << "udp: {\n"; 00206 fs << "\t" 00207 << "type: UDP\n"; 00208 fs << "\t" 00209 << "threshold: DEBUG\n"; 00210 fs << "\t" 00211 << "port: " << fwdPort << "\n"; 00212 fs << "\t" 00213 << "host: \"" << fwdIP << "\"\n"; 00214 fs << "}\n"; 00215 00216 // output QT Viewer config file 00217 std::fstream qtfs; 00218 qtfs.open(QT_CFG_FILE, std::fstream::out | std::fstream::trunc); 00219 if(qtfs.fail()) 00220 { 00221 fs.close(); 00222 __SS__ << "Failed to open QT Message Viewer table file: " 00223 << QT_CFG_FILE << std::endl; 00224 __SS_THROW__; 00225 } 00226 qtfs << "receivers: \n{\n"; 00227 qtfs << "\t" 00228 << "syslog: \n{\n"; 00229 qtfs << "\t\t" 00230 << "receiverType: " 00231 << "\"UDP\"" 00232 << "\n"; 00233 qtfs << "\t\t" 00234 << "port: " << fwdPort << "\n"; 00235 qtfs << "\t}\n"; // close syslog 00236 qtfs << "}\n"; // close receivers 00237 qtfs << "\n"; 00238 qtfs << "threshold: " 00239 << "DEBUG" 00240 << "\n"; 00241 qtfs.close(); 00242 } 00243 } 00244 else // write cout config (not forwarding to external process) 00245 { 00246 __COUT__ << "Using cout-only MesageFacility table." << std::endl; 00247 fs << "console: {\n"; 00248 fs << "\t" 00249 << "type: \"cout\"\n"; 00250 fs << "\t" 00251 << "threshold: \"DEBUG\"\n"; 00252 fs << "\t" 00253 << "noTimeStamps: true\n"; 00254 fs << "\t" 00255 << "noLineBreaks: true\n"; 00256 fs << "}\n"; 00257 } 00258 00259 break; // take first enable row only! 00260 } 00261 00262 // close MF config file 00263 fs.close(); 00264 } 00265 00266 DEFINE_OTS_TABLE(MessageFacilityTable)