diff --git a/src/common/integration/common-services.cpp b/src/common/integration/common-services.cpp new file mode 100644 index 000000000..50c8d7373 --- /dev/null +++ b/src/common/integration/common-services.cpp @@ -0,0 +1,110 @@ +/* + CommonServices - integrate some library facilities with common system services + + Copyright (C) Lumiera.org + 2012, 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 common-serivces.cpp + ** Wire library facilities directly into application core services + ** This translation unit serves to complete the definition of some parts of the Lumiera library. + ** While library facilities usually are written to be self-contained, at places we want "magic" + ** integration with central services, without incurring tight coupling to the application core. + ** In these special cases, the library just \em declares some function or constructor variant, + ** which is then \em defined here, causing the corresponding code to be emitted into the + ** Lumiera application library. Obviously, to use such integrated "magic" short-cuts, client code + ** needs to link against \c liblumieracore.so + ** + ** The typical usage pattern is to allow for references by name-ID, which is then magically + ** resolved behind the scenes, using the Advice system or more generic query facilities. + ** This pattern allows even to tap into facilities known to exist within some very specific + ** subsystem, like e.g. some session service. A typical example is Lumiera's time and time quantisation + ** framework, which allows a \link QuTime grid aligned time \endlink to refer to a frame grid definition + ** known to be provided by one of the session's timelines. + ** + ** @see advice.hpp + ** @see timequant.hpp + ** @see quantiser.hpp + ** + */ + + +#include "lib/error.hpp" +#include "lib/format-string.hpp" + +namespace error = lumiera::error; + + + +/* =========== Advice System integrations ================== */ + +#include "lib/time/timequant.hpp" +#include "lib/time/quantiser.hpp" +#include "common/advice.hpp" + + +namespace lib { +namespace time { + + namespace { // implementation helper to access the Advice system... + + using util::_Fmt; + + namespace advice = lumiera::advice; + + + PQuant + retrieveQuantiser (Symbol gridID) + { + advice::Request query(gridID); + PQuant grid_found = query.getAdvice(); + if (!grid_found) + throw error::Logic (_Fmt("unable to resolve the time quantisation grid with ID=\"%s\" -- was it already defined?") + % gridID + , LUMIERA_ERROR_UNKNOWN_GRID); + return grid_found; + } + }//(End) implementation helpers + + + /** + * build a quantised time value, referring the time grid by-name. + * This is the preferred standard way of establishing a quantisation, + * but it requires an existing time scale defined in the Lumiera Session, + * as TimeGrid (meta asset). Usually, such a time scale gets built based + * on the format and parameters of an output bus. + */ + QuTime::QuTime (TimeValue raw, Symbol gridID) + : Time(raw) + , quantiser_(retrieveQuantiser (gridID)) + { } + + + /** Access an existing grid definition or quantiser, known by the given symbolic ID. + * Typically this fetches a meta::TimeGrid (asset) from the session. + * @throw error::Logic if the given gridID wasn't registered + * @return smart-ptr to the quantiser instance */ + PQuant + Quantiser::retrieve (Symbol gridID) + { + return retrieveQuantiser (gridID); + } + + +}} // namespace lib::time diff --git a/src/lib/time/quantiser.cpp b/src/lib/time/quantiser.cpp index 5651df3b2..041aa7210 100644 --- a/src/lib/time/quantiser.cpp +++ b/src/lib/time/quantiser.cpp @@ -25,7 +25,6 @@ #include "lib/time/timevalue.hpp" #include "lib/time/timequant.hpp" #include "lib/time.h" -#include "lib/advice.hpp" #include @@ -39,21 +38,6 @@ namespace lib { namespace time { - namespace { // implementation helpers... - - PQuant - retrieveQuantiser (Symbol gridID) - { - advice::Request query(gridID); - PQuant grid_found = query.getAdvice(); - if (!grid_found) - throw error::Logic ("unable to fetch the quantisation grid -- was it already defined?" ////////TICKET #197 - , LUMIERA_ERROR_UNKNOWN_GRID); - return grid_found; - } - }//(End) implementation helpers - - PQuant getDefaultGridFallback() { @@ -68,17 +52,11 @@ namespace time { Grid::~Grid() { } // hint to emit the VTable here... - /** - * build a quantised time value, referring the time grid by-name. - * This is the preferred standard way of establishing a quantisation, - * but it requires an existing time scale defined in the Lumiera Session, - * as TimeGrid (meta asset). Usually, such a time scale gets built based - * on the format and parameters of an output bus. + /* Note: the ctor QuTime(TimeValue, Symbol) and the static function + * PQuant Quantiser::retrieve (Symbol) are defined in common-services.cpp + * To use this special convenience shortcuts, you need to link against liblumieracore.so + * This allows to use the Advice-system to retrieve grid definitions directly from the session */ - QuTime::QuTime (TimeValue raw, Symbol gridID) - : Time(raw) - , quantiser_(retrieveQuantiser (gridID)) - { } /** @@ -110,17 +88,6 @@ namespace time { - /** Access an existing grid definition or quantiser, known by the given symbolic ID. - * Typically this fetches a meta::TimeGrid (asset) from the session. - * @throw error::Logic if the given gridID wasn't registered - * @return smart-ptr to the quantiser instance */ - PQuant - Quantiser::retrieve (Symbol gridID) - { - return retrieveQuantiser (gridID); - } - - /** convenience shortcut: \em materialise a raw time value * based on this grid or time axis, but returning a raw time value. diff --git a/src/lib/time/quantiser.hpp b/src/lib/time/quantiser.hpp index d7717bb03..38cf9cf8e 100644 --- a/src/lib/time/quantiser.hpp +++ b/src/lib/time/quantiser.hpp @@ -103,7 +103,7 @@ namespace time { return supportedFormats_.check(); } - static PQuant retrieve (Symbol gridID); + static PQuant retrieve (Symbol gridID); ///< @note defined in common-services.cpp TimeValue materialise (TimeValue const& raw) const; diff --git a/src/lib/time/timequant.hpp b/src/lib/time/timequant.hpp index b12a761a3..4041d2dee 100644 --- a/src/lib/time/timequant.hpp +++ b/src/lib/time/timequant.hpp @@ -60,7 +60,7 @@ namespace time { PQuant quantiser_; public: - QuTime (TimeValue raw, Symbol gridID); + QuTime (TimeValue raw, Symbol gridID); ///< @note defined in common-services.cpp QuTime (TimeValue raw, PQuant quantisation_to_use); operator PQuant() const;