Fawkes API Fawkes Development Version
clips_feature_inifin.cpp
1
2/***************************************************************************
3 * clips_feature_inifin.cpp - CLIPSFeatureAspect initializer/finalizer
4 *
5 * Created: Fri Aug 16 13:15:27 2013
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 <core/threading/thread_finalizer.h>
25#include <plugins/clips/aspect/clips_env_manager.h>
26#include <plugins/clips/aspect/clips_feature_inifin.h>
27
28#include <clipsmm.h>
29
30namespace fawkes {
31
32/** @class CLIPSFeatureAspectIniFin <plugins/clips/aspect/clips_feature_inifin.h>
33 * CLIPSFeatureAspect initializer/finalizer.
34 * @author Tim Niemueller
35 */
36
37/** Constructor. */
39{
40}
41
42/** Destructor. */
44{
45}
46
47void
49{
50 CLIPSFeatureAspect *clips_thread;
51 clips_thread = dynamic_cast<CLIPSFeatureAspect *>(thread);
52 if (clips_thread == NULL) {
53 throw CannotInitializeThreadException("Thread '%s' claims to have the "
54 "CLIPSFeatureAspect, but RTTI says it "
55 "has not. ",
56 thread->name());
57 }
58
59 clips_env_mgr_->add_features(clips_thread->clips_features_);
60}
61
62bool
64{
65 CLIPSFeatureAspect *clips_thread;
66 clips_thread = dynamic_cast<CLIPSFeatureAspect *>(thread);
67 if (clips_thread == NULL)
68 return true;
69
70 try {
71 clips_env_mgr_->assert_can_remove_features(clips_thread->clips_features_);
72 return true;
73 } catch (Exception &e) {
74 return false;
75 }
76}
77
78void
80{
81 CLIPSFeatureAspect *clips_thread;
82 clips_thread = dynamic_cast<CLIPSFeatureAspect *>(thread);
83 if (clips_thread == NULL) {
84 throw CannotFinalizeThreadException("Thread '%s' claims to have the "
85 "CLIPSFeatureAspect, but RTTI says it "
86 "has not. ",
87 thread->name());
88 }
89
90 clips_env_mgr_->remove_features(clips_thread->clips_features_);
91}
92
93/** Set CLIPS environment manger.
94 * @param clips_env_mgr CLIPS environment manager
95 */
96void
98{
99 clips_env_mgr_ = clips_env_mgr;
100}
101
102} // end namespace fawkes
Aspect initializer/finalizer base class.
Definition: inifin.h:34
void set_manager(LockPtr< CLIPSEnvManager > &clips_env_mgr)
Set CLIPS environment manger.
virtual void init(Thread *thread)
Initialize thread.
virtual bool prepare_finalize(Thread *thread)
Default finalize preparation.
virtual void finalize(Thread *thread)
Finalize thread.
Thread aspect to provide a feature to CLIPS environments.
Definition: clips_feature.h:58
std::list< CLIPSFeature * > clips_features_
List of all clips features.
Definition: clips_feature.h:68
Thread cannot be finalized.
Base class for exceptions in Fawkes.
Definition: exception.h:36
LockPtr<> is a reference-counting shared lockable smartpointer.
Definition: lockptr.h:55
Thread class encapsulation of pthreads.
Definition: thread.h:46
const char * name() const
Get name of thread.
Definition: thread.h:100
Fawkes library namespace.