Fawkes API
Fawkes Development Version
gex_sender_thread.cpp
1
2
/***************************************************************************
3
* gex_sender_thread.cpp - Gossip Example Plugin - Sender
4
*
5
* Created: Wed Mar 05 14:29:19 2014
6
* Copyright 2006-2014 Tim Niemueller [www.niemueller.de]
7
****************************************************************************/
8
9
/* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
13
*
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Library General Public License for more details.
18
*
19
* Read the full text in the LICENSE.GPL file in the doc directory.
20
*/
21
22
#include "gex_sender_thread.h"
23
24
#include "TestMessage.pb.h"
25
26
#include <plugins/gossip/gossip/gossip_group.h>
27
28
using namespace
fawkes
;
29
30
/** @class GossipExampleSenderThread "clips-protobuf-thread.h"
31
* Gossip Example Plugin Thread - Sender.
32
* @author Tim Niemueller
33
*/
34
35
/** Constructor. */
36
GossipExampleSenderThread::GossipExampleSenderThread
()
37
:
Thread
(
"GossipExampleSenderThread"
,
Thread
::OPMODE_WAITFORWAKEUP),
38
BlockedTimingAspect
(
BlockedTimingAspect
::WAKEUP_HOOK_ACT),
39
GossipAspect
(
"example"
)
40
{
41
}
42
43
/** Destructor. */
44
GossipExampleSenderThread::~GossipExampleSenderThread
()
45
{
46
}
47
48
void
49
GossipExampleSenderThread::init
()
50
{
51
last_sent_ =
new
Time
(
clock
);
52
counter_ = 0;
53
}
54
55
void
56
GossipExampleSenderThread::finalize
()
57
{
58
delete
last_sent_;
59
}
60
61
void
62
GossipExampleSenderThread::loop
()
63
{
64
fawkes::Time
now(
clock
);
65
if
(now - last_sent_ >= 2.0) {
66
*last_sent_ = now;
67
68
logger
->
log_debug
(
name
(),
"Sending"
);
69
70
gossip_example::TestMessage m;
71
m.set_counter(++counter_);
72
m.set_sec(now.
get_sec
());
73
m.set_nsec(now.
get_nsec
());
74
gossip_group
->broadcast(m);
75
}
76
}
GossipExampleSenderThread::~GossipExampleSenderThread
virtual ~GossipExampleSenderThread()
Destructor.
Definition:
gex_sender_thread.cpp:43
GossipExampleSenderThread::loop
virtual void loop()
Code to execute in the thread.
Definition:
gex_sender_thread.cpp:61
fawkes::Time::get_sec
long get_sec() const
Definition:
time.h:121
fawkes::Time::get_nsec
long get_nsec() const
Definition:
time.h:136
fawkes::GossipAspect
Definition:
gossip.h:41
GossipExampleSenderThread::init
virtual void init()
Initialize the thread.
Definition:
gex_sender_thread.cpp:48
GossipExampleSenderThread::GossipExampleSenderThread
GossipExampleSenderThread()
Constructor.
Definition:
gex_sender_thread.cpp:35
GossipExampleSenderThread::finalize
virtual void finalize()
Finalize the thread.
Definition:
gex_sender_thread.cpp:55
fawkes::BlockedTimingAspect
Definition:
blocked_timing.h:54
fawkes::Thread::name
const char * name() const
Definition:
thread.h:99
fawkes::ClockAspect::clock
Clock * clock
Definition:
clock.h:53
fawkes::LoggingAspect::logger
Logger * logger
Definition:
logging.h:50
fawkes
fawkes::GossipAspect::gossip_group
RefPtr< GossipGroup > gossip_group
Definition:
gossip.h:50
fawkes::Time
Definition:
time.h:96
fawkes::Thread
Definition:
thread.h:44
fawkes::Logger::log_debug
virtual void log_debug(const char *component, const char *format,...)=0
src
plugins
gossip
example
gex_sender_thread.cpp
Generated by
1.8.16