Fawkes API  Fawkes Development Version
navgraph_inifin.cpp
1 
2 /***************************************************************************
3  * navgraph_inifin.cpp - Fawkes NavGraphAspect initializer/finalizer
4  *
5  * Created: Mon Dec 06 22:33:03 2010
6  * Copyright 2006-2010 Tim Niemueller [www.niemueller.de]
7  * 2014 Sebastian Reuter
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 <navgraph/aspect/navgraph_inifin.h>
25 #include <navgraph/aspect/navgraph.h>
26 #include <core/threading/thread_finalizer.h>
27 #include <navgraph/navgraph.h>
28 #include <cstddef>
29 
30 namespace fawkes {
31 #if 0 /* just to make Emacs auto-indent happy */
32 }
33 #endif
34 
35 /** @class NavGraphAspectIniFin <navgraph/aspect/navgraph_inifin.h>
36  * NavGraphAspect initializer/finalizer.
37  * @author Tim Niemueller
38  */
39 
40 /** Constructor. */
42  : AspectIniFin("NavGraphAspect")
43 {
44 }
45 
46 
47 /** Set navgraph.
48  * @param navgraph navgraph to pass to thread with the NavGraphAspect
49  */
50 void
52 {
53  navgraph_ = navgraph;
54 }
55 
56 void
58 {
59  NavGraphAspect *navgraph_thread;
60  navgraph_thread = dynamic_cast<NavGraphAspect *>(thread);
61  if (navgraph_thread == NULL) {
62  throw CannotInitializeThreadException("Thread '%s' claims to have the "
63  "NavGraphAspect, but RTTI says it "
64  "has not. ", thread->name());
65  }
66 
67  navgraph_thread->navgraph = navgraph_;
68 }
69 
70 void
72 {
73  NavGraphAspect *navgraph_thread;
74  navgraph_thread = dynamic_cast<NavGraphAspect *>(thread);
75  if (navgraph_thread == NULL) {
76  throw CannotFinalizeThreadException("Thread '%s' claims to have the "
77  "NavGraphAspect, but RTTI says it "
78  "has not. ", thread->name());
79  }
80 
81  navgraph_thread->navgraph.clear();
82 }
83 
84 
85 
86 } // end namespace fawkes
void set_navgraph(LockPtr< NavGraph > &navgraph)
Set navgraph.
fawkes::LockPtr< NavGraph > navgraph
NavGraph instance shared in framework.
Definition: navgraph.h:46
Fawkes library namespace.
Thread class encapsulation of pthreads.
Definition: thread.h:42
LockPtr<> is a reference-counting shared lockable smartpointer.
Definition: lockptr.h:57
Thread cannot be initialized.
const char * name() const
Get name of thread.
Definition: thread.h:95
virtual void init(Thread *thread)
Initialize thread.
Thread cannot be finalized.
virtual void finalize(Thread *thread)
Finalize thread.
Thread aspect to access NavGraph.
Definition: navgraph.h:37
Aspect initializer/finalizer base class.
Definition: inifin.h:36