Commit bc113345 authored by Ronan's avatar Ronan
Browse files

feat(c-wrapper): remove CPP_CLASS parameter of L_DECLARE_C_CLONABLE_STRUCT_IMPL

parent c7994eee
......@@ -21,7 +21,7 @@
// =============================================================================
L_DECLARE_C_CLONABLE_STRUCT_IMPL(Address, Address);
L_DECLARE_C_CLONABLE_STRUCT_IMPL(Address);
using namespace std;
......
......@@ -25,7 +25,7 @@
#define GET_MEDIA_CPP_PTR(obj) L_GET_CPP_PTR_FROM_C_STRUCT(obj, MediaSessionParams)
#define GET_MEDIA_CPP_PRIVATE_PTR(obj) L_GET_PRIVATE_FROM_C_STRUCT(obj, MediaSessionParams)
L_DECLARE_C_CLONABLE_STRUCT_IMPL(MediaSessionParams, CallParams)
L_DECLARE_C_CLONABLE_STRUCT_IMPL(CallParams)
using namespace std;
......
......@@ -28,11 +28,11 @@
// =============================================================================
L_DECLARE_C_CLONABLE_STRUCT_IMPL(EventLog, EventLog);
L_DECLARE_C_CLONABLE_STRUCT_IMPL(CallEvent, CallEvent);
L_DECLARE_C_CLONABLE_STRUCT_IMPL(ConferenceEvent, ConferenceEvent);
L_DECLARE_C_CLONABLE_STRUCT_IMPL(ConferenceParticipantEvent, ConferenceParticipantEvent);
L_DECLARE_C_CLONABLE_STRUCT_IMPL(ChatMessageEvent, ChatMessageEvent);
L_DECLARE_C_CLONABLE_STRUCT_IMPL(EventLog);
L_DECLARE_C_CLONABLE_STRUCT_IMPL(CallEvent);
L_DECLARE_C_CLONABLE_STRUCT_IMPL(ConferenceEvent);
L_DECLARE_C_CLONABLE_STRUCT_IMPL(ConferenceParticipantEvent);
L_DECLARE_C_CLONABLE_STRUCT_IMPL(ChatMessageEvent);
using namespace std;
......
......@@ -25,32 +25,16 @@
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
template<typename CppType, typename CType>
struct CppTypeToCType {
enum { Defined = false };
};
LINPHONE_END_NAMESPACE
#define L_REGISTER_TYPE(CPP_TYPE, C_TYPE) \
extern Linphone ## C_TYPE *_linphone_ ## C_TYPE ## _init (); \
namespace LINPHONE_NAMESPACE { \
class CPP_TYPE; \
}; \
template<> \
struct LINPHONE_NAMESPACE::CppTypeToCType<LINPHONE_NAMESPACE::CPP_TYPE, Linphone ## C_TYPE> { \
enum { Defined = true }; \
typedef C_TYPE cType; \
typedef LINPHONE_NAMESPACE::CPP_TYPE cppType; \
};
// =============================================================================
L_REGISTER_TYPE(Address, Address);
L_REGISTER_TYPE(Call, Call);
L_REGISTER_TYPE(CallEvent, CallEvent);
L_REGISTER_TYPE(ChatMessage, ChatMessage);
L_REGISTER_TYPE(ChatMessageEvent, ChatMessageEvent);
L_REGISTER_TYPE(ChatRoom, ChatRoom);
L_REGISTER_TYPE(ConferenceEvent, ConferenceEvent);
L_REGISTER_TYPE(ConferenceParticipantEvent, ConferenceParticipantEvent);
L_REGISTER_TYPE(EventLog, EventLog);
L_REGISTER_TYPE(MediaSessionParams, CallParams);
L_REGISTER_TYPE(Participant, Participant);
#endif // ifndef _C_WRAPPER_H_
......@@ -33,6 +33,16 @@
LINPHONE_BEGIN_NAMESPACE
template<typename CppType>
struct CppTypeToCType {
enum { defined = false };
};
template<typename CType>
struct CTypeToCppType {
enum { defined = false };
};
class Wrapper {
private:
template<typename T>
......@@ -287,6 +297,32 @@ LINPHONE_END_NAMESPACE
// Public Wrapper API.
// =============================================================================
// -----------------------------------------------------------------------------
// Register type.
// -----------------------------------------------------------------------------
#define L_REGISTER_TYPE(CPP_TYPE, C_TYPE) \
extern Linphone ## C_TYPE *_linphone_ ## C_TYPE ## _init (); \
namespace LINPHONE_NAMESPACE { \
class CPP_TYPE; \
}; \
template<> \
struct LINPHONE_NAMESPACE::CppTypeToCType<LINPHONE_NAMESPACE::CPP_TYPE> { \
enum { defined = true }; \
typedef Linphone ## C_TYPE type; \
}; \
template<> \
struct LINPHONE_NAMESPACE::CTypeToCppType<Linphone ## C_TYPE> { \
enum { defined = true }; \
typedef LINPHONE_NAMESPACE::CPP_TYPE type; \
};
#define L_ASSERT_C_TYPE(C_TYPE) \
static_assert(LINPHONE_NAMESPACE::CTypeToCppType<Linphone ## C_TYPE>::defined, "Type is not defined."); \
#define L_CPP_TYPE_OF_C_TYPE(C_TYPE) \
LINPHONE_NAMESPACE::CTypeToCppType<Linphone ## C_TYPE>::type
// -----------------------------------------------------------------------------
// C object declaration.
// -----------------------------------------------------------------------------
......@@ -310,10 +346,11 @@ LINPHONE_END_NAMESPACE
L_INTERNAL_DECLARE_C_STRUCT_FUNCTIONS(CPP_CLASS, C_TYPE, L_INTERNAL_C_STRUCT_NO_XTOR, L_INTERNAL_C_STRUCT_NO_XTOR)
// Declare clonable wrapped C object.
#define L_DECLARE_C_CLONABLE_STRUCT_IMPL(CPP_CLASS, C_TYPE, ...) \
#define L_DECLARE_C_CLONABLE_STRUCT_IMPL(C_TYPE, ...) \
L_ASSERT_C_TYPE(C_TYPE) \
struct _Linphone ## C_TYPE { \
belle_sip_object_t base; \
LINPHONE_NAMESPACE::CPP_CLASS *cppPtr; \
L_CPP_TYPE_OF_C_TYPE(C_TYPE) *cppPtr; \
__VA_ARGS__ \
}; \
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(Linphone ## C_TYPE); \
......@@ -325,14 +362,15 @@ LINPHONE_END_NAMESPACE
} \
static void _linphone_ ## C_TYPE ## _clone(Linphone ## C_TYPE * dest, const Linphone ## C_TYPE * src) { \
L_ASSERT(src->cppPtr); \
dest->cppPtr = new LINPHONE_NAMESPACE::CPP_CLASS(*src->cppPtr); \
dest->cppPtr = new L_CPP_TYPE_OF_C_TYPE(C_TYPE)(*src->cppPtr); \
} \
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(Linphone ## C_TYPE); \
BELLE_SIP_INSTANCIATE_VPTR(Linphone ## C_TYPE, belle_sip_object_t, \
_linphone_ ## C_TYPE ## _uninit, \
_linphone_ ## C_TYPE ## _clone, \
NULL, \
FALSE \
BELLE_SIP_INSTANCIATE_VPTR( \
Linphone ## C_TYPE, belle_sip_object_t, \
_linphone_ ## C_TYPE ## _uninit, \
_linphone_ ## C_TYPE ## _clone, \
NULL, \
FALSE \
);
#define L_DECLARE_C_STRUCT_NEW_DEFAULT(C_TYPE, C_NAME) \
......
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