Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
assetmanager.cpp
Go to the documentation of this file.
1/*
2 AssetManager - Facade for the Asset subsystem
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
21#include "steam/asset/db.hpp"
22
23#include "lib/sync.hpp"
24#include "lib/util-foreach.hpp"
25#include "lib/format-string.hpp"
26
27#include <functional>
28
29using std::static_pointer_cast;
30using std::function;
31using std::placeholders::_1;
32using util::for_each;
33using util::_Fmt;
34
35using lib::Depend;
36using lib::Sync;
37
38
39namespace lumiera {
40namespace error {
41 // ------pre-defined-common-error-cases---------------
42 LUMIERA_ERROR_DEFINE (UNKNOWN_ASSET_ID, "non-registered Asset ID");
43 LUMIERA_ERROR_DEFINE (WRONG_ASSET_KIND, "wrong Asset kind, unable to cast");
44}}
45
46namespace steam {
47namespace asset {
48 namespace error = lumiera::error;
49
54 struct IDErr
56 {
57 using error::Invalid::Invalid;
58 };
59
60
61
63 {
65 : IDErr(_Fmt("Query for Asset with ID=%d, which up to now "
66 "hasn't been created or encountered.") % aID
67 ,LERR_(UNKNOWN_ASSET_ID))
68 { }
69 };
70
72 {
74 : IDErr (_Fmt("Request for Asset(%s), specifying an Asset kind, "
75 "that doesn't match the actual type (and can't be "
76 "casted either).") % idi
77 ,LERR_(WRONG_ASSET_KIND))
78 { }
79 };
80
81
82
83
84
89
91 : registry (Depend<asset::DB>() ())
92 { }
93
94
95
99 {
100 return asset::hash_value (idi);
101 }
102
103
104
110 template<class KIND>
112 AssetManager::reg (KIND* obj, const Asset::Ident& idi)
113 {
115 DB& registry (_aMang.registry);
117 ID<KIND> asset_id (getID (idi));
118
119 DB::Lock guard{&registry};
121 lib::P<KIND> smart_ptr (obj, &destroy);
122
123 registry.put (asset_id, smart_ptr);
124 return asset_id;
125 }
126
127
132 template<class KIND>
135 {
136 if (lib::P<KIND> obj = registry.get (id))
137 return obj;
138 else
139 if (known (id)) // provide Ident tuple of existing Asset
140 throw WrongKind (registry.get(ID<Asset>(id))->ident);
141 else
142 throw UnknownID (id);
143 }
144
151 template<class KIND>
154 {
155 ENSURE (instance().known(asset.id),
156 "unregistered asset instance encountered.");
157 return static_pointer_cast<KIND,Asset>
158 (instance().registry.get (asset.id));
159 }
160
161
162
166 bool
168 {
169 return bool(registry.get (ID<Asset>(id)));
170 } // query most general Asset ID-kind and use implicit
171 // conversion from smart-ptr to bool (test if empty)
172
173
177 bool
179 {
180 PAsset pA = registry.get (id);
181 return ( pA and pA->ident.category.isWithin(cat));
182 }
183
184
185 namespace { // details implementing AssetManager::remove
186
187 void
189 {
190 instance->remove (pA->getID());
191 }
192
193 function<void(PAsset&)>
195 {
196 return bind( &recursive_call, &AssetManager::instance(), _1 );
197 }
198 }
199
204 void
206 {
207 PAsset asset = getAsset (id);
208 for_each (asset->dependants, detach_child_recursively());
209 asset->unlink();
210 registry.del(id);
211 }
212
213
214 void
216 {
217 INFO (progress, "Clearing the Asset registry...");
218 registry.clear();
219 }
220
221
222 list<PcAsset>
224 {
225 list<PcAsset> res;
226 registry.asList (res);
227 res.sort();
228 return res;
229 }
230
231
232}} // namespace steam::asset
233
234
235
236
237 /************************************************************/
238 /* explicit template instantiations for various Asset Kinds */
239 /************************************************************/
240
241#include "steam/asset/media.hpp"
242#include "steam/asset/clip.hpp"
243#include "steam/asset/proc.hpp"
244#include "steam/asset/struct.hpp"
245#include "steam/asset/pipe.hpp"
246#include "steam/asset/meta.hpp"
252
253namespace steam {
254namespace asset {
255 using lib::P;
256
257 template ID<Asset> AssetManager::reg (Asset* obj, const Asset::Ident& idi);
258
259
260 template P<Asset> AssetManager::getAsset (const ID<Asset>& id);
261 template P<Media> AssetManager::getAsset (const ID<Media>& id);
262 template P<Proc> AssetManager::getAsset (const ID<Proc>& id);
263 template P<Struct> AssetManager::getAsset (const ID<Struct>& id);
264 template P<Meta> AssetManager::getAsset (const ID<Meta>& id);
265 template P<Pipe> AssetManager::getAsset (const ID<Pipe>& id);
266
267 template P<Asset> AssetManager::wrap (const Asset& asset);
268 template P<Media> AssetManager::wrap (const Media& asset);
269 template P<Clip> AssetManager::wrap (const Clip& asset);
270 template P<Pipe> AssetManager::wrap (const Pipe& asset);
271 template P<ProcPatt> AssetManager::wrap (const ProcPatt& asset);
272 template P<Timeline> AssetManager::wrap (const Timeline& asset);
273 template P<Sequence> AssetManager::wrap (const Sequence& asset);
274
275 using meta::TimeGrid;
276 using meta::ErrorLog;
277 template P<TimeGrid> AssetManager::wrap (const TimeGrid& asset);
278 template P<ErrorLog> AssetManager::wrap (const ErrorLog& asset);
279
280
281}} // namespace steam::asset
Definition of Asset representation for a media clip.
Internal and organisational metadata.
Steam-Layer Interface: Asset Lookup and Organisation.
Access point to singletons and other kinds of dependencies designated by type.
Definition depend.hpp:281
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition p.hpp:77
scoped guard to control the actual locking.
Definition sync.hpp:228
Facility for monitor object based locking.
Definition sync.hpp:210
Derived specific exceptions within Lumiera's exception hierarchy.
Definition error.hpp:193
Facade for the Asset subsystem.
static void destroy(Asset *aa)
deleter function used by the Asset smart pointers to delete Asset objects
static ID< Asset > getID(const Asset::Ident &)
provide the unique ID for given Asset::Ident tuple
list< PcAsset > listContent() const
extract a sorted list of all registered Assets
void clear()
deregister and evict all known Assets.
static lib::P< KIND > wrap(const KIND &asset)
retrieve the registered smart-ptr for any asset
lib::P< KIND > getAsset(const ID< KIND > &id)
find and return corresponding object
static ID< KIND > reg(KIND *obj, const Asset::Ident &idi)
registers an asset object in the internal DB, providing its unique key.
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
void remove(IDA id)
remove the given asset from the internal DB.
Tree like classification of Assets.
Definition category.hpp:68
Implementation of the registry holding all Asset instances known to the Asset Manager subsystem.
Definition db.hpp:90
lib::P< KIND > get(ID< KIND > hash) const
Definition db.hpp:108
void asList(list< PcAsset > &output) const
intended for diagnostics
Definition db.hpp:159
bool del(ID< Asset > hash)
Definition db.hpp:127
void put(ID< KIND > hash, lib::P< KIND > &ptr)
Definition db.hpp:115
void clear()
removes all registered assets and does something similar to Asset::unlink() on each to break cyclic d...
Definition db.hpp:144
thin wrapper around a size_t hash ID used as primary key for all Asset objects.
Definition asset.hpp:98
A front-end for using printf-style formatting.
Implementation of the Asset database.
An entity to collect, possibly filter and persist incident records.
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition error.h:71
#define LERR_(_NAME_)
Definition error.hpp:45
Front-end for printf-style string template interpolation.
Media data represented a specific kind of Asset.
Lumiera public interface.
Definition advice.hpp:102
void recursive_call(AssetManager *instance, PAsset &pA)
The asset subsystem of the Steam-Layer.
size_t hash_value(Category const &cat)
Definition category.hpp:90
Steam-Layer implementation namespace root.
disable_if< can_IterForEach< Container >, FUN > for_each(Container const &coll, FUN doIt)
operate on all elements of a STL container.
A "processing pipe" represented as Asset.
Data processing Plugins and Codecs can be treated as a specific Kind of Asset.
Definition of a structural asset to express patterns of wiring or processing Processing patterns can ...
Structural building block of the session: a sequence of clips.
Asset representation of structural elements within the model.
a POD comprised of all the information sufficiently identifying any given Asset.
Definition asset.hpp:147
AssetManager error responses, caused by querying invalid Asset IDs from the internal DB.
UnknownID(ID< Asset > aID)
WrongKind(Asset::Ident idi)
Object Monitor based synchronisation.
To establish a reference scale for quantised time values.
Top level structural element within the session.
Perform operations "for each element" of a collection.