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
25#include "feature_blackboard.h"
26#include "feature_config.h"
27#include "feature_redefine_warning.h"
28
29#include <plugins/clips/aspect/clips_env_manager.h>
30
31#include <clipsmm.h>
32
33using namespace fawkes;
34
35/** @class CLIPSThread "clips_thread.h"
36 * CLIPS environment thread.
37 *
38 * @author Tim Niemueller
39 */
40
41/** Constructor. */
43: Thread("CLIPSThread", Thread::OPMODE_WAITFORWAKEUP), AspectProviderAspect(inifin_list())
44{
45}
46
47/** Destructor. */
49{
50}
51
52void
54{
55 std::string clips_dir = SRCDIR "/clips/";
56 try {
57 clips_dir = config->get_string("/clips/clips-dir");
58 } catch (Exception &e) {
59 } // ignored, use default
60
61 bool cfg_retract_early = false;
62 try {
63 cfg_retract_early = config->get_bool("/clips/retract-early");
64 } catch (Exception &) {
65 }
66
67 CLIPS::init();
68 clips_env_mgr_ = new CLIPSEnvManager(logger, clock, clips_dir);
69 clips_aspect_inifin_.set_manager(clips_env_mgr_);
70 clips_feature_aspect_inifin_.set_manager(clips_env_mgr_);
71 clips_manager_aspect_inifin_.set_manager(clips_env_mgr_);
72
73 features_.push_back(new BlackboardCLIPSFeature(logger, blackboard, cfg_retract_early));
74 features_.push_back(new ConfigCLIPSFeature(logger, config));
75 features_.push_back(new RedefineWarningCLIPSFeature(logger));
76 clips_env_mgr_->add_features(features_);
77}
78
79void
81{
82 clips_env_mgr_.clear();
83
84 for (auto f : features_) {
85 delete f;
86 }
87}
88
89void
91{
92}
93
94const std::list<AspectIniFin *>
95CLIPSThread::inifin_list()
96{
97 std::list<AspectIniFin *> rv;
98 rv.push_back(&clips_aspect_inifin_);
99 rv.push_back(&clips_feature_aspect_inifin_);
100 rv.push_back(&clips_manager_aspect_inifin_);
101 return rv;
102}
CLIPS blackboard feature.
virtual void init()
Initialize the thread.
virtual void finalize()
Finalize the thread.
virtual void loop()
Code to execute in the thread.
virtual ~CLIPSThread()
Destructor.
CLIPSThread()
Constructor.
CLIPS blackboard feature.
CLIPS warning on redefinition of names.
Thread aspect provide a new aspect.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
Definition: blackboard.h:44
void set_manager(LockPtr< CLIPSEnvManager > &clips_env_mgr)
Set CLIPS environment manger.
CLIPS environment manager.
void add_features(const std::list< CLIPSFeature * > &features)
Add a feature by name.
void set_manager(LockPtr< CLIPSEnvManager > &clips_env_mgr)
Set CLIPS environment manger.
void set_manager(LockPtr< CLIPSEnvManager > &clips_env_mgr)
Set CLIPS environment manger.
Clock * clock
By means of this member access to the clock is given.
Definition: clock.h:42
Configuration * config
This is the Configuration member used to access the configuration.
Definition: configurable.h:41
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
Base class for exceptions in Fawkes.
Definition: exception.h:36
void clear()
Set underlying instance to 0, decrementing reference count of existing instance appropriately.
Definition: lockptr.h:499
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
Thread class encapsulation of pthreads.
Definition: thread.h:46
Fawkes library namespace.