Fawkes API Fawkes Development Version
gossip_inifin.cpp
1
2/***************************************************************************
3 * gossip_inifin.cpp - Fawkes GossipAspect initializer/finalizer
4 *
5 * Created: Sat Jun 16 14:34:27 2012
6 * Copyright 2006-2012 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#include <core/threading/thread_finalizer.h>
25#include <plugins/gossip/aspect/gossip_inifin.h>
26#include <plugins/gossip/gossip/gossip_group.h>
27#include <plugins/gossip/gossip/gossip_group_manager.h>
28
29namespace fawkes {
30
31/** @class GossipAspectIniFin <plugins/gossip/aspect/gossip_inifin.h>
32 * GossipAspect initializer/finalizer.
33 * This initializer/finalizer will join and leave gossip groups on
34 * behalf of threads with the GossipAspect.
35 * @author Tim Niemueller
36 */
37
38/** Constructor. */
40{
41}
42
43/** Destructor. */
45{
46}
47
48void
50{
51 GossipAspect *gossip_thread;
52 gossip_thread = dynamic_cast<GossipAspect *>(thread);
53 if (gossip_thread == NULL) {
54 throw CannotInitializeThreadException("Thread '%s' claims to have the "
55 "GossipAspect, but RTTI says it "
56 "has not. ",
57 thread->name());
58 }
59
61 gossip_group_mgr_->join_group(gossip_thread->GossipAspect_group_name_);
62
63 gossip_thread->gossip_group = group;
64}
65
66void
68{
69 GossipAspect *gossip_thread;
70 gossip_thread = dynamic_cast<GossipAspect *>(thread);
71 if (gossip_thread == NULL) {
72 throw CannotFinalizeThreadException("Thread '%s' claims to have the "
73 "GossipAspect, but RTTI says it "
74 "has not. ",
75 thread->name());
76 }
77
78 gossip_group_mgr_->leave_group(gossip_thread->gossip_group);
79}
80
81/** Set gossip group manger.
82 * @param gossip_group_mgr Gossip group manager
83 */
84void
86{
87 gossip_group_mgr_ = gossip_group_mgr;
88}
89
90} // end namespace fawkes
Aspect initializer/finalizer base class.
Definition: inifin.h:34
Thread cannot be finalized.
virtual void finalize(Thread *thread)
Finalize thread.
void set_manager(GossipGroupManager *gossip_group_mgr)
Set gossip group manger.
GossipAspectIniFin()
Constructor.
virtual void init(Thread *thread)
Initialize thread.
Thread aspect to communicate with a group of robots.
Definition: gossip.h:38
RefPtr< GossipGroup > gossip_group
Gossip group to communicate with other robots.
Definition: gossip.h:46
Abstract class for a Gossip group manager.
virtual void leave_group(RefPtr< GossipGroup > &group)
Leave a gossip group.
virtual RefPtr< GossipGroup > join_group(const std::string &name)
Join a group.
RefPtr<> is a reference-counting shared smartpointer.
Definition: refptr.h:50
Thread class encapsulation of pthreads.
Definition: thread.h:46
const char * name() const
Get name of thread.
Definition: thread.h:100
Fawkes library namespace.