started a mock implementation for the capability queries.

Later on, I want to embedd Prolog, but for now it is more important to get ahead with the builder...
This commit is contained in:
Fischlurch 2008-01-18 16:43:53 +01:00
parent 7e345ffabc
commit 430f38ab2f
15 changed files with 294 additions and 32 deletions

View file

@ -0,0 +1,44 @@
/*
ConfigRules - 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.
* *****************************************************/
#include "common/configrules.hpp"
//#include "common/util.hpp"
#include "nobugcfg.h"
namespace cinelerra
{
namespace query
{
} // namespace query
/** storage for the Singleton instance factory */
Singleton<ConfigRules> ConfigRules::instance;
} // namespace cinelerra

View file

@ -0,0 +1,81 @@
/*
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...
**
** @see cinelerra::Query
** @see mobject::session::DefsManager
** @see asset::StructFactory
**
*/
#ifndef CINELERRA_CONFIGRULES_H
#define CINELERRA_CONFIGRULES_H
#include "common/query.hpp"
#include "common/singleton.hpp"
#include <string>
namespace cinelerra
{
using std::string;
/**
* Generic query interface for retrieving objects matching
* some capability query
*/
class ConfigRules
{
protected:
ConfigRules ();
friend class cinelerra::singleton::StaticCreate<ConfigRules>;
public:
static Singleton<ConfigRules> instance;
};
namespace query
{
} // namespace query
} // namespace cinelerra
#endif

View file

@ -21,7 +21,7 @@
* *****************************************************/
#include "proc/asset/query.hpp"
#include "common/query.hpp"
#include "common/util.hpp"
#include "nobugcfg.h"
@ -31,7 +31,7 @@ using boost::algorithm::is_upper;
using boost::algorithm::is_alpha;
namespace asset
namespace cinelerra
{
namespace query
@ -55,4 +55,4 @@ namespace asset
/** */
} // namespace asset
} // namespace cinelerra

View file

@ -21,16 +21,15 @@
*/
#ifndef ASSET_QUERY_H
#define ASSET_QUERY_H
#ifndef CINELERRA_QUERY_H
#define CINELERRA_QUERY_H
#include "common/util.hpp"
#include <string>
namespace asset
namespace cinelerra
{
using std::string;
@ -58,5 +57,5 @@ namespace asset
} // namespace query
} // namespace asset
} // namespace cinelerra
#endif

View file

@ -0,0 +1,43 @@
/*
MockConfigRules - mock implementation of the config rules system
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.
* *****************************************************/
#include "common/query/mockconfigrules.hpp"
//#include "common/util.hpp"
#include "nobugcfg.h"
namespace cinelerra
{
namespace query
{
} // namespace query
/** */
} // namespace cinelerra

View file

@ -0,0 +1,73 @@
/*
MOCKCONFIGRULES.hpp - mock implementation of the config rules system
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 mockconfigrules.hpp
** Mock/Test/Debugging Implementation of the config rules system.
** Instead of actually parsing/analyzing/resolving queries, this implementation
** uses a Table of hard wired queries together with preconfigured object instances
** as answer values. As of 1/2008 it is used to "keep the implementation work going"
** -- later on, when we use a real Prolog interpreter, it still may be useful for
** testing and debugging.
**
** @see cinelerra::Query
** @see cinelerra::ConfigRules
**
*/
#ifndef CINELERRA_MOCKCONFIGRULES_H
#define CINELERRA_MOCKCONFIGRULES_H
#include "common/configrules.hpp"
#include <string>
namespace cinelerra
{
using std::string;
/**
* Generic query interface for retrieving objects matching
* some capability query
*/
class MockConfigRules
{
protected:
MockConfigRules ();
friend class cinelerra::singleton::StaticCreate<MockConfigRules>;
public:
};
namespace query
{
} // namespace query
} // namespace cinelerra
#endif

View file

