Commit 4ac1ccdf authored by Ghislain MARY's avatar Ghislain MARY

Handle the callbacks associated with a chat message directly in the...

Handle the callbacks associated with a chat message directly in the LinphoneChatMessage object instead of in the LinphoneCore object.
parent e16e0456
......@@ -1172,11 +1172,14 @@ static void text_delivery_update(SalOp *op, SalTextDeliveryStatus status){
chat_msg->state=chatStatusSal2Linphone(status);
linphone_chat_message_update_state(chat_msg);
if (chat_msg && chat_msg->cb) {
if (chat_msg && (chat_msg->cb || (chat_msg->callbacks && linphone_chat_message_cbs_get_msg_state_changed(chat_msg->callbacks)))) {
ms_message("Notifying text delivery with status %i",chat_msg->state);
chat_msg->cb(chat_msg
,chat_msg->state
,chat_msg->cb_ud);
if (chat_msg->callbacks && linphone_chat_message_cbs_get_msg_state_changed(chat_msg->callbacks)) {
linphone_chat_message_cbs_get_msg_state_changed(chat_msg->callbacks)(chat_msg, chat_msg->state);
} else {
/* Legacy */
chat_msg->cb(chat_msg,chat_msg->state,chat_msg->cb_ud);
}
}
if (status != SalTextDeliveryInProgress) { /*only release op if not in progress*/
linphone_chat_message_destroy(chat_msg);
......
This diff is collapsed.
......@@ -48,7 +48,7 @@ static void stop(int signum){
/**
* function invoked to report file transfer progress.
* */
static void file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total) {
static void file_transfer_progress_indication(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total) {
const LinphoneAddress* from_address = linphone_chat_message_get_from(message);
const LinphoneAddress* to_address = linphone_chat_message_get_to(message);
char *address = linphone_chat_message_is_outgoing(message)?linphone_address_as_string(to_address):linphone_address_as_string(from_address);
......@@ -63,7 +63,7 @@ static void file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMess
/**
* function invoked when a file transfer is received.
**/
static void file_transfer_received(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size){
static void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size){
FILE* file=NULL;
if (!linphone_chat_message_get_user_data(message)) {
/*first chunk, creating file*/
......@@ -92,7 +92,7 @@ char big_file [128000];
/*
* function called when the file transfer is initiated. file content should be feed into object LinphoneContent
* */
static void file_transfer_send(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size){
static void file_transfer_send(LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size){
int offset=-1;
if (!linphone_chat_message_get_user_data(message)) {
......@@ -147,6 +147,7 @@ int main(int argc, char *argv[]){
LinphoneChatRoom* chat_room;
LinphoneContent* content;
LinphoneChatMessage* chat_message;
LinphoneChatMessageCbs *cbs;
/*seting dummy file content to something*/
for (i=0;i<sizeof(big_file);i+=strlen(big_file_content))
......@@ -160,15 +161,6 @@ int main(int argc, char *argv[]){
#ifdef DEBUG
linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/
#endif
/*
Fill the LinphoneCoreVTable with application callbacks.
All are optional. Here we only use the file_transfer_received callback
in order to get notifications about incoming file receive, file_transfer_send to feed file to be transfered
and file_transfer_progress_indication to print progress.
*/
vtable.file_transfer_recv=file_transfer_received;
vtable.file_transfer_send=file_transfer_send;
vtable.file_transfer_progress_indication=file_transfer_progress_indication;
vtable.message_received=message_received;
......@@ -201,8 +193,18 @@ int main(int argc, char *argv[]){
printf("returned message is null\n");
}
/**
* Fill the application callbacks. The file_transfer_received callback is used in order to get notifications
* about incoming file reception, file_transfer_send to feed file to be transfered and
* file_transfer_progress_indication to print progress.
*/
cbs = linphone_chat_message_get_callbacks(chat_message);
linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received);
linphone_chat_message_cbs_set_file_transfer_send(cbs, file_transfer_send);
linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication);
/*initiating file transfer*/
linphone_chat_room_send_message2(chat_room, chat_message, linphone_file_transfer_state_changed, NULL);
linphone_chat_room_send_chat_message(chat_room, chat_message);
/* main loop for receiving incoming messages and doing background linphone core work: */
while(running){
......
......@@ -1296,7 +1296,12 @@ struct _LinphoneChatRoom;
*/
/**
* A chat room message to old content to be sent.
* An object to handle the callbacks for the handling a LinphoneChatMessage objects.
*/
typedef struct _LinphoneChatMessageCbs LinphoneChatMessageCbs;
/**
* A chat room message to hold content to be sent.
* <br> Can be created by linphone_chat_room_create_message().
*/
typedef struct _LinphoneChatMessage LinphoneChatMessage;
......@@ -1327,6 +1332,46 @@ typedef enum _LinphoneChatMessageState {
*/
typedef void (*LinphoneChatMessageStateChangedCb)(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud);
/**
* Call back used to notify message delivery status
* @param msg #LinphoneChatMessage object
* @param status LinphoneChatMessageState
*/
typedef void (*LinphoneChatMessageMsgStateChangedCb)(LinphoneChatMessage* msg, LinphoneChatMessageState state);
/**
* File transfer receive callback prototype. This function is called by the core upon an incoming File transfer is started. This function may be call several time for the same file in case of large file.
*
* @param message #LinphoneChatMessage message from which the body is received.
* @param content #LinphoneContent incoming content information
* @param buff pointer to the received data
* @param size number of bytes to be read from buff. 0 means end of file.
*
*/
typedef void (*LinphoneChatMessageFileTransferRecvCb)(LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size);
/**
* File transfer send callback prototype. This function is called by the core upon an outgoing File transfer is started. This function is called until size is set to 0.
* <br> a #LinphoneContent with a size equal zero
*
* @param message #LinphoneChatMessage message from which the body is received.
* @param content #LinphoneContent outgoing content
* @param buff pointer to the buffer where data chunk shall be written by the app
* @param size as input value, it represents the number of bytes expected by the framework. As output value, it means the number of bytes wrote by the application in the buffer. 0 means end of file.
*
*/
typedef void (*LinphoneChatMessageFileTransferSendCb)(LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size);
/**
* File transfer progress indication callback prototype.
*
* @param message #LinphoneChatMessage message from which the body is received.
* @param content #LinphoneContent incoming content information
* @param offset The number of bytes sent/received since the beginning of the transfer.
* @param total The total number of bytes to be sent/received.
*/
typedef void (*LinphoneChatMessageFileTransferProgressIndicationCb)(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total);
LINPHONE_PUBLIC void linphone_core_set_chat_database_path(LinphoneCore *lc, const char *path);
LINPHONE_PUBLIC LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to);
LINPHONE_PUBLIC LinphoneChatRoom * linphone_core_get_or_create_chat_room(LinphoneCore *lc, const char *to);
......@@ -1377,6 +1422,7 @@ LINPHONE_PUBLIC LinphoneChatMessage* linphone_chat_room_create_file_transfer_mes
LINPHONE_PUBLIC const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr);
LINPHONE_PUBLIC void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg);
LINPHONE_PUBLIC void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangedCb status_cb,void* ud);
LINPHONE_PUBLIC void linphone_chat_room_send_chat_message(LinphoneChatRoom *cr, LinphoneChatMessage *msg);
LINPHONE_PUBLIC void linphone_chat_room_update_url(LinphoneChatRoom *cr, LinphoneChatMessage *msg);
LINPHONE_PUBLIC MSList *linphone_chat_room_get_history(LinphoneChatRoom *cr,int nb_message);
LINPHONE_PUBLIC void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr);
......@@ -1438,6 +1484,7 @@ LINPHONE_PUBLIC const char* linphone_chat_message_get_external_body_url(const Li
LINPHONE_PUBLIC void linphone_chat_message_set_external_body_url(LinphoneChatMessage* message,const char* url);
LINPHONE_PUBLIC const LinphoneContent* linphone_chat_message_get_file_transfer_information(const LinphoneChatMessage* message);
LINPHONE_PUBLIC void linphone_chat_message_start_file_download(LinphoneChatMessage* message, LinphoneChatMessageStateChangedCb status_cb, void* ud);
LINPHONE_PUBLIC void linphone_chat_message_download_file(LinphoneChatMessage *message);
LINPHONE_PUBLIC void linphone_chat_message_cancel_file_transfer(LinphoneChatMessage* msg);
LINPHONE_PUBLIC const char* linphone_chat_message_get_appdata(const LinphoneChatMessage* message);
LINPHONE_PUBLIC void linphone_chat_message_set_appdata(LinphoneChatMessage* message, const char* data);
......@@ -1457,6 +1504,21 @@ LINPHONE_PUBLIC LinphoneReason linphone_chat_message_get_reason(LinphoneChatMess
LINPHONE_PUBLIC const LinphoneErrorInfo *linphone_chat_message_get_error_info(const LinphoneChatMessage *msg);
LINPHONE_PUBLIC void linphone_chat_message_set_file_transfer_filepath(LinphoneChatMessage *msg, const char *filepath);
LINPHONE_PUBLIC const char * linphone_chat_message_get_file_transfer_filepath(LinphoneChatMessage *msg);
LINPHONE_PUBLIC LinphoneChatMessageCbs * linphone_chat_message_get_callbacks(const LinphoneChatMessage *msg);
LINPHONE_PUBLIC LinphoneChatMessageCbs * linphone_chat_message_cbs_ref(LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_unref(LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void *linphone_chat_message_cbs_get_user_data(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_user_data(LinphoneChatMessageCbs *cbs, void *ud);
LINPHONE_PUBLIC LinphoneChatMessageMsgStateChangedCb linphone_chat_message_cbs_get_msg_state_changed(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_msg_state_changed(LinphoneChatMessageCbs *cbs, LinphoneChatMessageMsgStateChangedCb cb);
LINPHONE_PUBLIC LinphoneChatMessageFileTransferRecvCb linphone_chat_message_cbs_get_file_transfer_recv(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_file_transfer_recv(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferRecvCb cb);
LINPHONE_PUBLIC LinphoneChatMessageFileTransferSendCb linphone_chat_message_cbs_get_file_transfer_send(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_file_transfer_send(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferSendCb cb);
LINPHONE_PUBLIC LinphoneChatMessageFileTransferProgressIndicationCb linphone_chat_message_cbs_get_file_transfer_progress_indication(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_file_transfer_progress_indication(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferProgressIndicationCb cb);
/**
* @}
*/
......@@ -1741,9 +1803,9 @@ typedef struct _LinphoneCoreVTable{
DisplayUrlCb display_url; /**< @deprecated */
ShowInterfaceCb show; /**< @deprecated Notifies the application that it should show up*/
LinphoneCoreTextMessageReceivedCb text_received; /**< @deprecated, use #message_received instead <br> A text message has been received */
LinphoneCoreFileTransferRecvCb file_transfer_recv; /**< Callback to store file received attached to a #LinphoneChatMessage */
LinphoneCoreFileTransferSendCb file_transfer_send; /**< Callback to collect file chunk to be sent for a #LinphoneChatMessage */
LinphoneCoreFileTransferProgressIndicationCb file_transfer_progress_indication; /**< Callback to indicate file transfer progress */
LinphoneCoreFileTransferRecvCb file_transfer_recv; /**< @deprecated Callback to store file received attached to a #LinphoneChatMessage */
LinphoneCoreFileTransferSendCb file_transfer_send; /**< @deprecated Callback to collect file chunk to be sent for a #LinphoneChatMessage */
LinphoneCoreFileTransferProgressIndicationCb file_transfer_progress_indication; /**< @deprecated Callback to indicate file transfer progress */
LinphoneCoreNetworkReachableCb network_reachable; /**< Callback to report IP network status (I.E up/down )*/
LinphoneCoreLogCollectionUploadStateChangedCb log_collection_upload_state_changed; /**< Callback to upload collected logs */
LinphoneCoreLogCollectionUploadProgressIndicationCb log_collection_upload_progress_indication; /**< Callback to indicate log collection upload progress */
......
......@@ -146,6 +146,17 @@ typedef struct _CallCallbackObj
void * _user_data;
}CallCallbackObj;
struct _LinphoneChatMessageCbs {
belle_sip_object_t base;
void *user_data;
LinphoneChatMessageMsgStateChangedCb msg_state_changed;
LinphoneChatMessageFileTransferRecvCb file_transfer_recv; /**< Callback to store file received attached to a #LinphoneChatMessage */
LinphoneChatMessageFileTransferSendCb file_transfer_send; /**< Callback to collect file chunk to be sent for a #LinphoneChatMessage */
LinphoneChatMessageFileTransferProgressIndicationCb file_transfer_progress_indication; /**< Callback to indicate file transfer progress */
};
BELLE_SIP_DECLARE_VPTR(LinphoneChatMessageCbs);
typedef enum _LinphoneChatMessageDir{
LinphoneChatMessageIncoming,
LinphoneChatMessageOutgoing
......@@ -154,6 +165,7 @@ typedef enum _LinphoneChatMessageDir{
struct _LinphoneChatMessage {
belle_sip_object_t base;
LinphoneChatRoom* chat_room;
LinphoneChatMessageCbs *callbacks;
LinphoneChatMessageDir dir;
char* message;
LinphoneChatMessageStateChangedCb cb;
......@@ -997,6 +1009,7 @@ BELLE_SIP_TYPE_ID(LinphoneCall),
BELLE_SIP_TYPE_ID(LinphoneCallLog),
BELLE_SIP_TYPE_ID(LinphoneCallParams),
BELLE_SIP_TYPE_ID(LinphoneChatMessage),
BELLE_SIP_TYPE_ID(LinphoneChatMessageCbs),
BELLE_SIP_TYPE_ID(LinphoneChatRoom),
BELLE_SIP_TYPE_ID(LinphoneContent),
BELLE_SIP_TYPE_ID(LinphoneLDAPContactProvider),
......
......@@ -276,7 +276,7 @@ void update_chat_state_message(LinphoneChatMessageState state,LinphoneChatMessag
}
}
static void on_chat_state_changed(LinphoneChatMessage *msg, LinphoneChatMessageState state, void *user_pointer){
static void on_chat_state_changed(LinphoneChatMessage *msg, LinphoneChatMessageState state){
update_chat_state_message(state,msg);
}
......@@ -300,8 +300,11 @@ void linphone_gtk_send_text(){
entered=gtk_entry_get_text(GTK_ENTRY(entry));
if (strlen(entered)>0) {
LinphoneChatMessage *msg;
LinphoneChatMessageCbs *cbs;
msg=linphone_chat_room_create_message(cr,entered);
linphone_chat_room_send_message2(cr,msg,on_chat_state_changed,NULL);
cbs=linphone_chat_message_get_callbacks(msg);
linphone_chat_message_cbs_set_msg_state_changed(cbs,on_chat_state_changed);
linphone_chat_room_send_chat_message(cr,msg);
linphone_gtk_push_text(w,linphone_chat_message_get_from(msg),
TRUE,cr,msg,FALSE);
......
......@@ -235,9 +235,9 @@ void linphone_transfer_state_changed(LinphoneCore *lc, LinphoneCall *transfered,
void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf);
void text_message_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from_address, const char *message);
void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage* message);
void file_transfer_received(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size);
void file_transfer_send(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size);
void file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total);
void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size);
void file_transfer_send(LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size);
void file_transfer_progress_indication(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total);
void is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room);
void info_message_received(LinphoneCore *lc, LinphoneCall *call, const LinphoneInfoMessage *msg);
void new_subscription_requested(LinphoneCore *lc, LinphoneFriend *lf, const char *url);
......@@ -269,6 +269,7 @@ LinphoneCoreManager *get_manager(LinphoneCore *lc);
const char *liblinphone_tester_get_subscribe_content(void);
const char *liblinphone_tester_get_notify_content(void);
void liblinphone_tester_chat_message_state_change(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud);
void liblinphone_tester_chat_message_msg_state_changed(LinphoneChatMessage *msg, LinphoneChatMessageState state);
void liblinphone_tester_check_rtcp(LinphoneCoreManager* caller, LinphoneCoreManager* callee);
void liblinphone_tester_clock_start(MSTimeSpec *start);
bool_t liblinphone_tester_clock_elapsed(const MSTimeSpec *start, int value_ms);
......
This diff is collapsed.
......@@ -234,9 +234,6 @@ LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_f
mgr->v_table.call_state_changed=call_state_changed;
mgr->v_table.text_received=text_message_received;
mgr->v_table.message_received=message_received;
mgr->v_table.file_transfer_recv=file_transfer_received;
mgr->v_table.file_transfer_send=file_transfer_send;
mgr->v_table.file_transfer_progress_indication=file_transfer_progress_indication;
mgr->v_table.is_composing_received=is_composing_received;
mgr->v_table.new_subscription_requested=new_subscription_requested;
mgr->v_table.notify_presence_received=notify_presence_received;
......
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