Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
aspect_provider.cpp
1 
2 /***************************************************************************
3  * aspect_provider.cpp - Fawkes Aspect Provider initializer/finalizer
4  *
5  * Created: Thu Nov 25 12:20:43 2010 (Thanksgiving, Pittsburgh)
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/aspect_provider.h>
25 #include <aspect/aspect_provider.h>
26 #include <aspect/manager.h>
27 
28 namespace fawkes {
29 #if 0 /* just to make Emacs auto-indent happy */
30 }
31 #endif
32 
33 /** @class AspectProviderAspectIniFin <aspect/inifins/aspect_provider.h>
34  * Initializer/finalizer for the AspectProviderAspect.
35  * This initializer/finalizer will register the AspectIniFin instance with
36  * the main aspect manager on init, and unregister it on finalization. it
37  * will deny unloading if there are still threads using the provided aspect.
38  * @author Tim Niemueller
39  */
40 
41 /** Constructor.
42  * @param manager aspect manager to register new aspects to
43  */
44 AspectProviderAspectIniFin::AspectProviderAspectIniFin(AspectManager *manager)
45  : AspectIniFin("AspectProviderAspect")
46 {
47  __aspect_manager = manager;
48 }
49 
50 
51 void
53 {
54  AspectProviderAspect *provider_thread;
55  provider_thread = dynamic_cast<AspectProviderAspect *>(thread);
56 
57  if (provider_thread == NULL) {
58  throw CannotInitializeThreadException("Thread '%s' claims to have the "
59  "AspectProviderAspect, but RTTI says it "
60  "has not. ", thread->name());
61  }
62 
63  __aspect_manager->register_inifin(provider_thread->aspect_provider_inifin());
64 }
65 
66 
67 bool
69 {
70  AspectProviderAspect *p_thr;
71  p_thr = dynamic_cast<AspectProviderAspect *>(thread);
72 
73  if (p_thr == NULL) return true;
74 
75  return ! __aspect_manager->has_threads_for_aspect(p_thr->aspect_provider_name());
76 }
77 
78 
79 void
81 {
82  AspectProviderAspect *provider_thread;
83  provider_thread = dynamic_cast<AspectProviderAspect *>(thread);
84 
85  if (provider_thread == NULL) {
86  throw CannotFinalizeThreadException("Thread '%s' claims to have the "
87  "AspectProviderAspect, but RTTI says it "
88  "has not. ", thread->name());
89  }
90 
91  __aspect_manager->unregister_inifin(provider_thread->aspect_provider_inifin());
92 }
93 
94 
95 } // end namespace fawkes