replicode
ast_controller.h
Go to the documentation of this file.
1 // ast_controller.h
2 //
3 // Author: Eric Nivel
4 //
5 // BSD license:
6 // Copyright (c) 2010, Eric Nivel
7 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are met:
10 //
11 // - Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // - Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 // - Neither the name of Eric Nivel nor the
17 // names of their contributors may be used to endorse or promote products
18 // derived from this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
24 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef ast_controller_h
32 #define ast_controller_h
33 
34 #include "overlay.h"
35 #include "factory.h"
36 #include "pattern_extractor.h"
37 
38 
39 namespace r_exec {
40 
41 // Atomic state controller. Attached to a null-pgm and monitoring to a (repeated) input fact (SYNC_PERIODIC or SYNC_HOLD).
42 // Has a resilience of 2 times the upr of the group its target comes from.
43 // Upon catching a counter-evidence, signal the TPX and kill the object (i.e. invalidate and kill views); this will kill the controller and TPX.
44 // Catching a predicted evidence means that there is a model that predicts the next value of the object: kill the CTPX.
45 // AST live in primary groups and take their inputs therefrom: these are filtered by the A/F WRT goals/predictions.
46 // There is no control over AST: instead, computation is minimal (just pattern-matching) and CTPX are killed asap whenever a model predicts a value change.
47 // There cannot be any control based on the semantics of the inputs as these are atomic and henceforth no icst is available at injection time.
48 template<class U> class ASTController:
49  public OController {
50 protected:
52  P<_Fact> target; // the repeated fact to be monitored.
53  uint64_t thz; // time horizon: if an input is caught with ijt<thz (meaning it's too old), discard it.
54 
55  void kill();
56 
57  ASTController(AutoFocusController *auto_focus, View *target);
58 public:
59  virtual ~ASTController();
60 
61  Code *get_core_object() const {
62  return getObject();
63  }
64 
65  void take_input(r_exec::View *input);
66  void reduce(View *input);
67 
68 private:
69  std::mutex m_mutex;
70 };
71 
72 // For SYNC_PERIODIC targets.
74  public ASTController<PASTController> {
75 public:
78 
79  void reduce(View *input) {
81  }
82  void reduce(View *v, _Fact *input);
83 };
84 
85 // For SYNC_HOLD targets.
87  public ASTController<HASTController> {
88 private:
89  P<_Fact> source; // to be invalidated if a counter-evidence is found.
90 public:
91  HASTController(AutoFocusController *auto_focus, View *target, _Fact *source);
93 
94  void reduce(View *input) {
96  }
97  void reduce(View *v, _Fact *input);
98 };
99 }
100 
101 
102 #include "ast_controller.tpl.cpp"
103 
104 
105 #endif
void reduce(View *input)
Definition: ast_controller.tpl.cpp:65
Definition: factory.h:98
Definition: auto_focus.h:44
Definition: ast_controller.h:86
~PASTController()
Definition: ast_controller.cpp:45
~HASTController()
Definition: ast_controller.cpp:76
HASTController(AutoFocusController *auto_focus, View *target, _Fact *source)
Definition: ast_controller.cpp:71
Definition: _context.cpp:34
void reduce(View *input)
Definition: ast_controller.h:94
P< _Fact > target
Definition: ast_controller.h:52
Definition: base.h:47
std::mutex m_mutex
Definition: ast_controller.h:69
P< _Fact > source
Definition: ast_controller.h:89
Definition: overlay.h:172
Definition: ast_controller.h:73
Definition: view.h:47
void take_input(r_exec::View *input)
Definition: ast_controller.tpl.cpp:49
Code * get_core_object() const
Definition: ast_controller.h:61
PASTController(AutoFocusController *auto_focus, View *target)
Definition: ast_controller.cpp:40
Definition: ast_controller.h:48
ASTController(AutoFocusController *auto_focus, View *target)
Definition: ast_controller.tpl.cpp:39
Definition: object.h:172
virtual ~ASTController()
Definition: ast_controller.tpl.cpp:46
P< CTPX > tpx
Definition: ast_controller.h:51
void reduce(View *input)
Definition: ast_controller.h:79
void kill()
Definition: ast_controller.tpl.cpp:103
uint64_t thz
Definition: ast_controller.h:53
r_code::Code * getObject() const
Definition: overlay.h:91