2011-05-23 04:43:56 +02:00
/*
2011-05-23 05:46:40 +02:00
DISPATCHER . hpp - translating calculation streams into frame jobs
2011-05-23 04:43:56 +02:00
Copyright ( C ) Lumiera . org
2011-05-23 05:46:40 +02:00
2011 , Hermann Vosseler < Ichthyostega @ web . de >
2011-05-23 04:43:56 +02:00
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation ; either version 2 of
the License , or ( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
2011-05-23 05:46:40 +02:00
# ifndef PROC_ENGINE_DISPATCHER_H
# define PROC_ENGINE_DISPATCHER_H
2011-05-23 04:43:56 +02:00
# include "proc/common.hpp"
2012-02-24 00:29:59 +01:00
# include "proc/mobject/model-port.hpp"
2012-02-09 22:24:05 +01:00
# include "proc/engine/time-anchor.hpp"
# include "proc/engine/frame-coord.hpp"
2012-02-13 00:37:57 +01:00
# include "proc/engine/job-ticket.hpp"
2012-07-01 03:42:50 +02:00
# include "proc/engine/job-planning.hpp"
2011-05-23 04:43:56 +02:00
# include "lib/time/timevalue.hpp"
2012-02-04 22:20:21 +01:00
# include <boost/noncopyable.hpp>
2012-04-26 04:11:31 +02:00
# include <tr1/functional>
2011-05-23 04:43:56 +02:00
2011-12-02 16:10:03 +01:00
namespace proc {
2011-05-23 04:43:56 +02:00
namespace engine {
2012-04-26 04:11:31 +02:00
using std : : tr1 : : function ;
2012-02-24 00:29:59 +01:00
using mobject : : ModelPort ;
2011-05-28 01:46:06 +02:00
using lib : : time : : TimeSpan ;
using lib : : time : : FSecs ;
using lib : : time : : Time ;
2013-01-12 12:38:33 +01:00
2011-05-23 04:43:56 +02:00
/**
2012-10-10 04:35:56 +02:00
* Internal abstraction : a service within the engine
* for translating a logical calculation stream ( corresponding to a PlayProcess )
* into a sequence of individual RenderJob entries for calculations and data access .
* The actual implementation of this service is tied to the low - level - model , i . e .
* the render nodes network . The Dispatcher service is used to implement the CalcStreams
* during playback and rendering ; there will be a continuous , chunk - wise proceeding
* evaluation and planning of new jobs , which can then be handed over to the Scheduler
* for time - bound activation .
*
* \ par usage considerations
* the asynchronous and ongoing nature of the render process mandates to avoid a central
* instance for operating this planning process . Instead , each chunk of planned jobs
* contains a continuation job , which - - on activation - - will pick up the planning
* of the next chunk . The Dispatcher interface was shaped to support this process ,
* with a local JobBuilder to be used within the continuation job , and a TimeAnchor
* to represent the continuation point . All the complexities of planning jobs are
* hidden within the JobPlanningSequence , which , for the purpose of dispatching
* a series of jobs just looks like a sequence of job descriptors
*
* @ todo 10 / 12 still WIP , but conceptually settled by now
2011-05-23 04:43:56 +02:00
*/
2011-05-23 05:46:40 +02:00
class Dispatcher
2012-10-10 04:35:56 +02:00
: public FrameLocator
2011-05-23 04:43:56 +02:00
{
2012-04-26 04:11:31 +02:00
struct JobBuilder
2012-02-24 00:29:59 +01:00
{
Dispatcher & dispatcher_ ;
2012-10-10 04:35:56 +02:00
TimeAnchor refPoint_ ;
2012-02-24 00:29:59 +01:00
ModelPort modelPort_ ;
uint channel_ ;
2012-10-06 02:29:19 +02:00
/////TODO need storage for the continuation
2013-05-21 04:35:25 +02:00
/////////TODO somehow need to represent the dimensions of a "planning chunk"...
2012-10-10 04:35:56 +02:00
FrameCoord relativeFrameLocation ( TimeAnchor refPoint , uint frameCountOffset = 0 ) ;
2012-04-26 04:11:31 +02:00
JobBuilder & establishNextJobs ( TimeAnchor refPoint ) ;
JobBuilder & prepareContinuation ( function < void ( TimeAnchor ) > delayedAction ) ;
2012-07-01 03:42:50 +02:00
operator JobPlanningSequence ( )
2012-04-26 04:11:31 +02:00
{
2013-01-12 12:49:26 +01:00
TimeAnchor nextPlanningAnchor = refPoint_ . buildNextAnchor ( ) ;
2012-10-10 04:35:56 +02:00
TODO ( " build the continuation job if necessary, wrap the sequence " ) ;
2012-04-26 04:11:31 +02:00
2012-10-10 04:35:56 +02:00
return JobPlanningSequence (
2013-01-12 12:49:26 +01:00
relativeFrameLocation ( refPoint_ ) ,
dispatcher_ ) ;
2012-04-26 04:11:31 +02:00
}
2012-02-24 00:29:59 +01:00
} ;
2011-05-23 04:43:56 +02:00
public :
2012-02-04 22:20:21 +01:00
virtual ~ Dispatcher ( ) ; ///< this is an interface
2012-04-26 04:11:31 +02:00
JobBuilder onCalcStream ( ModelPort modelPort , uint channel ) ;
2012-02-04 22:20:21 +01:00
2011-05-23 04:43:56 +02:00
2012-10-06 02:29:19 +02:00
protected :
virtual FrameCoord locateRelative ( FrameCoord , uint frameCountOffset ) = 0 ;
2012-10-10 04:35:56 +02:00
virtual FrameCoord locateRelative ( TimeAnchor , uint frameCountOffset ) = 0 ; //////////TODO is this really an interface operation, or just a convenience shortcut?
2013-05-30 02:10:56 +02:00
virtual bool seamlessNextFrame ( int64_t , ModelPort port ) = 0 ;
////////TODO: API-1 = just get next frame, without limitations .... CHECK
////////TODO: API-2 = query limitation of planning chunk .... CHECK
////////TODO: API-3 = establish next chunk .... still WIP
////////TODO: Question: why not embedding the time anchor directly within the location generator??
//////// Answer: no this would lead to a huge blob called "the dispatcher"
////////TODO: immediate point to consider: the time anchor is responsible for the real timing calculations. But how to introduce the play strategy *here* ?
2012-10-10 04:35:56 +02:00
virtual JobTicket & accessJobTicket ( ModelPort , TimeValue nominalTime ) = 0 ;
2011-05-23 04:43:56 +02:00
} ;
2011-12-02 16:10:03 +01:00
} } // namespace proc::engine
2011-05-23 04:43:56 +02:00
# endif