Changeset 176 in pacpusframework
- Timestamp:
- Oct 11, 2013, 2:10:06 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/ProducerConsumerExample/ConsumerExample.cpp
r165 r176 20 20 LOG_INFO("Thread " << thread.currentThread()); 21 21 LOG_INFO("Current Thread " << QThread::currentThread()); 22 23 namespace po = boost::program_options; 24 25 addParameters() 26 ("output-path", po::value<std::string>(&mOutputFileName)->default_value("consumer.txt"), "set output file path") 27 ; 22 28 } 23 29 … … 40 46 ConsumerExample::configureComponent(XmlComponentConfig /*config*/) 41 47 { 42 LOG_TRACE(Q_FUNC_INFO);48 PACPUS_LOG_FUNCTION(); 43 49 44 // load XML parameters 50 // load XML parameters -- NOT NEEDED - loaded by boost::program_options (used addParameters()) 45 51 46 LOG_INFO("component '" << name() << "' configured");52 LOG_INFO("component '" << getName() << "' configured"); 47 53 return ComponentBase::CONFIGURED_OK; 48 54 } … … 54 60 m_counter = 0; 55 61 56 static const char * outputFileName = "consumer.txt"; 57 m_file.open(outputFileName, std::ios_base::out | std::ios_base::app); 62 m_file.open(mOutputFileName.c_str(), std::ios_base::out | std::ios_base::app); 58 63 if (!m_file.is_open()) { 59 LOG_ERROR("file '" << outputFileName << "'cannot be opened");64 LOG_ERROR("file '" << mOutputFileName << "' cannot be opened"); 60 65 } 61 66 62 67 thread.start(); 63 68 setState(MONITOR_OK); 64 LOG_INFO("started component '" << name() << "'");69 LOG_INFO("started component '" << getName() << "'"); 65 70 } 66 71 … … 72 77 m_file.close(); 73 78 setState(STOPPED); 74 LOG_INFO("stopped component '" << name() << "'");79 LOG_INFO("stopped component '" << getName() << "'"); 75 80 } 76 81 -
trunk/examples/ProducerConsumerExample/ConsumerExample.h
r163 r176 8 8 #include <QImage> 9 9 #include <QThread> 10 #include <string> 10 11 11 12 namespace pacpus { … … 35 36 int m_counter; 36 37 std::ofstream m_file; 38 39 std::string mOutputFileName; 37 40 }; 38 41 -
trunk/examples/ProducerConsumerExample/ProducerExample.cpp
r165 r176 22 22 { 23 23 LOG_TRACE("constructor(" << name << ")"); 24 25 namespace po = boost::program_options; 26 27 addParameters() 28 ("output-path", po::value<std::string>(&mOutputFileName)->default_value("producer.txt"), "set output file path") 29 ; 24 30 } 25 31 … … 32 38 ProducerExample::configureComponent(XmlComponentConfig /*config*/) 33 39 { 34 LOG_TRACE(Q_FUNC_INFO);40 PACPUS_LOG_FUNCTION(); 35 41 36 LOG_INFO("component '" << name() << "' configured");42 LOG_INFO("component '" << getName() << "' configured"); 37 43 return ComponentBase::CONFIGURED_OK; 38 44 } … … 57 63 setActive(true); 58 64 setState(MONITOR_OK); 59 LOG_INFO("started component '" << name() << "'");65 LOG_INFO("started component '" << getName() << "'"); 60 66 } 61 67 … … 66 72 setActive(false); 67 73 setState(STOPPED); 68 LOG_INFO("stopped component '" << name() << "'");74 LOG_INFO("stopped component '" << getName() << "'"); 69 75 } 70 76 -
trunk/examples/ProducerConsumerExample/ProducerExample.h
r163 r176 47 47 48 48 private: 49 std::string mOutputFileName; 49 50 //QThread thread; 50 51 }; -
trunk/include/Pacpus/kernel/ComponentBase.h
r161 r176 31 31 #include <QMap> 32 32 33 #include <boost/program_options/options_description.hpp> 34 #include <boost/program_options/value_semantic.hpp> 35 #include <string> 36 33 37 class QWidget; 38 39 namespace boost { 40 namespace program_options { 41 class options_description_easy_init; 42 } 43 } 34 44 35 45 namespace pacpus { … … 94 104 * @return Name of the component. 95 105 */ 96 QString name() const;97 106 QString getName() const; 98 107 … … 127 136 virtual void addOutputs() {} 128 137 138 boost::program_options::options_description_easy_init addParameters(); 139 129 140 protected: 130 141 typedef QMap<QString, InputInterfaceBase *> InputsMap; … … 177 188 178 189 const XmlComponentConfig xmlParameters() const; 190 191 protected: 192 std::string mName; 193 std::string mTypeName; 194 bool mHasGui; 195 bool mVerbose; 196 int mVerbosityLevel; 179 197 180 198 private: 199 /// Called by ComponentManager to handle parameters 200 /// @throws 201 void parseParameters(const XmlComponentConfig & cfg); 202 181 203 /// called by the ComponentManager to start the component 182 204 int startComponent(); … … 186 208 187 209 private: 210 boost::program_options::options_description mOptionsDescription; 211 188 212 /// The XML node that is got in the configureComponent method 189 213 XmlComponentConfig param; -
trunk/include/Pacpus/kernel/Log.h
r143 r176 35 35 36 36 #if defined(PACPUS_USE_LOG) 37 # include <boost/log/attributes/named_scope.hpp> 38 # include <boost/log/trivial.hpp> 39 # include <iosfwd> 37 40 38 #include <boost/log/trivial.hpp>39 #include <iosfwd>40 41 class QString; 41 42 42 template< typename CharT, typename TraitsT > 43 43 PACPUSLIB_API std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, QString const& s); 44 44 45 #define DECLARE_STATIC_LOGGER(name) 46 47 #define LOG(level, message) BOOST_LOG_TRIVIAL(level) << message 48 #define LOG_TRACE(message) LOG(trace, message) 49 #define LOG_DEBUG(message) LOG(debug, message) 50 #define LOG_INFO(message) LOG(info, message) 51 #define LOG_WARN(message) LOG(warning, message) 52 #define LOG_ERROR(message) LOG(error, message) 53 #define LOG_FATAL(message) LOG(fatal, message) 54 45 # define DECLARE_STATIC_LOGGER(name) //BOOST_LOG_NAMED_SCOPE(name) 46 # define PACPUS_LOG_FUNCTION() BOOST_LOG_FUNCTION() 47 # define PACPUS_LOG_NAMED_SCOPE(name) BOOST_LOG_NAMED_SCOPE(name) 48 # define PACPUS_LOG(level, message) BOOST_LOG_TRIVIAL(level) << message 55 49 #else 56 57 50 /// @param name Name of the logger, displayed when logging a message. 58 #define DECLARE_STATIC_LOGGER(name) 59 /// Logs a message at TRACE level using default logger 60 #define LOG_TRACE(message) 61 /// Logs a message at DEBUG level using default logger 62 #define LOG_DEBUG(message) 63 /// Logs a message at INFO level using default logger 64 #define LOG_INFO(message) 65 /// Logs a message at WARN level using default logger 66 #define LOG_WARN(message) 67 /// Logs a message at ERROR level using default logger 68 #define LOG_ERROR(message) 69 /// Logs a message at FATAL level using default logger 70 #define LOG_FATAL(message) 71 51 # define DECLARE_STATIC_LOGGER(name) 52 # define PACPUS_LOG_FUNCTION() ((void) 0) 53 # define PACPUS_LOG_NAMED_SCOPE(name) ((void) 0) 54 # define PACPUS_LOG(level, message) ((void) 0) 72 55 #endif // PACPUS_USE_LOG 73 56 57 /// Logs a message at TRACE level using default logger 58 #define LOG_TRACE(message) PACPUS_LOG(trace, message) 59 /// Logs a message at DEBUG level using default logger 60 #define LOG_DEBUG(message) PACPUS_LOG(debug, message) 61 /// Logs a message at INFO level using default logger 62 #define LOG_INFO(message) PACPUS_LOG(info, message) 63 /// Logs a message at WARN level using default logger 64 #define LOG_WARN(message) PACPUS_LOG(warning, message) 65 /// Logs a message at ERROR level using default logger 66 #define LOG_ERROR(message) PACPUS_LOG(error, message) 67 /// Logs a message at FATAL level using default logger 68 #define LOG_FATAL(message) PACPUS_LOG(fatal, message) 69 74 70 #endif // DEF_PACPUS_LOG_H -
trunk/include/Pacpus/kernel/XmlComponentConfig.h
r89 r176 22 22 namespace pacpus { 23 23 24 //class QDomNamedNodeMap; 24 25 class XmlConfigFile; 25 26 … … 38 39 /** Dtor of XmlComponentConfig. */ 39 40 ~XmlComponentConfig(); 41 42 QDomNamedNodeMap getProperties() const; 40 43 41 44 /** Add the property @em name to the XML and set its value to @em 0 if it does not exist. … … 94 97 95 98 // Copy internally the node in the internal QDomElement. 96 void localCopy(const QDomElement & elementToCopy);99 void localCopy(const QDomElement & elementToCopy); 97 100 98 101 QString const getComponentName() const; 99 102 QString const getComponentType() const; 100 101 103 102 104 QString const getConnectionType() const; -
trunk/src/DBITEPlayerLib/DbtPlyEngine.cpp
r152 r176 162 162 << dataDir_ << "\""); 163 163 if (dataDir_.isNull()) { 164 LOG_FATAL("The data directory '" << name() << "' is invalid or unavailable!");164 LOG_FATAL("The data directory '" << getName() << "' is invalid or unavailable!"); 165 165 } 166 166 -
trunk/src/DBITEPlayerLib/DbtPlyFileManager.cpp
r152 r176 181 181 void DbtPlyFileManager::displayUI() 182 182 { 183 LOG_WARN("component '" << name() << "' has no user interface. Please set ui property to 0 in your XML configuration");183 LOG_WARN("component '" << getName() << "' has no user interface. Please set ui property to 0 in your XML configuration"); 184 184 } 185 185 … … 301 301 deltaTDbtTab_[(deltaTDbtTabLoop_++)%1000] = deltaT; 302 302 if (deltaT > kMaxPendingTimeFromEngineMicrosecs) { 303 LOG_WARN( name() << ": data not replayed: elapsed time since engine notification too big:" << deltaT << "us");303 LOG_WARN(getName() << ": data not replayed: elapsed time since engine notification too big:" << deltaT << "us"); 304 304 return; 305 305 } -
trunk/src/PacpusLib/ComponentBase.cpp
r152 r176 9 9 #include <Pacpus/kernel/Log.h> 10 10 11 #include <boost/program_options/parsers.hpp> 12 #include <boost/program_options/variables_map.hpp> 13 #include <string> 14 #include <vector> 15 16 namespace po = boost::program_options; 11 17 using namespace pacpus; 18 using namespace std; 19 20 std::vector<std::string> convertAttributesToArgumentVector(const QDomNamedNodeMap & attributes); 21 void logVariablesMap(boost::program_options::variables_map vm); 12 22 13 23 DECLARE_STATIC_LOGGER("pacpus.core.ComponentBase"); … … 20 30 , m_ui(NULL) 21 31 , m_componentState(NOT_MONITORED) 32 , mOptionsDescription("Component parameters") 22 33 { 23 34 LOG_TRACE("constructor"); 24 35 // Get a pointer on the instance of ComponentManager. 25 36 m_manager = ComponentManager::getInstance(); 26 LOG_INFO("component " << name() << " was created"); 37 LOG_INFO("component " << getName() << " was created"); 38 39 addParameters() 40 ("name", po::value<string>(&mName)->required(), "component name") 41 ("type", po::value<string>(&mTypeName)->required(), "component type") 42 ("ui", po::value<bool>(&mHasGui)->default_value(false), "whether to show GUI") 43 ("verbose", po::value<bool>(&mVerbose)->default_value(false), "set output verbose") 44 ("verbosity-level", po::value<int>(&mVerbosityLevel)->default_value(0), "set verbosity level") 45 ("recording", po::value<bool>(&m_isRecording)->default_value(false), "whether to record data") 46 ; 27 47 } 28 48 … … 113 133 } 114 134 115 QString ComponentBase::name() const116 {117 return m_componentName;118 }119 120 135 QString ComponentBase::getName() const 121 136 { … … 148 163 return inputs()[inputName]; 149 164 } 150 LOG_WARN("Component " << name() << " does not contain input " << inputName);165 LOG_WARN("Component " << getName() << " does not contain input " << inputName); 151 166 return NULL; 152 167 } … … 161 176 return outputs()[outputName]; 162 177 } 163 LOG_WARN("Component " << name() << " does not containt output " << outputName);178 LOG_WARN("Component " << getName() << " does not containt output " << outputName); 164 179 return NULL; 165 180 } 181 182 po::options_description_easy_init ComponentBase::addParameters() 183 { 184 return mOptionsDescription.add_options(); 185 } 186 187 void ComponentBase::parseParameters(const XmlComponentConfig & cfg) 188 { 189 LOG_INFO("Parsing parameters..."); 190 LOG_INFO(mOptionsDescription); 191 192 vector<string> xargs = convertAttributesToArgumentVector(cfg.getProperties()); 193 194 boost::program_options::variables_map vm; 195 try { 196 po::store( 197 po::command_line_parser(xargs) 198 .options(mOptionsDescription) 199 //.allow_unregistered() 200 .run() 201 , vm); 202 po::notify(vm); 203 } catch (po::error & e) { 204 LOG_ERROR(e.what()); 205 throw; 206 } 207 208 logVariablesMap(vm); 209 } 210 211 void logVariablesMap(boost::program_options::variables_map vm) 212 { 213 for (po::variables_map::iterator i = vm.begin(); i != vm.end(); ++i) { 214 const po::variable_value& v = i->second; 215 if (v.empty()) { 216 continue; 217 } 218 const type_info & type = v.value().type(); 219 if (type == typeid(string)) { 220 const string & val = v.as<string>(); 221 LOG_INFO(i->first << "=" << val); 222 } else if (type == typeid(int)) { 223 int val = v.as<int>(); 224 LOG_INFO(i->first << "=" << val); 225 } else if (type == typeid(bool)) { 226 int val = v.as<bool>(); 227 LOG_INFO(i->first << "=" << val); 228 } 229 } 230 } 231 232 vector<string> convertAttributesToArgumentVector(const QDomNamedNodeMap & attributes) 233 { 234 vector<string> xargs; 235 xargs.reserve(attributes.size()); 236 237 for (int i = 0; i < attributes.size(); ++i) { 238 QDomAttr parameter = attributes.item(i).toAttr(); 239 if (parameter.isNull()) { 240 LOG_WARN("node is not a parameter"); 241 continue; 242 } 243 244 QString arg = QString("--") + parameter.name() + "="; 245 246 bool shouldAddQuotes = parameter.value().contains(' '); 247 if (shouldAddQuotes) { 248 arg += '\"'; 249 arg += parameter.value(); 250 arg += '\"'; 251 } else { 252 arg += parameter.value(); 253 } 254 255 LOG_DEBUG("parameter: " << arg); 256 xargs.push_back(arg.toStdString()); 257 } 258 259 return xargs; 260 } -
trunk/src/PacpusLib/ComponentManager.cpp
r162 r176 255 255 } else { 256 256 component->param.localCopy(cfg.qDomElement()); 257 component->parseParameters(cfg); 257 258 component->setConfigurationState(component->configureComponent(cfg)); 258 259 } -
trunk/src/PacpusLib/Log.cpp
r146 r176 71 71 72 72 logging::add_common_attributes(); 73 logging::core::get()->add_global_attribute( 74 "ProcessID", 75 attrs::current_process_id()); 76 logging::core::get()->add_global_attribute( 77 "ThreadID", 78 attrs::current_thread_id()); 79 73 80 logging::core::get()->set_filter 74 81 ( … … 93 100 expr::stream 94 101 << std::setfill('0') << std::setw(6) << expr::attr< unsigned int >("LineID") 95 //<< " [" << expr::format_date_time< posix_time::ptime >("TimeStamp", date_time::iso_extended_format) << "] " 96 << " [" << expr::format_date_time< posix_time::ptime >("TimeStamp", "%Y-%m-%d %T.%f") << "] " 97 << "<" << logging::trivial::severity << ">" 98 << " " 99 << expr::smessage 102 //<< " [" << expr::format_date_time< posix_time::ptime >("TimeStamp", date_time::iso_extended_format) << "]" 103 << " [" << expr::format_date_time< posix_time::ptime >("TimeStamp", "%Y-%m-%d %T.%f") << "]" 104 << " <" << logging::trivial::severity << ">" 105 << " <" << expr::attr< attrs::current_process_id::value_type >("ProcessID") 106 << ":" << expr::attr< attrs::current_thread_id::value_type >("ThreadID") << ">" 107 << " " << expr::smessage 100 108 ) 101 109 ); -
trunk/src/PacpusLib/XmlComponentConfig.cpp
r165 r176 8 8 #include <Pacpus/kernel/Log.h> 9 9 #include <Pacpus/kernel/XmlConfigFile.h> 10 #include <QDomNamedNodeMap> 10 11 11 12 using namespace pacpus; … … 37 38 } 38 39 40 QDomNamedNodeMap XmlComponentConfig::getProperties() const 41 { 42 return component_.attributes(); 43 } 44 39 45 void XmlComponentConfig::addProperty(const QString& name) 40 46 { 41 if (hasProperty(name)) 42 { 47 if (hasProperty(name)) { 43 48 LOG_ERROR("cannot add component property:" 44 49 << " component '" << component_.attribute(kPropertyComponentName) << "'"
Note:
See TracChangeset
for help on using the changeset viewer.