Commit 4e798d8b authored by Ronan's avatar Ronan

feat(c-wrapper): L_GET_PRIVATE supports CPP_TYPE parameter

parent 6024a8fd
......@@ -149,7 +149,7 @@ void linphone_chat_room_send_chat_message (LinphoneChatRoom *cr, LinphoneChatMes
uint32_t linphone_chat_room_get_char (const LinphoneChatRoom *cr) {
if (linphone_core_realtime_text_enabled(linphone_chat_room_get_core(cr)))
return static_cast<const LinphonePrivate::RealTimeTextChatRoom *>(L_GET_CPP_PTR_FROM_C_OBJECT(cr).get())->getChar();
return L_GET_CPP_PTR_FROM_C_OBJECT(cr, RealTimeTextChatRoom)->getChar();
return 0;
}
......@@ -159,7 +159,7 @@ void linphone_chat_room_compose (LinphoneChatRoom *cr) {
LinphoneCall *linphone_chat_room_get_call (const LinphoneChatRoom *cr) {
if (linphone_core_realtime_text_enabled(linphone_chat_room_get_core(cr)))
return static_cast<const LinphonePrivate::RealTimeTextChatRoom *>(L_GET_CPP_PTR_FROM_C_OBJECT(cr).get())->getCall();
return L_GET_CPP_PTR_FROM_C_OBJECT(cr, RealTimeTextChatRoom)->getCall();
return nullptr;
}
......
......@@ -32,6 +32,12 @@
// Internal.
// =============================================================================
#ifdef DEBUG
#define L_INTERNAL_WRAPPER_CONSTEXPR
#else
#define L_INTERNAL_WRAPPER_CONSTEXPR constexpr
#endif
LINPHONE_BEGIN_NAMESPACE
template<typename CppType>
......@@ -60,6 +66,13 @@ private:
};
};
template<typename CppPrivateType>
struct IsPrivateCppObject {
enum {
value = std::is_base_of<ObjectPrivate, CppPrivateType>::value || std::is_base_of<ClonableObjectPrivate, CppPrivateType>::value
};
};
template<typename CppType>
struct IsDefinedCppObject {
enum {
......@@ -106,6 +119,29 @@ private:
}
public:
// ---------------------------------------------------------------------------
// Casts.
// ---------------------------------------------------------------------------
template<
typename CppDerivedPrivateType,
typename CppBasePrivateType,
typename = typename std::enable_if<IsPrivateCppObject<CppDerivedPrivateType>::value, CppDerivedPrivateType>::type
>
static L_INTERNAL_WRAPPER_CONSTEXPR CppDerivedPrivateType *cast (CppBasePrivateType *base) {
#ifdef DEBUG
if (!base)
return static_cast<CppDerivedPrivateType *>(base);
CppDerivedPrivateType *derived = dynamic_cast<CppDerivedPrivateType *>(base);
if (!derived)
fatal("Invalid cast.");
return derived;
#else
return static_cast<CppDerivedPrivateType *>(base);
#endif
}
// ---------------------------------------------------------------------------
// Get private data of cpp Object.
// ---------------------------------------------------------------------------
......@@ -122,12 +158,6 @@ public:
// Get c/cpp ptr helpers.
// ---------------------------------------------------------------------------
#ifdef DEBUG
#define L_INTERNAL_WRAPPER_CONSTEXPR
#else
#define L_INTERNAL_WRAPPER_CONSTEXPR constexpr
#endif
template<
typename CType,
typename CppType = typename CTypeMetaInfo<CType>::cppType,
......@@ -159,7 +189,7 @@ public:
>
static L_INTERNAL_WRAPPER_CONSTEXPR std::shared_ptr<const CppType> getCppPtrFromC (const CType *cObject) {
#ifdef DEBUG
return getCppPtrFromC(const_cast<CType *>(cObject));
return getCppPtrFromC<CType, CppType>(const_cast<CType *>(cObject));
#else
return reinterpret_cast<const WrappedObject<CppType> *>(cObject)->cppPtr;
#endif
......@@ -202,8 +232,6 @@ public:
#endif
}
#undef L_INTERNAL_WRAPPER_CONSTEXPR
// ---------------------------------------------------------------------------
// Set c/cpp ptr helpers.
// ---------------------------------------------------------------------------
......@@ -387,6 +415,8 @@ private:
LINPHONE_END_NAMESPACE
#undef L_INTERNAL_WRAPPER_CONSTEXPR
#define L_INTERNAL_C_OBJECT_NO_XTOR(C_OBJECT)
#define L_INTERNAL_DECLARE_C_OBJECT_FUNCTIONS(C_TYPE, CONSTRUCTOR, DESTRUCTOR) \
......@@ -552,14 +582,22 @@ LINPHONE_END_NAMESPACE
LINPHONE_NAMESPACE::Wrapper::setCppPtrFromC(C_OBJECT, CPP_OBJECT)
// Get the private data of a shared or simple cpp-ptr.
#define L_GET_PRIVATE(CPP_OBJECT) \
#define L_GET_PRIVATE_1_ARGS(CPP_OBJECT) \
LINPHONE_NAMESPACE::Wrapper::getPrivate(LINPHONE_NAMESPACE::Utils::getPtr(CPP_OBJECT))
#define L_GET_PRIVATE_2_ARGS(CPP_OBJECT, CPP_TYPE) \
LINPHONE_NAMESPACE::Wrapper::cast<CPP_TYPE ## Private>(L_GET_PRIVATE_1_ARGS(CPP_OBJECT))
#define L_GET_PRIVATE_MACRO_CHOOSER(...) \
L_EXPAND(L_GET_ARG_3(__VA_ARGS__, L_GET_PRIVATE_2_ARGS, L_GET_PRIVATE_1_ARGS))
#define L_GET_PRIVATE(...) \
L_EXPAND(L_GET_PRIVATE_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__))
// Get the private data of a shared or simple cpp-ptr of a wrapped C object.
#define L_GET_PRIVATE_FROM_C_OBJECT_1_ARGS(C_OBJECT) \
L_GET_PRIVATE(LINPHONE_NAMESPACE::Utils::getPtr(L_GET_CPP_PTR_FROM_C_OBJECT_1_ARGS(C_OBJECT)))
L_GET_PRIVATE_1_ARGS(LINPHONE_NAMESPACE::Utils::getPtr(L_GET_CPP_PTR_FROM_C_OBJECT_1_ARGS(C_OBJECT)))
#define L_GET_PRIVATE_FROM_C_OBJECT_2_ARGS(C_OBJECT, CPP_TYPE) \
L_GET_PRIVATE(LINPHONE_NAMESPACE::Utils::getPtr(L_GET_CPP_PTR_FROM_C_OBJECT_2_ARGS(C_OBJECT, CPP_TYPE)))
L_GET_PRIVATE_1_ARGS(LINPHONE_NAMESPACE::Utils::getPtr(L_GET_CPP_PTR_FROM_C_OBJECT_2_ARGS(C_OBJECT, CPP_TYPE)))
#define L_GET_PRIVATE_FROM_C_OBJECT_MACRO_CHOOSER(...) \
L_EXPAND(L_GET_ARG_3(__VA_ARGS__, L_GET_PRIVATE_FROM_C_OBJECT_2_ARGS, L_GET_PRIVATE_FROM_C_OBJECT_1_ARGS))
......
......@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "c-wrapper/c-wrapper.h"
#include "call-p.h"
#include "conference/local-conference.h"
#include "conference/participant-p.h"
......@@ -51,11 +52,11 @@ CallPrivate::~CallPrivate () {
// -----------------------------------------------------------------------------
shared_ptr<CallSession> CallPrivate::getActiveSession () const {
return conference->getActiveParticipant()->getPrivate()->getSession();
return L_GET_PRIVATE(conference->getActiveParticipant())->getSession();
}
bool CallPrivate::getAudioMuted () const {
return static_cast<MediaSession *>(getActiveSession().get())->getPrivate()->getAudioMuted();
return L_GET_PRIVATE(getActiveSession(), MediaSession)->getAudioMuted();
}
LinphoneProxyConfig *CallPrivate::getDestProxy () const {
......@@ -63,11 +64,11 @@ LinphoneProxyConfig *CallPrivate::getDestProxy () const {
}
IceSession *CallPrivate::getIceSession () const {
return static_cast<MediaSession *>(getActiveSession().get())->getPrivate()->getIceSession();
return L_GET_PRIVATE(getActiveSession(), MediaSession)->getIceSession();
}
MediaStream *CallPrivate::getMediaStream (LinphoneStreamType type) const {
return static_cast<MediaSession *>(getActiveSession().get())->getPrivate()->getMediaStream(type);
return L_GET_PRIVATE(getActiveSession(), MediaSession)->getMediaStream(type);
}
SalOp *CallPrivate::getOp () const {
......@@ -75,7 +76,7 @@ SalOp *CallPrivate::getOp () const {
}
void CallPrivate::setAudioMuted (bool value) {
static_cast<MediaSession *>(getActiveSession().get())->getPrivate()->setAudioMuted(value);
L_GET_PRIVATE(getActiveSession(), MediaSession)->setAudioMuted(value);
}
// -----------------------------------------------------------------------------
......
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