Commit 5e3ff318 authored by Simon Morlat's avatar Simon Morlat

add ref count to LinphoneChatMessage

parent 643d3963
......@@ -32,6 +32,18 @@
#define COMPOSING_DEFAULT_REFRESH_TIMEOUT 60
#define COMPOSING_DEFAULT_REMOTE_REFRESH_TIMEOUT 120
static void _linphone_chat_message_destroy(LinphoneChatMessage* msg);
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneChatMessage);
BELLE_SIP_INSTANCIATE_VPTR(LinphoneChatMessage,belle_sip_object_t,
(belle_sip_object_destroy_t)_linphone_chat_message_destroy,
NULL, // clone
NULL, // marshal
FALSE
);
/**
* @addtogroup chatroom
* @{
......@@ -406,7 +418,7 @@ const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr)
* @return a new #LinphoneChatMessage
*/
LinphoneChatMessage* linphone_chat_room_create_message(LinphoneChatRoom *cr, const char* message) {
LinphoneChatMessage* msg = ms_new0(LinphoneChatMessage,1);
LinphoneChatMessage* msg = belle_sip_object_new(LinphoneChatMessage);
msg->chat_room=(LinphoneChatRoom*)cr;
msg->message=message?ms_strdup(message):NULL;
msg->is_read=TRUE;
......@@ -429,7 +441,7 @@ LinphoneChatMessage* linphone_chat_room_create_message_2(
LinphoneChatMessageState state, time_t time, bool_t is_read, bool_t is_incoming) {
LinphoneCore *lc=linphone_chat_room_get_lc(cr);
LinphoneChatMessage* msg = ms_new0(LinphoneChatMessage,1);
LinphoneChatMessage* msg = belle_sip_object_new(LinphoneChatMessage);
msg->chat_room=(LinphoneChatRoom*)cr;
msg->message=message?ms_strdup(message):NULL;
msg->external_body_url=external_body_url?ms_strdup(external_body_url):NULL;
......@@ -803,14 +815,40 @@ LinphoneChatMessage* linphone_chat_message_clone(const LinphoneChatMessage* msg)
/**
* Destroys a LinphoneChatMessage.
**/
void linphone_chat_message_destroy(LinphoneChatMessage* msg) {
void linphone_chat_message_destroy(LinphoneChatMessage* msg){
belle_sip_object_unref(msg);
}
/**
* Destroys a LinphoneChatMessage.
**/
static void _linphone_chat_message_destroy(LinphoneChatMessage* msg) {
if (msg->op) sal_op_release(msg->op);
if (msg->message) ms_free(msg->message);
if (msg->external_body_url) ms_free(msg->external_body_url);
if (msg->from) linphone_address_destroy(msg->from);
if (msg->to) linphone_address_destroy(msg->to);
if (msg->custom_headers) sal_custom_header_free(msg->custom_headers);
ms_free(msg);
}
/**
* Acquire a reference to the chat message.
* @param msg the chat message
* @return the same chat message
**/
LinphoneChatMessage * linphone_chat_message_ref(LinphoneChatMessage *msg){
belle_sip_object_ref(msg);
return msg;
}
/**
* Release reference to the chat message.
* @param msg the chat message.
**/
void linphone_chat_message_unref(LinphoneChatMessage *msg){
belle_sip_object_unref(msg);
}
/**
......
......@@ -1067,6 +1067,8 @@ LINPHONE_PUBLIC unsigned int linphone_chat_message_store(LinphoneChatMessage *ms
LINPHONE_PUBLIC const char* linphone_chat_message_state_to_string(const LinphoneChatMessageState state);
LINPHONE_PUBLIC LinphoneChatMessageState linphone_chat_message_get_state(const LinphoneChatMessage* message);
LINPHONE_PUBLIC LinphoneChatMessage* linphone_chat_message_clone(const LinphoneChatMessage* message);
LINPHONE_PUBLIC LinphoneChatMessage * linphone_chat_message_ref(LinphoneChatMessage *msg);
LINPHONE_PUBLIC void linphone_chat_message_unref(LinphoneChatMessage *msg);
LINPHONE_PUBLIC void linphone_chat_message_destroy(LinphoneChatMessage* msg);
LINPHONE_PUBLIC void linphone_chat_message_set_from(LinphoneChatMessage* message, const LinphoneAddress* from);
LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_message_get_from(const LinphoneChatMessage* message);
......
......@@ -132,6 +132,7 @@ typedef enum _LinphoneChatMessageDir{
} LinphoneChatMessageDir;
struct _LinphoneChatMessage {
belle_sip_object_t base;
LinphoneChatRoom* chat_room;
LinphoneChatMessageDir dir;
char* message;
......@@ -149,6 +150,8 @@ struct _LinphoneChatMessage {
SalOp *op;
};
BELLE_SIP_DECLARE_VPTR(LinphoneChatMessage);
typedef struct StunCandidate{
char addr[64];
int port;
......@@ -862,7 +865,8 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(linphone,10000)
BELLE_SIP_TYPE_ID(LinphoneContactSearch),
BELLE_SIP_TYPE_ID(LinphoneContactProvider),
BELLE_SIP_TYPE_ID(LinphoneLDAPContactProvider),
BELLE_SIP_TYPE_ID(LinphoneLDAPContactSearch)
BELLE_SIP_TYPE_ID(LinphoneLDAPContactSearch),
BELLE_SIP_TYPE_ID(LinphoneChatMessage)
BELLE_SIP_DECLARE_TYPES_END
......
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