Lumiera  0.pre.03
»edit your freedom«
job.h
Go to the documentation of this file.
1 /*
2  JOB.h - render job closure
3 
4  Copyright (C) Lumiera.org
5  2012, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
51 #ifndef VAULT_GEAR_JOB_H
52 #define VAULT_GEAR_JOB_H
53 
54 
55 #include "lib/llist.h"
56 #include "lib/hash-value.h"
57 #include "lib/time.h"
58 
59 
60 
62  {
63  DONE,
69  };
70 
71 enum JobKind
72  {
76  };
77 
79  {
84  };
85 
86 
87 typedef int64_t FrameCnt;
88 
89 
90 
97 struct lumiera_jobClosure { /* placeholder */ };
98 typedef struct lumiera_jobClosure* LumieraJobClosure;
99 
100 
101 
112  {
113  lumiera_uid luid{0};
114 
115  /* ----- alternative accessors for test code ---- */
116  FrameCnt frameNumber;
117  struct { int32_t a,b;
118  int64_t t;
119  } part;
120  struct {
121  uint64_t w1;
122  uint64_t w2;
123  } code;
124  };
125 
126 
127 
128 
134  {
135  gavl_time_t nominalTime;
136  InvocationInstanceID invoKey;
140  };
141 typedef struct lumiera_jobParameter_struct lumiera_jobParameter;
142 typedef lumiera_jobParameter* LumieraJobParameter;
143 
144 
147  {
148  LumieraJobClosure jobClosure;
149  lumiera_jobParameter parameter;
150  };
151 typedef struct lumiera_jobDefinition_struct lumiera_jobDefinition;
152 typedef lumiera_jobDefinition* LumieraJobDefinition;
153 
154 
172  {
173  gavl_time_t deadline;
174  JobState jobState;
175 
176  lumiera_jobDefinition jobDefinition;
177 
178  /* == Job prerequisites == */
179  LList waiting;
180  LList failed;
181  LList completed;
182  };
183 typedef struct lumiera_jobDescriptor_struct lumiera_jobDescriptor;
184 typedef lumiera_jobDescriptor* LumieraJobDescriptor;
185 
186 
187 
188 
189 
190 
191 
192 
193 #ifdef __cplusplus /* ============== C++ Interface ================= */
194 
195 #include <string>
196 
197 
198 
199 namespace vault{
200 namespace gear {
201 
202  using lib::time::TimeValue;
203  using lib::time::Time;
204  using lib::HashVal;
205 
206  typedef lumiera_jobParameter const& JobParameter;
207 
208 
210  class JobFunctor
211  : util::NonCopyable // ....has distinct identity and stable address
212  {
213  public:
214  virtual ~JobFunctor();
215 
216  virtual std::string
217  diagnostic() const
218  {
219  return "JobFunctor";
220  }
221 
222  operator std::string() const
223  {
224  return diagnostic();
225  }
226  };
243  : public lumiera_jobClosure
244  , public JobFunctor
245  {
246  public:
247  virtual ~JobClosure();
248 
249 
250  virtual void invokeJobOperation (JobParameter parameter) =0;
251 
252  virtual JobKind getJobKind() const =0;
253  virtual HashVal hashOfInstance(InvocationInstanceID) const =0;
254  virtual InvocationInstanceID buildInstanceID(HashVal)const =0;
255 
256  lib::HashVal hash_value (JobParameter) const;
257  };
258 
259 
260 
261 
275  class Job
276  : public lumiera_jobDefinition
277  {
278 
279  public:
280 
281  Job (JobClosure& specificJobDefinition
282  ,InvocationInstanceID invoKey
283  ,Time nominalFrameTime)
284  {
285  this->jobClosure = &specificJobDefinition;
286  this->parameter.nominalTime = _raw(nominalFrameTime);
287  this->parameter.invoKey = invoKey;
288  }
289 
290  // using standard copy operations
291 
292 
293  void triggerJob() const;
294 
295 
296  Time
297  getNominalTime() const
298  {
299  return Time (TimeValue(parameter.nominalTime));
300  }
301 
303  getInvocationInstanceID() const
304  {
305  return this->parameter.invoKey;
306  }
307 
308  JobKind getKind() const;
309 
310  bool usesClosure (JobClosure const&) const;
311 
313  friend lib::HashVal hash_value (Job const&);
314  };
315 
316  inline bool
317  operator== (Job const& left, Job const& right)
318  {
319  return hash_value (left) == hash_value (right);
320  }
321 
322  inline bool
323  operator!= (Job const& left, Job const& right)
324  {
325  return hash_value (left) != hash_value (right);
326  }
327 
328 
329 
330 
331 
332 }} // namespace vault::gear
333 
334 
335 
336 
337 extern "C" {
338 #endif /* =========================== C Interface ===================== */
339 
340 
343 void lumiera_job_invoke (LumieraJobDefinition);
344 
346 size_t lumiera_job_get_hash (LumieraJobDefinition);
347 
348 int lumiera_invokey_eq (void* l, void* r);
349 
350 
351 #ifdef __cplusplus
352 }
353 #endif
354 #endif /*VAULT_GEAR_JOB_H*/
lumiera_jobDefinition jobDefinition
of interest only to Steam-Layer
Definition: job.h:176
LumieraJobClosure jobClosure
type and context of the job, including the actual functor
Definition: job.h:148
waiting for some prerequisite
Definition: job.h:65
Common functions for handling of time values.
invocation parameter for the individual frame calculation job.
Definition: job.h:133
closure representing the execution context of a job.
Definition: job.h:97
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
job is currently running
Definition: job.h:64
Description of a job.
Definition: job.h:171
complete definition of an individual job
Definition: job.h:146
accessing prerequisites, IO bound
Definition: job.h:74
background rendering job
Definition: job.h:83
got aborted
Definition: job.h:68
gavl_time_t deadline
given in real wall clock time
Definition: job.h:173
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:305
lumiera_jobParameter parameter
the "moving parts" for this individual invocation (Job)
Definition: job.h:149
size_t lumiera_job_get_hash(LumieraJobDefinition)
calculate a hash value based on the Job&#39;s identity.
Definition: job.cpp:153
regular job scheduled for time-bound delivery
Definition: job.h:80
JobKind
Definition: job.h:71
Definition: job.h:81
sorry, can&#39;t do that Dave
Definition: job.h:66
job for freewheeling calculation of final results
Definition: job.h:82
calculating frame data, CPU bound
Definition: job.h:73
deadline expired
Definition: job.h:67
opaque ID attached to each individual job invocation.
Definition: job.h:111
Hash value types and utilities.
Intrusive cyclic double linked list There is only one node type which contains a forward and a backwa...
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:56
JobPriority
Definition: job.h:78
Interface of the closure for frame rendering jobs.
Definition: job.h:242
void lumiera_job_invoke(LumieraJobDefinition)
trigger execution of a specific job, assuming availability of all prerequisites
Definition: job.cpp:146
unsigned char lumiera_uid[16]
storage for a Lumiera unique ID, based on a 128bit random number
Definition: hash-value.h:45
render process self organisation
Definition: job.h:75
Individual frame rendering task, forwarding to a closure.
Definition: job.h:275
basic constant internal time value.
Definition: timevalue.hpp:142
mission accomplished
Definition: job.h:63
Vault-Layer implementation namespace root.
JobState
Definition: job.h:61