From: <gk...@ke...> - 2010-12-26 15:53:00
|
Module: qt-gstreamer Branch: master Commit: c4acf3ed0e6f853051878ce146cfb82f15425db8 URL: http://cgit.freedesktop.org/gstreamer/qt-gstreamer/commit/?id=c4acf3ed0e6f853051878ce146cfb82f15425db8 Author: George Kiagiadakis <geo...@co...> Date: Sun Dec 26 13:39:05 2010 +0200 Add an emitWithDetail overload for emiting signals with a quark detail. --- src/QGlib/emitimpl.h | 54 ++++++++++++++++++++++++++++++++----------------- src/QGlib/signal.cpp | 9 ++++--- src/QGlib/signal.h | 11 +++++++++- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/QGlib/emitimpl.h b/src/QGlib/emitimpl.h index 7d368a9..6de84da 100644 --- a/src/QGlib/emitimpl.h +++ b/src/QGlib/emitimpl.h @@ -1,5 +1,7 @@ /* - Copyright (C) 2010 George Kiagiadakis <kia...@gm...> + Copyright (C) 2010 George Kiagiadakis <kia...@gm...> + Copyright (C) 2010 Collabora Ltd. + @author George Kiagiadakis <geo...@co...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -21,6 +23,7 @@ # endif # include "value.h" +# include "quark.h" # include <QtCore/QList> # include <QtCore/QDebug> # include <stdexcept> @@ -30,7 +33,7 @@ namespace QGlib { namespace Private { /*! This method is used internally from the templated emit() method. */ -Value emit(void *instance, const char *detailedSignal, const QList<Value> & args); +Value emit(void *instance, const char *signal, Quark detail, const QList<Value> & args); template <typename Signature> struct EmitImpl {}; @@ -69,13 +72,13 @@ QList<Value> packArguments(const Arg1 & a1, const Args & ... args) template <typename R, typename... Args> struct EmitImpl<R (Args...)> { - static inline R emit(void *instance, const char *detailedSignal, const Args & ... args) + static inline R emit(void *instance, const char *signal, Quark detail, const Args & ... args) { try { - Value && returnValue = Private::emit(instance, detailedSignal, packArguments(args...)); + Value && returnValue = Private::emit(instance, signal, detail, packArguments(args...)); return ValueImpl<R>::get(returnValue); } catch(const std::exception & e) { - qCritical() << "Error during emission of signal" << detailedSignal << ":" << e.what(); + qCritical() << "Error during emission of signal" << signal << ":" << e.what(); return R(); } } @@ -84,16 +87,16 @@ struct EmitImpl<R (Args...)> template <typename... Args> struct EmitImpl<void (Args...)> { - static inline void emit(void *instance, const char *detailedSignal, const Args & ... args) + static inline void emit(void *instance, const char *signal, Quark detail, const Args & ... args) { try { - Value && returnValue = Private::emit(instance, detailedSignal, packArguments(args...)); + Value && returnValue = Private::emit(instance, signal, detail, packArguments(args...)); if (returnValue.isValid()) { - qWarning() << "Ignoring return value from emission of signal" << detailedSignal; + qWarning() << "Ignoring return value from emission of signal" << signal; } } catch(const std::exception & e) { - qCritical() << "Error during emission of signal" << detailedSignal << ":" << e.what(); + qCritical() << "Error during emission of signal" << signal << ":" << e.what(); } } }; @@ -107,7 +110,13 @@ struct EmitImpl<void (Args...)> template <typename R, typename... Args> R emit(void *instance, const char *detailedSignal, const Args & ... args) { - return QGlib::Private::EmitImpl<R (Args...)>::emit(instance, detailedSignal, args...); + return Private::EmitImpl<R (Args...)>::emit(instance, detailedSignal, Quark(), args...); +} + +template <typename R, typename... Args> +R emitWithDetail(void *instance, const char *signal, Quark detail, const Args & ... args) +{ + return Private::EmitImpl<R (Args...)>::emit(instance, signal, detail, args...); } //END ******** QGlib::emit ******** @@ -177,16 +186,16 @@ namespace Private { template <typename R QGLIB_SIGNAL_IMPL_TRAILING_TEMPLATE_PARAMS> struct EmitImpl<R (QGLIB_SIGNAL_IMPL_TEMPLATE_ARGS)> { - static inline R emit(void *instance, const char *detailedSignal + static inline R emit(void *instance, const char *signal, Quark detail QGLIB_SIGNAL_IMPL_FUNCTION_PARAMS) { try { QList<Value> values; QGLIB_SIGNAL_IMPL_PACK_ARGS(values) - Value returnValue = Private::emit(instance, detailedSignal, values); + Value returnValue = Private::emit(instance, signal, detail, values); return ValueImpl<R>::get(returnValue); } catch(const std::exception & e) { - qCritical() << "Error during emission of signal" << detailedSignal << ":" << e.what(); + qCritical() << "Error during emission of signal" << signal << ":" << e.what(); return R(); } } @@ -195,18 +204,18 @@ struct EmitImpl<R (QGLIB_SIGNAL_IMPL_TEMPLATE_ARGS)> template <QGLIB_SIGNAL_IMPL_TEMPLATE_PARAMS> struct EmitImpl<void (QGLIB_SIGNAL_IMPL_TEMPLATE_ARGS)> { - static inline void emit(void *instance, const char *detailedSignal + static inline void emit(void *instance, const char *signal, Quark detail QGLIB_SIGNAL_IMPL_FUNCTION_PARAMS) { try { QList<Value> values; QGLIB_SIGNAL_IMPL_PACK_ARGS(values) - Value returnValue = Private::emit(instance, detailedSignal, values); + Value returnValue = Private::emit(instance, signal, detail, values); if (returnValue.isValid()) { - qWarning() << "Ignoring return value from emission of signal" << detailedSignal; + qWarning() << "Ignoring return value from emission of signal" << signal; } } catch(const std::exception & e) { - qCritical() << "Error during emission of signal" << detailedSignal << ":" << e.what(); + qCritical() << "Error during emission of signal" << signal << ":" << e.what(); } } }; @@ -223,8 +232,15 @@ struct EmitImpl<void (QGLIB_SIGNAL_IMPL_TEMPLATE_ARGS)> template <typename R QGLIB_SIGNAL_IMPL_TRAILING_TEMPLATE_PARAMS> R emit(void *instance, const char *detailedSignal QGLIB_SIGNAL_IMPL_FUNCTION_PARAMS) { - return QGlib::Private::EmitImpl<R (QGLIB_SIGNAL_IMPL_TEMPLATE_ARGS)> - ::emit(instance, detailedSignal QGLIB_SIGNAL_IMPL_FUNCTION_ARGS); + return Private::EmitImpl<R (QGLIB_SIGNAL_IMPL_TEMPLATE_ARGS)> + ::emit(instance, detailedSignal, Quark() QGLIB_SIGNAL_IMPL_FUNCTION_ARGS); +} + +template <typename R QGLIB_SIGNAL_IMPL_TRAILING_TEMPLATE_PARAMS> +R emitWithDetail(void *instance, const char *signal, Quark detail QGLIB_SIGNAL_IMPL_FUNCTION_PARAMS) +{ + return Private::EmitImpl<R (QGLIB_SIGNAL_IMPL_TEMPLATE_ARGS)> + ::emit(instance, signal, detail QGLIB_SIGNAL_IMPL_FUNCTION_ARGS); } //END ******** boostpp QGlib::emit ******** diff --git a/src/QGlib/signal.cpp b/src/QGlib/signal.cpp index 7500ee6..8a610c1 100644 --- a/src/QGlib/signal.cpp +++ b/src/QGlib/signal.cpp @@ -1,5 +1,7 @@ /* - Copyright (C) 2010 George Kiagiadakis <kia...@gm...> + Copyright (C) 2010 George Kiagiadakis <kia...@gm...> + Copyright (C) 2010 Collabora Ltd. + @author George Kiagiadakis <geo...@co...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -130,13 +132,12 @@ namespace Private { //BEGIN ******** emit ******** -Value emit(void *instance, const char *detailedSignal, const QList<Value> & args) +Value emit(void *instance, const char *detailedSignal, Quark detail, const QList<Value> & args) { Value result; Type itype = Type::fromInstance(instance); QStringList signalParts = QString::fromUtf8(detailedSignal).split(QLatin1String("::")); - Quark detail; - if (signalParts.size() > 1) { + if (!detail && signalParts.size() > 1) { detail = Quark(signalParts[1]); } diff --git a/src/QGlib/signal.h b/src/QGlib/signal.h index ea3e45c..cef47ea 100644 --- a/src/QGlib/signal.h +++ b/src/QGlib/signal.h @@ -1,5 +1,7 @@ /* - Copyright (C) 2010 George Kiagiadakis <kia...@gm...> + Copyright (C) 2010 George Kiagiadakis <kia...@gm...> + Copyright (C) 2010 Collabora Ltd. + @author George Kiagiadakis <geo...@co...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -129,6 +131,13 @@ private: template <typename R, typename... Args> R emit(void *instance, const char *detailedSignal, const Args & ... args); +/*! \overload + * This method takes the detail argument as a quark, separated from the signal name. + * It may be useful if you already have the quark of the detail that you want to specify. + */ +template <typename R, typename... Args> +R emitWithDetail(void *instance, const char *signal, Quark detail, const Args & ... args); + #endif //DOXYGEN_RUN } //namespace QGlib |