1 | // *********************************************************************
|
---|
2 | //
|
---|
3 | // created: 2015/10/26
|
---|
4 | // filename: AdditionComponent.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 "AdditionComponent.h"
|
---|
21 |
|
---|
22 | using namespace pacpus;
|
---|
23 |
|
---|
24 |
|
---|
25 | ////////////////////////////////////////////////////////////////////////////////
|
---|
26 | /// Construct the factory
|
---|
27 | static ComponentFactory<AdditionComponent> sFactory("AdditionComponent");
|
---|
28 |
|
---|
29 |
|
---|
30 |
|
---|
31 |
|
---|
32 | /************************************************************************/
|
---|
33 | /* Constructor
|
---|
34 | /************************************************************************/
|
---|
35 | AdditionComponent::AdditionComponent(QString name)
|
---|
36 | : ComponentBase(name)
|
---|
37 | {
|
---|
38 | valueToAdd_ = 0.0;
|
---|
39 | valueToSend_ = 0.0;
|
---|
40 | initiator_ = false;
|
---|
41 | }
|
---|
42 |
|
---|
43 |
|
---|
44 | /************************************************************************/
|
---|
45 | /* Destructor
|
---|
46 | /************************************************************************/
|
---|
47 | AdditionComponent::~AdditionComponent()
|
---|
48 | {
|
---|
49 |
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | /************************************************************************/
|
---|
54 | /* Start function, called by the ComponentManager when a start()
|
---|
55 | /* command is received
|
---|
56 | /************************************************************************/
|
---|
57 | void AdditionComponent::startActivity()
|
---|
58 | {
|
---|
59 | // if you add an ouput, uncomment the line
|
---|
60 | out1_ = getTypedOutput<double, AdditionComponent>("valueOut");
|
---|
61 | if (initiator_)
|
---|
62 | timer_.singleShot(1000, this, SLOT(produceOutput()));
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | /************************************************************************/
|
---|
67 | /* Stop function, called by the ComponentManager when a stop()
|
---|
68 | /* command is received
|
---|
69 | /************************************************************************/
|
---|
70 | void AdditionComponent::stopActivity()
|
---|
71 | {
|
---|
72 |
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | /************************************************************************/
|
---|
77 | /* Called by the framework at initialization
|
---|
78 | /************************************************************************/
|
---|
79 | void AdditionComponent::addInputs()
|
---|
80 | {
|
---|
81 | // uncomment to add an input
|
---|
82 | addInput<double, AdditionComponent>("valueIn", &AdditionComponent::processInput);
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | /************************************************************************/
|
---|
87 | /* Called by the framework at initialization
|
---|
88 | /************************************************************************/
|
---|
89 | void AdditionComponent::addOutputs()
|
---|
90 | {
|
---|
91 | // empty: no output
|
---|
92 | addOutput<double, AdditionComponent>("valueOut");
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | /************************************************************************/
|
---|
97 | /* Example function that produces an output
|
---|
98 | /************************************************************************/
|
---|
99 | void AdditionComponent::produceOutput()
|
---|
100 | {
|
---|
101 | checkedSend(out1_, valueToSend_);
|
---|
102 | LOG_INFO(getName() << ": value sent: " << valueToSend_);
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | /************************************************************************/
|
---|
107 | /* Example function that processes an input
|
---|
108 | /************************************************************************/
|
---|
109 | void AdditionComponent::processInput(const double& value)
|
---|
110 | {
|
---|
111 | LOG_INFO(getName() << ": value received: " << value);
|
---|
112 | valueToSend_ = value + valueToAdd_;
|
---|
113 |
|
---|
114 | // !!!!!!!!!!! WARNING !!!!!!!!!!!
|
---|
115 | // We avoid to use a "sleep()" which is blocking.
|
---|
116 | timer_.singleShot(1000, this, SLOT(produceOutput()));
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | /************************************************************************/
|
---|
121 | /* Configuration of the component, called by the ComponentManager after
|
---|
122 | /* the construction of the object
|
---|
123 | /************************************************************************/
|
---|
124 | ComponentBase::COMPONENT_CONFIGURATION AdditionComponent::configureComponent(XmlComponentConfig config)
|
---|
125 | {
|
---|
126 | valueToAdd_ = config.getDoubleProperty("valueToAdd");
|
---|
127 | initiator_ = config.getBoolProperty("initiateCommunication");
|
---|
128 |
|
---|
129 | return ComponentBase::CONFIGURED_OK;
|
---|
130 | }
|
---|
131 |
|
---|