Fawkes API  Fawkes Development Version
clips_thread.cpp
1 
2 /***************************************************************************
3  * clips_thread.cpp - CLIPS environment providing Thread
4  *
5  * Created: Sat Jun 16 14:40:56 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.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "clips_thread.h"
24 #include "feature_blackboard.h"
25 #include "feature_config.h"
26 #include "feature_redefine_warning.h"
27 #include <plugins/clips/aspect/clips_env_manager.h>
28 
29 #include <clipsmm.h>
30 
31 using namespace fawkes;
32 
33 /** @class CLIPSThread "clips_thread.h"
34  * CLIPS environment thread.
35  *
36  * @author Tim Niemueller
37  */
38 
39 /** Constructor. */
41  : Thread("CLIPSThread", Thread::OPMODE_WAITFORWAKEUP),
42  AspectProviderAspect(inifin_list())
43 {
44 }
45 
46 
47 /** Destructor. */
49 {
50 }
51 
52 
53 void
55 {
56  std::string clips_dir = SRCDIR"/clips/";
57  try {
58  clips_dir = config->get_string("/clips/clips-dir");
59  } catch (Exception &e) {} // ignored, use default
60 
61  CLIPS::init();
62  clips_env_mgr_ = new CLIPSEnvManager(logger, clock, clips_dir);
63  clips_aspect_inifin_.set_manager(clips_env_mgr_);
64  clips_feature_aspect_inifin_.set_manager(clips_env_mgr_);
65  clips_manager_aspect_inifin_.set_manager(clips_env_mgr_);
66 
67  features_.push_back(new BlackboardCLIPSFeature(logger, blackboard));
68  features_.push_back(new ConfigCLIPSFeature(logger, config));
69  features_.push_back(new RedefineWarningCLIPSFeature(logger));
70  clips_env_mgr_->add_features(features_);
71 }
72 
73 
74 void
76 {
77  clips_env_mgr_.clear();
78 
79  for (auto f : features_) {
80  delete f;
81  }
82 }
83 
84 
85 void
87 {
88 }
89 
90 
91 const std::list<AspectIniFin *>
92 CLIPSThread::inifin_list()
93 {
94  std::list<AspectIniFin *> rv;
95  rv.push_back(&clips_aspect_inifin_);
96  rv.push_back(&clips_feature_aspect_inifin_);
97  rv.push_back(&clips_manager_aspect_inifin_);
98  return rv;
99 }
CLIPS warning on redefinition of names.
Fawkes library namespace.
CLIPS blackboard feature.
Thread class encapsulation of pthreads.
Definition: thread.h:42
virtual void init()
Initialize the thread.
void add_features(const std::list< CLIPSFeature *> &features)
Add a feature by name.
virtual ~CLIPSThread()
Destructor.
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:44
Clock * clock
By means of this member access to the clock is given.
Definition: clock.h:45
CLIPS blackboard feature.
CLIPSThread()
Constructor.
Base class for exceptions in Fawkes.
Definition: exception.h:36
void set_manager(LockPtr< CLIPSEnvManager > &clips_env_mgr)
Set CLIPS environment manger.
void set_manager(LockPtr< CLIPSEnvManager > &clips_env_mgr)
Set CLIPS environment manger.
Thread aspect provide a new aspect.
void clear()
Set underlying instance to 0, decrementing reference count of existing instance appropriately.
Definition: lockptr.h:492
virtual void finalize()
Finalize the thread.
void set_manager(LockPtr< CLIPSEnvManager > &clips_env_mgr)
Set CLIPS environment manger.
virtual void loop()
Code to execute in the thread.
Configuration * config
This is the Configuration member used to access the configuration.
Definition: configurable.h:44
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
Definition: blackboard.h:44
CLIPS environment manager.