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