AERA
view.h
1 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
2 //_/_/
3 //_/_/ AERA
4 //_/_/ Autocatalytic Endogenous Reflective Architecture
5 //_/_/
6 //_/_/ Copyright (c) 2018-2025 Jeff Thompson
7 //_/_/ Copyright (c) 2018-2025 Kristinn R. Thorisson
8 //_/_/ Copyright (c) 2018-2025 Icelandic Institute for Intelligent Machines
9 //_/_/ http://www.iiim.is
10 //_/_/
11 //_/_/ Copyright (c) 2010-2012 Eric Nivel
12 //_/_/ Center for Analysis and Design of Intelligent Agents
13 //_/_/ Reykjavik University, Menntavegur 1, 102 Reykjavik, Iceland
14 //_/_/ http://cadia.ru.is
15 //_/_/
16 //_/_/ Part of this software was developed by Eric Nivel
17 //_/_/ in the HUMANOBS EU research project, which included
18 //_/_/ the following parties:
19 //_/_/
20 //_/_/ Autonomous Systems Laboratory
21 //_/_/ Technical University of Madrid, Spain
22 //_/_/ http://www.aslab.org/
23 //_/_/
24 //_/_/ Communicative Machines
25 //_/_/ Edinburgh, United Kingdom
26 //_/_/ http://www.cmlabs.com/
27 //_/_/
28 //_/_/ Istituto Dalle Molle di Studi sull'Intelligenza Artificiale
29 //_/_/ University of Lugano and SUPSI, Switzerland
30 //_/_/ http://www.idsia.ch/
31 //_/_/
32 //_/_/ Institute of Cognitive Sciences and Technologies
33 //_/_/ Consiglio Nazionale delle Ricerche, Italy
34 //_/_/ http://www.istc.cnr.it/
35 //_/_/
36 //_/_/ Dipartimento di Ingegneria Informatica
37 //_/_/ University of Palermo, Italy
38 //_/_/ http://diid.unipa.it/roboticslab/
39 //_/_/
40 //_/_/
41 //_/_/ --- HUMANOBS Open-Source BSD License, with CADIA Clause v 1.0 ---
42 //_/_/
43 //_/_/ Redistribution and use in source and binary forms, with or without
44 //_/_/ modification, is permitted provided that the following conditions
45 //_/_/ are met:
46 //_/_/ - Redistributions of source code must retain the above copyright
47 //_/_/ and collaboration notice, this list of conditions and the
48 //_/_/ following disclaimer.
49 //_/_/ - Redistributions in binary form must reproduce the above copyright
50 //_/_/ notice, this list of conditions and the following disclaimer
51 //_/_/ in the documentation and/or other materials provided with
52 //_/_/ the distribution.
53 //_/_/
54 //_/_/ - Neither the name of its copyright holders nor the names of its
55 //_/_/ contributors may be used to endorse or promote products
56 //_/_/ derived from this software without specific prior
57 //_/_/ written permission.
58 //_/_/
59 //_/_/ - CADIA Clause: The license granted in and to the software
60 //_/_/ under this agreement is a limited-use license.
61 //_/_/ The software may not be used in furtherance of:
62 //_/_/ (i) intentionally causing bodily injury or severe emotional
63 //_/_/ distress to any person;
64 //_/_/ (ii) invading the personal privacy or violating the human
65 //_/_/ rights of any person; or
66 //_/_/ (iii) committing or preparing for any act of war.
67 //_/_/
68 //_/_/ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
69 //_/_/ CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
70 //_/_/ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
71 //_/_/ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
72 //_/_/ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
73 //_/_/ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
74 //_/_/ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
75 //_/_/ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
76 //_/_/ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
77 //_/_/ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
78 //_/_/ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
79 //_/_/ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
80 //_/_/ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
81 //_/_/ OF SUCH DAMAGE.
82 //_/_/
83 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
84 
85 #ifndef view_h
86 #define view_h
87 
88 #include "../r_code/object.h"
89 #include "dll.h"
90 
91 
92 namespace r_exec {
93 
94 class Group;
95 class LObject;
96 class Controller;
97 
98 // OID is hidden at code_[VIEW_OID].
99 // Shared resources:
100 // none: all mod/set operations are pushed on the group and executed at update time.
101 class r_exec_dll View :
102  public r_code::_View {
103 private:
104  static uint32 lastOID_;
105  static uint32 GetOID();
106 
107  // Ctrl values.
108  uint32 sln_changes_;
109  float32 acc_sln_;
110  uint32 act_changes_;
111  float32 acc_act_;
112  uint32 vis_changes_;
113  float32 acc_vis_;
114  uint32 res_changes_;
115  float32 acc_res_;
116  void reset_ctrl_values();
117 
118  // Monitoring
119  float32 initial_sln_;
120  float32 initial_act_;
121 
122  void init(r_code::_View::SyncMode sync,
123  Timestamp ijt,
124  float32 sln,
125  int32 res,
126  r_code::Code *host,
127  r_code::Code *origin,
128  r_code::Code *object);
129 protected:
130  void reset_init_sln();
131  void reset_init_act();
132 public:
133  static uint16 ViewOpcode_;
134 
135  P<Controller> controller_; // built upon injection of the view (if the object is an ipgm/icpp_pgm/cst/mdl).
136 
137  static float32 MorphValue(float32 value, float32 source_thr, float32 destination_thr);
138  static float32 MorphChange(float32 change, float32 source_thr, float32 destination_thr);
139 
140  uint32 periods_at_low_sln_;
141  uint32 periods_at_high_sln_;
142  uint32 periods_at_low_act_;
143  uint32 periods_at_high_act_;
144 
145  View();
146  View(r_code::SysView *source, r_code::Code *object);
147  View(View *view, Group *group); // copy the view and assigns it to the group (used for cov); morph ctrl values.
148  View(const View *view, bool new_OID = false); // simple copy.
149  View(r_code::_View::SyncMode sync,
150  Timestamp ijt,
151  float32 sln,
152  int32 res,
153  r_code::Code *host,
154  r_code::Code *origin,
155  r_code::Code *object); // regular view; res set to -1 means forever.
156  View(r_code::_View::SyncMode sync,
157  Timestamp ijt,
158  float32 sln,
159  int32 res,
160  r_code::Code *host,
161  r_code::Code *origin,
162  r_code::Code *object,
163  float32 act); // pgm/mdl view; res set to -1 means forever.
164  ~View();
165 
166  void reset();
167  void set_object(r_code::Code *object);
168 
169  uint32 get_oid() const;
170 
171  virtual bool is_notification() const;
172 
173  Group *get_host();
174 
175  r_code::_View::SyncMode get_sync();
176  float32 get_res();
177  float32 get_sln();
178  float32 get_act();
179  bool get_cov();
180  float32 get_vis();
181  uint32 &ctrl0() { return code_[VIEW_CTRL_0].atom_; } // use only for non-group views.
182  uint32 &ctrl1() { return code_[VIEW_CTRL_1].atom_; } // idem.
183 
184  void mod_res(float32 value);
185  void set_res(float32 value);
186  void mod_sln(float32 value);
187  void set_sln(float32 value);
188  void mod_act(float32 value);
189  void set_act(float32 value);
190  void mod_vis(float32 value);
191  void set_vis(float32 value);
192 
193  float32 update_res();
194  float32 update_sln(float32 low, float32 high);
195  float32 update_act(float32 low, float32 high);
196  float32 update_vis();
197 
198  float32 update_sln_delta();
199  float32 update_act_delta();
200 
201  void force_res(float32 value); // unmediated.
202 
203  // Target res, sln, act, vis.
204  void mod(uint16 member_index, float32 value);
205  void set(uint16 member_index, float32 value);
206 
207  void delete_from_object();
208  void delete_from_group();
209 };
210 
211 class r_exec_dll NotificationView :
212  public View {
213 public:
214  NotificationView(r_code::Code *origin, r_code::Code *destination, r_code::Code *marker); // res=1, sln=1.
215 
216  bool is_notification() const override;
217 };
218 }
219 
220 
221 #include "view.inline.cpp"
222 
223 
224 #endif
r_code::_View
Definition: r_code/object.h:164
r_code::SysView
Definition: r_code/object.h:119
core::P
Definition: base.h:103
r_code::Code
Definition: r_code/object.h:224
r_exec::View
Definition: view.h:102
r_exec::Group
Definition: group.h:108
r_exec::NotificationView
Definition: view.h:212