@ -77,6 +77,7 @@ namespace asset
using std::size_t;
using std::tr1::shared_ptr;
using std::tr1::static_pointer_cast;
/**
@ -290,22 +291,31 @@ namespace asset
/** ordering of Asset smart ptrs based on Ident tuple.
* @todo currently supporting only smart_ptr<Asset>. */
inline bool operator== (const PAsset& a1, const PAsset& a2) { return a1 && a2 && ( 0==a1->ident.compare(a2->ident));}
inline bool operator< (const PAsset& a1, const PAsset& a2) { return a1 && a2 && (-1==a1->ident.compare(a2->ident));}
inline bool operator> (const PAsset& a1, const PAsset& a2) { return a2 < a1; }
inline bool operator>= (const PAsset& a1, const PAsset& a2) { return !(a1 < a2); }
inline bool operator<= (const PAsset& a1, const PAsset& a2) { return !(a1 > a2); }
inline bool operator!= (const PAsset& a1, const PAsset& a2) { return !(a1== a2); }
inline bool operator== (const PcAsset& a1, const PcAsset& a2) { return a1 && a2 && ( 0==a1->ident.compare(a2->ident));}
inline bool operator< (const PcAsset& a1, const PcAsset& a2) { return a1 && a2 && (-1==a1->ident.compare(a2->ident));}
inline bool operator> (const PcAsset& a1, const PcAsset& a2) { return a2 < a1; }
inline bool operator>= (const PcAsset& a1, const PcAsset& a2) { return !(a1 < a2); }
inline bool operator<= (const PcAsset& a1, const PcAsset& a2) { return !(a1 > a2); }
inline bool operator!= (const PcAsset& a1, const PcAsset& a2) { return !(a1== a2); }
/** ordering of Asset Ident tuples.
* @note version is irrelevant */
inline int Asset::Ident::compare (const Asset::Ident& oi) const
inline int
Asset::Ident::compare (const Asset::Ident& oi) const
{
int res;
if (0 != (res=category.compare (oi.category))) return res;
if (0 != (res=org.compare (oi.org))) return res;
return name.compare (oi.name);
}
/** promote to PAsset, e.g. for comparing */
template<class A>
inline PcAsset
pAsset (shared_ptr<A>& subPtr)
{
return static_pointer_cast<const Asset,A> (subPtr);
}
/** convienient for debugging */

View file

