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 
30 namespace 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 
47 void
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 
62 bool
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 
78 void
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  */
96 void
98 {
99  clips_env_mgr_ = clips_env_mgr;
100 }
101 
102 } // end namespace fawkes
fawkes::CLIPSFeatureAspectIniFin::set_manager
void set_manager(LockPtr< CLIPSEnvManager > &clips_env_mgr)
Set CLIPS environment manger.
Definition: clips_feature_inifin.cpp:97
fawkes::LockPtr
LockPtr<> is a reference-counting shared lockable smartpointer.
Definition: lockptr.h:55
fawkes::CannotInitializeThreadException
Thread cannot be initialized.
Definition: thread_initializer.h:34
fawkes::Thread::name
const char * name() const
Get name of thread.
Definition: thread.h:100
fawkes::AspectIniFin
Aspect initializer/finalizer base class.
Definition: inifin.h:34
fawkes
Fawkes library namespace.
fawkes::CLIPSFeatureAspectIniFin::finalize
virtual void finalize(Thread *thread)
Finalize thread.
Definition: clips_feature_inifin.cpp:79
fawkes::CLIPSFeatureAspectIniFin::prepare_finalize
virtual bool prepare_finalize(Thread *thread)
Default finalize preparation.
Definition: clips_feature_inifin.cpp:63
fawkes::Thread
Thread class encapsulation of pthreads.
Definition: thread.h:46
fawkes::CLIPSFeatureAspectIniFin::init
virtual void init(Thread *thread)
Initialize thread.
Definition: clips_feature_inifin.cpp:48
fawkes::CLIPSFeatureAspectIniFin::CLIPSFeatureAspectIniFin
CLIPSFeatureAspectIniFin()
Constructor.
Definition: clips_feature_inifin.cpp:38
fawkes::CLIPSFeatureAspectIniFin::~CLIPSFeatureAspectIniFin
~CLIPSFeatureAspectIniFin()
Destructor.
Definition: clips_feature_inifin.cpp:43
fawkes::CLIPSFeatureAspect
Thread aspect to provide a feature to CLIPS environments.
Definition: clips_feature.h:58
fawkes::CannotFinalizeThreadException
Thread cannot be finalized.
Definition: thread_finalizer.h:34
fawkes::Exception
Base class for exceptions in Fawkes.
Definition: exception.h:36