Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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
69#include "vault/gear/job.h"
71
72#include <string>
73#include <utility>
74
75
76namespace vault{
77namespace 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
99
100 Activity* invoke_{nullptr};
101 Activity* post_{nullptr};
102
103 Activity* gate_{nullptr};
104 Activity* callback_{nullptr};
105
106
107 public:
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();
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
221 {
222 switch (kind) {
223 case CALC_JOB:
224 setupGate();
226 break;
227 case LOAD_JOB:
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*
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
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
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
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*
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_*/
Descriptor for a piece of operational logic performed by the scheduler.
Memory management scheme for activities and parameter data passed through the Scheduler within the Lu...
basic constant internal time value.
Lumiera's internal time value datatype.
static const Time ANYTIME
border condition marker value. ANYTIME <= any time value
Record to describe an Activity, to happen within the Scheduler's control flow.
Definition activity.hpp:227
void setNotificationTarget(Activity *target, Time limitStart=Time::ANYTIME)
Definition activity.hpp:435
bool is(Activity::Verb expectedVerb) const
Definition activity.hpp:422
Activity * next
Activities are organised into chains to represent relations based on verbs.
Definition activity.hpp:249
@ NOTIFY
push a message to another Activity
Definition activity.hpp:235
@ FEED
supply additional payload data for a preceding Activity
Definition activity.hpp:238
@ GATE
probe window + count-down; activate next Activity, else re-schedule
Definition activity.hpp:236
@ WORKSTART
signal start of some processing and transition grooming mode ⟼ *work mode
Definition activity.hpp:233
@ WORKSTOP
correspondingly signal end of some processing
Definition activity.hpp:234
Interface of the closure for frame rendering jobs.
Definition job.h:244
Individual frame rendering task, forwarding to a closure.
Definition job.h:276
A Term of the »Activity Language«, describing the steps necessary to perform the calculation of a sin...
@ CALC_JOB
scheme for a synchronous media calculation job
@ LOAD_JOB
scheme for an asynchronous data retrieval job
@ META_JOB
scheme for planning and organisational job
Term & expectNotification(Activity &notificationSrc, bool unlimitedTime=false)
Builder operation: block this Term waiting for prerequisite notification.
Activity * setupPost(Time start, Time dead, Activity *followUp)
static void insert(Activity *anchor, Activity *target)
void configureTemplate(Template kind)
Term & requireDirectActivation()
Insert a self-inhibition to enforce activation is possible only after the scheduled start time.
Term & appendNotificationTo(Term &targetTerm, bool unlimitedTime=false)
Builder operation: append a Notification link to the end of this Term's chain.
Activity * setupInvocation(Job &job)
BlockFlowAlloc::AllocatorHandle AllocHandle
static Activity * findTail(Activity *chain)
Term(AllocHandle &&allocHandle, Template kind, Time start, Time dead, Job job)
Definition of a render job.
BlockFlow< blockFlow::RenderConfig > BlockFlowAlloc
Vault-Layer implementation namespace root.
a family of time value like entities and their relationships.