[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
|
---|
| 27 | ComponentFactory<MessageComponent> sFactory("MessageComponent");
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | /************************************************************************/
|
---|
| 32 | /* Constructor
|
---|
| 33 | /************************************************************************/
|
---|
| 34 | MessageComponent::MessageComponent(QString name)
|
---|
| 35 | : ComponentBase(name)
|
---|
| 36 | {
|
---|
| 37 | count_ = 0;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | /************************************************************************/
|
---|
| 42 | /* Destructor
|
---|
| 43 | /************************************************************************/
|
---|
| 44 | MessageComponent::~MessageComponent()
|
---|
| 45 | {
|
---|
| 46 |
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | /************************************************************************/
|
---|
| 51 | /* Start function, called by the ComponentManager when a start()
|
---|
| 52 | /* command is received
|
---|
| 53 | /************************************************************************/
|
---|
| 54 | void MessageComponent::startActivity()
|
---|
| 55 | {
|
---|
| 56 | // if you add an ouput, uncomment the line
|
---|
| 57 | // out1_ = getTypedOutput<int, MessageComponent>("value");
|
---|
| 58 |
|
---|
| 59 | count_ = 0;
|
---|
| 60 | connect(&timer_, SIGNAL(timeout()), this, SLOT(display()));
|
---|
| 61 | timer_.start(period_ * 1000); // start a timer, param in msec
|
---|
| 62 |
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | /************************************************************************/
|
---|
| 67 | /* Stop function, called by the ComponentManager when a stop()
|
---|
| 68 | /* command is received
|
---|
| 69 | /************************************************************************/
|
---|
| 70 | void MessageComponent::stopActivity()
|
---|
| 71 | {
|
---|
| 72 | timer_.stop();
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 | /************************************************************************/
|
---|
| 77 | /* Called by the framework at initialization
|
---|
| 78 | /************************************************************************/
|
---|
| 79 | void MessageComponent::addInputs()
|
---|
| 80 | {
|
---|
| 81 | // uncomment to add an input
|
---|
| 82 | // addInput<int, MessageComponent>("value", &MessageComponent::processInput);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | /************************************************************************/
|
---|
| 87 | /* Called by the framework at initialization
|
---|
| 88 | /************************************************************************/
|
---|
| 89 | void MessageComponent::addOutputs()
|
---|
| 90 | {
|
---|
| 91 | // empty: no output
|
---|
| 92 | // addOutput<int, ProducerExample>("value");
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 | /************************************************************************/
|
---|
| 97 | /* Slot
|
---|
| 98 | /************************************************************************/
|
---|
| 99 | void MessageComponent::display()
|
---|
| 100 | {
|
---|
| 101 | LOG_INFO(count_ << ": message from component " << name());
|
---|
| 102 | count++
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | /************************************************************************/
|
---|
| 107 | /* Example function that produces an output
|
---|
| 108 | /************************************************************************/
|
---|
| 109 | // void MessageComponent::produceOutput()
|
---|
| 110 | // {
|
---|
| 111 | // int val = 12;
|
---|
| 112 | // checkedSend(out1_, val);
|
---|
| 113 | // }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | /************************************************************************/
|
---|
| 117 | /* Example function that processes an input
|
---|
| 118 | /************************************************************************/
|
---|
| 119 | // void processInput(const int& value)
|
---|
| 120 | // {
|
---|
| 121 | //
|
---|
| 122 | // }
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | /************************************************************************/
|
---|
| 126 | /* Configuration of the component, called by the ComponentManager after
|
---|
| 127 | /* the construction of the object
|
---|
| 128 | /************************************************************************/
|
---|
| 129 | ComponentBase::COMPONENT_CONFIGURATION MessageComponent::configureComponent(XmlComponentConfig config)
|
---|
| 130 | {
|
---|
| 131 | period_ = config.getDoubleProperty("msg_period");
|
---|
| 132 |
|
---|
| 133 | return ComponentBase::CONFIGURED_OK;
|
---|
| 134 | }
|
---|
| 135 |
|
---|