Lumiera  0.pre.03
»edit your freedom«
job.cpp
Go to the documentation of this file.
1 /*
2  Job - 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 
36 #include "vault/gear/job.h"
38 #include "lib/util.hpp"
39 
40 #include <boost/functional/hash.hpp>
41 #include <typeinfo>
42 
43 
44 namespace vault{
45 namespace gear {
46 
47  namespace { // Details...
48 
49  inline JobClosure&
50  myClosure (const Job * const self)
51  {
52  ASSERT (self);
53  ASSERT (self->jobClosure);
54  return *static_cast<JobClosure*> (self->jobClosure);
55  }
56 
57  } // (END) Details...
58 
59 
60  using lib::HashVal;
61  using util::isSameObject;
62 
63 
64 
72 
73  NopJobFunctor::NopJobFunctor() { }
74 
75 
76 
77 
78  void
79  Job::triggerJob() const
80  {
81  myClosure(this).invokeJobOperation (parameter);
82  }
83 
84 
90  JobKind
91  Job::getKind() const
92  {
93  return myClosure(this).getJobKind();
94  }
95 
96 
97  bool
98  Job::usesClosure (JobClosure const& otherClosure) const
99  {
100  return isSameObject (myClosure(this), otherClosure);
101  }
102 
103 
104 
112  HashVal
113  hash_value (Job const& job)
114  {
115  return myClosure(&job).hash_value (job.parameter);
116  }
117 
118  HashVal
119  JobClosure::hash_value (JobParameter parameter) const
120  {
121  HashVal hash = this->hashOfInstance (parameter.invoKey);
122  boost::hash_combine(hash, typeid(*this).hash_code());
123  boost::hash_combine(hash, parameter.nominalTime);
124  return hash;
125  }
126 
127 
128 }} // namespace vault::gear
129 
130 namespace {
131  using vault::gear::Job;
132 
133  inline Job&
134  forwardInvocation (lumiera_jobDefinition& jobDef)
135  {
136  Job& job = static_cast<Job&> (jobDef);
137  return job;
138  }
139 }
140 
141 
142 
143 extern "C" { /* ==== implementation C interface for job invocation ======= */
144 
145 void
146 lumiera_job_invoke (LumieraJobDefinition jobDef)
147 {
148  REQUIRE (jobDef);
149  forwardInvocation(*jobDef).triggerJob();
150 }
151 
152 size_t
153 lumiera_job_get_hash (LumieraJobDefinition jobDef)
154 {
155  REQUIRE (jobDef);
156  return hash_value (forwardInvocation (*jobDef));
157 }
158 
160 #include "lib/luid.h"
161 
162 int
163 lumiera_invokey_eq (void* l, void* r)
164 {
165  return lumiera_uid_eq ((LumieraUid)l, (LumieraUid)r);
166 }
167 }/* extern "C" */
void lumiera_job_invoke(LumieraJobDefinition jobDef)
trigger execution of a specific job, assuming availability of all prerequisites
Definition: job.cpp:146
Generic implementation of a JobFunctor to perform no calculations.
virtual ~JobFunctor()
this is an interface
Definition: job.cpp:70
Lumiera unique object identifier.
size_t lumiera_job_get_hash(LumieraJobDefinition jobDef)
calculate a hash value based on the Job&#39;s identity.
Definition: job.cpp:153
JobKind
Definition: job.h:71
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
JobKind getKind() const
find out about the classification of this job.
Definition: job.cpp:91
int lumiera_uid_eq(const lumiera_uid *luida, const lumiera_uid *luidb)
Test 2 luid&#39;s for equality.
Definition: luid.c:106
Definition of a render job.
size_t HashVal
a STL compatible hash value
Definition: hash-value.h:56
Interface of the closure for frame rendering jobs.
Definition: job.h:244
Individual frame rendering task, forwarding to a closure.
Definition: job.h:277
Vault-Layer implementation namespace root.
virtual ~JobClosure()
this is an interface
Definition: job.cpp:71