diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index 65f5c9b25..a2041e866 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -166,7 +166,7 @@ void linphone_chat_room_set_call (LinphoneChatRoom *cr, LinphoneCall *call) { } bctbx_list_t *linphone_chat_room_get_transient_messages (const LinphoneChatRoom *cr) { - return L_GET_C_LIST_FROM_CPP_LIST(GET_CPP_PRIVATE_PTR(cr)->getTransientMessages(), LinphoneChatMessage); + return L_GET_C_LIST_FROM_CPP_LIST(GET_CPP_PRIVATE_PTR(cr)->getTransientMessages()); } void linphone_chat_room_mark_as_read (LinphoneChatRoom *cr) { @@ -190,11 +190,11 @@ void linphone_chat_room_delete_history (LinphoneChatRoom *cr) { } bctbx_list_t *linphone_chat_room_get_history_range (LinphoneChatRoom *cr, int startm, int endm) { - return L_GET_C_LIST_FROM_CPP_LIST(GET_CPP_PTR(cr)->getHistoryRange(startm, endm), LinphoneChatMessage); + return L_GET_C_LIST_FROM_CPP_LIST(GET_CPP_PTR(cr)->getHistoryRange(startm, endm)); } bctbx_list_t *linphone_chat_room_get_history (LinphoneChatRoom *cr, int nb_message) { - return L_GET_C_LIST_FROM_CPP_LIST(GET_CPP_PTR(cr)->getHistory(nb_message), LinphoneChatMessage); + return L_GET_C_LIST_FROM_CPP_LIST(GET_CPP_PTR(cr)->getHistory(nb_message)); } LinphoneChatMessage *linphone_chat_room_find_message (LinphoneChatRoom *cr, const char *message_id) { diff --git a/src/c-wrapper/internal/c-tools.h b/src/c-wrapper/internal/c-tools.h index 10821be11..3c61e27de 100644 --- a/src/c-wrapper/internal/c-tools.h +++ b/src/c-wrapper/internal/c-tools.h @@ -155,6 +155,10 @@ public: return cppPtr; } + // --------------------------------------------------------------------------- + // Get c back ptr helpers. + // --------------------------------------------------------------------------- + template static inline CType *getCBackPtr (const std::shared_ptr &object, CType *(*cTypeAllocator)()) { Variant v = object->getProperty("LinphonePrivate::Wrapper::cBackPtr"); @@ -177,6 +181,8 @@ public: return reinterpret_cast(value); } + // --------------------------------------------------------------------------- + // Get/set user data. // --------------------------------------------------------------------------- template @@ -203,16 +209,26 @@ public: object->setProperty("LinphonePrivate::Wrapper::userData", value); } + // --------------------------------------------------------------------------- + // List helpers. // --------------------------------------------------------------------------- template - static inline bctbx_list_t *getCListFromCppList (const std::list cppList) { + static inline bctbx_list_t *getCListFromCppList (const std::list &cppList) { bctbx_list_t *result = nullptr; for (const auto &value : cppList) result = bctbx_list_append(result, value); return result; } + template + static inline std::list getCppListFromCList (const bctbx_list_t *cList) { + std::list result; + for (auto it = cList; it; it = bctbx_list_next(it)) + result.push_back(static_cast(bctbx_list_get_data(it))); + return result; + } + template static inline bctbx_list_t *getCListOfStructPtrFromCppListOfCppObj (const std::list> cppList, CType *(*cTypeAllocator)()) { bctbx_list_t *result = nullptr; @@ -229,14 +245,6 @@ public: return result; } - template - static inline std::list getCppListFromCList (const bctbx_list_t *cList) { - std::list result; - for (auto it = cList; it; it = bctbx_list_next(it)) - result.push_back(static_cast(bctbx_list_get_data(it))); - return result; - } - template< typename CppType, typename CType, @@ -432,10 +440,11 @@ LINPHONE_END_NAMESPACE VALUE \ ) -#define L_GET_C_LIST_FROM_CPP_LIST(LIST, TYPE) \ - LINPHONE_NAMESPACE::Wrapper::getCListFromCppList(LIST) +#define L_GET_C_LIST_FROM_CPP_LIST(LIST) \ + LINPHONE_NAMESPACE::Wrapper::getCListFromCppList(LIST) #define L_GET_CPP_LIST_FROM_C_LIST(LIST, TYPE) \ - LINPHONE_NAMESPACE::Wrapper::getCppListFromCList(LIST) + LINPHONE_NAMESPACE::Wrapper::getCppListFromCList(LIST) + #define L_GET_C_LIST_OF_STRUCT_PTR_FROM_CPP_LIST_OF_CPP_OBJ(LIST, CPP_TYPE, C_TYPE) \ LINPHONE_NAMESPACE::Wrapper::getCListOfStructPtrFromCppListOfCppObj(LIST, _linphone_ ## C_TYPE ## _init) #define L_GET_CPP_LIST_OF_CPP_OBJ_FROM_C_LIST_OF_STRUCT_PTR(LIST, CPP_TYPE, C_TYPE) \