Changeset 176 in pacpusframework for trunk/examples/ProducerConsumerExample


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.

Location:
trunk/examples/ProducerConsumerExample
Files:
4 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
  • trunk/examples/ProducerConsumerExample/ConsumerExample.h

    r163 r176  
    88#include <QImage>
    99#include <QThread>
     10#include <string>
    1011
    1112namespace pacpus {
     
    3536    int m_counter;
    3637    std::ofstream m_file;
     38
     39    std::string mOutputFileName;
    3740};
    3841
  • trunk/examples/ProducerConsumerExample/ProducerExample.cpp

    r165 r176  
    2222{
    2323    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    ;
    2430}
    2531
     
    3238ProducerExample::configureComponent(XmlComponentConfig /*config*/)
    3339{
    34     LOG_TRACE(Q_FUNC_INFO);
     40    PACPUS_LOG_FUNCTION();
    3541
    36     LOG_INFO("component '" << name() << "' configured");
     42    LOG_INFO("component '" << getName() << "' configured");
    3743    return ComponentBase::CONFIGURED_OK;
    3844}
     
    5763    setActive(true);
    5864    setState(MONITOR_OK);
    59     LOG_INFO("started component '" << name() << "'");
     65    LOG_INFO("started component '" << getName() << "'");
    6066}
    6167
     
    6672    setActive(false);
    6773    setState(STOPPED);
    68     LOG_INFO("stopped component '" << name() << "'");
     74    LOG_INFO("stopped component '" << getName() << "'");
    6975}
    7076
  • trunk/examples/ProducerConsumerExample/ProducerExample.h

    r163 r176  
    4747
    4848private:
     49    std::string mOutputFileName;
    4950    //QThread thread;
    5051};
Note: See TracChangeset for help on using the changeset viewer.