diff --git a/src/common/configrules.cpp b/src/common/configrules.cpp new file mode 100644 index 000000000..3213df15a --- /dev/null +++ b/src/common/configrules.cpp @@ -0,0 +1,44 @@ +/* + ConfigRules - interface for rule based configuration + + Copyright (C) CinelerraCV + 2007, Hermann Vosseler + + 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::instance; + + +} // namespace cinelerra diff --git a/src/common/configrules.hpp b/src/common/configrules.hpp new file mode 100644 index 000000000..265cae29e --- /dev/null +++ b/src/common/configrules.hpp @@ -0,0 +1,81 @@ +/* + CONFIGRULES.hpp - interface for rule based configuration + + Copyright (C) CinelerraCV + 2007, Hermann Vosseler + + 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 + + + +namespace cinelerra + { + using std::string; + + /** + * Generic query interface for retrieving objects matching + * some capability query + */ + class ConfigRules + { + protected: + ConfigRules (); + friend class cinelerra::singleton::StaticCreate; + + public: + static Singleton instance; + }; + + + namespace query + { + + + + } // namespace query + +} // namespace cinelerra +#endif diff --git a/src/proc/asset/query.cpp b/src/common/query.cpp similarity index 95% rename from src/proc/asset/query.cpp rename to src/common/query.cpp index e729195c6..bb3e6ae86 100644 --- a/src/proc/asset/query.cpp +++ b/src/common/query.cpp @@ -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 diff --git a/src/proc/asset/query.hpp b/src/common/query.hpp similarity index 92% rename from src/proc/asset/query.hpp rename to src/common/query.hpp index 0d91bd3de..85172d965 100644 --- a/src/proc/asset/query.hpp +++ b/src/common/query.hpp @@ -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 -namespace asset +namespace cinelerra { using std::string; @@ -58,5 +57,5 @@ namespace asset } // namespace query -} // namespace asset +} // namespace cinelerra #endif diff --git a/src/common/query/mockconfigrules.cpp b/src/common/query/mockconfigrules.cpp new file mode 100644 index 000000000..7a938728e --- /dev/null +++ b/src/common/query/mockconfigrules.cpp @@ -0,0 +1,43 @@ +/* + MockConfigRules - mock implementation of the config rules system + + Copyright (C) CinelerraCV + 2007, Hermann Vosseler + + 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 diff --git a/src/common/query/mockconfigrules.hpp b/src/common/query/mockconfigrules.hpp new file mode 100644 index 000000000..4d942dd29 --- /dev/null +++ b/src/common/query/mockconfigrules.hpp @@ -0,0 +1,73 @@ +/* + MOCKCONFIGRULES.hpp - mock implementation of the config rules system + + Copyright (C) CinelerraCV + 2007, Hermann Vosseler + + 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 + + + +namespace cinelerra + { + using std::string; + + /** + * Generic query interface for retrieving objects matching + * some capability query + */ + class MockConfigRules + { + protected: + MockConfigRules (); + friend class cinelerra::singleton::StaticCreate; + + public: + }; + + + namespace query + { + + + + } // namespace query + +} // namespace cinelerra +#endif diff --git a/src/proc/asset.hpp b/src/proc/asset.hpp index 0df25a3fd..d9e2e5833 100644 --- a/src/proc/asset.hpp +++ b/src/proc/asset.hpp @@ -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. */ - 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 + inline PcAsset + pAsset (shared_ptr& subPtr) + { + return static_pointer_cast (subPtr); + } /** convienient for debugging */ diff --git a/src/proc/asset/struct.cpp b/src/proc/asset/struct.cpp index e0436de9e..3f9a911f5 100644 --- a/src/proc/asset/struct.cpp +++ b/src/proc/asset/struct.cpp @@ -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 StructFactory::operator() (string portID, string streamID) { - query::normalizeID (portID); - query::normalizeID (streamID); + normalizeID (portID); + normalizeID (streamID); PProcPatt processingPattern = Session::current->defaults (Query("stream("+streamID+")")); Port* pP = new Port (processingPattern, portID); return AssetManager::instance().wrap (*pP); diff --git a/src/proc/asset/struct.hpp b/src/proc/asset/struct.hpp index 723c332a3..18554f770 100644 --- a/src/proc/asset/struct.hpp +++ b/src/proc/asset/struct.hpp @@ -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 @@ -49,6 +49,7 @@ using std::wstring; namespace asset { + using cinelerra::Query; class Struct; class StructFactory; diff --git a/src/proc/assetmanager.cpp b/src/proc/assetmanager.cpp index 246411d60..4d988aa61 100644 --- a/src/proc/assetmanager.cpp +++ b/src/proc/assetmanager.cpp @@ -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 AssetManager::getAsset (const ID& id) throw(cinelerra::error::Invalid); template shared_ptr AssetManager::getAsset (const ID& id) throw(cinelerra::error::Invalid); - template shared_ptr AssetManager::wrap (const Asset& asset); - template shared_ptr AssetManager::wrap (const Media& asset); - template shared_ptr AssetManager::wrap (const Clip& asset); - template shared_ptr AssetManager::wrap (const Track& asset); - template shared_ptr AssetManager::wrap (const Port& asset); + template shared_ptr AssetManager::wrap (const Asset& asset); + template shared_ptr AssetManager::wrap (const Media& asset); + template shared_ptr AssetManager::wrap (const Clip& asset); + template shared_ptr AssetManager::wrap (const Track& asset); + template shared_ptr AssetManager::wrap (const Port& asset); + template shared_ptr AssetManager::wrap (const ProcPatt& asset); } // namespace asset diff --git a/src/proc/mobject/session/defsmanager.cpp b/src/proc/mobject/session/defsmanager.cpp index 53c5f1862..305db5cab 100644 --- a/src/proc/mobject/session/defsmanager.cpp +++ b/src/proc/mobject/session/defsmanager.cpp @@ -43,7 +43,7 @@ namespace mobject * @param */ template<> - shared_ptr + shared_ptr DefsManager::operator() (const Query& properties) { diff --git a/src/proc/mobject/session/defsmanager.hpp b/src/proc/mobject/session/defsmanager.hpp index bc7323322..ccc75d6ac 100644 --- a/src/proc/mobject/session/defsmanager.hpp +++ b/src/proc/mobject/session/defsmanager.hpp @@ -25,7 +25,7 @@ #define MOBJECT_SESSION_DEFSMANAGER_H -#include "proc/asset/query.hpp" +#include "common/query.hpp" //#include //#include @@ -61,7 +61,7 @@ namespace mobject public: template - shared_ptr operator() (const asset::Query&); + shared_ptr operator() (const cinelerra::Query&); }; diff --git a/tests/components/proc/asset/assetdiagnostics.hpp b/tests/components/proc/asset/assetdiagnostics.hpp index c8df758f8..4788b687f 100644 --- a/tests/components/proc/asset/assetdiagnostics.hpp +++ b/tests/components/proc/asset/assetdiagnostics.hpp @@ -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))); diff --git a/tests/components/proc/asset/basicporttest.cpp b/tests/components/proc/asset/basicporttest.cpp index 7e68f4950..e68a20738 100644 --- a/tests/components/proc/asset/basicporttest.cpp +++ b/tests/components/proc/asset/basicporttest.cpp @@ -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); diff --git a/wiki/renderengine.html b/wiki/renderengine.html index 55c7c0c61..468a41b16 100644 --- a/wiki/renderengine.html +++ b/wiki/renderengine.html @@ -792,7 +792,12 @@ TertiaryMid: #99a TertiaryDark: #667 Error: #f88 -
+
+
Configuration Queries are requests to the system to "create or retrieve an object with //this and that // capabilities". 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<Port> ("stream(mpeg)")}}} requests a port excepting/delivering mpeg stream data &mdash; and it depends on the current configuration what "mpeg" 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.
+&rarr; [[Configuration Rules system|ConfigRules]]
+
+
+
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
* 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 "stream" is the //predicate, // meaning here "the stream type is...?" and "mpeg" is a //term // denoting an actual property, object, thing, number etc &mdash; the actual kind of stream in the given example. Multible comma separated predicates are combined with logical "and". 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 "stream" is the //predicate, // meaning here "the stream type is...?" and "mpeg" is a //term // denoting an actual property, object, thing, number etc &mdash; the actual kind of stream in the given example. Multible comma separated predicates are combined with logical "and". 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<TYPE>}}} template, because their actual meaning is "retrieve or create an object of TYPE, configured such that...!". 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 "{{{object(tYPE)}}}" !executing a Configuration Query