Fawkes API  Fawkes Development Version
clips_env_manager.h
1 
2 /***************************************************************************
3  * clips_env_manager.h - CLIPS environment manager
4  *
5  * Created: Thu Aug 15 18:55:32 2013
6  * Copyright 2006-2014 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version. A runtime exception applies to
13  * this software (see LICENSE.GPL_WRE file mentioned below for details).
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_WRE file in the doc directory.
21  */
22 
23 #ifndef _PLUGINS_CLIPS_ASPECT_CLIPS_ENV_MANAGER_H_
24 #define _PLUGINS_CLIPS_ASPECT_CLIPS_ENV_MANAGER_H_
25 
26 #include <core/utils/lockptr.h>
27 
28 #include <clipsmm.h>
29 #include <list>
30 #include <map>
31 #include <string>
32 
33 namespace fawkes {
34 
35 class Logger;
36 class Clock;
37 class CLIPSFeature;
38 
39 class CLIPSEnvManager
40 {
41 public:
42  CLIPSEnvManager(Logger *logger, Clock *clock, std::string &clips_dir);
43  virtual ~CLIPSEnvManager();
44 
45  LockPtr<CLIPS::Environment> create_env(const std::string &env_name,
46  const std::string &log_component_name);
47  void destroy_env(const std::string &env_name);
48 
49  void add_features(const std::list<CLIPSFeature *> &features);
50  void remove_features(const std::list<CLIPSFeature *> &features);
51  void assert_can_remove_features(const std::list<CLIPSFeature *> &features);
52 
53  std::map<std::string, LockPtr<CLIPS::Environment>> environments() const;
54 
55 private:
56  LockPtr<CLIPS::Environment> new_env(const std::string &log_component_name);
57  void assert_features(LockPtr<CLIPS::Environment> &clips, bool immediate_assert);
58  void add_functions(const std::string &env_name, LockPtr<CLIPS::Environment> &clips);
59  CLIPS::Value clips_request_feature(std::string env_name, std::string feature_name);
60  CLIPS::Values clips_now();
61  CLIPS::Values clips_now_systime();
62  void guarded_load(const std::string &env_name, const std::string &filename);
63 
64 private:
65  Logger *logger_;
66  Clock * clock_;
67 
68  std::string clips_dir_;
69 
70  /// @cond INTERNAL
71  typedef struct
72  {
74  std::list<std::string> req_feat;
75  } ClipsEnvData;
76  /// @endcond
77 
78  std::map<std::string, ClipsEnvData> envs_;
79  std::map<std::string, CLIPSFeature *> features_;
80 };
81 
82 } // end namespace fawkes
83 
84 #endif
fawkes::LockPtr< CLIPS::Environment >
fawkes::CLIPSEnvManager::create_env
LockPtr< CLIPS::Environment > create_env(const std::string &env_name, const std::string &log_component_name)
Create a new environment.
Definition: clips_env_manager.cpp:240
fawkes::CLIPSEnvManager::CLIPSEnvManager
CLIPSEnvManager(Logger *logger, Clock *clock, std::string &clips_dir)
Constructor.
Definition: clips_env_manager.cpp:175
fawkes::CLIPSEnvManager::remove_features
void remove_features(const std::list< CLIPSFeature * > &features)
Remove a feature by name.
Definition: clips_env_manager.cpp:483
fawkes::CLIPSEnvManager::~CLIPSEnvManager
virtual ~CLIPSEnvManager()
Destructor.
Definition: clips_env_manager.cpp:183
fawkes::Logger
Definition: logger.h:40
fawkes
fawkes::CLIPSEnvManager::add_features
void add_features(const std::list< CLIPSFeature * > &features)
Add a feature by name.
Definition: clips_env_manager.cpp:428
fawkes::CLIPSEnvManager::destroy_env
void destroy_env(const std::string &env_name)
Destroy the named environment.
Definition: clips_env_manager.cpp:275
fawkes::CLIPSEnvManager::assert_can_remove_features
void assert_can_remove_features(const std::list< CLIPSFeature * > &features)
Assert that a feature can be removed.
Definition: clips_env_manager.cpp:460
fawkes::CLIPSEnvManager::environments
std::map< std::string, LockPtr< CLIPS::Environment > > environments() const
Get map of environments.
Definition: clips_env_manager.cpp:299
fawkes::Clock
Definition: clock.h:39