2008-01-18 16:43:53 +01:00
|
|
|
/*
|
|
|
|
|
CONFIGRULES.hpp - interface for rule based configuration
|
|
|
|
|
|
|
|
|
|
Copyright (C) CinelerraCV
|
|
|
|
|
2007, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
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 02139, USA.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @file configrules.hpp
|
|
|
|
|
** Interface for accessing rule based configuration.
|
|
|
|
|
** By using the Query template, you can pose a query in prolog syntax and get some
|
|
|
|
|
** existing or newly created object fulfilling the requested predicates. The actual
|
|
|
|
|
** implementation is hidden behind the #instance (Singleton factory). As of 1/2008,
|
|
|
|
|
** it is \i planned to use an embedded YAP Prolog system at some point in the future,
|
|
|
|
|
** for now we use a \link MockConfigRules mock implementation \endlink employing a
|
|
|
|
|
** preconfigured Map.
|
|
|
|
|
**
|
|
|
|
|
** Fully implementing this facility would require the participating objects to register capabilities
|
|
|
|
|
** they want to provide, together with functors carrying out the neccessary configuration steps.
|
|
|
|
|
** All details and consequences of this approach still have to be worked out...
|
|
|
|
|
**
|
2008-01-28 06:05:46 +01:00
|
|
|
** @note this is rather a scrapbook and in flux... don't take this code too literal!
|
|
|
|
|
**
|
2008-01-18 16:43:53 +01:00
|
|
|
** @see cinelerra::Query
|
|
|
|
|
** @see mobject::session::DefsManager
|
|
|
|
|
** @see asset::StructFactory
|
|
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CINELERRA_CONFIGRULES_H
|
|
|
|
|
#define CINELERRA_CONFIGRULES_H
|
|
|
|
|
|
|
|
|
|
#include "common/query.hpp"
|
2008-02-06 05:34:19 +01:00
|
|
|
#include "common/typelistutil.hpp"
|
2008-02-01 15:35:33 +01:00
|
|
|
#include "common/singletonsubclass.hpp"
|
2008-01-21 02:57:09 +01:00
|
|
|
|
2008-02-10 17:23:16 +01:00
|
|
|
//TODO: is it sensible to bring in the types explicitly here? (it's not necessary, but may be convienient...)
|
2008-01-21 02:57:09 +01:00
|
|
|
#include "proc/mobject/session/track.hpp"
|
2008-01-28 06:05:46 +01:00
|
|
|
#include "proc/asset/procpatt.hpp"
|
2008-02-14 04:12:30 +01:00
|
|
|
#include "proc/asset/pipe.hpp"
|
2008-02-10 17:23:16 +01:00
|
|
|
#include "proc/asset/track.hpp"
|
2008-01-18 16:43:53 +01:00
|
|
|
|
|
|
|
|
#include <string>
|
2008-01-28 06:05:46 +01:00
|
|
|
#include <tr1/memory>
|
2008-01-18 16:43:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace cinelerra
|
|
|
|
|
{
|
|
|
|
|
using std::string;
|
2008-01-28 06:05:46 +01:00
|
|
|
using std::tr1::shared_ptr;
|
|
|
|
|
|
2008-01-19 14:24:24 +01:00
|
|
|
|
2008-01-18 16:43:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace query
|
|
|
|
|
{
|
2008-01-19 14:24:24 +01:00
|
|
|
// The intention is to support the following style of Prolog code
|
|
|
|
|
//
|
2008-01-21 02:57:09 +01:00
|
|
|
// retrieve(O, Cap) :- find(T), capabilities(Cap).
|
|
|
|
|
// retrieve(O, Cap) :- make(T), capabilities(Cap).
|
|
|
|
|
// capabilities(Q) :- call(Q).
|
2008-01-19 14:24:24 +01:00
|
|
|
//
|
2008-02-14 04:12:30 +01:00
|
|
|
// stream(T, mpeg) :- type(T, track), type(P, pipe), retrieve(P, stream(P,mpeg)), place_to(P, T).
|
2008-01-19 14:24:24 +01:00
|
|
|
//
|
|
|
|
|
// The type guard is inserted auomatically, while the predicate implementations for
|
|
|
|
|
// find/1, make/1, stream/2, and place_to/2 are to be provided by the target types.
|
2008-01-21 02:57:09 +01:00
|
|
|
//
|
|
|
|
|
// As a example, the goal ":-retrieve(T, stream(T,mpeg))." would search a Track object, try to
|
2008-02-14 04:12:30 +01:00
|
|
|
// retrieve a pipe object with stream-type=mpeg and associate the track with this Pipe. The
|
|
|
|
|
// predicate "stream(P,mpeg)" needs to be implemented (natively) for the pipe object.
|
2008-01-19 14:24:24 +01:00
|
|
|
|
|
|
|
|
class Resolver
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
};
|
2008-02-10 17:23:16 +01:00
|
|
|
|
|
|
|
|
|
2008-01-19 14:24:24 +01:00
|
|
|
template
|
|
|
|
|
< const Symbol SYM, // Predicate symbol
|
|
|
|
|
typename SIG = bool(string) // Signature
|
|
|
|
|
>
|
|
|
|
|
class Pred
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2008-02-10 17:23:16 +01:00
|
|
|
/**
|
|
|
|
|
* the "backside" interface towards the classes participating
|
|
|
|
|
* in the configuration system (the config system will be
|
|
|
|
|
* delivering instances of these classes for a given query).
|
|
|
|
|
* This one currently is just brainstorming. The idea is that
|
|
|
|
|
* a participating class would provide such and TypeHandler
|
|
|
|
|
* implementing the predicates which make sense for this special
|
|
|
|
|
* type of object. Registering such a TypeHandler should create
|
|
|
|
|
* the necessary handler functions to be installed into
|
|
|
|
|
* the Prolog system.
|
|
|
|
|
*/
|
2008-01-19 14:24:24 +01:00
|
|
|
template<class TY>
|
|
|
|
|
class TypeHandler
|
|
|
|
|
{
|
|
|
|
|
static const TY NIL;
|
|
|
|
|
|
|
|
|
|
template<Symbol SYM, typename SIG>
|
|
|
|
|
TY find (Pred<SYM,SIG> capability);
|
|
|
|
|
|
|
|
|
|
template<Symbol SYM, typename SIG>
|
|
|
|
|
TY make (Pred<SYM,SIG> capability, TY& refObj =NIL);
|
|
|
|
|
};
|
2008-02-10 17:23:16 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* the "frontside" interface: the Proc-Layer code can
|
|
|
|
|
* use this QueryHandler to retrieve instances of the
|
|
|
|
|
* type TY fulfilling the given Query. To start with,
|
|
|
|
|
* we use a mock implementation-
|
|
|
|
|
* @see cinelerra::query::LookupPreconfigured
|
|
|
|
|
* @see cinelerra::query::MockTable
|
|
|
|
|
*/
|
2008-01-19 14:24:24 +01:00
|
|
|
template<class TY>
|
|
|
|
|
class QueryHandler
|
|
|
|
|
{
|
2008-01-21 02:57:09 +01:00
|
|
|
protected:
|
2008-01-29 05:39:32 +01:00
|
|
|
virtual ~QueryHandler() { }
|
2008-01-21 02:57:09 +01:00
|
|
|
public:
|
2008-02-10 17:23:16 +01:00
|
|
|
/** try to find or create an object of type TY
|
|
|
|
|
* fulfilling the given query.
|
|
|
|
|
* @return empty shared-ptr if not found,
|
|
|
|
|
*/
|
2008-02-06 05:34:19 +01:00
|
|
|
virtual shared_ptr<TY> resolve (const Query<TY>& q) = 0;
|
2008-01-21 02:57:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TODO: the Idea is to provide specialisations for the concrete types
|
|
|
|
|
// we want to participate in the ConfigRules system....
|
|
|
|
|
// Thus we get the possibility to create a specific return type,
|
2008-02-14 04:12:30 +01:00
|
|
|
// e.g. return a shared_ptr<Pipe> but a Placement<Track>, using the appropriate factory.
|
2008-01-21 02:57:09 +01:00
|
|
|
// Of course then the definitions need to be split up in separate headers.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generic query interface for retrieving objects matching
|
|
|
|
|
* some capability query. To be instantiated using a typelist,
|
|
|
|
|
* thus inheriting from the Handler classes for each type. In
|
|
|
|
|
* the (future) version using YAP Prolog, this will drive the
|
|
|
|
|
* generation and registration of the necessary predicate
|
|
|
|
|
* implementations for each concrete type, using the speicalisations
|
|
|
|
|
* given alongside with the types. For now it just serves to generate
|
|
|
|
|
* the necessary resolve(Query<TY>) virtual functions (implemented
|
|
|
|
|
* by MockConfigRules)
|
|
|
|
|
*/
|
2008-02-01 15:35:33 +01:00
|
|
|
template<typename TYPES>
|
2008-01-21 02:57:09 +01:00
|
|
|
class ConfigRules
|
2008-02-06 05:34:19 +01:00
|
|
|
: public typelist::InstantiateForEach<TYPES, QueryHandler>
|
2008-01-21 02:57:09 +01:00
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
ConfigRules () {}
|
|
|
|
|
virtual ~ConfigRules() {}
|
|
|
|
|
|
2008-02-01 15:35:33 +01:00
|
|
|
public:
|
2008-01-21 02:57:09 +01:00
|
|
|
// TODO: find out what operations we need to support here for the »real solution« (using Prolog)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-01-18 16:43:53 +01:00
|
|
|
|
2008-01-28 06:05:46 +01:00
|
|
|
|
|
|
|
|
CINELERRA_ERROR_DECLARE (CAPABILITY_QUERY); ///< unresolvable capability query.
|
2008-01-18 16:43:53 +01:00
|
|
|
|
|
|
|
|
} // namespace query
|
2008-01-21 02:57:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ============= global configuration ==================== */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* the list of all concrete types participating in the
|
|
|
|
|
* rule based config query system
|
|
|
|
|
*/
|
|
|
|
|
typedef cinelerra::typelist::Types < mobject::session::Track
|
2008-02-10 17:23:16 +01:00
|
|
|
, asset::Track
|
2008-02-14 04:12:30 +01:00
|
|
|
, asset::Pipe
|
2008-01-28 06:05:46 +01:00
|
|
|
, const asset::ProcPatt
|
2008-02-06 05:34:19 +01:00
|
|
|
> ::List
|
2008-01-21 02:57:09 +01:00
|
|
|
InterfaceTypes;
|
|
|
|
|
|
2008-02-01 15:35:33 +01:00
|
|
|
/**
|
|
|
|
|
* user-visible Interface to the ConfigRules subsystem.
|
|
|
|
|
* Configured as Singleton (with hidden Implementation class)
|
|
|
|
|
*/
|
|
|
|
|
class ConfigRules
|
|
|
|
|
: public query::ConfigRules<InterfaceTypes>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static SingletonSub<ConfigRules> instance;
|
|
|
|
|
|
|
|
|
|
};
|
2008-01-21 02:57:09 +01:00
|
|
|
|
|
|
|
|
|
2008-01-18 16:43:53 +01:00
|
|
|
} // namespace cinelerra
|
|
|
|
|
#endif
|