source: pacpustutorials/solutions/project_exercises/plugin_exercise_1/component_message/MessageComponent.cpp

Last change on this file was 10, checked in by DHERBOMEZ Gérald, 9 years ago

update tutorials

File size: 4.1 KB
Line 
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
22using namespace pacpus;
23
24
25////////////////////////////////////////////////////////////////////////////////
26/// Construct the factory
27static ComponentFactory<MessageComponent> sFactory("MessageComponent");
28
29
30
31
32/************************************************************************/
33/* Constructor
34/************************************************************************/
35MessageComponent::MessageComponent(QString name)
36 : ComponentBase(name)
37{
38 counter_ = 0;
39}
40
41
42/************************************************************************/
43/* Destructor
44/************************************************************************/
45MessageComponent::~MessageComponent()
46{
47
48}
49
50
51/************************************************************************/
52/* Start function, called by the ComponentManager when a start()
53/* command is received
54/************************************************************************/
55void 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
62 LOG_INFO("timer started with the period " << period_ << " sec");
63
64}
65
66
67/************************************************************************/
68/* Stop function, called by the ComponentManager when a stop()
69/* command is received
70/************************************************************************/
71void MessageComponent::stopActivity()
72{
73 timer_.stop();
74 LOG_INFO("timer stopped");
75}
76
77
78/************************************************************************/
79/* Called by the framework at initialization
80/************************************************************************/
81void 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/************************************************************************/
91void MessageComponent::addOutputs()
92{
93 // empty: no output
94 // addOutput<int, ProducerExample>("value");
95}
96
97
98/************************************************************************/
99/* Slot
100/************************************************************************/
101void MessageComponent::display()
102{
103 LOG_INFO(counter_ << ": message from component " << name());
104 counter_++;
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/************************************************************************/
131ComponentBase::COMPONENT_CONFIGURATION MessageComponent::configureComponent(XmlComponentConfig config)
132{
133 period_ = config.getDoubleProperty("msg_period");
134
135 return ComponentBase::CONFIGURED_OK;
136}
137
Note: See TracBrowser for help on using the repository browser.