Commit 0d5db700 authored by Wescoeur's avatar Wescoeur

feat(Object): add skeleton to find signal with MetaObject

parent b578f0c4
......@@ -29,6 +29,7 @@
LINPHONE_BEGIN_NAMESPACE
class BaseObjectPrivate;
class MetaObject;
/*
* Base Object of Linphone. Cannot be cloned. Can be Shared.
......@@ -41,7 +42,9 @@ class LINPHONE_PUBLIC BaseObject {
public:
virtual ~BaseObject ();
virtual void lParent () {};
virtual const MetaObject *getMetaObject () const {
return nullptr;
};
protected:
explicit BaseObject (BaseObjectPrivate &p);
......
......@@ -31,20 +31,22 @@
// Declare Smart Object implementation.
#define L_OBJECT_IMPL(CLASS) \
constexpr LinphonePrivate::MetaObject CLASS::metaObject = LinphonePrivate::MetaObjectBuilder::createMetaObject<CLASS>();
constexpr LinphonePrivate::MetaObject CLASS::metaObject = LinphonePrivate::Private::createMetaObject<CLASS>(); \
const LinphonePrivate::MetaObject *CLASS::getMetaObject () const { \
return &CLASS::metaObject; \
};
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class MetaObjectBuilder {
public:
namespace Private {
template<typename T>
static constexpr MetaObject createMetaObject () {
constexpr MetaObject createMetaObject () {
// TODO.
return MetaObject();
}
private:
L_DISABLE_COPY(MetaObjectBuilder);
};
class ObjectPrivate : public BaseObjectPrivate {
......
......@@ -28,6 +28,36 @@ LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
void MetaObject::activateSignal (Object *sender, const MetaObject *metaObject, int signalIndex, void **args) {
// TODO.
}
const char *MetaObject::getClassName () const {
// TODO.
return nullptr;
}
const MetaObject *MetaObject::getParent () const {
// TODO
return nullptr;
}
int MetaObject::getSignalsNumber () const {
// TODO
return 0;
}
int MetaObject::getSignalIndex (void **signal) const {
// TODO
return -1;
}
// =============================================================================
L_OBJECT_IMPL(Object);
// -----------------------------------------------------------------------------
Object::Object (ObjectPrivate &p) : BaseObject(p) {}
// -----------------------------------------------------------------------------
......@@ -55,10 +85,6 @@ const Object::Lock &Object::getLock () const {
// -----------------------------------------------------------------------------
void MetaObject::activateSignal (Object *sender, const MetaObject *metaObject, int signalIndex, void **args) {
// TODO.
}
#define CHECK_CONNECT_PARAM(PARAM) \
do { \
if (!PARAM) { \
......@@ -73,7 +99,8 @@ Connection Object::connectInternal (
void **signal,
const Object *receiver,
void **slot,
Private::SlotObject *slotObject
Private::SlotObject *slotObject,
const MetaObject *metaObject
) {
// Note: `receiver` can be null with non-member function slot.
CHECK_CONNECT_PARAM(sender);
......@@ -81,6 +108,22 @@ Connection Object::connectInternal (
CHECK_CONNECT_PARAM(slot);
CHECK_CONNECT_PARAM(slotObject);
// 1. Try to find signal index and signal's meta object.
int signalIndex = -1;
for (; metaObject && signalIndex < 0; metaObject = metaObject->getParent()) {
signalIndex = metaObject->getSignalIndex(signal);
if (signalIndex >= 0)
break;
}
if (!metaObject) {
lError() << "Unable to find signal in: `" << sender->getMetaObject()->getClassName() << "`";
slotObject->call(Private::SlotObject::Delete, nullptr, nullptr);
return Connection();
}
// TODO: 2. Add connection in list.
return Connection();
}
......
......@@ -72,13 +72,14 @@
public: \
typedef CLASS lType; \
using lParentType = std::remove_reference< \
decltype(LinphonePrivate::Private::getParentObject(&lType::lParent)) \
decltype(LinphonePrivate::Private::getParentObject(&lType::getMetaObject)) \
>::type; \
private: \
friend constexpr std::tuple<> lMetaSignals (LinphonePrivate::Private::MetaObjectCounter<0>, lType **) { return {}; } \
public: \
struct MetaObjectBuilder; \
static const LinphonePrivate::MetaObject metaObject; \
virtual void lParent () override {};
const MetaObject *getMetaObject () const override;
// Declare one signal method.
#define L_SIGNAL(NAME, TYPES, ...) \
......@@ -109,12 +110,13 @@
LINPHONE_BEGIN_NAMESPACE
/*
* Meta data of one object.
* Gives a lot of info on one object.
*/
class LINPHONE_PUBLIC MetaObject {
public:
const char *getClassName () const;
const MetaObject *getParent () const;
int getSignalsNumber () const;
int getSignalIndex (void **signal) const;
static void activateSignal (Object *sender, const MetaObject *metaObject, int signalIndex, void **args);
};
......@@ -146,7 +148,7 @@ namespace Private {
};
template<typename T>
T &getParentObject (void (T::*)());
T &getParentObject (const MetaObject *(T::*)() const);
};
/*
......@@ -182,7 +184,8 @@ public:
new Private::SlotObjectFunction<
Func2,
typename Private::ListBuilder<typename SignalType::Arguments, SlotType::ArgumentsNumber>::Value
>(slot)
>(slot),
&SignalType::Object::metaObject
);
}
......@@ -198,11 +201,13 @@ public:
L_INTERNAL_CHECK_CONNECT_TYPES(SignalType, SlotType)
return connectInternal(sender, reinterpret_cast<void **>(&signal), receiver, reinterpret_cast<void **>(&slot),
return connectInternal(
sender, reinterpret_cast<void **>(&signal), receiver, reinterpret_cast<void **>(&slot),
new Private::SlotObjectMemberFunction<
Func2,
typename Private::ListBuilder<typename SignalType::Arguments, SlotType::ArgumentsNumber>::Value
>(slot)
>(slot),
&SignalType::Object::metaObject
);
}
......@@ -219,7 +224,8 @@ private:
void **signal,
const Object *receiver,
void **slot,
Private::SlotObject *slotObject
Private::SlotObject *slotObject,
const MetaObject *metaObject
);
L_DECLARE_PRIVATE(Object);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment