Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
fake-configrules.cpp
Go to the documentation of this file.
1/*
2 FakeConfigRules - dummy implementation of the config rules system
3
4 Copyright (C)
5 2008, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
14
31
35#include "steam/asset/pipe.hpp"
36#include "lib/query-util.hpp"
37#include "common/query.hpp"
38
39#include "include/logging.h"
40#include "lib/symbol.hpp"
41#include "lib/util.hpp"
42
43using lib::Literal;
44using util::isnil;
45
47
48namespace steam {
49namespace mobject {
50namespace session {
51
52 namespace query {
53
54 using asset::Struct;
55 using asset::Pipe;
56 using asset::PPipe;
57
58 using asset::ProcPatt;
59 using asset::PProcPatt;
60
61// using lib::query::extractID;
64
65
66 namespace {
67
68 using AnyPair = std::pair<const QueryKey, any>;
69
71 template<class TY>
72 AnyPair entry (Query<TY> const& query, typename WrapReturn<TY>::Wrapper& obj)
73 {
74 return AnyPair(query, any(obj));
75 }
76
78 template<class STRU>
80 {
81 using Ptr = WrapReturn<STRU>::Wrapper;
82
83 string capabilities (caps);
84 Query<STRU> query (capabilities);
85 Ptr obj = Struct::retrieve (query);
86 return AnyPair(query, obj);
87 }
88 }
89
90
96 void
98 {
99 INFO (config, "creating mock answers for some hard wired config queries...");
100 isInit_ = true; // allow re-entrance
101
102 using cPP = const ProcPatt;
103
104
105 // for baiscpipetest.cpp ---------
106 answer_.insert (entry_Struct<cPP> ("stream(video)"));
107 answer_.insert (entry_Struct<cPP> ("stream(teststream)"));
108 item<cPP> ("stream(default)") = item<cPP> ("stream(video)"); // set up a default stream
109
110 answer_.insert (entry_Struct<Pipe> ("pipe(master), stream(video)"));
111 item<Pipe> ("") = item<Pipe>("pipe(master), stream(video)");// use as default
112
113 answer_.insert (entry_Struct<Pipe> ("pipe(ambiance)"));
114 }
115
116
120 void
122 {
123 answer_.clear();
124 isInit_ = false;
125 INFO (config, "discarded all config query mock answers.");
126 }
127
128
129
130
131
132 /* under some circumstances we need to emulate the behaviour *
133 * of a real resolution engine in a more detailed manner. *
134 * The code below implements these cases hard wired. */
135
137 bool
138 MockTable::fabricate_matching_new_Pipe (Query<Pipe> const& q, string const& pipeID, string const& streamID)
139 {
140 using Ptr = WrapReturn<Pipe>::Wrapper;
141
142 Ptr newPipe (Struct::retrieve.newPipe (pipeID, streamID));
143 answer_.insert (entry<Pipe> (q, newPipe));
144 return true; // indicates that the query will now succeed...
145 }
146
148 bool
150 {
151 using Ptr = WrapReturn<Pipe>::Wrapper;
152
153 Ptr newPipe (Struct::retrieve.made4fake (q));
154 answer_.insert (entry<Pipe> (q, newPipe));
155 return true;
156 }
157
159 bool
161 {
162 typedef const ProcPatt cPP;
163 typedef WrapReturn<cPP>::Wrapper Ptr;
164
165 Ptr newPP (Struct::retrieve.made4fake (q));
166 answer_.insert (entry<cPP> (q, newPP));
167 return true;
168 }
169
174 bool
176 {
177 using aTL = asset::Timeline;
178 using Ptr = WrapReturn<aTL>::Wrapper;
179
180 string nameID = query.extractID("id");
181 if (isnil (nameID))
182 nameID = query.extractID("timeline");
183 if (isnil (nameID))
184 nameID = "prime";
185
186 Query<aTL> normalisedQuery =
187 query.rebuild()
188 .removeTerm("id")
189 .removeTerm("timeline")
190 .prependConditions("id("+nameID+")");
191
192 // try to find an existing one with the desired id
193 Ptr newTimeline;
194 size_t i=0, cnt=Session::current->timelines.size();
195 for ( ; i < cnt; ++i)
196 if (nameID == Session::current->timelines[i]->ident.name)
197 {
198 newTimeline = Session::current->timelines[i];
199 break;
200 }
201
202 if (!newTimeline)
203 newTimeline = Struct::retrieve.made4fake (normalisedQuery); // no suitable Timeline found: create and attach new one
204 answer_.insert (entry<aTL> (normalisedQuery, newTimeline)); // "learn" the found/created Timeline as new solution
205 answer_.insert (entry<aTL> (query, newTimeline));
206 return true;
207 }
208
210 bool
212 {
213 using aSeq = asset::Sequence;
214 using Ptr = WrapReturn<aSeq>::Wrapper;
215
216 string nameID = query.extractID("id");
217 if (isnil (nameID))
218 nameID = query.extractID("sequence");
219 if (isnil (nameID))
220 nameID = "first";
221
222 Query<aSeq> normalisedQuery =
223 query.rebuild()
224 .removeTerm("id")
225 .removeTerm("sequence")
226 .prependConditions("id("+nameID+")");
227
228 // try to find an existing sequence with the desired id
229 Ptr newSequence;
230 size_t i=0, cnt=Session::current->sequences.size();
231 for ( ; i < cnt; ++i)
232 if (nameID == Session::current->sequences[i]->ident.name)
233 {
234 newSequence = Session::current->sequences[i];
235 break;
236 }
237
238 if (!newSequence)
239 newSequence = Struct::retrieve.made4fake (normalisedQuery); // no suitable found: create and attach new Sequence
240 answer_.insert (entry<aSeq> (normalisedQuery, newSequence)); // "learn" the found/created new solution
241 answer_.insert (entry<aSeq> (query, newSequence));
242 return true;
243 }
244
245
247 template<class TY>
248 bool
249 MockTable::set_new_mock_solution (Query<TY> const& q, typename WrapReturn<TY>::Wrapper& obj)
250 {
251 answer_.erase (q);
252 answer_.insert (entry<TY> (q, obj));
253 return true;
254 }
255 // generate the necessary specialisations-----------------------------------
256 template bool MockTable::set_new_mock_solution (Query<Pipe> const&, PPipe&);
257
258
259
260
261
263 {
264 WARN (config, "using a mock implementation of the ConfigQuery interface");
265 }
266
267
269 : answer_()
270 , isInit_(false)
271 { }
272
273
274
275
286 any const&
288 {
289 static const any NOTFOUND;
290 if (!isInit_) fill_mock_table();
291
292 Tab::iterator i = answer_.find (query);
293 if (i == answer_.end())
294 return NOTFOUND;
295 else
296 return i->second;
297 }
298
299
300
301 } // namespace query
302}}} // namespace steam::mobject::session
Inline string literal.
Definition symbol.hpp:78
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition p.hpp:77
Wrapper for indexing and ordering.
Definition query.hpp:371
Builder & prependConditions(string additionalQueryPredicates)
Definition query.hpp:522
Builder & removeTerm(Symbol termPredicate)
remove the first term from this query definition, which matches the given predicate symbol
Definition query.hpp:507
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition query.hpp:254
Builder rebuild() const
Definition query.hpp:550
string extractID(Symbol predicate) const
convenience shortcut to extract a desired name-ID.
Definition query.hpp:564
structural asset corresponding to the part of the model forming a processing pipe for generating medi...
Definition pipe.hpp:72
"Processing Pattern" is a structural Asset representing information how to build some part of the ren...
Definition procpatt.hpp:54
TODO type comment.
Definition sequence.hpp:86
lib::P< STRU > made4fake(Query< STRU > const &query)
special backdoor for fake-configrules.hpp This allows to simulate creation of objects triggered by ru...
Definition struct.cpp:140
key abstraction: structural asset Created automatically as a sideeffect of building the structure of ...
Definition struct.hpp:105
static StructFactory retrieve
storage for the static StructFactory instance
Definition struct.hpp:107
TimelineAccess timelines
collection of timelines (top level)
Definition session.hpp:124
SequenceAccess sequences
collection of sequences
Definition session.hpp:125
static session::SessManager & current
access point to the current Session
Definition session.hpp:120
MockConfigRules()
to be used only by the singleton factory
bool fabricate_Timeline_on_demand(Query< asset::Timeline > const &q)
special case: fabricate new Timeline, maybe using specific sub-objects as hinted by the IDs given wit...
bool fabricate_ProcPatt_on_demand(Query< const ProcPatt > const &q)
special case: create/retrieve new processing pattern for given stream ID...
any const & fetch_from_table_for(QueryKey const &query)
this is the (preliminary/mock) implementation handling queries for objects of a specific type and wit...
void fill_mock_table()
hard coded answers to configuration queries.
bool fabricate_matching_new_Pipe(Query< Pipe > const &q, string const &pipeID, string const &streamID)
special case: create a new pipe with matching pipe and stream IDs on the fly when referred....
bool fabricate_just_new_Pipe(Query< Pipe > const &q)
special case: create a new pipe for a specific stream ID
bool fabricate_Sequence_on_demand(Query< asset::Sequence > const &q)
special case: fabricate new Timeline, maybe using ID specs from the query...
bool set_new_mock_solution(Query< TY > const &q, typename WrapReturn< TY >::Wrapper &candidate)
for entering "valid" solutions on-the-fly from tests
virtual void reset()
clear the contents of the mock solution table.
Mock/Test/Debugging Implementation of the config rules system.
Organisational grouping device within the Session model ("Track" / "Media Bin").
This header is for including and configuring NoBug.
string extractID(Symbol sym, const string &termString)
(preliminary) helper: instead of really parsing and evaluating the terms, just do a regular expressio...
string removeTerm(Symbol sym, string &queryString)
(preliminary) helper: cut a term with the given symbol.
AnyPair entry(Query< TY > const &query, typename WrapReturn< TY >::Wrapper &obj)
helper to simplify creating mock table entries, wrapped correctly
AnyPair entry_Struct(Literal caps)
helper especially for creating structural assets from a capability query
Namespace of Session and user visible high-level objects.
Definition sequence.hpp:65
Steam-Layer implementation namespace root.
bool isnil(lib::time::Duration const &dur)
A "processing pipe" represented as Asset.
Definition of a structural asset to express patterns of wiring or processing Processing patterns can ...
Utilities to support working with predicate queries.
Basic and generic representation of an internal query.
Primary Interface to the current Session.
Marker types to indicate a literal string and a Symbol.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...