replicode
view.h
Go to the documentation of this file.
1 // view.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 view_h
32 #define view_h
33 
34 #include "r_code/object.h"
35 #include "overlay.h"
36 #include "CoreLibrary/dll.h"
37 
38 
39 namespace r_exec {
40 
41 class Group;
42 class LObject;
43 
44 // OID is hidden at _code[VIEW_OID].
45 // Shared resources:
46 // none: all mod/set operations are pushed on the group and executed at update time.
48  public r_code::View {
49 private:
50  static uint64_t LastOID;
51  static uint64_t GetOID();
52 
53 // Ctrl values.
55  float acc_sln;
57  float acc_act;
59  float acc_vis;
61  float acc_res;
62  void reset_ctrl_values();
63 
64 // Monitoring
65  double initial_sln;
66  double initial_act;
67 
68  void init(SyncMode sync,
69  uint64_t ijt,
70  double sln,
71  int64_t res,
72  r_code::Code *host,
73  r_code::Code *origin,
74  r_code::Code *object);
75 protected:
76  void reset_init_sln();
77  void reset_init_act();
78 public:
79  static uint16_t ViewOpcode;
80 
81  P<Controller> controller; // built upon injection of the view (if the object is an ipgm/icpp_pgm/cst/mdl).
82 
83  static double MorphValue(double value, double source_thr, double destination_thr);
84  static double MorphChange(double change, double source_thr, double destination_thr);
85 
90 
91  View();
92  View(r_code::SysView *source, r_code::Code *object);
93  View(View *view, Group *group); // copy the view and assigns it to the group (used for cov); morph ctrl values.
94  View(const View *view, bool new_OID = false); // simple copy.
95  View(SyncMode sync,
96  uint64_t ijt,
97  double sln,
98  int64_t res,
99  Code *host,
100  Code *origin,
101  Code *object); // regular view; res set to -1 means forever.
102  View(SyncMode sync,
103  uint64_t ijt,
104  double sln,
105  int64_t res,
106  Code *host,
107  Code *origin,
108  Code *object,
109  double act); // pgm/mdl view; res set to -1 means forever.
110  ~View();
111 
112  void reset();
113  void set_object(r_code::Code *object);
114 
115  uint64_t get_oid() const;
116 
117  virtual bool isNotification() const;
118 
119  Group *get_host();
120 
121  SyncMode get_sync();
122  float get_res();
123  float get_sln();
124  float get_act();
125  bool get_cov();
126  float get_vis();
127  uint32_t &ctrl0() {
128  return _code[VIEW_CTRL_0].atom; // use only for non-group views.
129  }
130  uint32_t &ctrl1() {
131  return _code[VIEW_CTRL_1].atom; // idem.
132  }
133 
134  void mod_res(double value);
135  void set_res(double value);
136  void mod_sln(double value);
137  void set_sln(double value);
138  void mod_act(double value);
139  void set_act(double value);
140  void mod_vis(double value);
141  void set_vis(double value);
142 
143  double update_res();
144  double update_sln(double low, double high);
145  double update_act(double low, double high);
146  double update_vis();
147 
148  float update_sln_delta();
149  float update_act_delta();
150 
151  void force_res(double value); // unmediated.
152 
153 // Target res, sln, act, vis.
154  void mod(uint16_t member_index, double value);
155  void set(uint16_t member_index, double value);
156 
157  void delete_from_object();
158  void delete_from_group();
159 private:
160  std::mutex m_groupMutex;
161 };
162 
164  public View {
165 public:
166  NotificationView(Code *origin, Code *destination, Code *marker); // res=1, sln=1.
167 
168  bool isNotification() const;
169 };
170 }
171 
172 #endif
uint64_t periods_at_low_sln
Definition: view.h:86
float acc_act
Definition: view.h:57
Definition: view.h:163
float acc_vis
Definition: view.h:59
uint64_t periods_at_high_act
Definition: view.h:89
double initial_sln
Definition: view.h:65
uint64_t sln_changes
Definition: view.h:54
static uint16_t ViewOpcode
Definition: view.h:79
#define dll_export
Definition: dll.h:44
#define VIEW_CTRL_1
Definition: replicode_defs.h:51
Definition: _context.cpp:34
uint64_t res_changes
Definition: view.h:60
float acc_sln
Definition: view.h:55
std::mutex m_groupMutex
Definition: view.h:160
Definition: base.h:47
Definition: group.h:49
double initial_act
Definition: view.h:66
SyncMode
Definition: object.h:132
Definition: object.h:270
Definition: view.h:47
uint32_t & ctrl1()
Definition: view.h:130
uint32_t & ctrl0()
Definition: view.h:127
float acc_res
Definition: view.h:61
Definition: object.h:100
uint64_t vis_changes
Definition: view.h:58
Definition: object.h:172
static uint64_t LastOID
Definition: view.h:50
uint64_t periods_at_high_sln
Definition: view.h:87
P< Controller > controller
Definition: view.h:81
uint64_t periods_at_low_act
Definition: view.h:88
#define VIEW_CTRL_0
Definition: replicode_defs.h:50
uint64_t act_changes
Definition: view.h:56
Definition: object.h:62