mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-21 04:58:14 +00:00
Use c-tools for LinphoneChatRoom.
This commit is contained in:
parent
4732e417d7
commit
8e9bbb6899
17 changed files with 391 additions and 317 deletions
221
coreapi/chat.c
221
coreapi/chat.c
|
|
@ -42,14 +42,6 @@
|
|||
#include "chat/real-time-text-chat-room-p.h"
|
||||
#include "content/content-type.h"
|
||||
|
||||
struct _LinphoneChatRoom{
|
||||
belle_sip_object_t base;
|
||||
void *user_data;
|
||||
LinphonePrivate::ChatRoom *cr;
|
||||
LinphoneAddress *peerAddressCache;
|
||||
};
|
||||
|
||||
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneChatRoom);
|
||||
|
||||
static void _linphone_chat_message_destroy(LinphoneChatMessage *msg);
|
||||
|
||||
|
|
@ -165,47 +157,14 @@ const bctbx_list_t *linphone_core_get_chat_rooms(LinphoneCore *lc) {
|
|||
return lc->chatrooms;
|
||||
}
|
||||
|
||||
static bool_t linphone_chat_room_matches(LinphoneChatRoom *cr, const LinphoneAddress *from) {
|
||||
LinphoneAddress *addr = linphone_address_new(cr->cr->getPeerAddress().asString().c_str());
|
||||
bool_t result = linphone_address_weak_equal(addr, from);
|
||||
linphone_address_unref(addr);
|
||||
return result;
|
||||
}
|
||||
|
||||
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneChatRoom);
|
||||
|
||||
static void _linphone_chat_room_destroy(LinphoneChatRoom *cr) {
|
||||
delete cr->cr;
|
||||
if (cr->peerAddressCache) {
|
||||
linphone_address_unref(cr->peerAddressCache);
|
||||
cr->peerAddressCache = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
BELLE_SIP_INSTANCIATE_VPTR(LinphoneChatRoom, belle_sip_object_t,
|
||||
(belle_sip_object_destroy_t)_linphone_chat_room_destroy,
|
||||
NULL, // clone
|
||||
NULL, // marshal
|
||||
FALSE);
|
||||
|
||||
LinphoneChatRoom *_linphone_core_create_chat_room_base(LinphoneCore *lc, const LinphoneAddress *addr) {
|
||||
LinphoneChatRoom *cr = belle_sip_object_new(LinphoneChatRoom);
|
||||
if (linphone_core_realtime_text_enabled(lc))
|
||||
cr->cr = new LinphonePrivate::RealTimeTextChatRoom(lc, *L_GET_CPP_PTR_FROM_C_STRUCT(addr, Address, Address));
|
||||
else
|
||||
cr->cr = new LinphonePrivate::BasicChatRoom(lc, *L_GET_CPP_PTR_FROM_C_STRUCT(addr, Address, Address));
|
||||
L_GET_PRIVATE(cr->cr)->setCBackPointer(cr);
|
||||
return cr;
|
||||
}
|
||||
|
||||
static LinphoneChatRoom *_linphone_core_create_chat_room(LinphoneCore *lc, const LinphoneAddress *addr) {
|
||||
LinphoneChatRoom *cr = _linphone_core_create_chat_room_base(lc, addr);
|
||||
LinphoneChatRoom *cr = linphone_chat_room_new(lc, addr);
|
||||
lc->chatrooms = bctbx_list_append(lc->chatrooms, (void *)cr);
|
||||
return cr;
|
||||
}
|
||||
|
||||
LinphoneChatRoom *_linphone_core_create_chat_room_from_call(LinphoneCall *call){
|
||||
LinphoneChatRoom *cr = _linphone_core_create_chat_room_base(linphone_call_get_core(call),
|
||||
LinphoneChatRoom *cr = linphone_chat_room_new(linphone_call_get_core(call),
|
||||
linphone_address_clone(linphone_call_get_remote_address(call)));
|
||||
linphone_chat_room_set_call(cr, call);
|
||||
return cr;
|
||||
|
|
@ -219,6 +178,13 @@ static LinphoneChatRoom *_linphone_core_create_chat_room_from_url(LinphoneCore *
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static bool_t linphone_chat_room_matches(LinphoneChatRoom *cr, const LinphoneAddress *from) {
|
||||
LinphoneAddress *addr = linphone_address_new(L_GET_CPP_PTR_FROM_C_STRUCT(cr, ChatRoom, ChatRoom)->getPeerAddress().asString().c_str());
|
||||
bool_t result = linphone_address_weak_equal(addr, from);
|
||||
linphone_address_unref(addr);
|
||||
return result;
|
||||
}
|
||||
|
||||
LinphoneChatRoom *_linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAddress *addr) {
|
||||
LinphoneChatRoom *cr = NULL;
|
||||
bctbx_list_t *elem;
|
||||
|
|
@ -256,24 +222,8 @@ LinphoneChatRoom *linphone_core_get_chat_room(LinphoneCore *lc, const LinphoneAd
|
|||
return ret;
|
||||
}
|
||||
|
||||
LinphoneChatRoom * linphone_core_create_client_group_chat_room(LinphoneCore *lc, bctbx_list_t *addresses) {
|
||||
const char *factoryUri = linphone_core_get_chat_conference_factory_uri(lc);
|
||||
if (!factoryUri)
|
||||
return nullptr;
|
||||
LinphoneChatRoom *cr = belle_sip_object_new(LinphoneChatRoom);
|
||||
LinphoneAddress *factoryAddr = linphone_address_new(factoryUri);
|
||||
LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(lc, factoryAddr);
|
||||
linphone_address_unref(factoryAddr);
|
||||
std::string from;
|
||||
if (proxy)
|
||||
from = L_GET_CPP_PTR_FROM_C_STRUCT(linphone_proxy_config_get_identity_address(proxy), Address, Address)->asString();
|
||||
if (from.empty())
|
||||
from = linphone_core_get_primary_contact(lc);
|
||||
LinphonePrivate::Address me(from);
|
||||
std::list<LinphonePrivate::Address> l = L_GET_CPP_LIST_OF_CPP_OBJ_FROM_C_LIST_OF_STRUCT_PTR(addresses, Address);
|
||||
cr->cr = new LinphonePrivate::ClientGroupChatRoom(lc, me, l);
|
||||
L_GET_PRIVATE(cr->cr)->setCBackPointer(cr);
|
||||
return cr;
|
||||
LinphoneChatRoom * linphone_core_create_client_group_chat_room(LinphoneCore *lc, const bctbx_list_t *addresses) {
|
||||
return linphone_client_group_chat_room_new(lc, addresses);
|
||||
}
|
||||
|
||||
void linphone_core_delete_chat_room(LinphoneCore *lc, LinphoneChatRoom *cr) {
|
||||
|
|
@ -290,48 +240,15 @@ LinphoneChatRoom *linphone_core_get_chat_room_from_uri(LinphoneCore *lc, const c
|
|||
return _linphone_core_get_or_create_chat_room(lc, to);
|
||||
}
|
||||
|
||||
void linphone_chat_room_destroy(LinphoneChatRoom *cr) {
|
||||
linphone_chat_room_unref(cr);
|
||||
}
|
||||
|
||||
void linphone_chat_room_release(LinphoneChatRoom *cr) {
|
||||
L_GET_PRIVATE(cr->cr)->release();
|
||||
}
|
||||
|
||||
LinphoneChatRoom *linphone_chat_room_ref(LinphoneChatRoom *cr) {
|
||||
belle_sip_object_ref(cr);
|
||||
return cr;
|
||||
}
|
||||
|
||||
void linphone_chat_room_unref(LinphoneChatRoom *cr) {
|
||||
belle_sip_object_unref(cr);
|
||||
}
|
||||
|
||||
void *linphone_chat_room_get_user_data(const LinphoneChatRoom *cr) {
|
||||
return cr->user_data;
|
||||
}
|
||||
|
||||
void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void *ud) {
|
||||
cr->user_data = ud;
|
||||
}
|
||||
|
||||
void linphone_chat_room_remove_transient_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
|
||||
L_GET_PRIVATE(cr->cr)->removeTransientMessage(msg);
|
||||
}
|
||||
|
||||
void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMessageState new_state) {
|
||||
linphone_chat_message_set_state(msg, new_state);
|
||||
linphone_chat_message_store_state(msg);
|
||||
|
||||
if (msg->state == LinphoneChatMessageStateDelivered || msg->state == LinphoneChatMessageStateNotDelivered) {
|
||||
L_GET_PRIVATE(msg->chat_room->cr)->moveTransientMessageToWeakMessages(msg);
|
||||
L_GET_PRIVATE_FROM_C_STRUCT(msg->chat_room, ChatRoom, ChatRoom)->moveTransientMessageToWeakMessages(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg) {
|
||||
cr->cr->sendMessage(cr->cr->createMessage(msg));
|
||||
}
|
||||
|
||||
void create_file_transfer_information_from_vnd_gsma_rcs_ft_http_xml(LinphoneChatMessage *msg) {
|
||||
xmlChar *file_url = NULL;
|
||||
xmlDocPtr xmlMessageBody;
|
||||
|
|
@ -415,76 +332,11 @@ 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 = L_GET_PRIVATE(cr->cr)->messageReceived(op, sal_msg);
|
||||
LinphoneReason reason = L_GET_PRIVATE_FROM_C_STRUCT(cr, ChatRoom, ChatRoom)->messageReceived(op, sal_msg);
|
||||
linphone_address_unref(addr);
|
||||
return reason;
|
||||
}
|
||||
|
||||
bool_t linphone_chat_room_is_remote_composing(const LinphoneChatRoom *cr) {
|
||||
return cr->cr->isRemoteComposing();
|
||||
}
|
||||
|
||||
LinphoneCore *linphone_chat_room_get_lc(const LinphoneChatRoom *cr) {
|
||||
return linphone_chat_room_get_core(cr);
|
||||
}
|
||||
|
||||
LinphoneCore *linphone_chat_room_get_core(const LinphoneChatRoom *cr) {
|
||||
return cr->cr->getCore();
|
||||
}
|
||||
|
||||
const LinphoneAddress *linphone_chat_room_get_peer_address(LinphoneChatRoom *cr) {
|
||||
if (cr->peerAddressCache) {
|
||||
linphone_address_unref(cr->peerAddressCache);
|
||||
}
|
||||
cr->peerAddressCache = linphone_address_new(cr->cr->getPeerAddress().asString().c_str());
|
||||
return cr->peerAddressCache;
|
||||
}
|
||||
|
||||
LinphoneChatMessage *linphone_chat_room_create_message(LinphoneChatRoom *cr, const char *message) {
|
||||
return cr->cr->createMessage(message ? message : "");
|
||||
}
|
||||
|
||||
LinphoneChatMessage *linphone_chat_room_create_message_2(LinphoneChatRoom *cr, const char *message,
|
||||
const char *external_body_url, LinphoneChatMessageState state,
|
||||
time_t time, bool_t is_read, bool_t is_incoming) {
|
||||
LinphoneChatMessage *msg = linphone_chat_room_create_message(cr, message);
|
||||
LinphoneCore *lc = linphone_chat_room_get_core(cr);
|
||||
msg->external_body_url = external_body_url ? ms_strdup(external_body_url) : NULL;
|
||||
msg->time = time;
|
||||
msg->is_secured = FALSE;
|
||||
linphone_chat_message_set_state(msg, state);
|
||||
if (is_incoming) {
|
||||
msg->dir = LinphoneChatMessageIncoming;
|
||||
linphone_chat_message_set_from(msg, linphone_chat_room_get_peer_address(cr));
|
||||
msg->to = linphone_address_new(linphone_core_get_identity(lc)); /*direct assignment*/
|
||||
} else {
|
||||
msg->dir = LinphoneChatMessageOutgoing;
|
||||
linphone_chat_message_set_to(msg, linphone_chat_room_get_peer_address(cr));
|
||||
msg->from = linphone_address_new(linphone_core_get_identity(lc));/*direct assignment*/
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage *msg,
|
||||
LinphoneChatMessageStateChangedCb status_cb, void *ud) {
|
||||
msg->message_state_changed_cb = status_cb;
|
||||
msg->message_state_changed_user_data = ud;
|
||||
cr->cr->sendMessage(msg);
|
||||
}
|
||||
|
||||
void linphone_chat_room_send_chat_message_2(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
|
||||
linphone_chat_message_ref(msg);
|
||||
cr->cr->sendMessage(msg);
|
||||
}
|
||||
|
||||
void linphone_chat_room_send_chat_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
|
||||
cr->cr->sendMessage(msg);
|
||||
}
|
||||
|
||||
LinphonePrivate::ChatRoom& linphone_chat_room_get_cpp_obj(LinphoneChatRoom *cr) {
|
||||
return *cr->cr;
|
||||
}
|
||||
|
||||
void _linphone_chat_message_resend(LinphoneChatMessage *msg, bool_t ref_msg) {
|
||||
LinphoneChatMessageState state = linphone_chat_message_get_state(msg);
|
||||
LinphoneChatRoom *cr;
|
||||
|
|
@ -496,7 +348,7 @@ void _linphone_chat_message_resend(LinphoneChatMessage *msg, bool_t ref_msg) {
|
|||
|
||||
cr = linphone_chat_message_get_chat_room(msg);
|
||||
if (ref_msg) linphone_chat_message_ref(msg);
|
||||
cr->cr->sendMessage(msg);
|
||||
L_GET_CPP_PTR_FROM_C_STRUCT(cr, ChatRoom, ChatRoom)->sendMessage(msg);
|
||||
}
|
||||
|
||||
void linphone_chat_message_resend(LinphoneChatMessage *msg) {
|
||||
|
|
@ -612,7 +464,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) {
|
||||
L_GET_PRIVATE(linphone_chat_message_get_chat_room(cm)->cr)->sendImdn(content, reason);
|
||||
L_GET_PRIVATE_FROM_C_STRUCT(linphone_chat_message_get_chat_room(cm), ChatRoom, ChatRoom)->sendImdn(content, reason);
|
||||
ms_free(content);
|
||||
}
|
||||
}
|
||||
|
|
@ -636,21 +488,21 @@ 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) {
|
||||
if (linphone_core_realtime_text_enabled(lc))
|
||||
L_GET_PRIVATE(static_cast<LinphonePrivate::RealTimeTextChatRoom *>(cr->cr))->realtimeTextReceived(character, call);
|
||||
}
|
||||
|
||||
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<LinphonePrivate::RealTimeTextChatRoom *>(cr->cr)->getChar();
|
||||
return 0;
|
||||
if (linphone_core_realtime_text_enabled(lc)) {
|
||||
std::shared_ptr<LinphonePrivate::RealTimeTextChatRoom> rttcr =
|
||||
std::static_pointer_cast<LinphonePrivate::RealTimeTextChatRoom>(L_GET_CPP_PTR_FROM_C_STRUCT(cr, ChatRoom, ChatRoom));
|
||||
L_GET_PRIVATE(rttcr)->realtimeTextReceived(character, call);
|
||||
//L_GET_PRIVATE(std::static_pointer_cast<LinphonePrivate::RealTimeTextChatRoom>(L_GET_CPP_PTR_FROM_C_STRUCT(cr, ChatRoom, ChatRoom)))->realtimeTextReceived(character, call);
|
||||
}
|
||||
}
|
||||
|
||||
LinphoneStatus linphone_chat_message_put_char(LinphoneChatMessage *msg, uint32_t character) {
|
||||
LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(msg);
|
||||
if (linphone_core_realtime_text_enabled(linphone_chat_room_get_core(cr))) {
|
||||
LinphoneCall *call = static_cast<LinphonePrivate::RealTimeTextChatRoom *>(cr->cr)->getCall();
|
||||
LinphoneCore *lc = static_cast<LinphonePrivate::RealTimeTextChatRoom *>(cr->cr)->getCore();
|
||||
std::shared_ptr<LinphonePrivate::RealTimeTextChatRoom> rttcr =
|
||||
std::static_pointer_cast<LinphonePrivate::RealTimeTextChatRoom>(L_GET_CPP_PTR_FROM_C_STRUCT(cr, ChatRoom, ChatRoom));
|
||||
LinphoneCall *call = rttcr->getCall();
|
||||
LinphoneCore *lc = rttcr->getCore();
|
||||
const uint32_t new_line = 0x2028;
|
||||
const uint32_t crlf = 0x0D0A;
|
||||
const uint32_t lf = 0x0A;
|
||||
|
|
@ -688,24 +540,6 @@ const char* linphone_chat_message_get_message_id(const LinphoneChatMessage *cm)
|
|||
return cm->message_id;
|
||||
}
|
||||
|
||||
void linphone_chat_room_compose(LinphoneChatRoom *cr) {
|
||||
cr->cr->compose();
|
||||
}
|
||||
|
||||
LinphoneCall *linphone_chat_room_get_call(const LinphoneChatRoom *room) {
|
||||
if (linphone_core_realtime_text_enabled(linphone_chat_room_get_core(room)))
|
||||
return static_cast<LinphonePrivate::RealTimeTextChatRoom *>(room->cr)->getCall();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void linphone_chat_room_set_call(LinphoneChatRoom *cr, LinphoneCall *call) {
|
||||
L_GET_PRIVATE(cr->cr)->setCall(call);
|
||||
}
|
||||
|
||||
bctbx_list_t * linphone_chat_room_get_transient_messages(const LinphoneChatRoom *cr) {
|
||||
return L_GET_C_LIST_FROM_CPP_LIST(L_GET_PRIVATE(cr->cr)->getTransientMessages(), LinphoneChatMessage);
|
||||
}
|
||||
|
||||
const char *linphone_chat_message_state_to_string(const LinphoneChatMessageState state) {
|
||||
switch (state) {
|
||||
case LinphoneChatMessageStateIdle:
|
||||
|
|
@ -814,10 +648,7 @@ const LinphoneAddress *linphone_chat_message_get_to_address(const LinphoneChatMe
|
|||
if (msg->to)
|
||||
return msg->to;
|
||||
if (msg->dir == LinphoneChatMessageOutgoing) {
|
||||
if (msg->chat_room->peerAddressCache)
|
||||
linphone_address_unref(msg->chat_room->peerAddressCache);
|
||||
msg->chat_room->peerAddressCache = linphone_address_new(msg->chat_room->cr->getPeerAddress().asString().c_str());
|
||||
return msg->chat_room->peerAddressCache;
|
||||
return linphone_chat_room_get_peer_address(msg->chat_room);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,10 +26,9 @@
|
|||
#include "private.h"
|
||||
#include "ortp/b64.h"
|
||||
|
||||
#include "c-wrapper/c-tools.h"
|
||||
#include "chat/chat-room.h"
|
||||
|
||||
extern LinphonePrivate::ChatRoom& linphone_chat_room_get_cpp_obj(LinphoneChatRoom *cr);
|
||||
|
||||
static bool_t file_transfer_in_progress_and_valid(LinphoneChatMessage* msg) {
|
||||
return (msg->chat_room && linphone_chat_room_get_core(msg->chat_room) && msg->http_request && !belle_http_request_is_cancelled(msg->http_request));
|
||||
}
|
||||
|
|
@ -342,7 +341,7 @@ static void linphone_chat_message_process_response_from_post_file(void *data, co
|
|||
linphone_chat_message_ref(msg);
|
||||
linphone_chat_message_set_state(msg, LinphoneChatMessageStateFileTransferDone);
|
||||
_release_http_request(msg);
|
||||
linphone_chat_room_get_cpp_obj(msg->chat_room).sendMessage(msg);
|
||||
L_GET_CPP_PTR_FROM_C_STRUCT(msg->chat_room, ChatRoom, ChatRoom)->sendMessage(msg);
|
||||
file_upload_end_background_task(msg);
|
||||
linphone_chat_message_unref(msg);
|
||||
} else {
|
||||
|
|
@ -658,5 +657,5 @@ const char *linphone_chat_message_get_file_transfer_filepath(LinphoneChatMessage
|
|||
}
|
||||
|
||||
LinphoneChatMessage *linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr, const LinphoneContent *initial_content) {
|
||||
return linphone_chat_room_get_cpp_obj(cr).createFileTransferMessage(initial_content);
|
||||
return L_GET_CPP_PTR_FROM_C_STRUCT(cr, ChatRoom, ChatRoom)->createFileTransferMessage(initial_content);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,9 +43,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include <assert.h>
|
||||
|
||||
|
||||
extern LinphonePrivate::ChatRoom& linphone_chat_room_get_cpp_obj(LinphoneChatRoom *cr);
|
||||
|
||||
|
||||
static char *utf8_convert(const char *filename){
|
||||
char db_file_utf8[MAX_PATH_SIZE] = "";
|
||||
#if defined(_WIN32)
|
||||
|
|
@ -316,46 +313,6 @@ void linphone_chat_message_store_appdata(LinphoneChatMessage* msg){
|
|||
}
|
||||
}
|
||||
|
||||
void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr) {
|
||||
linphone_chat_room_get_cpp_obj(cr).markAsRead();
|
||||
}
|
||||
|
||||
int linphone_chat_room_get_unread_messages_count(LinphoneChatRoom *cr) {
|
||||
return linphone_chat_room_get_cpp_obj(cr).getUnreadMessagesCount();
|
||||
}
|
||||
|
||||
int linphone_chat_room_get_history_size(LinphoneChatRoom *cr) {
|
||||
return linphone_chat_room_get_cpp_obj(cr).getHistorySize();
|
||||
}
|
||||
|
||||
void linphone_chat_room_delete_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
|
||||
linphone_chat_room_get_cpp_obj(cr).deleteMessage(msg);
|
||||
}
|
||||
|
||||
void linphone_chat_room_delete_history(LinphoneChatRoom *cr) {
|
||||
linphone_chat_room_get_cpp_obj(cr).deleteHistory();
|
||||
}
|
||||
|
||||
bctbx_list_t *linphone_chat_room_get_history_range(LinphoneChatRoom *cr, int startm, int endm) {
|
||||
std::list<LinphoneChatMessage *> l = linphone_chat_room_get_cpp_obj(cr).getHistoryRange(startm, endm);
|
||||
bctbx_list_t *result = nullptr;
|
||||
for (auto it = l.begin(); it != l.end(); it++)
|
||||
result = bctbx_list_append(result, *it);
|
||||
return result;
|
||||
}
|
||||
|
||||
bctbx_list_t *linphone_chat_room_get_history(LinphoneChatRoom *cr, int nb_message) {
|
||||
std::list<LinphoneChatMessage *> l = linphone_chat_room_get_cpp_obj(cr).getHistory(nb_message);
|
||||
bctbx_list_t *result = nullptr;
|
||||
for (auto it = l.begin(); it != l.end(); it++)
|
||||
result = bctbx_list_append(result, *it);
|
||||
return result;
|
||||
}
|
||||
|
||||
LinphoneChatMessage * linphone_chat_room_find_message(LinphoneChatRoom *cr, const char *message_id) {
|
||||
return linphone_chat_room_get_cpp_obj(cr).findMessage(message_id);
|
||||
}
|
||||
|
||||
static void linphone_create_history_table(sqlite3* db){
|
||||
char* errmsg=NULL;
|
||||
int ret;
|
||||
|
|
|
|||
|
|
@ -503,6 +503,8 @@ void _linphone_proxy_config_unregister(LinphoneProxyConfig *obj);
|
|||
void _linphone_proxy_config_release_ops(LinphoneProxyConfig *obj);
|
||||
|
||||
/*chat*/
|
||||
LinphoneChatRoom * linphone_chat_room_new(LinphoneCore *core, const LinphoneAddress *addr);
|
||||
LinphoneChatRoom * linphone_client_group_chat_room_new(LinphoneCore *lc, const bctbx_list_t *addresses);
|
||||
void linphone_chat_room_release(LinphoneChatRoom *cr);
|
||||
void linphone_chat_room_set_call(LinphoneChatRoom *cr, LinphoneCall *call);
|
||||
bctbx_list_t * linphone_chat_room_get_transient_messages(const LinphoneChatRoom *cr);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#define LINPHONE_CHAT_H_
|
||||
|
||||
|
||||
#include "linphone/callbacks.h"
|
||||
#include "linphone/types.h"
|
||||
|
||||
|
||||
|
|
@ -457,7 +458,7 @@ LINPHONE_PUBLIC void linphone_chat_message_set_user_data(LinphoneChatMessage* me
|
|||
**/
|
||||
LINPHONE_PUBLIC LinphoneChatRoom* linphone_chat_message_get_chat_room(LinphoneChatMessage *msg);
|
||||
|
||||
LINPHONE_PUBLIC LinphoneChatRoom * linphone_core_create_client_group_chat_room(LinphoneCore *lc, bctbx_list_t *addresses);
|
||||
LINPHONE_PUBLIC LinphoneChatRoom * linphone_core_create_client_group_chat_room(LinphoneCore *lc, const bctbx_list_t *addresses);
|
||||
|
||||
LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_message_get_peer_address(LinphoneChatMessage *msg);
|
||||
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
|
|||
address/address.cpp
|
||||
c-wrapper/api/c-address.cpp
|
||||
c-wrapper/api/c-call-params.cpp
|
||||
c-wrapper/api/c-chat-room.cpp
|
||||
c-wrapper/api/c-event-log.cpp
|
||||
call/call.cpp
|
||||
chat/basic-chat-room.cpp
|
||||
|
|
|
|||
|
|
@ -1,21 +1,20 @@
|
|||
/*
|
||||
linphone
|
||||
Copyright (C) 2010-2014 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 2
|
||||
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, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
* c-call-params.cpp
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "linphone/call_params.h"
|
||||
#include "private.h"
|
||||
|
|
|
|||
251
src/c-wrapper/api/c-chat-room.cpp
Normal file
251
src/c-wrapper/api/c-chat-room.cpp
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
/*
|
||||
* c-chat-room.cpp
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "linphone/chat.h"
|
||||
#include "linphone/wrapper_utils.h"
|
||||
#include "private.h"
|
||||
|
||||
#include "c-wrapper/c-tools.h"
|
||||
#include "chat/basic-chat-room.h"
|
||||
#include "chat/chat-room.h"
|
||||
#include "chat/chat-room-p.h"
|
||||
#include "chat/client-group-chat-room.h"
|
||||
#include "chat/real-time-text-chat-room.h"
|
||||
#include "chat/real-time-text-chat-room-p.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define GET_CPP_PTR(obj) L_GET_CPP_PTR_FROM_C_STRUCT(obj, ChatRoom, ChatRoom)
|
||||
#define GET_CPP_PRIVATE_PTR(obj) L_GET_PRIVATE_FROM_C_STRUCT(obj, ChatRoom, ChatRoom)
|
||||
|
||||
|
||||
static void _linphone_chat_room_constructor(LinphoneChatRoom *cr);
|
||||
static void _linphone_chat_room_destructor(LinphoneChatRoom *cr);
|
||||
|
||||
L_DECLARE_C_STRUCT_IMPL_WITH_XTORS(ChatRoom, ChatRoom, chat_room,
|
||||
_linphone_chat_room_constructor, _linphone_chat_room_destructor,
|
||||
LinphoneAddress *peerAddressCache;
|
||||
)
|
||||
|
||||
static void _linphone_chat_room_constructor(LinphoneChatRoom *cr) {}
|
||||
|
||||
static void _linphone_chat_room_destructor(LinphoneChatRoom *cr) {
|
||||
if (cr->peerAddressCache) {
|
||||
linphone_address_unref(cr->peerAddressCache);
|
||||
cr->peerAddressCache = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Public functions *
|
||||
******************************************************************************/
|
||||
|
||||
void linphone_chat_room_release(LinphoneChatRoom *cr) {
|
||||
GET_CPP_PRIVATE_PTR(cr)->release();
|
||||
}
|
||||
|
||||
void linphone_chat_room_remove_transient_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
|
||||
GET_CPP_PRIVATE_PTR(cr)->removeTransientMessage(msg);
|
||||
}
|
||||
|
||||
void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg) {
|
||||
GET_CPP_PTR(cr)->sendMessage(GET_CPP_PTR(cr)->createMessage(msg));
|
||||
}
|
||||
|
||||
bool_t linphone_chat_room_is_remote_composing(const LinphoneChatRoom *cr) {
|
||||
return GET_CPP_PTR(cr)->isRemoteComposing();
|
||||
}
|
||||
|
||||
LinphoneCore *linphone_chat_room_get_lc(const LinphoneChatRoom *cr) {
|
||||
return linphone_chat_room_get_core(cr);
|
||||
}
|
||||
|
||||
LinphoneCore *linphone_chat_room_get_core(const LinphoneChatRoom *cr) {
|
||||
return GET_CPP_PTR(cr)->getCore();
|
||||
}
|
||||
|
||||
const LinphoneAddress *linphone_chat_room_get_peer_address(LinphoneChatRoom *cr) {
|
||||
if (cr->peerAddressCache) {
|
||||
linphone_address_unref(cr->peerAddressCache);
|
||||
}
|
||||
cr->peerAddressCache = linphone_address_new(GET_CPP_PTR(cr)->getPeerAddress().asString().c_str());
|
||||
return cr->peerAddressCache;
|
||||
}
|
||||
|
||||
LinphoneChatMessage *linphone_chat_room_create_message(LinphoneChatRoom *cr, const char *message) {
|
||||
return GET_CPP_PTR(cr)->createMessage(message ? message : "");
|
||||
}
|
||||
|
||||
LinphoneChatMessage *linphone_chat_room_create_message_2(LinphoneChatRoom *cr, const char *message,
|
||||
const char *external_body_url, LinphoneChatMessageState state,
|
||||
time_t time, bool_t is_read, bool_t is_incoming) {
|
||||
LinphoneChatMessage *msg = linphone_chat_room_create_message(cr, message);
|
||||
LinphoneCore *lc = linphone_chat_room_get_core(cr);
|
||||
msg->external_body_url = external_body_url ? ms_strdup(external_body_url) : NULL;
|
||||
msg->time = time;
|
||||
msg->is_secured = FALSE;
|
||||
linphone_chat_message_set_state(msg, state);
|
||||
if (is_incoming) {
|
||||
msg->dir = LinphoneChatMessageIncoming;
|
||||
linphone_chat_message_set_from(msg, linphone_chat_room_get_peer_address(cr));
|
||||
msg->to = linphone_address_new(linphone_core_get_identity(lc)); /*direct assignment*/
|
||||
} else {
|
||||
msg->dir = LinphoneChatMessageOutgoing;
|
||||
linphone_chat_message_set_to(msg, linphone_chat_room_get_peer_address(cr));
|
||||
msg->from = linphone_address_new(linphone_core_get_identity(lc));/*direct assignment*/
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage *msg,
|
||||
LinphoneChatMessageStateChangedCb status_cb, void *ud) {
|
||||
msg->message_state_changed_cb = status_cb;
|
||||
msg->message_state_changed_user_data = ud;
|
||||
GET_CPP_PTR(cr)->sendMessage(msg);
|
||||
}
|
||||
|
||||
void linphone_chat_room_send_chat_message_2(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
|
||||
linphone_chat_message_ref(msg);
|
||||
GET_CPP_PTR(cr)->sendMessage(msg);
|
||||
}
|
||||
|
||||
void linphone_chat_room_send_chat_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
|
||||
GET_CPP_PTR(cr)->sendMessage(msg);
|
||||
}
|
||||
|
||||
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 *>(GET_CPP_PTR(cr).get())->getChar();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void linphone_chat_room_compose(LinphoneChatRoom *cr) {
|
||||
GET_CPP_PTR(cr)->compose();
|
||||
}
|
||||
|
||||
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 *>(GET_CPP_PTR(cr).get())->getCall();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void linphone_chat_room_set_call(LinphoneChatRoom *cr, LinphoneCall *call) {
|
||||
if (linphone_core_realtime_text_enabled(linphone_chat_room_get_core(cr)))
|
||||
static_cast<LinphonePrivate::RealTimeTextChatRoomPrivate *>(GET_CPP_PRIVATE_PTR(cr))->setCall(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);
|
||||
}
|
||||
|
||||
void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr) {
|
||||
GET_CPP_PTR(cr)->markAsRead();
|
||||
}
|
||||
|
||||
int linphone_chat_room_get_unread_messages_count(LinphoneChatRoom *cr) {
|
||||
return GET_CPP_PTR(cr)->getUnreadMessagesCount();
|
||||
}
|
||||
|
||||
int linphone_chat_room_get_history_size(LinphoneChatRoom *cr) {
|
||||
return GET_CPP_PTR(cr)->getHistorySize();
|
||||
}
|
||||
|
||||
void linphone_chat_room_delete_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg) {
|
||||
GET_CPP_PTR(cr)->deleteMessage(msg);
|
||||
}
|
||||
|
||||
void linphone_chat_room_delete_history(LinphoneChatRoom *cr) {
|
||||
GET_CPP_PTR(cr)->deleteHistory();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
LinphoneChatMessage * linphone_chat_room_find_message(LinphoneChatRoom *cr, const char *message_id) {
|
||||
return GET_CPP_PTR(cr)->findMessage(message_id);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Reference and user data handling functions *
|
||||
******************************************************************************/
|
||||
|
||||
LinphoneChatRoom *linphone_chat_room_ref(LinphoneChatRoom *cr) {
|
||||
belle_sip_object_ref(cr);
|
||||
return cr;
|
||||
}
|
||||
|
||||
void linphone_chat_room_unref(LinphoneChatRoom *cr) {
|
||||
belle_sip_object_unref(cr);
|
||||
}
|
||||
|
||||
void *linphone_chat_room_get_user_data(const LinphoneChatRoom *cr) {
|
||||
// TODO
|
||||
return nullptr;
|
||||
//return cr->userData;
|
||||
}
|
||||
|
||||
void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void *ud) {
|
||||
// TODO
|
||||
//cr->userData = ud;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Constructor and destructor functions *
|
||||
******************************************************************************/
|
||||
|
||||
LinphoneChatRoom * linphone_chat_room_new(LinphoneCore *core, const LinphoneAddress *addr) {
|
||||
LinphoneChatRoom *cr = _linphone_chat_room_init();
|
||||
if (linphone_core_realtime_text_enabled(core))
|
||||
L_SET_CPP_PTR_FROM_C_STRUCT(cr, std::make_shared<LinphonePrivate::RealTimeTextChatRoom>(core, *L_GET_CPP_PTR_FROM_C_STRUCT(addr, Address, Address)));
|
||||
else
|
||||
L_SET_CPP_PTR_FROM_C_STRUCT(cr, std::make_shared<LinphonePrivate::BasicChatRoom>(core, *L_GET_CPP_PTR_FROM_C_STRUCT(addr, Address, Address)));
|
||||
return cr;
|
||||
}
|
||||
|
||||
LinphoneChatRoom * linphone_client_group_chat_room_new(LinphoneCore *lc, const bctbx_list_t *addresses) {
|
||||
const char *factoryUri = linphone_core_get_chat_conference_factory_uri(lc);
|
||||
if (!factoryUri)
|
||||
return nullptr;
|
||||
LinphoneAddress *factoryAddr = linphone_address_new(factoryUri);
|
||||
LinphoneProxyConfig *proxy = linphone_core_lookup_known_proxy(lc, factoryAddr);
|
||||
linphone_address_unref(factoryAddr);
|
||||
std::string from;
|
||||
if (proxy)
|
||||
from = L_GET_CPP_PTR_FROM_C_STRUCT(linphone_proxy_config_get_identity_address(proxy), Address, Address)->asString();
|
||||
if (from.empty())
|
||||
from = linphone_core_get_primary_contact(lc);
|
||||
LinphonePrivate::Address me(from);
|
||||
std::list<LinphonePrivate::Address> l = L_GET_CPP_LIST_OF_CPP_OBJ_FROM_C_LIST_OF_STRUCT_PTR(addresses, Address);
|
||||
LinphoneChatRoom *cr = _linphone_chat_room_init();
|
||||
L_SET_CPP_PTR_FROM_C_STRUCT(cr, make_shared<LinphonePrivate::ClientGroupChatRoom>(lc, me, l));
|
||||
return cr;
|
||||
}
|
||||
|
||||
/* DEPRECATED */
|
||||
void linphone_chat_room_destroy(LinphoneChatRoom *cr) {
|
||||
linphone_chat_room_unref(cr);
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ using namespace std;
|
|||
// Event log.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
L_DECLARE_C_STRUCT_IMPL(EventLog, event_log);
|
||||
L_DECLARE_C_STRUCT_IMPL(EventLog, EventLog, event_log);
|
||||
L_DECLARE_C_STRUCT_NEW_DEFAULT(EventLog, event_log);
|
||||
|
||||
LinphoneEventLogType linphone_event_log_get_type (const LinphoneEventLog *eventLog) {
|
||||
|
|
@ -43,7 +43,7 @@ LinphoneEventLogType linphone_event_log_get_type (const LinphoneEventLog *eventL
|
|||
// Message event.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
L_DECLARE_C_STRUCT_IMPL(MessageEvent, message_event);
|
||||
L_DECLARE_C_STRUCT_IMPL(MessageEvent, MessageEvent, message_event);
|
||||
|
||||
LinphoneMessageEvent *linphone_message_event_new (LinphoneMessage *message) {
|
||||
LinphoneMessageEvent *object = _linphone_message_event_init();
|
||||
|
|
|
|||
|
|
@ -50,7 +50,14 @@ public:
|
|||
template<typename T>
|
||||
static inline decltype (std::declval<T>().getPrivate()) getPrivate (T *object) {
|
||||
if (!object)
|
||||
return nullptr;
|
||||
return nullptr;
|
||||
return object->getPrivate();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static inline decltype (std::declval<T>().getPrivate()) getPrivate (const std::shared_ptr<T> &object) {
|
||||
if (!object)
|
||||
return nullptr;
|
||||
return object->getPrivate();
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +68,8 @@ public:
|
|||
template<
|
||||
typename CppType,
|
||||
typename CType,
|
||||
typename std::enable_if<std::is_base_of<Object, CppType>::value>::type = 0
|
||||
typename = typename std::enable_if<std::is_base_of<Object, CppType>::value, CppType>::type
|
||||
//typename std::enable_if<std::is_base_of<Object, CppType>::value, CppType>::type = 0
|
||||
>
|
||||
static inline std::shared_ptr<CppType> getCppPtrFromC (CType *object) {
|
||||
L_ASSERT(object);
|
||||
|
|
@ -71,7 +79,8 @@ public:
|
|||
template<
|
||||
typename CppType,
|
||||
typename CType,
|
||||
typename std::enable_if<std::is_base_of<Object, CppType>::value, CppType>::type = 0
|
||||
typename = typename std::enable_if<std::is_base_of<Object, CppType>::value, CppType>::type
|
||||
//typename std::enable_if<std::is_base_of<Object, CppType>::value, CppType>::type = 0
|
||||
>
|
||||
static inline std::shared_ptr<const CppType> getCppPtrFromC (const CType *object) {
|
||||
L_ASSERT(object);
|
||||
|
|
@ -160,7 +169,7 @@ public:
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
static inline std::list<T> getCppListFromCList (bctbx_list_t *cList) {
|
||||
static inline std::list<T> getCppListFromCList (const bctbx_list_t *cList) {
|
||||
std::list<T> result;
|
||||
for (auto it = cList; it; it = bctbx_list_next(it))
|
||||
result.push_back(static_cast<T>(bctbx_list_get_data(it)));
|
||||
|
|
@ -168,7 +177,7 @@ public:
|
|||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
static inline std::list<T> getCppListOfCppObjFromCListOfStructPtr (bctbx_list_t *cList) {
|
||||
static inline std::list<T> getCppListOfCppObjFromCListOfStructPtr (const bctbx_list_t *cList) {
|
||||
std::list<T> result;
|
||||
for (auto it = cList; it; it = bctbx_list_next(it))
|
||||
result.push_back(*getCppPtrFromC<T>(reinterpret_cast<U *>(bctbx_list_get_data(it))));
|
||||
|
|
@ -185,29 +194,50 @@ LINPHONE_END_NAMESPACE
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define L_DECLARE_C_STRUCT_IMPL(STRUCT, C_NAME, ...) \
|
||||
struct _Linphone ## STRUCT { \
|
||||
#define L_DECLARE_C_STRUCT_IMPL_WITH_XTORS(CPP_CLASS, C_STRUCT, C_NAME, CONSTRUCTOR, DESTRUCTOR, ...) \
|
||||
struct _Linphone ## C_STRUCT { \
|
||||
belle_sip_object_t base; \
|
||||
std::shared_ptr<LINPHONE_NAMESPACE::STRUCT> cppPtr; \
|
||||
std::shared_ptr<LINPHONE_NAMESPACE::CPP_CLASS> cppPtr; \
|
||||
__VA_ARGS__ \
|
||||
}; \
|
||||
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(Linphone ## STRUCT); \
|
||||
static Linphone ## STRUCT *_linphone_ ## C_NAME ## _init() { \
|
||||
Linphone ## STRUCT * object = belle_sip_object_new(Linphone ## STRUCT); \
|
||||
new(&object->cppPtr) std::shared_ptr<LINPHONE_NAMESPACE::STRUCT>(); \
|
||||
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(Linphone ## C_STRUCT); \
|
||||
Linphone ## C_STRUCT *_linphone_ ## C_NAME ## _init() { \
|
||||
Linphone ## C_STRUCT * object = belle_sip_object_new(Linphone ## C_STRUCT); \
|
||||
new(&object->cppPtr) std::shared_ptr<LINPHONE_NAMESPACE::CPP_CLASS>(); \
|
||||
CONSTRUCTOR(object); \
|
||||
return object; \
|
||||
} \
|
||||
static void _linphone_ ## C_NAME ## _uninit(Linphone ## STRUCT * object) { \
|
||||
void _linphone_ ## C_NAME ## _uninit(Linphone ## C_STRUCT * object) { \
|
||||
DESTRUCTOR(object); \
|
||||
object->cppPtr.~shared_ptr (); \
|
||||
} \
|
||||
static void _linphone_ ## C_NAME ## _clone(Linphone ## STRUCT * dest, const Linphone ## STRUCT * src) { \
|
||||
new(&dest->cppPtr) std::shared_ptr<LINPHONE_NAMESPACE::STRUCT>(); \
|
||||
dest->cppPtr = std::make_shared<LINPHONE_NAMESPACE::STRUCT>(*src->cppPtr.get()); \
|
||||
} \
|
||||
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(Linphone ## STRUCT); \
|
||||
BELLE_SIP_INSTANCIATE_VPTR(Linphone ## STRUCT, belle_sip_object_t, \
|
||||
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(Linphone ## C_STRUCT); \
|
||||
BELLE_SIP_INSTANCIATE_VPTR(Linphone ## C_STRUCT, belle_sip_object_t, \
|
||||
_linphone_ ## C_NAME ## _uninit, \
|
||||
_linphone_ ## C_NAME ## _clone, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
FALSE \
|
||||
);
|
||||
|
||||
#define L_DECLARE_C_STRUCT_IMPL(CPP_CLASS, C_STRUCT, C_NAME, ...) \
|
||||
struct _Linphone ## C_STRUCT { \
|
||||
belle_sip_object_t base; \
|
||||
std::shared_ptr<LINPHONE_NAMESPACE::CPP_CLASS> cppPtr; \
|
||||
__VA_ARGS__ \
|
||||
}; \
|
||||
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(Linphone ## C_STRUCT); \
|
||||
Linphone ## C_STRUCT *_linphone_ ## C_NAME ## _init() { \
|
||||
Linphone ## C_STRUCT * object = belle_sip_object_new(Linphone ## C_STRUCT); \
|
||||
new(&object->cppPtr) std::shared_ptr<LINPHONE_NAMESPACE::CPP_CLASS>(); \
|
||||
return object; \
|
||||
} \
|
||||
void _linphone_ ## C_NAME ## _uninit(Linphone ## C_STRUCT * object) { \
|
||||
object->cppPtr.~shared_ptr (); \
|
||||
} \
|
||||
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(Linphone ## C_STRUCT); \
|
||||
BELLE_SIP_INSTANCIATE_VPTR(Linphone ## C_STRUCT, belle_sip_object_t, \
|
||||
_linphone_ ## C_NAME ## _uninit, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
FALSE \
|
||||
);
|
||||
|
|
@ -220,13 +250,13 @@ LINPHONE_END_NAMESPACE
|
|||
__VA_ARGS__ \
|
||||
}; \
|
||||
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(Linphone ## C_STRUCT); \
|
||||
static Linphone ## C_STRUCT *_linphone_ ## C_NAME ## _init() { \
|
||||
Linphone ## C_STRUCT *_linphone_ ## C_NAME ## _init() { \
|
||||
return belle_sip_object_new(Linphone ## C_STRUCT); \
|
||||
} \
|
||||
static void _linphone_ ## C_NAME ## _uninit(Linphone ## C_STRUCT * object) { \
|
||||
void _linphone_ ## C_NAME ## _uninit(Linphone ## C_STRUCT * object) { \
|
||||
delete object->cppPtr; \
|
||||
} \
|
||||
static void _linphone_ ## C_NAME ## _clone(Linphone ## C_STRUCT * dest, const Linphone ## C_STRUCT * src) { \
|
||||
void _linphone_ ## C_NAME ## _clone(Linphone ## C_STRUCT * dest, const Linphone ## C_STRUCT * src) { \
|
||||
L_ASSERT(src->cppPtr); \
|
||||
dest->cppPtr = new LINPHONE_NAMESPACE::CPP_CLASS(*src->cppPtr); \
|
||||
} \
|
||||
|
|
|
|||
|
|
@ -54,13 +54,6 @@ public:
|
|||
void sendImdn (const std::string &content, LinphoneReason reason);
|
||||
|
||||
int getMessagesCount (bool unreadOnly);
|
||||
void setCBackPointer (LinphoneChatRoom *cr) {
|
||||
this->cBackPointer = cr;
|
||||
}
|
||||
|
||||
void setCall (LinphoneCall *call) {
|
||||
this->call = call;
|
||||
}
|
||||
|
||||
protected:
|
||||
void sendIsComposingNotification ();
|
||||
|
|
@ -90,7 +83,6 @@ private:
|
|||
void onIsComposingRefreshNeeded ();
|
||||
|
||||
public:
|
||||
LinphoneChatRoom *cBackPointer = nullptr;
|
||||
LinphoneCore *core = nullptr;
|
||||
LinphoneCall *call = nullptr;
|
||||
Address peerAddress;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@
|
|||
|
||||
#include "chat-room.h"
|
||||
|
||||
extern LinphoneChatRoom * _linphone_chat_room_init();
|
||||
#define GET_BACK_PTR(object) L_GET_C_BACK_PTR(object->shared_from_this(), ChatRoom, chat_room)
|
||||
|
||||
// =============================================================================
|
||||
|
||||
using namespace std;
|
||||
|
|
@ -38,15 +41,16 @@ ChatRoomPrivate::ChatRoomPrivate (LinphoneCore *core)
|
|||
: core(core), isComposingHandler(core, this) {}
|
||||
|
||||
ChatRoomPrivate::~ChatRoomPrivate () {
|
||||
L_Q(ChatRoom);
|
||||
for (auto it = transientMessages.begin(); it != transientMessages.end(); it++) {
|
||||
linphone_chat_message_release(*it);
|
||||
}
|
||||
if (core) {
|
||||
if (bctbx_list_find(core->chatrooms, cBackPointer)) {
|
||||
lError() << "LinphoneChatRoom[" << cBackPointer << "] is destroyed while still being used by the LinphoneCore. " <<
|
||||
if (bctbx_list_find(core->chatrooms, GET_BACK_PTR(q))) {
|
||||
lError() << "LinphoneChatRoom[" << GET_BACK_PTR(q) << "] is destroyed while still being used by the LinphoneCore. " <<
|
||||
"This is abnormal. linphone_core_get_chat_room() doesn't give a reference, there is no need to call linphone_chat_room_unref(). " <<
|
||||
"In order to remove a chat room from the core, use linphone_core_delete_chat_room().";
|
||||
core->chatrooms = bctbx_list_remove(core->chatrooms, cBackPointer);
|
||||
core->chatrooms = bctbx_list_remove(core->chatrooms, GET_BACK_PTR(q));
|
||||
}
|
||||
}
|
||||
if (pendingMessage)
|
||||
|
|
@ -101,6 +105,7 @@ void ChatRoomPrivate::removeTransientMessage (LinphoneChatMessage *msg) {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ChatRoomPrivate::release () {
|
||||
L_Q(ChatRoom);
|
||||
isComposingHandler.stopTimers();
|
||||
for (auto it = weakMessages.begin(); it != weakMessages.end(); it++) {
|
||||
linphone_chat_message_deactivate(*it);
|
||||
|
|
@ -109,7 +114,7 @@ void ChatRoomPrivate::release () {
|
|||
linphone_chat_message_deactivate(*it);
|
||||
}
|
||||
core = nullptr;
|
||||
linphone_chat_room_unref(cBackPointer);
|
||||
linphone_chat_room_unref(GET_BACK_PTR(q));
|
||||
}
|
||||
|
||||
void ChatRoomPrivate::sendImdn (const string &content, LinphoneReason reason) {
|
||||
|
|
@ -140,7 +145,7 @@ void ChatRoomPrivate::sendImdn (const string &content, LinphoneReason reason) {
|
|||
LinphoneImEncryptionEngineCbs *imeeCbs = linphone_im_encryption_engine_get_callbacks(imee);
|
||||
LinphoneImEncryptionEngineCbsOutgoingMessageCb cbProcessOutgoingMessage = linphone_im_encryption_engine_cbs_get_process_outgoing_message(imeeCbs);
|
||||
if (cbProcessOutgoingMessage) {
|
||||
retval = cbProcessOutgoingMessage(imee, cBackPointer, msg);
|
||||
retval = cbProcessOutgoingMessage(imee, GET_BACK_PTR(q), msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +224,7 @@ void ChatRoomPrivate::sendIsComposingNotification () {
|
|||
LinphoneImEncryptionEngineCbs *imeeCbs = linphone_im_encryption_engine_get_callbacks(imee);
|
||||
LinphoneImEncryptionEngineCbsOutgoingMessageCb cbProcessOutgoingMessage = linphone_im_encryption_engine_cbs_get_process_outgoing_message(imeeCbs);
|
||||
if (cbProcessOutgoingMessage) {
|
||||
retval = cbProcessOutgoingMessage(imee, cBackPointer, msg);
|
||||
retval = cbProcessOutgoingMessage(imee, GET_BACK_PTR(q), msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -424,12 +429,12 @@ LinphoneReason ChatRoomPrivate::messageReceived (SalOp *op, const SalMessage *sa
|
|||
LinphoneImEncryptionEngineCbs *imeeCbs = linphone_im_encryption_engine_get_callbacks(imee);
|
||||
LinphoneImEncryptionEngineCbsIncomingMessageCb cbProcessIncomingMessage = linphone_im_encryption_engine_cbs_get_process_incoming_message(imeeCbs);
|
||||
if (cbProcessIncomingMessage) {
|
||||
retval = cbProcessIncomingMessage(imee, cBackPointer, msg);
|
||||
retval = cbProcessIncomingMessage(imee, GET_BACK_PTR(q), msg);
|
||||
if (retval == 0) {
|
||||
msg->is_secured = TRUE;
|
||||
} else if (retval > 0) {
|
||||
/* Unable to decrypt message */
|
||||
linphone_core_notify_message_received_unable_decrypt(core, cBackPointer, msg);
|
||||
linphone_core_notify_message_received_unable_decrypt(core, GET_BACK_PTR(q), msg);
|
||||
reason = linphone_error_code_to_reason(retval);
|
||||
linphone_chat_message_send_delivery_notification(msg, reason);
|
||||
/* Return LinphoneReasonNone to avoid flexisip resending us a message we can't decrypt */
|
||||
|
|
@ -499,14 +504,15 @@ end:
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ChatRoomPrivate::chatMessageReceived (LinphoneChatMessage *msg) {
|
||||
L_Q(ChatRoom);
|
||||
if (msg->message) {
|
||||
/* Legacy API */
|
||||
linphone_core_notify_text_message_received(core, cBackPointer, msg->from, msg->message);
|
||||
linphone_core_notify_text_message_received(core, GET_BACK_PTR(q), msg->from, msg->message);
|
||||
}
|
||||
linphone_core_notify_message_received(core, cBackPointer, msg);
|
||||
linphone_core_notify_message_received(core, GET_BACK_PTR(q), msg);
|
||||
if (!ContentType::isImdn(msg->content_type) && !ContentType::isImIsComposing(msg->content_type)) {
|
||||
remoteIsComposing = false;
|
||||
linphone_core_notify_is_composing_received(core, cBackPointer);
|
||||
linphone_core_notify_is_composing_received(core, GET_BACK_PTR(q));
|
||||
linphone_chat_message_send_delivery_notification(msg, LinphoneReasonNone);
|
||||
}
|
||||
}
|
||||
|
|
@ -528,8 +534,9 @@ void ChatRoomPrivate::onIsComposingStateChanged (bool isComposing) {
|
|||
}
|
||||
|
||||
void ChatRoomPrivate::onIsRemoteComposingStateChanged (bool isComposing) {
|
||||
L_Q(ChatRoom);
|
||||
remoteIsComposing = isComposing;
|
||||
linphone_core_notify_is_composing_received(core, cBackPointer);
|
||||
linphone_core_notify_is_composing_received(core, GET_BACK_PTR(q));
|
||||
}
|
||||
|
||||
void ChatRoomPrivate::onIsComposingRefreshNeeded () {
|
||||
|
|
@ -558,7 +565,7 @@ LinphoneChatMessage *ChatRoom::createFileTransferMessage (const LinphoneContent
|
|||
L_D(ChatRoom);
|
||||
LinphoneChatMessage *cm = belle_sip_object_new(LinphoneChatMessage);
|
||||
cm->callbacks = linphone_chat_message_cbs_new();
|
||||
cm->chat_room = d->cBackPointer;
|
||||
cm->chat_room = GET_BACK_PTR(this);
|
||||
cm->message = nullptr;
|
||||
cm->file_transfer_information = linphone_content_copy(initialContent);
|
||||
cm->dir = LinphoneChatMessageOutgoing;
|
||||
|
|
@ -575,11 +582,10 @@ LinphoneChatMessage *ChatRoom::createFileTransferMessage (const LinphoneContent
|
|||
}
|
||||
|
||||
LinphoneChatMessage *ChatRoom::createMessage (const string &msg) {
|
||||
L_D(ChatRoom);
|
||||
LinphoneChatMessage *cm = belle_sip_object_new(LinphoneChatMessage);
|
||||
cm->state = LinphoneChatMessageStateIdle;
|
||||
cm->callbacks = linphone_chat_message_cbs_new();
|
||||
cm->chat_room = d->cBackPointer;
|
||||
cm->chat_room = GET_BACK_PTR(this);
|
||||
cm->message = msg.empty() ? nullptr : ms_strdup(msg.c_str());
|
||||
cm->content_type = ms_strdup("text/plain");
|
||||
cm->file_transfer_information = nullptr; /* this property is used only when transfering file */
|
||||
|
|
@ -817,7 +823,7 @@ void ChatRoom::sendMessage (LinphoneChatMessage *msg) {
|
|||
LinphoneImEncryptionEngineCbs *imeeCbs = linphone_im_encryption_engine_get_callbacks(imee);
|
||||
LinphoneImEncryptionEngineCbsOutgoingMessageCb cbProcessOutgoingMessage = linphone_im_encryption_engine_cbs_get_process_outgoing_message(imeeCbs);
|
||||
if (cbProcessOutgoingMessage) {
|
||||
retval = cbProcessOutgoingMessage(imee, d->cBackPointer, msg);
|
||||
retval = cbProcessOutgoingMessage(imee, GET_BACK_PTR(this), msg);
|
||||
if (retval == 0) {
|
||||
msg->is_secured = TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,12 @@
|
|||
#include "linphone/utils/utils.h"
|
||||
|
||||
#include "real-time-text-chat-room-p.h"
|
||||
#include "c-wrapper/c-tools.h"
|
||||
#include "logger/logger.h"
|
||||
|
||||
extern LinphoneChatRoom * _linphone_chat_room_init();
|
||||
#define GET_BACK_PTR(object) L_GET_C_BACK_PTR(object->shared_from_this(), ChatRoom, chat_room)
|
||||
|
||||
// =============================================================================
|
||||
|
||||
using namespace std;
|
||||
|
|
@ -62,7 +66,7 @@ void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, Linp
|
|||
receivedRttCharacters.push_back(cmc);
|
||||
|
||||
remoteIsComposing = true;
|
||||
linphone_core_notify_is_composing_received(core, cBackPointer);
|
||||
linphone_core_notify_is_composing_received(core, GET_BACK_PTR(q));
|
||||
|
||||
if ((character == new_line) || (character == crlf) || (character == lf)) {
|
||||
/* End of message */
|
||||
|
|
|
|||
|
|
@ -881,7 +881,7 @@ void CallSession::startIncomingNotification () {
|
|||
if (d->listener)
|
||||
d->listener->onCallSessionAccepted(*this);
|
||||
/* Prevent the CallSession from being destroyed while we are notifying, if the user declines within the state callback */
|
||||
shared_ptr<CallSession> ref = shared_from_this();
|
||||
shared_ptr<CallSession> ref = static_pointer_cast<CallSession>(shared_from_this());
|
||||
#if 0
|
||||
call->bg_task_id=sal_begin_background_task("liblinphone call notification", NULL, NULL);
|
||||
#endif
|
||||
|
|
@ -937,7 +937,7 @@ int CallSession::startInvite (const Address *destination) {
|
|||
linphone_core_notify_display_status(d->core, os.str().c_str());
|
||||
char *from = linphone_address_as_string(d->log->from);
|
||||
/* Take a ref because sal_call() may destroy the CallSession if no SIP transport is available */
|
||||
shared_ptr<CallSession> ref = shared_from_this();
|
||||
shared_ptr<CallSession> ref = static_pointer_cast<CallSession>(shared_from_this());
|
||||
int result = sal_call(d->op, from, destinationStr.c_str());
|
||||
ms_free(from);
|
||||
if (result < 0) {
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@
|
|||
#ifndef _CALL_SESSION_H_
|
||||
#define _CALL_SESSION_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "object/object.h"
|
||||
#include "address/address.h"
|
||||
#include "conference/conference.h"
|
||||
|
|
@ -34,7 +32,7 @@ LINPHONE_BEGIN_NAMESPACE
|
|||
class CallPrivate;
|
||||
class CallSessionPrivate;
|
||||
|
||||
class CallSession : public Object, public std::enable_shared_from_this<CallSession> {
|
||||
class CallSession : public Object {
|
||||
friend class CallPrivate;
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -626,7 +626,7 @@ float MediaSessionPrivate::aggregateQualityRatings (float audioRating, float vid
|
|||
void MediaSessionPrivate::setState (LinphoneCallState newState, const string &message) {
|
||||
L_Q(MediaSession);
|
||||
/* Take a ref on the session otherwise it might get destroyed during the call to setState */
|
||||
shared_ptr<CallSession> session = q->shared_from_this();
|
||||
shared_ptr<CallSession> session = static_pointer_cast<CallSession>(q->shared_from_this());
|
||||
CallSessionPrivate::setState(newState, message);
|
||||
updateReportingCallState();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
#ifndef _OBJECT_H_
|
||||
#define _OBJECT_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "linphone/utils/general.h"
|
||||
|
||||
#include "property-container.h"
|
||||
|
|
@ -27,7 +29,8 @@
|
|||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class LINPHONE_PUBLIC Object : public PropertyContainer {
|
||||
class LINPHONE_PUBLIC Object : public std::enable_shared_from_this<Object>, public PropertyContainer {
|
||||
|
||||
public:
|
||||
virtual ~Object ();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue