2008-01-18 16:43:53 +01:00
/*
2012-12-01 08:44:07 +01:00
CONFIG - RULES . hpp - interface for rule based configuration
2010-12-17 23:28:49 +01:00
2008-03-10 08:38:59 +01:00
Copyright ( C ) Lumiera . org
2008 , Hermann Vosseler < Ichthyostega @ web . de >
2010-12-17 23:28:49 +01:00
2008-01-18 16:43:53 +01:00
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License as
2010-12-17 23:28:49 +01:00
published by the Free Software Foundation ; either version 2 of
the License , or ( at your option ) any later version .
2008-01-18 16:43:53 +01:00
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 .
2010-12-17 23:28:49 +01:00
2008-01-18 16:43:53 +01:00
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 .
2010-12-17 23:28:49 +01:00
2008-01-18 16:43:53 +01:00
*/
2012-12-01 08:44:07 +01:00
/** @file config-rules.hpp
2008-01-18 16:43:53 +01:00
* * 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 ,
2008-02-22 04:58:37 +01:00
* * it is \ e planned to use an embedded YAP Prolog system at some point in the future ,
2008-01-18 16:43:53 +01:00
* * 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
2008-12-05 11:07:01 +01:00
* * they want to provide , together with functors carrying out the necessary configuration steps .
2008-01-18 16:43:53 +01:00
* * All details and consequences of this approach still have to be worked out . . .
2012-12-09 02:42:36 +01:00
* *
* * \ par relation to Query and QueryResolver
* * The ConfigRules resolver is just a special kind of QueryResolver , able to handle specific kinds
* * of queries . Clients using the ConfigRules directly get a more easy to use point - and - shot style
* * interface , allowing just to retrieve some \ em suitable solution , instead of having to iterate
* * through a result set .
* *
* * @ todo right now ( 12 / 2012 ) the above paragraph is a lie .
* * ConfigQuery is way older than QueryResolver and will be retrofitted step by step .
* * Not much of a problem , since the currently utilised mock implementation isn ' t able to
* * deal with a real query anyway .
2008-01-18 16:43:53 +01:00
* *
2012-12-09 02:42:36 +01:00
* * @ note this is rather a concept draft and left as such for now . . . don ' t take this code too literal !
2010-10-25 06:08:36 +02:00
* * @ todo clarify the relation of config query and query - for - defaults ///////////////TICKET #705
2008-01-28 06:05:46 +01:00
* *
2008-03-10 08:38:59 +01:00
* * @ see lumiera : : Query
2008-01-18 16:43:53 +01:00
* * @ see mobject : : session : : DefsManager
* * @ see asset : : StructFactory
2012-12-09 02:42:36 +01:00
* * @ see config - resolver . hpp specialised setup for the Proc - Layer
2010-02-28 07:17:12 +01:00
* * @ see fake - configrules . hpp currently used dummy - implementation
2012-11-26 01:22:01 +01:00
* * @ see
2008-01-18 16:43:53 +01:00
* *
*/
2012-12-01 08:44:07 +01:00
# ifndef LUMIERA_CONFIG_RULES_H
# define LUMIERA_CONFIG_RULES_H
2008-01-18 16:43:53 +01:00
2008-12-17 17:53:32 +01:00
# include "lib/p.hpp"
2009-09-24 23:02:40 +02:00
# include "lib/symbol.hpp"
2008-12-17 17:53:32 +01:00
# include "lib/meta/generator.hpp"
2012-12-01 08:44:07 +01:00
# include "common/query.hpp"
2008-01-18 16:43:53 +01:00
# include <string>
2012-12-01 08:44:07 +01:00
namespace lumiera {
2010-03-12 01:49:30 +01:00
2008-01-18 16:43:53 +01:00
using std : : string ;
2011-12-02 16:10:03 +01:00
using lib : : P ;
2008-01-19 14:24:24 +01:00
2008-01-18 16:43:53 +01:00
2012-12-01 08:44:07 +01:00
/////////////////////////////////////////////////////////////////////TICKET #705 this is draft/preview code; a real resolution system needs to be integrated
2010-04-04 06:38:22 +02:00
2010-03-12 01:49:30 +01:00
namespace query {
2008-01-19 14:24:24 +01:00
// The intention is to support the following style of Prolog code
//
2008-02-29 18:58:29 +01:00
// resolve(O, Cap) :- find(O), capabilities(Cap).
// resolve(O, Cap) :- make(O), capabilities(Cap).
// capabilities(Q) :- call(Q).
//
2015-05-31 02:03:24 +02:00
// stream(T, mpeg) :- type(T, fork), type(P, pipe), resolve(P, stream(P,mpeg)), placed_to(P, T).
2008-01-19 14:24:24 +01:00
//
2008-12-05 11:07:01 +01:00
// The type guard is inserted automatically, while the predicate implementations for
2010-10-28 03:57:12 +02:00
// find/1, make/1, stream/2, and placed_to/2 are to be provided by the target types.
2008-01-21 02:57:09 +01:00
//
2015-05-31 02:03:24 +02:00
// As a example, the goal ":-retrieve(T, stream(T,mpeg))." would search a Fork object (a "track"), try to
// retrieve a pipe object with stream-type=mpeg and associate the Fork with this Pipe. The
2008-02-14 04:12:30 +01:00
// predicate "stream(P,mpeg)" needs to be implemented (natively) for the pipe object.
2008-01-19 14:24:24 +01:00
class Resolver
{
2012-12-01 08:44:07 +01:00
///////////////////////////////////////////////////////////////TICKET #705 a real resolution system needs to be integrated
2008-01-19 14:24:24 +01:00
} ;
2008-02-10 17:23:16 +01:00
2009-09-24 23:02:40 +02:00
using lib : : Symbol ;
using lib : : Literal ;
2012-12-01 08:44:07 +01:00
using lumiera : : Query ;
2009-09-24 23:02:40 +02:00
/** placeholder definition for later.
* @ todo intention is to integrate with lib : : Symbol
*/
# define SYMBOL uint
2008-01-19 14:24:24 +01:00
template
2009-09-24 23:02:40 +02:00
< SYMBOL SYM , // Predicate symbol
2008-01-19 14:24:24 +01:00
typename SIG = bool ( string ) // Signature
>
class Pred
2010-04-04 06:38:22 +02:00
{ } ;
2008-01-19 14:24:24 +01:00
2008-02-10 17:23:16 +01:00
/**
2008-12-05 11:07:01 +01:00
* the " back side " interface towards the classes participating
2008-02-10 17:23:16 +01:00
* 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 .
2015-01-17 16:08:56 +01:00
* @ deprecated it can ' t be done exactly this way , but I leave it in the
* current shape as a reminder for later , to show the intention . . .
* @ todo 6 / 2010 unify this with the TypeHandler in typed - id . hpp
2008-02-10 17:23:16 +01:00
*/
2008-01-19 14:24:24 +01:00
template < class TY >
class TypeHandler
{
static const TY NIL ;
2009-09-24 23:02:40 +02:00
template < SYMBOL SYM , typename SIG >
2008-01-19 14:24:24 +01:00
TY find ( Pred < SYM , SIG > capability ) ;
2009-09-24 23:02:40 +02:00
template < SYMBOL SYM , typename SIG >
2008-01-19 14:24:24 +01:00
TY make ( Pred < SYM , SIG > capability , TY & refObj = NIL ) ;
} ;
2008-02-10 17:23:16 +01:00
/**
2008-12-05 11:07:01 +01:00
* the " front side " interface : the Proc - Layer code can
2008-02-10 17:23:16 +01:00
* use this QueryHandler to retrieve instances of the
* type TY fulfilling the given Query . To start with ,
2008-02-29 18:58:29 +01:00
* we use a mock implementation .
* ( this code works and is already used 2 / 2008 )
2012-12-09 02:42:36 +01:00
* @ todo retrofit this to install and use a QueryResolver
2008-03-10 08:38:59 +01:00
* @ see lumiera : : query : : LookupPreconfigured
* @ see lumiera : : query : : MockTable
2008-02-10 17:23:16 +01:00
*/
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 .
2008-02-29 18:58:29 +01:00
* @ param solution object fulfilling the query . Will be bound or
* unified ( in case it ' s already bound ) with the first solution .
* @ query any goals to be fulfilled by the solution .
* @ return false if resolution failed . In this case , solution ptr is empty .
2008-02-10 17:23:16 +01:00
*/
2012-12-25 01:16:19 +01:00
virtual bool resolve ( P < TY > & solution , Query < TY > const & q ) = 0 ;
2008-01-21 02:57:09 +01:00
} ;
2010-04-04 06:38:22 +02:00
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,
2015-05-31 02:03:24 +02:00
// e.g. return a P<Pipe> but a Placement<Fork>, 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
2008-12-05 11:07:01 +01:00
* implementations for each concrete type , using the specialisations
2008-01-21 02:57:09 +01:00
* 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
2011-12-03 02:56:50 +01:00
: public lib : : meta : : InstantiateForEach < TYPES , QueryHandler >
2008-01-21 02:57:09 +01:00
{
protected :
ConfigRules ( ) { }
virtual ~ ConfigRules ( ) { }
2008-02-01 15:35:33 +01:00
public :
2012-12-27 02:31:58 +01:00
/** roll back to a pristine yet operational state.
* Discards all information collected through use */
virtual void reset ( ) = 0 ;
2008-01-21 02:57:09 +01:00
// TODO: find out what operations we need to support here for the »real solution« (using Prolog)
} ;
2010-04-04 06:38:22 +02:00
2008-01-18 16:43:53 +01:00
2008-01-28 06:05:46 +01:00
2008-03-10 08:38:59 +01:00
LUMIERA_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
2008-04-07 08:03:22 +02:00
2010-04-04 06:38:22 +02:00
namespace query {
2008-04-07 08:03:22 +02:00
/** backdoor for tests: the next config query with this query string
2010-04-04 06:38:22 +02:00
* will magically succeed with every candidate object provided . This
2008-04-07 08:03:22 +02:00
* is currently necessary to get objects into the defaults manager ,
* as the query system is not able to do real query resolution */
2012-12-25 01:16:19 +01:00
void setFakeBypass ( lumiera : : QueryKey const & q ) ;
bool isFakeBypass ( lumiera : : QueryKey const & q ) ;
2010-11-02 04:09:06 +01:00
/////////////////////////////////////////////////////////////////////////////TICKET 710
2008-04-07 08:03:22 +02:00
} // namespace query
2008-03-10 08:38:59 +01:00
} // namespace lumiera
2008-01-18 16:43:53 +01:00
# endif