Fawkes API  Fawkes Development Version
clips_inifin.cpp
1 
2 /***************************************************************************
3  * clips_inifin.cpp - Fawkes CLIPSAspect initializer/finalizer
4  *
5  * Created: Sat Jun 16 14:34:27 2012
6  * Copyright 2006-2012 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 <plugins/clips/aspect/clips_inifin.h>
25 #include <plugins/clips/aspect/clips_env_manager.h>
26 #include <core/threading/thread_finalizer.h>
27 
28 #include <clipsmm.h>
29 
30 namespace fawkes {
31 #if 0 /* just to make Emacs auto-indent happy */
32 }
33 #endif
34 
35 /** @class CLIPSAspectIniFin <plugins/clips/aspect/clips_inifin.h>
36  * CLIPSAspect initializer/finalizer.
37  * This initializer/finalizer will provide the CLIPS node handle to
38  * threads with the CLIPSAspect.
39  * @author Tim Niemueller
40  */
41 
42 /** Constructor. */
44  : AspectIniFin("CLIPSAspect")
45 {
46 }
47 
48 /** Destructor. */
50 {
51 }
52 
53 
54 
55 void
57 {
58  CLIPSAspect *clips_thread;
59  clips_thread = dynamic_cast<CLIPSAspect *>(thread);
60  if (clips_thread == NULL) {
61  throw CannotInitializeThreadException("Thread '%s' claims to have the "
62  "CLIPSAspect, but RTTI says it "
63  "has not. ", thread->name());
64  }
65 
67  clips_env_mgr_->create_env(clips_thread->clips_env_name,
68  clips_thread->CLIPSAspect_log_component_name_);
69 
70  clips_thread->clips = clips;
71 }
72 
73 void
75 {
76  CLIPSAspect *clips_thread;
77  clips_thread = dynamic_cast<CLIPSAspect *>(thread);
78  if (clips_thread == NULL) {
79  throw CannotFinalizeThreadException("Thread '%s' claims to have the "
80  "CLIPSAspect, but RTTI says it "
81  "has not. ", thread->name());
82  }
83 
84  clips_env_mgr_->destroy_env(clips_thread->clips_env_name);
85  clips_thread->finalize_CLIPSAspect();
86 }
87 
88 
89 
90 /** Set CLIPS environment manger.
91  * @param clips_env_mgr CLIPS environment manager
92  */
93 void
95 {
96  clips_env_mgr_ = clips_env_mgr;
97 }
98 
99 } // end namespace fawkes
virtual void init(Thread *thread)
Initialize thread.
Fawkes library namespace.
virtual void finalize(Thread *thread)
Finalize thread.
CLIPSAspectIniFin()
Constructor.
~CLIPSAspectIniFin()
Destructor.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Thread cannot be initialized.
const char * name() const
Get name of thread.
Definition: thread.h:95
LockPtr< CLIPS::Environment > clips
CLIPS environment for exclusive usage.
Definition: clips.h:51
void set_manager(LockPtr< CLIPSEnvManager > &clips_env_mgr)
Set CLIPS environment manger.
Thread cannot be finalized.
const std::string clips_env_name
CLIPS environment name.
Definition: clips.h:50
Thread aspect to get access to a CLIPS environment.
Definition: clips.h:41
Aspect initializer/finalizer base class.
Definition: inifin.h:36