Ignore:
Timestamp:
10/11/13 14:10:06 (11 years ago)
Author:
Marek Kurdej
Message:

Added: addParameters() method in ComponentBase using Boost.Program_Options.
Each component can declare its parameters and they will be read automatically before configureComponent() method.
See example ProducerConsumerExample constructors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/ProducerConsumerExample/ConsumerExample.cpp

    r165 r176  
    2020    LOG_INFO("Thread " << thread.currentThread());
    2121    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    ;
    2228}
    2329
     
    4046ConsumerExample::configureComponent(XmlComponentConfig /*config*/)
    4147{
    42     LOG_TRACE(Q_FUNC_INFO);
     48    PACPUS_LOG_FUNCTION();
    4349
    44     // load XML parameters
     50    // load XML parameters -- NOT NEEDED - loaded by boost::program_options (used addParameters())
    4551
    46     LOG_INFO("component '" << name() << "' configured");
     52    LOG_INFO("component '" << getName() << "' configured");
    4753    return ComponentBase::CONFIGURED_OK;
    4854}
     
    5460    m_counter = 0;
    5561   
    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);
    5863    if (!m_file.is_open()) {
    59         LOG_ERROR("file '" << outputFileName << "'cannot be opened");
     64        LOG_ERROR("file '" << mOutputFileName << "' cannot be opened");
    6065    }
    6166
    6267    thread.start();
    6368    setState(MONITOR_OK);
    64     LOG_INFO("started component '" << name() << "'");
     69    LOG_INFO("started component '" << getName() << "'");
    6570}
    6671
     
    7277    m_file.close();
    7378    setState(STOPPED);
    74     LOG_INFO("stopped component '" << name() << "'");
     79    LOG_INFO("stopped component '" << getName() << "'");
    7580}
    7681
Note: See TracChangeset for help on using the changeset viewer.