Fawkes API  Fawkes Development Version
blackboard.cpp
1 
2 /***************************************************************************
3  * blackboard.cpp - Fawkes BlackBoard Aspect initializer/finalizer
4  *
5  * Created: Tue Nov 23 23:06:13 2010
6  * Copyright 2006-2010 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 <aspect/inifins/blackboard.h>
25 #include <aspect/blackboard.h>
26 #include <blackboard/blackboard.h>
27 #include <blackboard/ownership.h>
28 
29 namespace fawkes {
30 #if 0 /* just to make Emacs auto-indent happy */
31 }
32 #endif
33 
34 /** @class BlackBoardAspectIniFin <aspect/inifins/blackboard.h>
35  * Initializer/finalizer for the BlackBoardAspect.
36  * @author Tim Niemueller
37  */
38 
39 /** Constructor.
40  * @param blackboard blackboard instance to pass to threads
41  */
43  : AspectIniFin("BlackBoardAspect")
44 {
45  __blackboard = blackboard;
46 }
47 
48 void
50 {
51  BlackBoardAspect *blackboard_thread;
52  blackboard_thread = dynamic_cast<BlackBoardAspect *>(thread);
53  if (blackboard_thread == NULL) {
54  throw CannotInitializeThreadException("Thread '%s' claims to have the "
55  "BlackBoardAspect, but RTTI says it "
56  "has not. ", thread->name());
57  }
58 
59  BlackBoard *bb;
60  if (blackboard_thread->blackboard_owner_name_) {
61  bb = new BlackBoardWithOwnership(__blackboard,
62  blackboard_thread->blackboard_owner_name_);
63  } else {
64  bb = new BlackBoardWithOwnership(__blackboard, thread->name());
65  }
66 
67  blackboard_thread->init_BlackBoardAspect(bb);
68 }
69 
70 void
72 {
73  BlackBoardAspect *blackboard_thread;
74  blackboard_thread = dynamic_cast<BlackBoardAspect *>(thread);
75  if (blackboard_thread == NULL) {
76  throw CannotFinalizeThreadException("Thread '%s' claims to have the "
77  "BlackBoardAspect, but RTTI says it "
78  "has not. ", thread->name());
79  }
80 
81  delete blackboard_thread->blackboard;
82  blackboard_thread->blackboard = NULL;
83 }
84 
85 
86 } // end namespace fawkes
void init_BlackBoardAspect(BlackBoard *bb)
Init BlackBoard aspect.
Definition: blackboard.cpp:72
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
virtual void finalize(Thread *thread)
Finalize thread.
Definition: blackboard.cpp:71
virtual void init(Thread *thread)
Initialize thread.
Definition: blackboard.cpp:49
Fawkes library namespace.
BlackBoardAspectIniFin(BlackBoard *blackboard)
Constructor.
Definition: blackboard.cpp:42
Thread class encapsulation of pthreads.
Definition: thread.h:42
Thread cannot be initialized.
BlackBoard that traces interface ownership.
Definition: ownership.h:34
const char * name() const
Get name of thread.
Definition: thread.h:95
Thread cannot be finalized.
The BlackBoard abstract class.
Definition: blackboard.h:48
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
Definition: blackboard.h:44
Aspect initializer/finalizer base class.
Definition: inifin.h:36