forked from mirrors/linphone-iphone
feat(c-wrapper): provide a wrapper helper to access private data
This commit is contained in:
parent
09a533a8a9
commit
289dc072ed
7 changed files with 79 additions and 57 deletions
|
|
@ -22,6 +22,10 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
#include <libxml/xmlwriter.h>
|
||||
|
||||
#include "linphone/core.h"
|
||||
#include "private.h"
|
||||
#include "linphone/lpconfig.h"
|
||||
|
|
@ -29,14 +33,12 @@
|
|||
#include "ortp/b64.h"
|
||||
#include "linphone/wrapper_utils.h"
|
||||
|
||||
#include "chat/chat-room.h"
|
||||
#include "c-wrapper/wrapper.h"
|
||||
#include "chat/chat-room-p.h"
|
||||
#include "chat/chat-room.h"
|
||||
#include "utils/content-type.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
#include <libxml/xmlwriter.h>
|
||||
|
||||
struct _LinphoneChatRoom{
|
||||
belle_sip_object_t base;
|
||||
|
|
@ -179,7 +181,7 @@ BELLE_SIP_INSTANCIATE_VPTR(LinphoneChatRoom, belle_sip_object_t,
|
|||
LinphoneChatRoom *_linphone_core_create_chat_room_base(LinphoneCore *lc, LinphoneAddress *addr){
|
||||
LinphoneChatRoom *cr = belle_sip_object_new(LinphoneChatRoom);
|
||||
cr->cr = new LinphonePrivate::ChatRoom(lc, addr);
|
||||
cr->cr->getPrivate()->setCBackPointer(cr);
|
||||
L_GET_PRIVATE(cr->cr)->setCBackPointer(cr);
|
||||
return cr;
|
||||
}
|
||||
|
||||
|
|
@ -260,7 +262,7 @@ void linphone_chat_room_destroy(LinphoneChatRoom *cr) {
|
|||
}
|
||||
|
||||
void linphone_chat_room_release(LinphoneChatRoom *cr) {
|
||||
cr->cr->getPrivate()->release();
|
||||
L_GET_PRIVATE(cr->cr)->release();
|
||||
}
|
||||
|
||||
LinphoneChatRoom *linphone_chat_room_ref(LinphoneChatRoom *cr) {
|
||||
|
|
@ -281,7 +283,7 @@ void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void *ud) {
|
|||
}
|
||||
|
||||
void linphone_chat_room_remove_transient_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
|
||||
cr->cr->getPrivate()->removeTransientMessage(msg);
|
||||
L_GET_PRIVATE(cr->cr)->removeTransientMessage(msg);
|
||||
}
|
||||
|
||||
void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMessageState new_state) {
|
||||
|
|
@ -289,7 +291,7 @@ void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMe
|
|||
linphone_chat_message_store_state(msg);
|
||||
|
||||
if (msg->state == LinphoneChatMessageStateDelivered || msg->state == LinphoneChatMessageStateNotDelivered) {
|
||||
msg->chat_room->cr->getPrivate()->moveTransientMessageToWeakMessages(msg);
|
||||
L_GET_PRIVATE(msg->chat_room->cr)->moveTransientMessageToWeakMessages(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -346,7 +348,7 @@ void create_file_transfer_information_from_vnd_gsma_rcs_ft_http_xml(LinphoneChat
|
|||
file_url = xmlGetProp(cur, (const xmlChar *)"url");
|
||||
}
|
||||
|
||||
if (!xmlStrcmp(cur->name, (const xmlChar *)"file-key")) {
|
||||
if (!xmlStrcmp(cur->name, (const xmlChar *)"file-key")) {
|
||||
/* there is a key in the msg: file has been encrypted */
|
||||
/* convert the key from base 64 */
|
||||
xmlChar *keyb64 = xmlNodeListGetString(xmlMessageBody, cur->xmlChildrenNode, 1);
|
||||
|
|
@ -354,7 +356,7 @@ void create_file_transfer_information_from_vnd_gsma_rcs_ft_http_xml(LinphoneChat
|
|||
uint8_t *keyBuffer = (uint8_t *)malloc(keyLength);
|
||||
/* decode the key into local key buffer */
|
||||
b64::b64_decode((char *)keyb64, strlen((char *)keyb64), keyBuffer, keyLength);
|
||||
linphone_content_set_key(msg->file_transfer_information, (char *)keyBuffer, keyLength);
|
||||
linphone_content_set_key(msg->file_transfer_information, (char *)keyBuffer, keyLength);
|
||||
/* duplicate key value into the linphone content private structure */
|
||||
xmlFree(keyb64);
|
||||
free(keyBuffer);
|
||||
|
|
@ -380,7 +382,7 @@ int linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessage
|
|||
LinphoneAddress *addr = linphone_address_new(sal_msg->from);
|
||||
linphone_address_clean(addr);
|
||||
LinphoneChatRoom *cr = linphone_core_get_chat_room(lc, addr);
|
||||
LinphoneReason reason = cr->cr->getPrivate()->messageReceived(op, sal_msg);
|
||||
LinphoneReason reason = L_GET_PRIVATE(cr->cr)->messageReceived(op, sal_msg);
|
||||
linphone_address_unref(addr);
|
||||
return reason;
|
||||
}
|
||||
|
|
@ -573,7 +575,7 @@ static char *linphone_chat_message_create_imdn_xml(LinphoneChatMessage *cm, Imdn
|
|||
void linphone_chat_message_send_imdn(LinphoneChatMessage *cm, ImdnType imdn_type, LinphoneReason reason) {
|
||||
char *content = linphone_chat_message_create_imdn_xml(cm, imdn_type, reason);
|
||||
if (content) {
|
||||
linphone_chat_message_get_chat_room(cm)->cr->getPrivate()->sendImdn(content, reason);
|
||||
L_GET_PRIVATE(linphone_chat_message_get_chat_room(cm)->cr)->sendImdn(content, reason);
|
||||
ms_free(content);
|
||||
}
|
||||
}
|
||||
|
|
@ -597,7 +599,7 @@ void linphone_chat_message_send_display_notification(LinphoneChatMessage *cm) {
|
|||
}
|
||||
|
||||
void linphone_core_real_time_text_received(LinphoneCore *lc, LinphoneChatRoom *cr, uint32_t character, LinphoneCall *call) {
|
||||
cr->cr->getPrivate()->realtimeTextReceived(character, call);
|
||||
L_GET_PRIVATE(cr->cr)->realtimeTextReceived(character, call);
|
||||
}
|
||||
|
||||
uint32_t linphone_chat_room_get_char(const LinphoneChatRoom *cr) {
|
||||
|
|
@ -652,11 +654,11 @@ LinphoneCall *linphone_chat_room_get_call(const LinphoneChatRoom *room) {
|
|||
}
|
||||
|
||||
void linphone_chat_room_set_call(LinphoneChatRoom *cr, LinphoneCall *call) {
|
||||
cr->cr->getPrivate()->setCall(call);
|
||||
L_GET_PRIVATE(cr->cr)->setCall(call);
|
||||
}
|
||||
|
||||
bctbx_list_t * linphone_chat_room_get_transient_messages(const LinphoneChatRoom *cr) {
|
||||
std::list<LinphoneChatMessage *> l = cr->cr->getPrivate()->getTransientMessages();
|
||||
std::list<LinphoneChatMessage *> l = L_GET_PRIVATE(cr->cr)->getTransientMessages();
|
||||
bctbx_list_t *result = nullptr;
|
||||
for (auto it = l.begin(); it != l.end(); it++)
|
||||
result = bctbx_list_append(result, *it);
|
||||
|
|
@ -807,7 +809,7 @@ int linphone_chat_message_set_text(LinphoneChatMessage *msg, const char* text) {
|
|||
msg->message = ms_strdup(text);
|
||||
else
|
||||
msg->message = NULL;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
|
|||
c-wrapper/api/c-event-log.h
|
||||
c-wrapper/c-tools.h
|
||||
c-wrapper/c-types.h
|
||||
c-wrapper/wrapper.h
|
||||
chat/chat-room-p.h
|
||||
chat/chat-room.h
|
||||
content/content.h
|
||||
|
|
|
|||
48
src/c-wrapper/wrapper.h
Normal file
48
src/c-wrapper/wrapper.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* wrapper.h
|
||||
* Copyright (C) 2017 Belledonne Communications SARL
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _WRAPPER_H_
|
||||
#define _WRAPPER_H_
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "object/object.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class Wrapper {
|
||||
public:
|
||||
template<typename T>
|
||||
static decltype(std::declval<T>().getPrivate()) getPrivate (T *object) {
|
||||
return object->getPrivate();
|
||||
}
|
||||
|
||||
private:
|
||||
Wrapper ();
|
||||
|
||||
L_DISABLE_COPY(Wrapper);
|
||||
};
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
||||
#define L_GET_PRIVATE(OBJECT) \
|
||||
LINPHONE_NAMESPACE::Wrapper::getPrivate(OBJECT)
|
||||
|
||||
#endif // ifndef _WRAPPER_H_
|
||||
|
|
@ -19,15 +19,11 @@
|
|||
#ifndef _CHAT_ROOM_P_H_
|
||||
#define _CHAT_ROOM_P_H_
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "object/object-p.h"
|
||||
|
||||
#include "chat-room.h"
|
||||
|
||||
// From coreapi.
|
||||
#include "private.h"
|
||||
|
||||
#include <belle-sip/belle-sip.h>
|
||||
#include "chat-room.h"
|
||||
#include "object/object-p.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
|
|
@ -122,7 +118,7 @@ public:
|
|||
std::list<LinphoneChatMessageCharacter *> receivedRttCharacters;
|
||||
LinphoneChatMessage *pendingMessage = nullptr;
|
||||
|
||||
public:
|
||||
private:
|
||||
L_DECLARE_PUBLIC(ChatRoom);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -19,18 +19,18 @@
|
|||
#include <algorithm>
|
||||
|
||||
#include "chat-room-p.h"
|
||||
|
||||
#include "chat-room.h"
|
||||
#include "logger/logger.h"
|
||||
#include "utils/content-type.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
#include "chat-room.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
using namespace std;
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
// =============================================================================
|
||||
|
||||
const string ChatRoomPrivate::imdnPrefix = "/imdn:imdn";
|
||||
const string ChatRoomPrivate::isComposingPrefix = "/xsi:isComposing";
|
||||
|
||||
|
|
|
|||
|
|
@ -20,28 +20,10 @@
|
|||
#define _CHAT_ROOM_H_
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include "object/object.h"
|
||||
|
||||
#include "linphone/types.h"
|
||||
#include "sal/sal.h"
|
||||
|
||||
#include "private.h"
|
||||
|
||||
#include <bctoolbox/port.h>
|
||||
|
||||
extern "C" {
|
||||
LinphoneChatRoom *_linphone_core_create_chat_room_base (LinphoneCore *lc, LinphoneAddress *addr);
|
||||
int linphone_core_message_received (LinphoneCore *lc, SalOp *op, const SalMessage *sal_msg);
|
||||
void linphone_core_real_time_text_received (LinphoneCore *lc, LinphoneChatRoom *cr, uint32_t character, LinphoneCall *call);
|
||||
bctbx_list_t *linphone_chat_room_get_transient_messages (const LinphoneChatRoom *cr);
|
||||
void linphone_chat_room_remove_transient_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg);
|
||||
void linphone_chat_room_set_call (LinphoneChatRoom *cr, LinphoneCall *call);
|
||||
void linphone_chat_room_release (LinphoneChatRoom *cr);
|
||||
void linphone_chat_message_send_imdn (LinphoneChatMessage *cm, ImdnType imdn_type, LinphoneReason reason);
|
||||
void linphone_chat_message_update_state (LinphoneChatMessage *msg, LinphoneChatMessageState new_state);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
|
|
@ -50,16 +32,6 @@ LINPHONE_BEGIN_NAMESPACE
|
|||
class ChatRoomPrivate;
|
||||
|
||||
class ChatRoom : public Object {
|
||||
friend LinphoneChatRoom *::_linphone_core_create_chat_room_base (LinphoneCore *lc, LinphoneAddress *addr);
|
||||
friend int ::linphone_core_message_received(LinphoneCore * lc, SalOp * op, const SalMessage * sal_msg);
|
||||
friend void ::linphone_core_real_time_text_received(LinphoneCore * lc, LinphoneChatRoom * cr, uint32_t character, LinphoneCall * call);
|
||||
friend bctbx_list_t *::linphone_chat_room_get_transient_messages (const LinphoneChatRoom *cr);
|
||||
friend void ::linphone_chat_room_remove_transient_message(LinphoneChatRoom * cr, LinphoneChatMessage * msg);
|
||||
friend void ::linphone_chat_room_set_call(LinphoneChatRoom * cr, LinphoneCall * call);
|
||||
friend void ::linphone_chat_room_release(LinphoneChatRoom * cr);
|
||||
friend void ::linphone_chat_message_send_imdn(LinphoneChatMessage * cm, ImdnType imdn_type, LinphoneReason reason);
|
||||
friend void ::linphone_chat_message_update_state(LinphoneChatMessage * msg, LinphoneChatMessageState new_state);
|
||||
|
||||
public:
|
||||
ChatRoom (LinphoneCore *core, LinphoneAddress *peerAddress);
|
||||
virtual ~ChatRoom () = default;
|
||||
|
|
|
|||
|
|
@ -63,6 +63,8 @@ void l_assert (const char *condition, const char *file, int line);
|
|||
#define L_ASSERT(CONDITION) ((CONDITION) ? static_cast<void>(0) : l_assert(#CONDITION, __FILE__, __LINE__))
|
||||
#endif
|
||||
|
||||
// Allows access to private internal data.
|
||||
// Gives a control to C Wrapper.
|
||||
#define L_DECLARE_PRIVATE(CLASS) \
|
||||
inline CLASS ## Private * getPrivate() { \
|
||||
return reinterpret_cast<CLASS ## Private *>(mPrivate); \
|
||||
|
|
@ -70,7 +72,8 @@ void l_assert (const char *condition, const char *file, int line);
|
|||
inline const CLASS ## Private *getPrivate() const { \
|
||||
return reinterpret_cast<const CLASS ## Private *>(mPrivate); \
|
||||
} \
|
||||
friend class CLASS ## Private;
|
||||
friend class CLASS ## Private; \
|
||||
friend class Wrapper;
|
||||
|
||||
class ClonableObject;
|
||||
class ClonableObjectPrivate;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue