summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/QGlib/connectimpl.h7
-rw-r--r--src/QGlib/emitimpl.h11
-rw-r--r--src/QGlib/signal.cpp160
-rw-r--r--src/QGlib/signal.h9
4 files changed, 90 insertions, 97 deletions
diff --git a/src/QGlib/connectimpl.h b/src/QGlib/connectimpl.h
index 023da11..0d51dcf 100644
--- a/src/QGlib/connectimpl.h
+++ b/src/QGlib/connectimpl.h
@@ -70,6 +70,9 @@ protected:
*/
ClosurePtr createCppClosure(ClosureDataBase *data); //implemented in signal.cpp
+/*! This method is used internally from the templated connect() method. */
+SignalHandler connect(void *instance, const char *detailedSignal,
+ const ClosurePtr & closure, ConnectFlags flags);
template <typename Function, typename Signature>
struct CppClosure {};
@@ -227,7 +230,7 @@ SignalHandler connect(void *instance, const char *detailedSignal,
F && f = QGlib::Private::mem_fn(slot, receiver);
ClosurePtr && closure = QGlib::Private::CppClosure<F, R (Args...)>::create(f, flags & PassSender);
- return connect(instance, detailedSignal, closure, flags);
+ return Private::connect(instance, detailedSignal, closure, flags);
}
//END ******** QGlib::connect ********
@@ -359,7 +362,7 @@ SignalHandler connect(void *instance, const char *detailedSignal,
R (QGLIB_SIGNAL_IMPL_TEMPLATE_ARGS)
>::create(f, flags & PassSender);
- return connect(instance, detailedSignal, closure, flags);
+ return Private::connect(instance, detailedSignal, closure, flags);
}
# undef QGLIB_SIGNAL_IMPL_BIND_ARGS
diff --git a/src/QGlib/emitimpl.h b/src/QGlib/emitimpl.h
index 87f0fa2..d47c202 100644
--- a/src/QGlib/emitimpl.h
+++ b/src/QGlib/emitimpl.h
@@ -30,6 +30,9 @@
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);
+
template <typename Signature>
struct EmitImpl {};
@@ -70,7 +73,7 @@ struct EmitImpl<R (Args...)>
static inline R emit(void *instance, const char *detailedSignal, const Args & ... args)
{
try {
- Value && returnValue = QGlib::emit(instance, detailedSignal, packArguments(args...));
+ Value && returnValue = Private::emit(instance, detailedSignal, packArguments(args...));
return ValueImpl<R>::get(returnValue);
} catch(const std::exception & e) {
qCritical() << "Error during emission of signal" << detailedSignal << ":" << e.what();
@@ -85,7 +88,7 @@ struct EmitImpl<void (Args...)>
static inline void emit(void *instance, const char *detailedSignal, const Args & ... args)
{
try {
- Value && returnValue = QGlib::emit(instance, detailedSignal, packArguments(args...));
+ Value && returnValue = Private::emit(instance, detailedSignal, packArguments(args...));
if (returnValue.isValid()) {
qWarning() << "Ignoring return value from emission of signal" << detailedSignal;
@@ -179,7 +182,7 @@ struct EmitImpl<R (QGLIB_SIGNAL_IMPL_TEMPLATE_ARGS)>
try {
QList<Value> values;
QGLIB_SIGNAL_IMPL_PACK_ARGS(values)
- Value returnValue = QGlib::emit(instance, detailedSignal, values);
+ Value returnValue = Private::emit(instance, detailedSignal, values);
return ValueImpl<R>::get(returnValue);
} catch(const std::exception & e) {
qCritical() << "Error during emission of signal" << detailedSignal << ":" << e.what();
@@ -197,7 +200,7 @@ struct EmitImpl<void (QGLIB_SIGNAL_IMPL_TEMPLATE_ARGS)>
try {
QList<Value> values;
QGLIB_SIGNAL_IMPL_PACK_ARGS(values)
- Value returnValue = QGlib::emit(instance, detailedSignal, values);
+ Value returnValue = Private::emit(instance, detailedSignal, values);
if (returnValue.isValid()) {
qWarning() << "Ignoring return value from emission of signal" << detailedSignal;
}
diff --git a/src/QGlib/signal.cpp b/src/QGlib/signal.cpp
index 513737b..5acc4db 100644
--- a/src/QGlib/signal.cpp
+++ b/src/QGlib/signal.cpp
@@ -148,82 +148,6 @@ QList<Signal> Signal::listSignals(Type type)
}
//END ******** Signal ********
-//BEGIN ******** QGlib::emit ********
-
-//static
-Value emit(void *instance, const char *detailedSignal, const QList<Value> & args)
-{
- Value result;
- Type itype = Type::fromInstance(instance);
- QStringList signalParts = QString::fromUtf8(detailedSignal).split(QLatin1String("::"));
- Quark detail;
- if (signalParts.size() > 1) {
- detail = Quark(signalParts[1]);
- }
-
- //initialize arguments array
- GValue *values = new GValue[args.size() + 1];
- memset(values, 0, sizeof(GValue) * (args.size() + 1));
-
- //set instance
- g_value_init(&values[0], itype);
- g_value_set_instance(&values[0], instance);
-
- try {
- //find the signal and perform sanity checks
- Signal signal = Signal::lookup(signalParts[0].toUtf8(), itype);
- if (!signal.isValid()) {
- throw QString(QLatin1String("Could not find any signal named %1 "
- "on this instance type")).arg(signalParts[0]);
- }
-
- QList<Type> paramTypes = signal.paramTypes();
- if (paramTypes.size() != args.size()) {
- throw QString(QLatin1String("The number of arguments that the signal accepts differ "
- "from the number of arguments provided to emit"));
- }
-
- //set arguments
- for(int i=0; i<args.size(); i++) {
- if (!paramTypes[i].isA(args[i].type())) {
- throw QString(QLatin1String("Argument %1 provided to emit is not of the "
- "type that the signal expects")).arg(i);
- } else {
- g_value_init(&values[i+1], args[i].type());
- g_value_copy(args[i], &values[i+1]);
- }
- }
-
- //initialize return value
- GValue returnValue = QGLIB_G_VALUE_INITIALIZER;
- if (signal.returnType() != Type::None) {
- g_value_init(&returnValue, signal.returnType());
- }
-
- //emit the signal
- g_signal_emitv(values, signal.id(), detail, &returnValue);
-
- if (G_IS_VALUE(&returnValue)) {
- result = Value(&returnValue);
- g_value_unset(&returnValue);
- }
- } catch (const QString & msg) {
- QString instanceName = Value(&values[0]).toString();
-
- qCritical() << "Error during emission of signal" << detailedSignal
- << "on object"<< instanceName << ":" << msg;
- }
-
- //cleanup
- for(int i=0; i<args.size() + 1; i++) {
- g_value_unset(&values[i]);
- }
- delete[] values;
-
- return result;
-}
-
-//END ******** QGlib::emit ********
//BEGIN ******** Closure ********
void Closure::ref(bool increaseRef)
@@ -331,12 +255,8 @@ ClosurePtr createCppClosure(ClosureDataBase *closureData)
}
//END ******** Closure internals ********
+//BEGIN ******** connect ********
-} //namespace Private
-
-//BEGIN ******** QGlib::connect ********
-
-//static
SignalHandler connect(void *instance, const char *detailedSignal,
const ClosurePtr & closure, ConnectFlags flags)
{
@@ -345,6 +265,82 @@ SignalHandler connect(void *instance, const char *detailedSignal,
return SignalHandler(instance, id);
}
-//END ******** QGlib::connect ********
+//END ******** connect ********
+//BEGIN ******** emit ********
+
+Value emit(void *instance, const char *detailedSignal, const QList<Value> & args)
+{
+ Value result;
+ Type itype = Type::fromInstance(instance);
+ QStringList signalParts = QString::fromUtf8(detailedSignal).split(QLatin1String("::"));
+ Quark detail;
+ if (signalParts.size() > 1) {
+ detail = Quark(signalParts[1]);
+ }
+
+ //initialize arguments array
+ GValue *values = new GValue[args.size() + 1];
+ memset(values, 0, sizeof(GValue) * (args.size() + 1));
+
+ //set instance
+ g_value_init(&values[0], itype);
+ g_value_set_instance(&values[0], instance);
+
+ try {
+ //find the signal and perform sanity checks
+ Signal signal = Signal::lookup(signalParts[0].toUtf8(), itype);
+ if (!signal.isValid()) {
+ throw QString(QLatin1String("Could not find any signal named %1 "
+ "on this instance type")).arg(signalParts[0]);
+ }
+
+ QList<Type> paramTypes = signal.paramTypes();
+ if (paramTypes.size() != args.size()) {
+ throw QString(QLatin1String("The number of arguments that the signal accepts differ "
+ "from the number of arguments provided to emit"));
+ }
+
+ //set arguments
+ for(int i=0; i<args.size(); i++) {
+ if (!paramTypes[i].isA(args[i].type())) {
+ throw QString(QLatin1String("Argument %1 provided to emit is not of the "
+ "type that the signal expects")).arg(i);
+ } else {
+ g_value_init(&values[i+1], args[i].type());
+ g_value_copy(args[i], &values[i+1]);
+ }
+ }
+
+ //initialize return value
+ GValue returnValue = QGLIB_G_VALUE_INITIALIZER;
+ if (signal.returnType() != Type::None) {
+ g_value_init(&returnValue, signal.returnType());
+ }
+
+ //emit the signal
+ g_signal_emitv(values, signal.id(), detail, &returnValue);
+
+ if (G_IS_VALUE(&returnValue)) {
+ result = Value(&returnValue);
+ g_value_unset(&returnValue);
+ }
+ } catch (const QString & msg) {
+ QString instanceName = Value(&values[0]).toString();
+
+ qCritical() << "Error during emission of signal" << detailedSignal
+ << "on object"<< instanceName << ":" << msg;
+ }
+
+ //cleanup
+ for(int i=0; i<args.size() + 1; i++) {
+ g_value_unset(&values[i]);
+ }
+ delete[] values;
+
+ return result;
+}
+
+//END ******** emit ********
+} //namespace Private
} //namespace QGlib
diff --git a/src/QGlib/signal.h b/src/QGlib/signal.h
index 08b9a9e..b51f770 100644
--- a/src/QGlib/signal.h
+++ b/src/QGlib/signal.h
@@ -232,15 +232,6 @@ BOOST_PP_REPEAT_FROM_TO(0, BOOST_PP_INC(QGLIB_SIGNAL_MAX_ARGS), QGLIB_SIGNAL_CON
#endif //QGLIB_HAVE_CXX0X
-
-/*! \internal This method is used internally from the templated emit() method. */
-Value emit(void *instance, const char *detailedSignal, const QList<Value> & args);
-
-/*! \internal This method is used internally from the templated connect() method. */
-SignalHandler connect(void *instance, const char *detailedSignal,
- const ClosurePtr & closure, ConnectFlags flags = 0);
-
-
} //namespace QGlib
Q_DECLARE_OPERATORS_FOR_FLAGS(QGlib::Signal::SignalFlags)