- Timestamp:
- Oct 11, 2013, 2:10:06 PM (11 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
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.