Fawkes API  Fawkes Development Version
aspect_provider.cpp
1 
2 /***************************************************************************
3  * aspect_provider.h - Aspect to provider a new aspect for Fawkes
4  *
5  * Created: Thu Nov 25 12:08:21 2010 (Thanksgiving)
6  * Copyright 2006-2013 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/aspect_provider.h>
25 #include <aspect/inifins/inifin.h>
26 
27 namespace fawkes {
28 #if 0 /* just to make Emacs auto-indent happy */
29 }
30 #endif
31 
32 /** @class AspectProviderAspect <aspect/aspect_provider.h>
33  * Thread aspect provide a new aspect.
34  * Aspects in Fawkes are used to provide access to framework features.
35  * More generally speaking they are used to provide access to features on the
36  * C++ programming level. In some situations, it might be useful to provide
37  * a custom aspect to allow for access to a resource on this level, e.g.
38  * bypassing the blackboard for communication. In this case the
39  * AspectProviderAspect can be used.
40  *
41  * Use this rarely! Be absolutely certain, that there is no better or equally
42  * good way to implement a feature without a new aspect. If used it allows
43  * for a well-defined way to exchange resources between threads (and even
44  * plugins). Make sure that you define strong guarantees and keep them by
45  * means of your aspect initializer/finalizer. For example if you share a
46  * (pointer to a) resource, you <i>must</i> make sure, that this
47  * resource stays as long as there is any user!
48  *
49  * @ingroup Aspects
50  * @author Tim Niemueller
51  */
52 
53 /** Constructor.
54  * Add a single aspect.
55  * @param inifin intializer/finalizer for the aspect. The inifin
56  * must exist for the whole lifetime of this AspectProviderAspect instance!
57  */
59 {
60  add_aspect("AspectProviderAspect");
61  __aspect_provider_aspects.push_back(inifin);
62 }
63 
64 /** Constructor.
65  * Add multiple aspects.
66  * @param aspects Map from aspect name to initializer/finalizer
67  */
68 AspectProviderAspect::AspectProviderAspect(const std::list<AspectIniFin *> aspects)
69 {
70  add_aspect("AspectProviderAspect");
71  __aspect_provider_aspects = aspects;
72 }
73 
74 
75 /** Virtual empty destructor. */
77 {
78 }
79 
80 
81 /** Get name of the provided aspect.
82  * @return name of the provided aspect
83  */
84 const std::list<AspectIniFin *> &
86 {
87  return __aspect_provider_aspects;
88 }
89 
90 } // end namespace fawkes
Fawkes library namespace.
AspectProviderAspect(AspectIniFin *inifin)
Constructor.
void add_aspect(const char *name)
Add an aspect to a thread.
Definition: aspect.cpp:52
virtual ~AspectProviderAspect()
Virtual empty destructor.
const std::list< AspectIniFin * > & aspect_provider_aspects() const
Get name of the provided aspect.
Aspect initializer/finalizer base class.
Definition: inifin.h:36