@ -27,10 +27,12 @@
#include "proc/asset/track.hpp"
#include "proc/mobject/session.hpp"
#include "common/query.hpp"
#include "common/util.hpp"
#include "nobugcfg.h"
using mobject::Session;
using cinelerra::query::normalizeID;
namespace asset
{
@ -84,8 +86,8 @@ namespace asset
shared_ptr<Port>
StructFactory::operator() (string portID, string streamID)
{
query::normalizeID (portID);
query::normalizeID (streamID);
normalizeID (portID);
normalizeID (streamID);
PProcPatt processingPattern = Session::current->defaults (Query<ProcPatt>("stream("+streamID+")"));
Port* pP = new Port (processingPattern, portID);
return AssetManager::instance().wrap (*pP);

View file

@ -38,7 +38,7 @@
#define ASSET_STRUCT_H
#include "proc/asset.hpp"
#include "proc/asset/query.hpp"
#include "common/query.hpp"
#include "common/factory.hpp"
#include<string>
@ -49,6 +49,7 @@ using std::wstring;
namespace asset
{
using cinelerra::Query;
class Struct;
class StructFactory;

View file

@ -237,6 +237,7 @@ namespace asset
#include "proc/asset/track.hpp"
#include "proc/asset/port.hpp"
#include "proc/asset/meta.hpp"
#include "proc/asset/procpatt.hpp"
namespace asset
@ -251,11 +252,12 @@ namespace asset
template shared_ptr<Struct> AssetManager::getAsset (const ID<Struct>& id) throw(cinelerra::error::Invalid);
template shared_ptr<Meta> AssetManager::getAsset (const ID<Meta>& id) throw(cinelerra::error::Invalid);
template shared_ptr<Asset> AssetManager::wrap (const Asset& asset);
template shared_ptr<Media> AssetManager::wrap (const Media& asset);
template shared_ptr<Clip> AssetManager::wrap (const Clip& asset);
template shared_ptr<Track> AssetManager::wrap (const Track& asset);
template shared_ptr<Port> AssetManager::wrap (const Port& asset);
template shared_ptr<Asset> AssetManager::wrap (const Asset& asset);
template shared_ptr<Media> AssetManager::wrap (const Media& asset);
template shared_ptr<Clip> AssetManager::wrap (const Clip& asset);
template shared_ptr<Track> AssetManager::wrap (const Track& asset);
template shared_ptr<Port> AssetManager::wrap (const Port& asset);
template shared_ptr<ProcPatt> AssetManager::wrap (const ProcPatt& asset);
} // namespace asset

View file

@ -43,7 +43,7 @@ namespace mobject
* @param
*/
template<>
shared_ptr<const Port>
shared_ptr<Port>
DefsManager::operator() (const Query<Port>& properties)
{

View file

@ -25,7 +25,7 @@
#define MOBJECT_SESSION_DEFSMANAGER_H
#include "proc/asset/query.hpp"
#include "common/query.hpp"
//#include <boost/scoped_ptr.hpp>
//#include <vector>
@ -61,7 +61,7 @@ namespace mobject
public:
template<class TAR>
shared_ptr<const TAR> operator() (const asset::Query<TAR>&);
shared_ptr<TAR> operator() (const cinelerra::Query<TAR>&);
};

View file

@ -75,7 +75,7 @@ namespace asset
inline bool
dependencyCheck (C child, P parent)
{
return (child == parent)
return (pAsset(child) == pAsset(parent))
|| (0 < child->getParents().size()
&& (parent == child->getParents()[0])
&& (contains (parent->getDependant(), child)));

View file

@ -26,7 +26,7 @@
#include "proc/asset/category.hpp"
#include "proc/asset/port.hpp"
#include "proc/asset/query.hpp"
#include "common/query.hpp"
#include "proc/assetmanager.hpp"
#include "proc/mobject/session.hpp"
#include "proc/asset/assetdiagnostics.hpp"
@ -47,6 +47,8 @@ namespace asset
namespace test
{
using mobject::Session;
using cinelerra::Query;
using cinelerra::query::normalizeID;
@ -77,7 +79,7 @@ namespace asset
void createExplicit (string pID, string sID)
{
string pID_sane (pID);
query::normalizeID (pID_sane);
normalizeID (pID_sane);
PPort thePort = asset::Struct::create (pID,sID);
@ -101,7 +103,7 @@ namespace asset
void create_or_ref(string pID)
{
query::normalizeID (pID);
normalizeID (pID);
PPort port1 = Port::query ("port("+pID+")");
ASSERT (port1);

View file

@ -792,7 +792,12 @@ TertiaryMid: #99a
TertiaryDark: #667
Error: #f88</pre>
</div>
<div title="ConfigRules" modifier="Ichthyostega" modified="200801171439" created="200801171352" tags="overview spec" changecount="4">
<div title="ConfigQuery" modifier="Ichthyostega" modified="200801181309" created="200801181308" tags="def" changecount="4">
<pre>Configuration Queries are requests to the system to &quot;create or retrieve an object with //this and that // capabilities&quot;. They are resolved by a rule based system ({{red{planned feature}}}) and the user can extend the used rules for each Session. Syntactically, they are stated in ''prolog'' syntax as a conjunction (=logical and) of ''predicates'', for example {{{stream(mpeg), port(myPort)}}}. Queries are typed to the kind of expected result object: {{{Query&lt;Port&gt; (&quot;stream(mpeg)&quot;)}}} requests a port excepting/delivering mpeg stream data &amp;mdash; and it depends on the current configuration what &quot;mpeg&quot; means. If there is any stream data producing component in the system, which advertises to deliver {{{stream(mpeg)}}}, and a port can be configured or connected with this component, then the [[defaults manager|DefaultsManagement]] will create/deliver a [[Port|PortHandling]] object configured accordingly.
&amp;rarr; [[Configuration Rules system|ConfigRules]]
</pre>
</div>
<div title="ConfigRules" modifier="Ichthyostega" modified="200801181301" created="200801171352" tags="overview spec" changecount="6">
<pre>Many features can be implemented by specifically configuring and wiring some unspecific components. Rather than tie the client code in need of some given feature to these configuration internals, in Cinelerra-3 the client can //query // for some kind of object providing the //needed capabilities. // Right from start (summer 2007), Ichthyo had the intention to implement such a feature using sort of a ''declarative database'', e.g. by embedding a Prolog system. By adding rules to the basic session configuration, users should be able to customize the semi-automatic part of Cinelerra's behaviour to great extent.
[[Configuration Queries|ConfigQuery]] are used at various places, when creating and adding new objects, as well when building or optimizing the render engine node network.
@ -802,7 +807,7 @@ Error: #f88</pre>
* actually building such a connection may create additional degrees of freedom, like panning for sound or layering for video.
!anatomy of a Configuration Query
The query is given as a number of logic predicates, which are required to be true. Syntactically, it is a string in prolog syntax, e.g. {{{stream(mpeg).}}}, where &quot;stream&quot; is the //predicate, // meaning here &quot;the stream type is...?&quot; and &quot;mpeg&quot; is a //term // denoting an actual property, object, thing, number etc &amp;mdash; the actual kind of stream in the given example. Multible comma separated predicates are combined with logical &quot;and&quot;. Terms may be //variable // at start, which is denoted syntactically by starting them with a uppercase letter. But any variable term need to be //bound // to some constant while computing the solution to the query, otherwise the query fails. A failed query is treated as a local failure, which may cause some operation being aborted or just some other possibility being chosen.
The query is given as a number of logic predicates, which are required to be true. Syntactically, it is a string in prolog syntax, e.g. {{{stream(mpeg)}}}, where &quot;stream&quot; is the //predicate, // meaning here &quot;the stream type is...?&quot; and &quot;mpeg&quot; is a //term // denoting an actual property, object, thing, number etc &amp;mdash; the actual kind of stream in the given example. Multible comma separated predicates are combined with logical &quot;and&quot;. Terms may be //variable // at start, which is denoted syntactically by starting them with a uppercase letter. But any variable term need to be //bound // to some known value while computing the solution to the query, otherwise the query fails. A failed query is treated as a local failure, which may cause some operation being aborted or just some other possibility being chosen.
Queries are represented by instantiations of the {{{Query&lt;TYPE&gt;}}} template, because their actual meaning is &quot;retrieve or create an object of TYPE, configured such that...!&quot;. At the C++ side, this ensures type safety and fosters programming against interfaces, while being implemented rule-wise by silently prepending the query with the predicate &quot;{{{object(tYPE)}}}&quot;
!executing a Configuration Query