Lumiera  0.pre.03
»edit your freedom«
activity-term.hpp
Go to the documentation of this file.
1 /*
2  ACTIVITY-TERM.hpp - definition language framework for scheduler activities
3 
4  Copyright (C)
5  2023, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
63 #ifndef SRC_VAULT_GEAR_ACTIVITY_TERM_H_
64 #define SRC_VAULT_GEAR_ACTIVITY_TERM_H_
65 
66 
67 #include "vault/gear/activity.hpp"
69 #include "vault/gear/job.h"
70 #include "lib/time/timevalue.hpp"
71 
72 #include <string>
73 #include <utility>
74 
75 
76 namespace vault{
77 namespace gear {
78 
79  using lib::time::Time;
81  using std::string;
82  using std::move;
83 
84  using BlockFlowAlloc = BlockFlow<blockFlow::RenderConfig>;
85 
86 
87  namespace activity {
88 
93  class Term
94  {
95 
96  using AllocHandle = BlockFlowAlloc::AllocatorHandle;
97 
98  AllocHandle alloc_;
99 
100  Activity* invoke_{nullptr};
101  Activity* post_{nullptr};
102 
103  Activity* gate_{nullptr};
104  Activity* callback_{nullptr};
105 
106 
107  public:
111  };
112 
113  explicit
114  Term (AllocHandle&& allocHandle, Template kind, Time start, Time dead, Job job)
115  : alloc_{move (allocHandle)}
116  , invoke_{setupInvocation (job)}
117  , post_{setupPost (start,dead, invoke_)}
118  {
119  configureTemplate (kind);
120  }
121 
122  // standard copy acceptable
123 
124  operator std::string() const
125  {
126  return "Term-"
127  + (post_? string{*post_} : util::BOTTOM_INDICATOR)
128  + "⧐"
129  + (invoke_? string{*invoke_} : util::BOTTOM_INDICATOR);
130  }
131 
132 
137  Activity&
139  {
140  REQUIRE (post_, "Activity Term not yet fully configured");
141  return *post_;
142  }
143 
148  Activity&
150  {
151  REQUIRE (callback_, "Activity Term properly configured for async IO");
152  return *callback_;
153  }
154 
164  Term&
165  expectNotification (Activity& notificationSrc, bool unlimitedTime =false)
166  {
167  REQUIRE (notificationSrc.is (Activity::NOTIFY));
168  setupGate();
169  gate_->incDependencies();
170  Time triggerTimeStart{unlimitedTime? Time::ANYTIME : post_->data_.timeWindow.life};
171  notificationSrc.setNotificationTarget (gate_, triggerTimeStart);
172  return *this;
173  }
174 
181  Term&
182  appendNotificationTo (Term& targetTerm, bool unlimitedTime =false)
183  {
184  Activity& success = alloc_.create (Activity::NOTIFY);
185  insert (findTail (callback_? callback_ : invoke_), &success);
186  targetTerm.expectNotification (success, unlimitedTime);
187  return *this;
188  }
189 
209  Term&
211  {
212  Activity& trigger = alloc_.create (Activity::NOTIFY);
213  expectNotification (trigger);
214  insert (post_, &trigger);
215  return *this;
216  }
217 
218  private:
219  void
220  configureTemplate (Template kind)
221  {
222  switch (kind) {
223  case CALC_JOB:
224  setupGate();
225  insertWorkBracket();
226  break;
227  case LOAD_JOB:
228  insertWorkBracket();
229  severAsyncChain();
230  break;
231  case META_JOB:
232  /* use the minimal default wiring */
233  break;
234  default:
235  NOTREACHED ("unknown wiring scheme for Render Jobs.");
236  break;
237  }
238  }
239 
240 
241  Activity*
242  setupInvocation (Job& job)
243  {
244  Activity& feed1 = alloc_.create (job.parameter.invoKey.code.w1
245  ,job.parameter.invoKey.code.w2);
246  Activity& feed2 = alloc_.create (Activity::FEED);
247  feed1.next = &feed2;
248 
249  JobClosure* functor = static_cast<JobClosure*> (job.jobClosure);
250  REQUIRE (functor);
251  Activity& invo = alloc_.create (*functor
252  , Time{TimeValue{job.parameter.nominalTime}}
253  , feed1);
254  return & invo;
255  }
256 
257  Activity*
258  setupPost (Time start, Time dead, Activity* followUp)
259  {
260  return & alloc_.create (start,dead,followUp);
261  }
262 
263  void
264  setupGate()
265  {
266  if (gate_) return;
267  gate_ = & alloc_.create (0, Time{post_->data_.timeWindow.dead});
268  ENSURE (gate_);
269  ENSURE (gate_->is (Activity::GATE));
270  insert (post_, gate_);
271  }
272 
273  void
274  insertWorkBracket()
275  {
276  Activity& start = alloc_.create (Activity::WORKSTART);
277  Activity& stop = alloc_.create (Activity::WORKSTOP);
279 
280  insert (gate_? gate_: post_, &start);
281  insert (findTail (start.next), &stop);
282  }
283 
284  void
285  severAsyncChain()
286  {
287  if (callback_) return;
288  Activity& cut = *invoke_->next->next;
289  REQUIRE (cut.is (Activity::FEED));
290  callback_ = cut.next;
291  cut.next = nullptr;
292  ENSURE (callback_);
293  }
294 
295 
296  static void
297  insert (Activity* anchor, Activity* target)
298  {
299  REQUIRE (anchor);
300  REQUIRE (target);
301  target->next = anchor->next;
302  anchor->next = target;
303  }
304 
305  static Activity*
306  findTail (Activity* chain)
307  {
308  REQUIRE (chain);
309  while (chain->next)
310  chain = chain->next;
311  return chain;
312  }
313  };
314 
315  }//(End)namespace activity
316 }}// namespace vault::gear
317 #endif /*SRC_VAULT_GEAR_ACTIVITY_TERM_H_*/
static const Time ANYTIME
border condition marker value. ANYTIME <= any time value
Definition: timevalue.hpp:313
signal start of some processing and transition grooming mode ⟼ *work mode
Definition: activity.hpp:233
Record to describe an Activity, to happen within the Scheduler&#39;s control flow.
Definition: activity.hpp:226
Memory management scheme for activities and parameter data passed through the Scheduler within the Lu...
Term & requireDirectActivation()
Insert a self-inhibition to enforce activation is possible only after the scheduled start time...
correspondingly signal end of some processing
Definition: activity.hpp:234
supply additional payload data for a preceding Activity
Definition: activity.hpp:238
scheme for a synchronous media calculation job
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
scheme for an asynchronous data retrieval job
Term & expectNotification(Activity &notificationSrc, bool unlimitedTime=false)
Builder operation: block this Term waiting for prerequisite notification.
A Term of the »Activity Language«, describing the steps necessary to perform the calculation of a sin...
ElementBoxWidget::Config::Qualifier kind(Kind kind)
qualify the basic use case for the new ElementBoxWidget
probe window + count-down; activate next Activity, else re-schedule
Definition: activity.hpp:236
Activity * next
Activities are organised into chains to represent relations based on verbs.
Definition: activity.hpp:249
Term & appendNotificationTo(Term &targetTerm, bool unlimitedTime=false)
Builder operation: append a Notification link to the end of this Term&#39;s chain.
Definition of a render job.
push a message to another Activity
Definition: activity.hpp:235
scheme for planning and organisational job
Interface of the closure for frame rendering jobs.
Definition: job.h:235
Individual frame rendering task, forwarding to a closure.
Definition: job.h:268
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:133
Vault-Layer implementation namespace root.
Descriptor for a piece of operational logic performed by the scheduler.