[9] | 1 | // *********************************************************************
|
---|
| 2 | //
|
---|
| 3 | // created: 2015/09/18
|
---|
| 4 | // filename: MessageComponent.cpp
|
---|
| 5 | //
|
---|
| 6 | // author: Gerald Dherbomez
|
---|
| 7 | // Copyright Heudiasyc (c) UMR UTC/CNRS 7253
|
---|
| 8 | //
|
---|
| 9 | // license: CECILL-C
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // brief: Pacpus template component source file
|
---|
| 14 | //
|
---|
| 15 | // *********************************************************************
|
---|
| 16 |
|
---|
| 17 | #include "Pacpus/kernel/ComponentFactory.h"
|
---|
| 18 | #include "Pacpus/kernel/DbiteFileTypes.h"
|
---|
| 19 |
|
---|
| 20 | #include "MessageComponent.h"
|
---|
| 21 |
|
---|
| 22 | using namespace pacpus;
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | ////////////////////////////////////////////////////////////////////////////////
|
---|
| 26 | /// Construct the factory
|
---|
[10] | 27 | static ComponentFactory<MessageComponent> sFactory("MessageComponent");
|
---|
[9] | 28 |
|
---|
| 29 |
|
---|
| 30 |
|
---|
[10] | 31 |
|
---|
[9] | 32 | /************************************************************************/
|
---|
| 33 | /* Constructor
|
---|
| 34 | /************************************************************************/
|
---|
| 35 | MessageComponent::MessageComponent(QString name)
|
---|
| 36 | : ComponentBase(name)
|
---|
| 37 | {
|
---|
[10] | 38 | counter_ = 0;
|
---|
[9] | 39 | }
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | /************************************************************************/
|
---|
| 43 | /* Destructor
|
---|
| 44 | /************************************************************************/
|
---|
| 45 | MessageComponent::~MessageComponent()
|
---|
| 46 | {
|
---|
| 47 |
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | /************************************************************************/
|
---|
| 52 | /* Start function, called by the ComponentManager when a start()
|
---|
| 53 | /* command is received
|
---|
| 54 | /************************************************************************/
|
---|
| 55 | void MessageComponent::startActivity()
|
---|
| 56 | {
|
---|
| 57 | // if you add an ouput, uncomment the line
|
---|
| 58 | // out1_ = getTypedOutput<int, MessageComponent>("value");
|
---|
| 59 |
|
---|
| 60 | connect(&timer_, SIGNAL(timeout()), this, SLOT(display()));
|
---|
| 61 | timer_.start(period_ * 1000); // start a timer, param in msec
|
---|
[10] | 62 | LOG_INFO("timer started with the period " << period_ << " sec");
|
---|
[9] | 63 |
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | /************************************************************************/
|
---|
| 68 | /* Stop function, called by the ComponentManager when a stop()
|
---|
| 69 | /* command is received
|
---|
| 70 | /************************************************************************/
|
---|
| 71 | void MessageComponent::stopActivity()
|
---|
| 72 | {
|
---|
| 73 | timer_.stop();
|
---|
[10] | 74 | LOG_INFO("timer stopped");
|
---|
[9] | 75 | }
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | /************************************************************************/
|
---|
| 79 | /* Called by the framework at initialization
|
---|
| 80 | /************************************************************************/
|
---|
| 81 | void MessageComponent::addInputs()
|
---|
| 82 | {
|
---|
| 83 | // uncomment to add an input
|
---|
| 84 | // addInput<int, MessageComponent>("value", &MessageComponent::processInput);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | /************************************************************************/
|
---|
| 89 | /* Called by the framework at initialization
|
---|
| 90 | /************************************************************************/
|
---|
| 91 | void MessageComponent::addOutputs()
|
---|
| 92 | {
|
---|
| 93 | // empty: no output
|
---|
| 94 | // addOutput<int, ProducerExample>("value");
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | /************************************************************************/
|
---|
| 99 | /* Slot
|
---|
| 100 | /************************************************************************/
|
---|
| 101 | void MessageComponent::display()
|
---|
| 102 | {
|
---|
[10] | 103 | LOG_INFO(counter_ << ": message from component " << name());
|
---|
| 104 | counter_++;
|
---|
[9] | 105 | }
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | /************************************************************************/
|
---|
| 109 | /* Example function that produces an output
|
---|
| 110 | /************************************************************************/
|
---|
| 111 | // void MessageComponent::produceOutput()
|
---|
| 112 | // {
|
---|
| 113 | // int val = 12;
|
---|
| 114 | // checkedSend(out1_, val);
|
---|
| 115 | // }
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | /************************************************************************/
|
---|
| 119 | /* Example function that processes an input
|
---|
| 120 | /************************************************************************/
|
---|
| 121 | // void processInput(const int& value)
|
---|
| 122 | // {
|
---|
| 123 | //
|
---|
| 124 | // }
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | /************************************************************************/
|
---|
| 128 | /* Configuration of the component, called by the ComponentManager after
|
---|
| 129 | /* the construction of the object
|
---|
| 130 | /************************************************************************/
|
---|
| 131 | ComponentBase::COMPONENT_CONFIGURATION MessageComponent::configureComponent(XmlComponentConfig config)
|
---|
| 132 | {
|
---|
| 133 | period_ = config.getDoubleProperty("msg_period");
|
---|
| 134 |
|
---|
| 135 | return ComponentBase::CONFIGURED_OK;
|
---|
| 136 | }
|
---|
| 137 |
|
---|