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 
29 namespace 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. */
39 GossipAspectIniFin::GossipAspectIniFin() : AspectIniFin("GossipAspect")
40 {
41 }
42 
43 /** Destructor. */
45 {
46 }
47 
48 void
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 
60  RefPtr<GossipGroup> group =
61  gossip_group_mgr_->join_group(gossip_thread->GossipAspect_group_name_);
62 
63  gossip_thread->gossip_group = group;
64 }
65 
66 void
67 GossipAspectIniFin::finalize(Thread *thread)
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  */
84 void
85 GossipAspectIniFin::set_manager(GossipGroupManager *gossip_group_mgr)
86 {
87  gossip_group_mgr_ = gossip_group_mgr;
88 }
89 
90 } // end namespace fawkes
fawkes::GossipAspectIniFin::finalize
virtual void finalize(Thread *thread)
Definition: gossip_inifin.cpp:73
fawkes::RefPtr
RefPtr<> is a reference-counting shared smartpointer.
Definition: refptr.h:57
fawkes::GossipGroupManager::join_group
virtual RefPtr< GossipGroup > join_group(const std::string &name)
Join a group.
Definition: gossip_group_manager.cpp:141
fawkes::GossipAspectIniFin::~GossipAspectIniFin
~GossipAspectIniFin()
Destructor.
Definition: gossip_inifin.cpp:50
fawkes::GossipAspect
Definition: gossip.h:43
fawkes::GossipGroupManager::leave_group
virtual void leave_group(RefPtr< GossipGroup > &group)
Leave a gossip group.
Definition: gossip_group_manager.cpp:159
fawkes::CannotInitializeThreadException
Definition: thread_initializer.h:39
fawkes::Thread::name
const char * name() const
Definition: thread.h:100
fawkes::GossipAspectIniFin::GossipAspectIniFin
GossipAspectIniFin()
Constructor.
Definition: gossip_inifin.cpp:45
fawkes::GossipAspectIniFin::init
virtual void init(Thread *thread)
Definition: gossip_inifin.cpp:55
fawkes
fawkes::GossipAspectIniFin::set_manager
void set_manager(GossipGroupManager *gossip_group_mgr)
Set gossip group manger.
Definition: gossip_inifin.cpp:91
fawkes::Thread
Definition: thread.h:45