From 251ba960c5060ff801e12dca1c5cd68010948296 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Mon, 15 Sep 2014 14:06:09 +0200 Subject: [PATCH] add new functions linphone_core_add_listener to enable multiple vtable to be registered --- coreapi/callbacks.c | 102 ++++++++----------- coreapi/chat.c | 30 ++---- coreapi/event.c | 10 +- coreapi/friend.c | 3 +- coreapi/info.c | 3 +- coreapi/linphonecall.c | 36 +++---- coreapi/linphonecore.c | 192 ++++++++++++++++++++++++++++-------- coreapi/linphonecore.h | 36 +++++-- coreapi/misc.c | 6 +- coreapi/presence.c | 7 +- coreapi/private.h | 41 +++++++- coreapi/proxy.c | 17 ++-- tester/call_tester.c | 10 +- tester/liblinphone_tester.h | 2 + tester/message_tester.c | 7 +- tester/register_tester.c | 23 ++--- tester/tester.c | 11 ++- 17 files changed, 328 insertions(+), 208 deletions(-) diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index 89e61bfeb..ef17b080b 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -351,8 +351,7 @@ static void call_ringing(SalOp *h){ /*set privacy*/ call->current_params->privacy=(LinphonePrivacyMask)sal_op_get_privacy(call->op); - if (lc->vtable.display_status) - lc->vtable.display_status(lc,_("Remote ringing.")); + linphone_core_notify_display_status(lc,_("Remote ringing.")); md=sal_call_get_final_media_description(h); if (md==NULL){ @@ -369,8 +368,7 @@ static void call_ringing(SalOp *h){ } } ms_message("Remote ringing..."); - if (lc->vtable.display_status) - lc->vtable.display_status(lc,_("Remote ringing...")); + linphone_core_notify_display_status(lc,_("Remote ringing...")); linphone_call_set_state(call,LinphoneCallOutgoingRinging,"Remote ringing"); }else{ /*accept early media */ @@ -379,9 +377,8 @@ static void call_ringing(SalOp *h){ try_early_media_forking(call,md); return; } - if (lc->vtable.show) lc->vtable.show(lc); - if (lc->vtable.display_status) - lc->vtable.display_status(lc,_("Early media.")); + linphone_core_notify_show_interface(lc); + linphone_core_notify_display_status(lc,_("Early media.")); linphone_call_set_state(call,LinphoneCallOutgoingEarlyMedia,"Early media"); linphone_core_stop_ringing(lc); ms_message("Doing early media..."); @@ -430,10 +427,10 @@ static void call_accepted(SalOp *op){ linphone_call_update_remote_session_id_and_ver(call); if (sal_media_description_has_dir(md,SalStreamSendOnly) || sal_media_description_has_dir(md,SalStreamInactive)){ - if (lc->vtable.display_status){ + { char *tmp=linphone_call_get_remote_address_as_string (call); char *msg=ms_strdup_printf(_("Call with %s is paused."),tmp); - lc->vtable.display_status(lc,msg); + linphone_core_notify_display_status(lc,msg); ms_free(tmp); ms_free(msg); } @@ -443,10 +440,10 @@ static void call_accepted(SalOp *op){ linphone_core_start_refered_call(lc,call,NULL); }else if (sal_media_description_has_dir(md,SalStreamRecvOnly)){ /*we are put on hold when the call is initially accepted */ - if (lc->vtable.display_status){ + { char *tmp=linphone_call_get_remote_address_as_string (call); char *msg=ms_strdup_printf(_("Call answered by %s - on hold."),tmp); - lc->vtable.display_status(lc,msg); + linphone_core_notify_display_status(lc,msg); ms_free(tmp); ms_free(msg); } @@ -455,14 +452,12 @@ static void call_accepted(SalOp *op){ }else{ if (call->state!=LinphoneCallUpdating){ if (call->state==LinphoneCallResuming){ - if (lc->vtable.display_status){ - lc->vtable.display_status(lc,_("Call resumed.")); - } + linphone_core_notify_display_status(lc,_("Call resumed.")); }else{ - if (lc->vtable.display_status){ + { char *tmp=linphone_call_get_remote_address_as_string (call); char *msg=ms_strdup_printf(_("Call answered by %s."),tmp); - lc->vtable.display_status(lc,msg); + linphone_core_notify_display_status(lc,msg); ms_free(tmp); ms_free(msg); } @@ -508,8 +503,7 @@ static void call_ack(SalOp *op){ static void call_resumed(LinphoneCore *lc, LinphoneCall *call){ /*when we are resumed, increment session id, because sdp is changed (a=recvonly disapears)*/ linphone_call_increment_local_media_description(call); - if(lc->vtable.display_status) - lc->vtable.display_status(lc,_("We have been resumed.")); + linphone_core_notify_display_status(lc,_("We have been resumed.")); _linphone_core_accept_call_update(lc,call,NULL,LinphoneCallStreamsRunning,"Connected (streams running)"); } @@ -517,8 +511,7 @@ static void call_paused_by_remote(LinphoneCore *lc, LinphoneCall *call){ /*when we are paused, increment session id, because sdp is changed (a=recvonly appears)*/ linphone_call_increment_local_media_description(call); /* we are being paused */ - if(lc->vtable.display_status) - lc->vtable.display_status(lc,_("We are paused by other party.")); + linphone_core_notify_display_status(lc,_("We are paused by other party.")); _linphone_core_accept_call_update(lc,call,NULL,LinphoneCallPausedByRemote,"Call paused by remote"); } @@ -552,8 +545,7 @@ static void call_updated_by_remote(LinphoneCore *lc, LinphoneCall *call, bool_t if (call->state==LinphoneCallStreamsRunning) { /*reINVITE and in-dialogs UPDATE go here*/ - if(lc->vtable.display_status) - lc->vtable.display_status(lc,_("Call is updated by remote.")); + linphone_core_notify_display_status(lc,_("Call is updated by remote.")); call->defer_update=FALSE; linphone_call_set_state(call, LinphoneCallUpdatedByRemote,"Call updated by remote"); if (call->defer_update==FALSE){ @@ -652,10 +644,8 @@ static void call_terminated(SalOp *op, const char *from){ linphone_core_stop_ringing(lc); } linphone_call_stop_media_streams(call); - if (lc->vtable.show!=NULL) - lc->vtable.show(lc); - if (lc->vtable.display_status!=NULL) - lc->vtable.display_status(lc,_("Call terminated.")); + linphone_core_notify_show_interface(lc); + linphone_core_notify_display_status(lc,_("Call terminated.")); #ifdef BUILD_UPNP linphone_call_delete_upnp_session(call); @@ -698,24 +688,21 @@ static void call_failure(SalOp *op){ return ; } - if (lc->vtable.show) lc->vtable.show(lc); + linphone_core_notify_show_interface(lc); switch(ei->reason){ case SalReasonNone: break; case SalReasonRequestTimeout: msg=_("Request timeout."); - if (lc->vtable.display_status) - lc->vtable.display_status(lc,msg); + linphone_core_notify_display_status(lc,msg); break; case SalReasonDeclined: msg=msg603; - if (lc->vtable.display_status) - lc->vtable.display_status(lc,msg603); + linphone_core_notify_display_status(lc,msg603); break; case SalReasonBusy: msg=msg486; - if (lc->vtable.display_status) - lc->vtable.display_status(lc,msg486); + linphone_core_notify_display_status(lc,msg486); break; case SalReasonRedirect: { @@ -735,23 +722,19 @@ static void call_failure(SalOp *op){ } } msg=_("Redirected"); - if (lc->vtable.display_status) - lc->vtable.display_status(lc,msg); + linphone_core_notify_display_status(lc,msg); } break; case SalReasonTemporarilyUnavailable: msg=msg480; - if (lc->vtable.display_status) - lc->vtable.display_status(lc,msg480); + linphone_core_notify_display_status(lc,msg480); break; case SalReasonNotFound: - if (lc->vtable.display_status) - lc->vtable.display_status(lc,msg); + linphone_core_notify_display_status(lc,msg); break; case SalReasonDoNotDisturb: msg=msg600; - if (lc->vtable.display_status) - lc->vtable.display_status(lc,msg600); + linphone_core_notify_display_status(lc,msg600); break; case SalReasonUnsupportedContent: /*vtable.display_status) - lc->vtable.display_status(lc,msg); + linphone_core_notify_display_status(lc,msg); break; case SalReasonRequestPending: /*restore previous state, the application will decide to resubmit the action if relevant*/ @@ -794,8 +776,7 @@ static void call_failure(SalOp *op){ return; break; default: - if (lc->vtable.display_status) - lc->vtable.display_status(lc,_("Call failed.")); + linphone_core_notify_display_status(lc,_("Call failed.")); } /*some call error are not fatal*/ @@ -855,9 +836,7 @@ static void auth_failure(SalOp *op, SalAuthInfo* info) { if (ai){ ms_message("%s/%s/%s authentication fails.",info->realm,info->username,info->domain); /*ask again for password if auth info was already supplied but apparently not working*/ - if (lc->vtable.auth_info_requested) { - lc->vtable.auth_info_requested(lc,info->realm,info->username,info->domain); - } + linphone_core_notify_auth_info_requested(lc,info->realm,info->username,info->domain); } } @@ -874,10 +853,10 @@ static void register_success(SalOp *op, bool_t registered){ } linphone_proxy_config_set_state(cfg, registered ? LinphoneRegistrationOk : LinphoneRegistrationCleared , registered ? "Registration successful" : "Unregistration done"); - if (lc->vtable.display_status){ + { if (registered) msg=ms_strdup_printf(_("Registration on %s successful."),sal_op_get_proxy(op)); else msg=ms_strdup_printf(_("Unregistration on %s done."),sal_op_get_proxy(op)); - lc->vtable.display_status(lc,msg); + linphone_core_notify_display_status(lc,msg); ms_free(msg); } @@ -896,9 +875,9 @@ static void register_failure(SalOp *op){ if (details==NULL) details=_("no response timeout"); - if (lc->vtable.display_status) { + { char *msg=ortp_strdup_printf(_("Registration on %s failed: %s"),sal_op_get_proxy(op), details); - lc->vtable.display_status(lc,msg); + linphone_core_notify_display_status(lc,msg); ms_free(msg); } @@ -931,8 +910,7 @@ static void vfu_request(SalOp *op){ static void dtmf_received(SalOp *op, char dtmf){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); - if (lc->vtable.dtmf_received != NULL) - lc->vtable.dtmf_received(lc, call, dtmf); + linphone_core_notify_dtmf_received(lc, call, dtmf); } static void refer_received(Sal *sal, SalOp *op, const char *referto){ @@ -945,14 +923,14 @@ static void refer_received(Sal *sal, SalOp *op, const char *referto){ call->refer_to=ms_strdup(referto); call->refer_pending=TRUE; linphone_call_set_state(call,LinphoneCallRefered,"Refered"); - if (lc->vtable.display_status){ + { char *msg=ms_strdup_printf(_("We are transferred to %s"),referto); - lc->vtable.display_status(lc,msg); + linphone_core_notify_display_status(lc,msg); ms_free(msg); } if (call->refer_pending) linphone_core_start_refered_call(lc,call,NULL); - }else if (lc->vtable.refer_received){ - lc->vtable.refer_received(lc,referto); + }else { + linphone_core_notify_refer_received(lc,referto); } } @@ -1072,8 +1050,8 @@ static bool_t auth_requested(Sal* sal, SalAuthInfo* sai) { if (fill_auth_info(lc,sai)) { return TRUE; } else { - if (lc->vtable.auth_info_requested) { - lc->vtable.auth_info_requested(lc,sai->realm,sai->username,sai->domain); + { + linphone_core_notify_auth_info_requested(lc,sai->realm,sai->username,sai->domain); if (fill_auth_info(lc,sai)) { return TRUE; } @@ -1180,9 +1158,9 @@ static void notify(SalOp *op, SalSubscribeStatus st, const char *eventname, cons /*out of subscribe notify */ lev=linphone_event_new_with_out_of_dialog_op(lc,op,LinphoneSubscriptionOutgoing,eventname); } - if (lc->vtable.notify_received){ + { const LinphoneContent *ct=linphone_content_from_sal_body(&content,body); - if (ct) lc->vtable.notify_received(lc,lev,eventname,ct); + if (ct) linphone_core_notify_notify_received(lc,lev,eventname,ct); } if (st!=SalSubscribeNone){ linphone_event_set_state(lev,linphone_subscription_state_from_sal(st)); diff --git a/coreapi/chat.c b/coreapi/chat.c index 8c853f891..bcd16bd14 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -77,9 +77,7 @@ static void linphone_chat_message_file_transfer_on_progress(belle_sip_body_handl LinphoneChatMessage* chatMsg=(LinphoneChatMessage *)data; LinphoneCore *lc = chatMsg->chat_room->lc; /* call back given by application level */ - if (lc->vtable.file_transfer_progress_indication != NULL) { - lc->vtable.file_transfer_progress_indication(lc, chatMsg, chatMsg->file_transfer_information, (size_t)(((double)offset/(double)total)*100.0)); - } + linphone_core_notify_file_transfer_progress_indication(lc, chatMsg, chatMsg->file_transfer_information, (size_t)(((double)offset/(double)total)*100.0)); return; } @@ -102,7 +100,7 @@ static int linphone_chat_message_file_transfer_on_send_body(belle_sip_user_body_ /* if we've not reach the end of file yet, ask for more data*/ if (offsetfile_transfer_information->size){ /* get data from call back */ - lc->vtable.file_transfer_send(lc, chatMsg, chatMsg->file_transfer_information, buf, size); + linphone_core_notify_file_transfer_send(lc, chatMsg, chatMsg->file_transfer_information, buf, size); } return BELLE_SIP_CONTINUE; @@ -510,12 +508,10 @@ void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg) { void linphone_chat_room_message_received(LinphoneChatRoom *cr, LinphoneCore *lc, LinphoneChatMessage *msg){ if (msg->message) //legacy API - if (lc->vtable.text_received!=NULL) lc->vtable.text_received(lc, cr, msg->from, msg->message); - if (lc->vtable.message_received!=NULL) lc->vtable.message_received(lc, cr,msg); - if (cr->lc->vtable.is_composing_received != NULL) { - cr->remote_is_composing = LinphoneIsComposingIdle; - cr->lc->vtable.is_composing_received(cr->lc, cr); - } + linphone_core_notify_text_message_received(lc, cr, msg->from, msg->message); + linphone_core_notify_message_received(lc, cr,msg); + cr->remote_is_composing = LinphoneIsComposingIdle; + linphone_core_notify_is_composing_received(cr->lc, cr); } void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessage *sal_msg){ @@ -629,8 +625,7 @@ static int linphone_chat_room_remote_refresh_composing_expired(void *data, unsig belle_sip_object_unref(cr->remote_composing_refresh_timer); cr->remote_composing_refresh_timer = NULL; cr->remote_is_composing = LinphoneIsComposingIdle; - if (cr->lc->vtable.is_composing_received != NULL) - cr->lc->vtable.is_composing_received(cr->lc, cr); + linphone_core_notify_is_composing_received(cr->lc, cr); return BELLE_SIP_STOP; } @@ -675,8 +670,7 @@ static void process_im_is_composing_notification(LinphoneChatRoom *cr, xmlparsin } cr->remote_is_composing = state; - if (cr->lc->vtable.is_composing_received != NULL) - cr->lc->vtable.is_composing_received(cr->lc, cr); + linphone_core_notify_is_composing_received(cr->lc, cr); } } @@ -1034,9 +1028,7 @@ static void on_recv_body(belle_sip_user_body_handler_t *bh, belle_sip_message_t return; } /* call back given by application level */ - if (lc->vtable.file_transfer_recv != NULL) { - lc->vtable.file_transfer_recv(lc, chatMsg, chatMsg->file_transfer_information, (char *)buffer, size); - } + linphone_core_notify_file_transfer_recv(lc, chatMsg, chatMsg->file_transfer_information, (char *)buffer, size); return; } @@ -1101,9 +1093,7 @@ static void linphone_chat_process_response_from_get_file(void *data, const belle LinphoneChatMessage* chatMsg=(LinphoneChatMessage *)data; LinphoneCore *lc = chatMsg->chat_room->lc; /* file downloaded succesfully, call again the callback with size at zero */ - if (lc->vtable.file_transfer_recv != NULL) { - lc->vtable.file_transfer_recv(lc, chatMsg, chatMsg->file_transfer_information, NULL, 0); - } + linphone_core_notify_file_transfer_recv(lc, chatMsg, chatMsg->file_transfer_information, NULL, 0); } } } diff --git a/coreapi/event.c b/coreapi/event.c index 992d058ab..372e0a953 100644 --- a/coreapi/event.c +++ b/coreapi/event.c @@ -89,13 +89,10 @@ LinphoneEvent *linphone_event_new_with_out_of_dialog_op(LinphoneCore *lc, SalOp } void linphone_event_set_state(LinphoneEvent *lev, LinphoneSubscriptionState state){ - LinphoneCore *lc=lev->lc; if (lev->subscription_state!=state){ ms_message("LinphoneEvent [%p] moving to subscription state %s",lev,linphone_subscription_state_to_string(state)); lev->subscription_state=state; - if (lc->vtable.subscription_state_changed){ - lc->vtable.subscription_state_changed(lev->lc,lev,state); - } + linphone_core_notify_subscription_state_changed(lev->lc,lev,state); if (state==LinphoneSubscriptionTerminated){ linphone_event_unref(lev); } @@ -103,13 +100,10 @@ void linphone_event_set_state(LinphoneEvent *lev, LinphoneSubscriptionState stat } void linphone_event_set_publish_state(LinphoneEvent *lev, LinphonePublishState state){ - LinphoneCore *lc=lev->lc; if (lev->publish_state!=state){ ms_message("LinphoneEvent [%p] moving to publish state %s",lev,linphone_publish_state_to_string(state)); lev->publish_state=state; - if (lc->vtable.publish_state_changed){ - lc->vtable.publish_state_changed(lev->lc,lev,state); - } + linphone_core_notify_publish_state_changed(lev->lc,lev,state); switch(state){ case LinphonePublishCleared: linphone_event_unref(lev); diff --git a/coreapi/friend.c b/coreapi/friend.c index 7b0ddd816..d1ecd560c 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -253,8 +253,7 @@ static void linphone_friend_invalidate_subscription(LinphoneFriend *lf){ linphone_presence_model_unref(lf->presence); } lf->presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityOffline,"unknown activity"); - if (lc->vtable.notify_presence_received) - lc->vtable.notify_presence_received(lc,lf); + linphone_core_notify_notify_presence_received(lc,lf); } lf->initial_subscribes_sent=FALSE; } diff --git a/coreapi/info.c b/coreapi/info.c index 2bf2b85ad..ad8cd1f8e 100644 --- a/coreapi/info.c +++ b/coreapi/info.c @@ -192,8 +192,7 @@ void linphone_core_notify_info_message(LinphoneCore* lc,SalOp *op, const SalBody LinphoneInfoMessage *info=ms_new0(LinphoneInfoMessage,1); info->headers=sal_custom_header_clone(sal_op_get_recv_custom_header(op)); if (body) linphone_content_copy_from_sal_body(&info->content,body); - if (lc->vtable.info_received) - lc->vtable.info_received(lc,call,info); + linphone_core_notify_info_received(lc,call,info); linphone_info_message_destroy(info); } } diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 74e72cd7e..620fbba04 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -153,17 +153,14 @@ static uint16_t linphone_call_get_avpf_rr_interval(const LinphoneCall *call) { } static void propagate_encryption_changed(LinphoneCall *call){ - LinphoneCore *lc=call->core; if (!linphone_call_all_streams_encrypted(call)) { ms_message("Some streams are not encrypted"); call->current_params->media_encryption=LinphoneMediaEncryptionNone; - if (lc->vtable.call_encryption_changed) - lc->vtable.call_encryption_changed(call->core, call, FALSE, call->auth_token); + linphone_core_notify_call_encryption_changed(call->core, call, FALSE, call->auth_token); } else { ms_message("All streams are encrypted"); call->current_params->media_encryption=LinphoneMediaEncryptionZRTP; - if (lc->vtable.call_encryption_changed) - lc->vtable.call_encryption_changed(call->core, call, TRUE, call->auth_token); + linphone_core_notify_call_encryption_changed(call->core, call, TRUE, call->auth_token); } } @@ -173,9 +170,9 @@ static void linphone_call_audiostream_encryption_changed(void *data, bool_t encr call = (LinphoneCall *)data; - if (encrypted && call->core->vtable.display_status != NULL) { + if (encrypted) { snprintf(status,sizeof(status)-1,_("Authentication token is %s"),call->auth_token); - call->core->vtable.display_status(call->core, status); + linphone_core_notify_display_status(call->core, status); } propagate_encryption_changed(call); @@ -974,8 +971,8 @@ void linphone_call_set_state_base(LinphoneCall *call, LinphoneCallState cstate, call->media_start_time=time(NULL); } - if (lc->vtable.call_state_changed && !silently) - lc->vtable.call_state_changed(lc,call,cstate,message); + if (!silently) + linphone_core_notify_call_state_changed(lc,call,cstate,message); linphone_reporting_call_state_updated(call); @@ -1640,8 +1637,7 @@ static void linphone_core_dtmf_received(LinphoneCore *lc, int dtmf){ ms_warning("Bad dtmf value %i",dtmf); return; } - if (lc->vtable.dtmf_received != NULL) - lc->vtable.dtmf_received(lc, linphone_core_get_current_call(lc), dtmf_tab[dtmf]); + linphone_core_notify_dtmf_received(lc, linphone_core_get_current_call(lc), dtmf_tab[dtmf]); } static void parametrize_equalizer(LinphoneCore *lc, AudioStream *st){ @@ -1728,7 +1724,7 @@ static void post_configure_audio_streams(LinphoneCall*call){ AudioStream *st=call->audiostream; LinphoneCore *lc=call->core; _post_configure_audio_stream(st,lc,call->audio_muted); - if (lc->vtable.dtmf_received!=NULL){ + if (linphone_core_dtmf_received_has_listener(lc)){ audio_stream_play_received_dtmfs(call->audiostream,FALSE); } if (call->record_active) @@ -2713,8 +2709,7 @@ static void linphone_core_disconnected(LinphoneCore *lc, LinphoneCall *call){ if (from) ms_free(from); ms_message("On call [%p]: %s",call,temp); - if (lc->vtable.display_warning!=NULL) - lc->vtable.display_warning(lc,temp); + linphone_core_notify_display_warning(lc,temp); linphone_core_terminate_call(lc,call); linphone_core_play_named_tone(lc,LinphoneToneCallLost); } @@ -2836,8 +2831,7 @@ void linphone_call_notify_stats_updated(LinphoneCall *call, int stream_index){ LinphoneCore *lc=call->core; if (stats->updated){ linphone_reporting_on_rtcp_update(call, stream_index); - if (lc->vtable.call_stats_updated) - lc->vtable.call_stats_updated(lc, call, stats); + linphone_core_notify_call_stats_updated(lc, call, stats); stats->updated = 0; } } @@ -2932,8 +2926,7 @@ void linphone_call_log_completed(LinphoneCall *call){ info=ortp_strdup_printf(ngettext("You have missed %i call.", "You have missed %i calls.", lc->missed_calls), lc->missed_calls); - if (lc->vtable.display_status!=NULL) - lc->vtable.display_status(lc,info); + linphone_core_notify_display_status(lc,info); ms_free(info); } lc->call_logs=ms_list_prepend(lc->call_logs,linphone_call_log_ref(call->log)); @@ -2947,9 +2940,7 @@ void linphone_call_log_completed(LinphoneCall *call){ linphone_call_log_unref((LinphoneCallLog*)elem->data); lc->call_logs=ms_list_remove_link(lc->call_logs,elem); } - if (lc->vtable.call_log_updated!=NULL){ - lc->vtable.call_log_updated(lc,call->log); - } + linphone_core_notify_call_log_updated(lc,call->log); call_logs_write_to_config_file(lc); } @@ -2968,8 +2959,7 @@ void linphone_call_set_transfer_state(LinphoneCall* call, LinphoneCallState stat ,linphone_call_state_to_string(call->transfer_state) ,linphone_call_state_to_string(state)); call->transfer_state = state; - if (lc->vtable.transfer_state_changed) - lc->vtable.transfer_state_changed(lc, call, state); + linphone_core_notify_transfer_state_changed(lc, call, state); } } diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 6e6d3f7f2..1e1c7fbbb 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -992,9 +992,7 @@ static void linphone_core_free_payload_types(LinphoneCore *lc){ void linphone_core_set_state(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message){ lc->state=gstate; - if (lc->vtable.global_state_changed){ - lc->vtable.global_state_changed(lc,gstate,message); - } + linphone_core_notify_global_state_changed(lc,gstate,message); } static void misc_config_read(LinphoneCore *lc) { @@ -1030,15 +1028,13 @@ static void linphone_core_start(LinphoneCore * lc) { if (lc->tunnel) linphone_tunnel_configure(lc->tunnel); #endif - if (lc->vtable.display_status) - lc->vtable.display_status(lc,_("Ready")); + linphone_core_notify_display_status(lc,_("Ready")); lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon; linphone_core_set_state(lc,LinphoneGlobalOn,"Ready"); } void linphone_configuring_terminated(LinphoneCore *lc, LinphoneConfiguringState state, const char *message) { - if (lc->vtable.configuring_status) - lc->vtable.configuring_status(lc, state, message); + linphone_core_notify_configuring_status(lc, state, message); if (state == LinphoneConfiguringSuccessful) { if (linphone_core_is_provisioning_transient(lc) == TRUE) @@ -1051,13 +1047,15 @@ void linphone_configuring_terminated(LinphoneCore *lc, LinphoneConfiguringState static void linphone_core_init(LinphoneCore * lc, const LinphoneCoreVTable *vtable, LpConfig *config, void * userdata) { const char *remote_provisioning_uri = NULL; + LinphoneCoreVTable* local_vtable= linphone_vtable_new(); ms_message("Initializing LinphoneCore %s", linphone_core_get_version()); memset (lc, 0, sizeof (LinphoneCore)); lc->config=lp_config_ref(config); lc->data=userdata; lc->ringstream_autorelease=TRUE; - memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable)); + memcpy(local_vtable,vtable,sizeof(LinphoneCoreVTable)); + lc->vtables=ms_list_append(lc->vtables,local_vtable); linphone_core_set_state(lc,LinphoneGlobalStartup,"Starting up"); ortp_init(); @@ -1654,8 +1652,7 @@ const char *linphone_core_get_user_agent_version(void){ static void transport_error(LinphoneCore *lc, const char* transport, int port){ char *msg=ortp_strdup_printf("Could not start %s transport on port %i, maybe this port is already used.",transport,port); ms_warning("%s",msg); - if (lc->vtable.display_warning) - lc->vtable.display_warning(lc,msg); + linphone_core_notify_display_warning(lc,msg); ms_free(msg); } @@ -1868,8 +1865,7 @@ static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){ if (lf!=NULL){ lf->info=info; ms_message("%s has a BuddyInfo assigned with image %p",info->sip_uri, info->image_data); - if (lc->vtable.buddy_info_updated) - lc->vtable.buddy_info_updated(lc,lf); + linphone_core_notify_buddy_info_updated(lc,lf); }else{ ms_warning("Could not any friend with uri %s",info->sip_uri); } @@ -1955,7 +1951,10 @@ void linphone_core_iterate(LinphoneCore *lc){ int elapsed; bool_t one_second_elapsed=FALSE; const char *remote_provisioning_uri = NULL; - + if (lc->network_reachable_to_be_notified) { + lc->network_reachable_to_be_notified=FALSE; + linphone_core_notify_network_reachable(lc,lc->network_reachable); + } if (linphone_core_get_global_state(lc) == LinphoneGlobalStartup) { if (sal_get_root_ca(lc->sal)) { belle_tls_verify_policy_t *tls_policy = belle_tls_verify_policy_new(); @@ -1963,8 +1962,7 @@ void linphone_core_iterate(LinphoneCore *lc){ belle_http_provider_set_tls_verify_policy(lc->http_provider, tls_policy); } - if (lc->vtable.display_status) - lc->vtable.display_status(lc, _("Configuring")); + linphone_core_notify_display_status(lc, _("Configuring")); linphone_core_set_state(lc, LinphoneGlobalConfiguring, "Configuring"); remote_provisioning_uri = linphone_core_get_provisioning_uri(lc); @@ -2129,11 +2127,9 @@ LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url) if (*url=='\0') return NULL; if (is_enum(url,&enum_domain)){ - if (lc->vtable.display_status!=NULL) - lc->vtable.display_status(lc,_("Looking for telephone number destination...")); + linphone_core_notify_display_status(lc,_("Looking for telephone number destination...")); if (enum_lookup(enum_domain,&enumres)<0){ - if (lc->vtable.display_status!=NULL) - lc->vtable.display_status(lc,_("Could not resolve this number.")); + linphone_core_notify_display_status(lc,_("Could not resolve this number.")); ms_free(enum_domain); return NULL; } @@ -2416,13 +2412,11 @@ int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, const Linph call->log->call_id=ms_strdup(sal_op_get_call_id(call->op)); /*must be known at that time*/ barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url); - if (lc->vtable.display_status!=NULL) - lc->vtable.display_status(lc,barmsg); + linphone_core_notify_display_status(lc,barmsg); ms_free(barmsg); if (err<0){ - if (lc->vtable.display_status!=NULL) - lc->vtable.display_status(lc,_("Could not call")); + linphone_core_notify_display_status(lc,_("Could not call")); linphone_call_stop_media_streams(call); linphone_call_set_state(call,LinphoneCallError,"Call failed"); }else { @@ -2572,8 +2566,7 @@ LinphoneCall * linphone_core_invite_address_with_params(LinphoneCore *lc, const linphone_core_preempt_sound_resources(lc); if(!linphone_core_can_we_add_call(lc)){ - if (lc->vtable.display_warning) - lc->vtable.display_warning(lc,_("Sorry, we have reached the maximum number of simultaneous calls")); + linphone_core_notify_display_warning(lc,_("Sorry, we have reached the maximum number of simultaneous calls")); return NULL; } @@ -2744,9 +2737,8 @@ void linphone_core_notify_incoming_call(LinphoneCore *lc, LinphoneCall *call){ linphone_address_destroy(from_parsed); barmesg=ortp_strdup_printf("%s %s%s",tmp,_("is contacting you"), (sal_call_autoanswer_asked(call->op)) ?_(" and asked autoanswer."):_(".")); - if (lc->vtable.show) lc->vtable.show(lc); - if (lc->vtable.display_status) - lc->vtable.display_status(lc,barmesg); + linphone_core_notify_show_interface(lc); + linphone_core_notify_display_status(lc,barmesg); /* play the ring if this is the only call*/ if (ms_list_size(lc->calls)==1){ @@ -2861,8 +2853,7 @@ int linphone_core_start_update_call(LinphoneCore *lc, LinphoneCall *call){ }else{ subject="Refreshing"; } - if (lc->vtable.display_status) - lc->vtable.display_status(lc,_("Modifying call parameters...")); + linphone_core_notify_display_status(lc,_("Modifying call parameters...")); sal_call_set_local_media_description (call->op,call->localdesc); if (call->dest_proxy && call->dest_proxy->op){ /*give a chance to update the contact address if connectivity has changed*/ @@ -3190,8 +3181,7 @@ int linphone_core_accept_call_with_params(LinphoneCore *lc, LinphoneCall *call, linphone_call_update_remote_session_id_and_ver(call); sal_call_accept(call->op); - if (lc->vtable.display_status!=NULL) - lc->vtable.display_status(lc,_("Connected.")); + linphone_core_notify_display_status(lc,_("Connected.")); lc->current_call=call; linphone_call_set_state(call,LinphoneCallConnected,"Connected"); new_md=sal_call_get_final_media_description(call->op); @@ -3216,8 +3206,7 @@ int linphone_core_abort_call(LinphoneCore *lc, LinphoneCall *call, const char *e linphone_call_delete_upnp_session(call); #endif //BUILD_UPNP - if (lc->vtable.display_status!=NULL) - lc->vtable.display_status(lc,_("Call aborted") ); + linphone_core_notify_display_status(lc,_("Call aborted") ); linphone_call_set_state(call,LinphoneCallError,error); return 0; } @@ -3236,8 +3225,7 @@ static void terminate_call(LinphoneCore *lc, LinphoneCall *call){ linphone_call_delete_upnp_session(call); #endif //BUILD_UPNP - if (lc->vtable.display_status!=NULL) - lc->vtable.display_status(lc,_("Call ended") ); + linphone_core_notify_display_status(lc,_("Call ended") ); linphone_call_set_state(call,LinphoneCallEnd,"Call terminated"); } @@ -3408,13 +3396,11 @@ int _linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *call) } sal_call_set_local_media_description(call->op,call->localdesc); if (sal_call_update(call->op,subject,FALSE) != 0){ - if (lc->vtable.display_warning) - lc->vtable.display_warning(lc,_("Could not pause the call")); + linphone_core_notify_display_warning(lc,_("Could not pause the call")); } lc->current_call=NULL; linphone_call_set_state(call,LinphoneCallPausing,"Pausing call"); - if (lc->vtable.display_status) - lc->vtable.display_status(lc,_("Pausing the current call...")); + linphone_core_notify_display_status(lc,_("Pausing the current call...")); if (call->audiostream || call->videostream) linphone_call_stop_media_streams (call); call->paused_by_app=FALSE; @@ -3499,8 +3485,7 @@ int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *call){ if (call->params->in_conference==FALSE) lc->current_call=call; snprintf(temp,sizeof(temp)-1,"Resuming the call with %s",linphone_call_get_remote_address_as_string(call)); - if (lc->vtable.display_status) - lc->vtable.display_status(lc,temp); + linphone_core_notify_display_status(lc,temp); return 0; } @@ -5767,6 +5752,7 @@ static void linphone_core_uninit(LinphoneCore *lc) if (liblinphone_serialize_logs == TRUE) { ortp_set_log_thread_id(0); } + ms_list_free_with_data(lc->vtables,(void (*)(void *))linphone_vtable_destroy); } static void set_network_reachable(LinphoneCore* lc,bool_t isReachable, time_t curtime){ @@ -5774,7 +5760,7 @@ static void set_network_reachable(LinphoneCore* lc,bool_t isReachable, time_t cu const MSList *elem=linphone_core_get_proxy_config_list(lc); if (lc->network_reachable==isReachable) return; // no change, ignore. - + lc->network_reachable_to_be_notified=TRUE; ms_message("Network state is now [%s]",isReachable?"UP":"DOWN"); for(;elem!=NULL;elem=elem->next){ LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data; @@ -6456,3 +6442,123 @@ char * linphone_payload_type_get_mime_type(const LinphonePayloadType *pt) { int linphone_payload_type_get_channels(const LinphonePayloadType *pt) { return pt->channels; } + +LinphoneCoreVTable *linphone_vtable_new() { + return ms_new0(LinphoneCoreVTable,1); +} + +void linphone_vtable_destroy(LinphoneCoreVTable* table) { + ms_free(table); +} +#define NOTIFY_IF_EXIST(function_name) \ + MSList* iterator; \ + ms_message ("Linphone core [%p] notifying [%s]",lc,#function_name);\ + for (iterator=lc->vtables; iterator!=NULL; iterator=iterator->next) \ + if (((LinphoneCoreVTable*)(iterator->data))->function_name)\ + ((LinphoneCoreVTable*)(iterator->data))->function_name + +void linphone_core_notify_global_state_changed(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message) { + NOTIFY_IF_EXIST(global_state_changed)(lc,gstate,message); +} +void linphone_core_notify_call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *message){ + NOTIFY_IF_EXIST(call_state_changed)(lc,call,cstate,message); +} +void linphone_core_notify_call_encryption_changed(LinphoneCore *lc, LinphoneCall *call, bool_t on, const char *authentication_token) { + NOTIFY_IF_EXIST(call_encryption_changed)(lc,call,on,authentication_token); +} +void linphone_core_notify_registration_state_changed(LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message){ + NOTIFY_IF_EXIST(registration_state_changed)(lc,cfg,cstate,message); +} +void linphone_core_notify_show_interface(LinphoneCore *lc){ + NOTIFY_IF_EXIST(show)(lc); +} +void linphone_core_notify_display_status(LinphoneCore *lc, const char *message) { + NOTIFY_IF_EXIST(display_status)(lc,message); +} +void linphone_core_notify_display_message(LinphoneCore *lc, const char *message){ + NOTIFY_IF_EXIST(display_message)(lc,message); +} +void linphone_core_notify_display_warning(LinphoneCore *lc, const char *message){ + NOTIFY_IF_EXIST(display_warning)(lc,message); +} +void linphone_core_notify_display_url(LinphoneCore *lc, const char *message, const char *url){ + NOTIFY_IF_EXIST(display_url)(lc,message,url); +} +void linphone_core_notify_notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf){ + NOTIFY_IF_EXIST(notify_presence_received)(lc,lf); +} +void linphone_core_notify_new_subscription_requested(LinphoneCore *lc, LinphoneFriend *lf, const char *url){ + NOTIFY_IF_EXIST(new_subscription_requested)(lc,lf,url); +} +void linphone_core_notify_auth_info_requested(LinphoneCore *lc, const char *realm, const char *username, const char *domain){ + NOTIFY_IF_EXIST(auth_info_requested)(lc,realm,username,domain); +} +void linphone_core_notify_call_log_updated(LinphoneCore *lc, LinphoneCallLog *newcl){ + NOTIFY_IF_EXIST(call_log_updated)(lc,newcl); +} +void linphone_core_notify_text_message_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message){ + NOTIFY_IF_EXIST(text_received)(lc,room,from,message); +} +void linphone_core_notify_message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *message){ + NOTIFY_IF_EXIST(message_received)(lc,room,message); +} +void linphone_core_notify_file_transfer_recv(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size) { + NOTIFY_IF_EXIST(file_transfer_recv)(lc,message,content,buff,size); +} +void linphone_core_notify_file_transfer_send(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size) { + NOTIFY_IF_EXIST(file_transfer_send)(lc,message,content,buff,size); +} +void linphone_core_notify_file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, size_t progress) { + NOTIFY_IF_EXIST(file_transfer_progress_indication)(lc,message,content,progress); +} +void linphone_core_notify_is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room) { + NOTIFY_IF_EXIST(is_composing_received)(lc,room); +} +void linphone_core_notify_dtmf_received(LinphoneCore* lc, LinphoneCall *call, int dtmf) { + NOTIFY_IF_EXIST(dtmf_received)(lc,call,dtmf); +} +bool_t linphone_core_dtmf_received_has_listener(const LinphoneCore* lc) { + MSList* iterator; + for (iterator=lc->vtables; iterator!=NULL; iterator=iterator->next) + if (((LinphoneCoreVTable*)(iterator->data))->dtmf_received) + return TRUE; + return FALSE; +} +void linphone_core_notify_refer_received(LinphoneCore *lc, const char *refer_to) { + NOTIFY_IF_EXIST(refer_received)(lc,refer_to); +} +void linphone_core_notify_buddy_info_updated(LinphoneCore *lc, LinphoneFriend *lf) { + NOTIFY_IF_EXIST(buddy_info_updated)(lc,lf); +} +void linphone_core_notify_transfer_state_changed(LinphoneCore *lc, LinphoneCall *transfered, LinphoneCallState new_call_state) { + NOTIFY_IF_EXIST(transfer_state_changed)(lc,transfered,new_call_state); +} +void linphone_core_notify_call_stats_updated(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallStats *stats) { + NOTIFY_IF_EXIST(call_stats_updated)(lc,call,stats); +} +void linphone_core_notify_info_received(LinphoneCore *lc, LinphoneCall *call, const LinphoneInfoMessage *msg) { + NOTIFY_IF_EXIST(info_received)(lc,call,msg); +} +void linphone_core_notify_configuring_status(LinphoneCore *lc, LinphoneConfiguringState status, const char *message) { + NOTIFY_IF_EXIST(configuring_status)(lc,status,message); +} +void linphone_core_notify_network_reachable(LinphoneCore *lc, bool_t reachable) { + NOTIFY_IF_EXIST(network_reachable)(lc,reachable); +} +void linphone_core_notify_notify_received(LinphoneCore *lc, LinphoneEvent *lev, const char *notified_event, const LinphoneContent *body) { + NOTIFY_IF_EXIST(notify_received)(lc,lev,notified_event,body); +} +void linphone_core_notify_subscription_state_changed(LinphoneCore *lc, LinphoneEvent *lev, LinphoneSubscriptionState state) { + NOTIFY_IF_EXIST(subscription_state_changed)(lc,lev,state); +} +void linphone_core_notify_publish_state_changed(LinphoneCore *lc, LinphoneEvent *lev, LinphonePublishState state) { + NOTIFY_IF_EXIST(publish_state_changed)(lc,lev,state); +} +void linphone_core_add_listener(LinphoneCore *lc, LinphoneCoreVTable *vtable) { + ms_message("Vtable [%p] registered on core [%p]",lc,vtable); + lc->vtables=ms_list_append(lc->vtables,vtable); +} +void linphone_core_remove_listener(LinphoneCore *lc, const LinphoneCoreVTable *vtable) { + ms_message("Vtable [%p] unregistered on core [%p]",lc,vtable); + lc->vtables=ms_list_remove(lc->vtables,(void*)vtable); +} diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 778bdc2dd..0977c8790 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -1611,6 +1611,13 @@ typedef enum _LinphoneConfiguringState { */ typedef void (*LinphoneCoreConfiguringStatusCb)(LinphoneCore *lc, LinphoneConfiguringState status, const char *message); +/** + * Callback prototype for reporting network change either automatically detected or notified by #linphone_core_set_network_reachable. + * @param lc the LinphoneCore + * @param reachable true if network is reachable. + */ +typedef void (*LinphoneCoreNetworkReachableCb)(LinphoneCore *lc, bool_t reachable); + /** * This structure holds all callbacks that the application should implement. * None is mandatory. @@ -1645,8 +1652,21 @@ typedef struct _LinphoneCoreVTable{ 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*/ + LinphoneCoreNetworkReachableCb network_reachable; /** Call back to report IP network status (I.E up/down)*/ } LinphoneCoreVTable; +/** + * Instantiate a vtable with all argument set to NULL + * @returns newly allocated vtable + */ +LINPHONE_PUBLIC LinphoneCoreVTable *linphone_vtable_new(); + +/** + * destroy a vtable. + * @param vtable to be destroyed + */ +LINPHONE_PUBLIC void linphone_vtable_destroy(LinphoneCoreVTable* table); + /** * @} **/ @@ -1751,24 +1771,26 @@ LINPHONE_PUBLIC LinphoneCore *linphone_core_new_with_config(const LinphoneCoreVT /* function to be periodically called in a main loop */ /* For ICE to work properly it should be called every 20ms */ LINPHONE_PUBLIC void linphone_core_iterate(LinphoneCore *lc); -#if 0 /*not implemented yet*/ + /** * @ingroup initializing - * Provide Linphone Core with an unique identifier. This be later used to identified contact address coming from this device. - * Value is not saved. + * add a listener to be notified of linphone core events. Once events are received, registered vtable are invoked in order. + * @param vtable a LinphoneCoreVTable structure holding your application callbacks. Object is owned by linphone core until linphone_core_remove_listener. * @param lc object * @param string identifying the device, can be EMEI or UDID * */ -void linphone_core_set_device_identifier(LinphoneCore *lc,const char* device_id); +LINPHONE_PUBLIC void linphone_core_add_listener(LinphoneCore *lc, LinphoneCoreVTable *vtable); /** * @ingroup initializing - * get Linphone unique identifier + * remove a listener registred by linphone_core_add_listener. + * @param vtable a LinphoneCoreVTable structure holding your application callbacks + * @param lc object + * @param string identifying the device, can be EMEI or UDID * */ -const char* linphone_core_get_device_identifier(const LinphoneCore *lc); +LINPHONE_PUBLIC void linphone_core_remove_listener(LinphoneCore *lc, const LinphoneCoreVTable *vtable); -#endif /*sets the user-agent string in sip messages, ideally called just after linphone_core_new() or linphone_core_init() */ LINPHONE_PUBLIC void linphone_core_set_user_agent(LinphoneCore *lc, const char *ua_name, const char *version); diff --git a/coreapi/misc.c b/coreapi/misc.c index 670a3f923..a91d02432 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -421,8 +421,7 @@ int linphone_core_run_stun_tests(LinphoneCore *lc, LinphoneCall *call){ ms_error("Could not obtain stun server addrinfo."); return -1; } - if (lc->vtable.display_status!=NULL) - lc->vtable.display_status(lc,_("Stun lookup in progress...")); + linphone_core_notify_display_status(lc,_("Stun lookup in progress...")); /*create the two audio and video RTP sockets, and send STUN message to our stun server */ sock1=create_socket(call->media_ports[0].rtp_port); @@ -603,8 +602,7 @@ int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call) ms_warning("Fail to resolve STUN server for ICE gathering."); return -1; } - if (lc->vtable.display_status != NULL) - lc->vtable.display_status(lc, _("ICE local candidates gathering in progress...")); + linphone_core_notify_display_status(lc, _("ICE local candidates gathering in progress...")); /* Gather local host candidates. */ if (linphone_core_get_local_ip_for(AF_INET, NULL, local_addr) < 0) { diff --git a/coreapi/presence.c b/coreapi/presence.c index 97aca82b4..870d69cf8 100644 --- a/coreapi/presence.c +++ b/coreapi/presence.c @@ -1443,9 +1443,9 @@ void linphone_core_add_subscriber(LinphoneCore *lc, const char *subscriber, SalO linphone_friend_set_inc_subscribe_policy(fl,LinphoneSPAccept); fl->inc_subscribe_pending=TRUE; lc->subscribers=ms_list_append(lc->subscribers,(void *)fl); - if (lc->vtable.new_subscription_requested!=NULL) { + { char *tmp=linphone_address_as_string(fl->uri); - lc->vtable.new_subscription_requested(lc,fl,tmp); + linphone_core_notify_new_subscription_requested(lc,fl,tmp); ms_free(tmp); } } @@ -1876,8 +1876,7 @@ void linphone_notify_recv(LinphoneCore *lc, SalOp *op, SalSubscribeStatus ss, Sa } lf->presence = presence; lf->subscribe_active=TRUE; - if (lc->vtable.notify_presence_received) - lc->vtable.notify_presence_received(lc,(LinphoneFriend*)lf); + linphone_core_notify_notify_presence_received(lc,(LinphoneFriend*)lf); ms_free(tmp); }else{ ms_message("But this person is not part of our friend list, so we don't care."); diff --git a/coreapi/private.h b/coreapi/private.h index b19682718..f02c16637 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -677,7 +677,7 @@ typedef struct _LinphoneConference LinphoneConference; struct _LinphoneCore { - LinphoneCoreVTable vtable; + MSList* vtables; Sal *sal; LinphoneGlobalState state; struct _LpConfig *config; @@ -735,6 +735,7 @@ struct _LinphoneCore bool_t preview_finished; bool_t auto_net_state_mon; bool_t network_reachable; + bool_t network_reachable_to_be_notified; /*set to true when state must be notified in next iterate*/ bool_t use_preview_window; time_t network_last_check; @@ -978,6 +979,44 @@ BELLE_SIP_TYPE_ID(LinphoneProxyConfig) BELLE_SIP_DECLARE_TYPES_END + +void linphone_core_notify_global_state_changed(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message); +void linphone_core_notify_call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *message); +void linphone_core_notify_call_encryption_changed(LinphoneCore *lc, LinphoneCall *call, bool_t on, const char *authentication_token); +void linphone_core_notify_registration_state_changed(LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message); +void linphone_core_notify_show_interface(LinphoneCore *lc); +void linphone_core_notify_display_status(LinphoneCore *lc, const char *message); +void linphone_core_notify_display_message(LinphoneCore *lc, const char *message); +void linphone_core_notify_display_warning(LinphoneCore *lc, const char *message); +void linphone_core_notify_display_url(LinphoneCore *lc, const char *message, const char *url); +void linphone_core_notify_notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf); +void linphone_core_notify_new_subscription_requested(LinphoneCore *lc, LinphoneFriend *lf, const char *url); +void linphone_core_notify_auth_info_requested(LinphoneCore *lc, const char *realm, const char *username, const char *domain); +void linphone_core_notify_call_log_updated(LinphoneCore *lc, LinphoneCallLog *newcl); +void linphone_core_notify_text_message_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message); +void linphone_core_notify_message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *message); +void linphone_core_notify_file_transfer_recv(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size); +void linphone_core_notify_file_transfer_send(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size); +void linphone_core_notify_file_transfer_progress_indication(LinphoneCore *lc, LinphoneChatMessage *message, const LinphoneContent* content, size_t progress); +void linphone_core_notify_is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room); +void linphone_core_notify_dtmf_received(LinphoneCore* lc, LinphoneCall *call, int dtmf); +/* + * return true if at least a registered vtable has a cb for dtmf received*/ +bool_t linphone_core_dtmf_received_has_listener(const LinphoneCore* lc); +void linphone_core_notify_refer_received(LinphoneCore *lc, const char *refer_to); +void linphone_core_notify_buddy_info_updated(LinphoneCore *lc, LinphoneFriend *lf); +void linphone_core_notify_transfer_state_changed(LinphoneCore *lc, LinphoneCall *transfered, LinphoneCallState new_call_state); +void linphone_core_notify_call_stats_updated(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallStats *stats); +void linphone_core_notify_info_received(LinphoneCore *lc, LinphoneCall *call, const LinphoneInfoMessage *msg); +void linphone_core_notify_configuring_status(LinphoneCore *lc, LinphoneConfiguringState status, const char *message); +void linphone_core_notify_network_reachable(LinphoneCore *lc, bool_t reachable); + +void linphone_core_notify_notify_received(LinphoneCore *lc, LinphoneEvent *lev, const char *notified_event, const LinphoneContent *body); +void linphone_core_notify_subscription_state_changed(LinphoneCore *lc, LinphoneEvent *lev, LinphoneSubscriptionState state); +void linphone_core_notify_publish_state_changed(LinphoneCore *lc, LinphoneEvent *lev, LinphonePublishState state); + + + #ifdef __cplusplus } #endif diff --git a/coreapi/proxy.c b/coreapi/proxy.c index 546835854..0b4f6246a 100644 --- a/coreapi/proxy.c +++ b/coreapi/proxy.c @@ -310,14 +310,14 @@ int linphone_proxy_config_set_route(LinphoneProxyConfig *obj, const char *route) bool_t linphone_proxy_config_check(LinphoneCore *lc, LinphoneProxyConfig *obj){ if (obj->reg_proxy==NULL){ - if (lc && lc->vtable.display_warning) - lc->vtable.display_warning(lc,_("The sip proxy address you entered is invalid, it must start with \"sip:\"" + if (lc) + linphone_core_notify_display_warning(lc,_("The sip proxy address you entered is invalid, it must start with \"sip:\"" " followed by a hostname.")); return FALSE; } if (obj->reg_identity==NULL){ - if (lc && lc->vtable.display_warning) - lc->vtable.display_warning(lc,_("The sip identity you entered is invalid.\nIt should look like " + if (lc) + linphone_core_notify_display_warning(lc,_("The sip identity you entered is invalid.\nIt should look like " "sip:username@proxydomain, such as sip:alice@example.net")); return FALSE; } @@ -1365,9 +1365,9 @@ static void linphone_proxy_config_activate_sip_setup(LinphoneProxyConfig *cfg){ caps=sip_setup_context_get_capabilities(ssc); if (caps & SIP_SETUP_CAP_ACCOUNT_MANAGER){ if (sip_setup_context_login_account(ssc,cfg->reg_identity,NULL,NULL)!=0){ - if (lc->vtable.display_warning){ + { char *tmp=ms_strdup_printf(_("Could not login as %s"),cfg->reg_identity); - lc->vtable.display_warning(lc,tmp); + linphone_core_notify_display_warning(lc,tmp); ms_free(tmp); } return; @@ -1567,9 +1567,8 @@ void linphone_proxy_config_set_state(LinphoneProxyConfig *cfg, LinphoneRegistrat if (update_friends){ linphone_core_update_friends_subscriptions(lc,cfg,TRUE); } - if (lc && lc->vtable.registration_state_changed){ - lc->vtable.registration_state_changed(lc,cfg,state,message); - } + if (lc) + linphone_core_notify_registration_state_changed(lc,cfg,state,message); } else { /*state already reported*/ } diff --git a/tester/call_tester.c b/tester/call_tester.c index 6831ee04c..d57375369 100644 --- a/tester/call_tester.c +++ b/tester/call_tester.c @@ -2297,10 +2297,10 @@ static void call_transfer_existing_call_outgoing_call(void) { MSList* lcs=ms_list_append(NULL,marie->lc); const MSList* calls; - + linphone_core_use_files (pauline->lc,TRUE); linphone_core_use_files (laure->lc,TRUE); - + lcs=ms_list_append(lcs,pauline->lc); lcs=ms_list_append(lcs,laure->lc); @@ -2315,7 +2315,7 @@ static void call_transfer_existing_call_outgoing_call(void) { CU_ASSERT_TRUE(call(marie,laure)); marie_call_laure=linphone_core_get_current_call(marie->lc); laure_called_by_marie=linphone_core_get_current_call(laure->lc); - /*marie pause pauline*/ + /*marie pause laure*/ CU_ASSERT_TRUE(pause_call_1(marie,marie_call_laure,laure,laure_called_by_marie)); reset_counters(&marie->stat); @@ -2570,7 +2570,9 @@ static void call_rejected_because_wrong_credentials_with_params(const char* user linphone_core_set_user_agent(marie->lc,user_agent,NULL); } if (!enable_auth_req_cb) { - marie->lc->vtable.auth_info_requested=NULL; + + ((LinphoneCoreVTable*)(marie->lc->vtables->data))->auth_info_requested=NULL; + linphone_core_add_auth_info(marie->lc,wrong_auth_info); } diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index 38aeafa4d..67b68f87c 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -193,6 +193,8 @@ typedef struct _stats { int number_of_LinphoneCallEncryptedOn; int number_of_LinphoneCallEncryptedOff; + int number_of_NetworkReachableTrue; + int number_of_NetworkReachableFalse; LinphoneChatMessage* last_received_chat_message; }stats; diff --git a/tester/message_tester.c b/tester/message_tester.c index 68eddfa08..977243085 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -216,12 +216,9 @@ static void text_message_within_dialog(void) { static LinphoneAuthInfo* text_message_with_credential_from_auth_cb_auth_info; static void text_message_with_credential_from_auth_cb_auth_info_requested(LinphoneCore *lc, const char *realm, const char *username, const char *domain) { - stats* counters; ms_message("text_message_with_credential_from_auth_cb:Auth info requested for user id [%s] at realm [%s]\n" ,username ,realm); - counters = get_stats(lc); - counters->number_of_auth_info_requested++; linphone_core_add_auth_info(lc,text_message_with_credential_from_auth_cb_auth_info); /*add stored authentication info to LinphoneCore*/ } @@ -229,13 +226,15 @@ static void text_message_with_credential_from_auth_cb_auth_info_requested(Linpho static void text_message_with_credential_from_auth_cb(void) { char* to; LinphoneChatRoom* chat_room; + LinphoneCoreVTable* vtable = linphone_vtable_new(); LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); text_message_with_credential_from_auth_cb_auth_info=linphone_auth_info_clone((LinphoneAuthInfo*)(linphone_core_get_auth_info_list(marie->lc)->data)); /*to force cb to be called*/ linphone_core_clear_all_auth_info(marie->lc); - marie->lc->vtable.auth_info_requested=text_message_with_credential_from_auth_cb_auth_info_requested; + vtable->auth_info_requested=text_message_with_credential_from_auth_cb_auth_info_requested; + linphone_core_add_listener(marie->lc, vtable); to = linphone_address_as_string(marie->identity); chat_room = linphone_core_create_chat_room(pauline->lc,to); diff --git a/tester/register_tester.c b/tester/register_tester.c index 612e40a0b..d47ffa2df 100644 --- a/tester/register_tester.c +++ b/tester/register_tester.c @@ -22,20 +22,10 @@ #include "private.h" #include "liblinphone_tester.h" -static void auth_info_requested2(LinphoneCore *lc, const char *realm, const char *username, const char *domain) { - stats* counters; - ms_message("Auth info requested for user id [%s] at realm [%s]\n" - ,username - ,realm); - counters = get_stats(lc); - counters->number_of_auth_info_requested++; - -} static void auth_info_requested(LinphoneCore *lc, const char *realm, const char *username, const char *domain) { LinphoneAuthInfo *info; - auth_info_requested2(lc,realm,username,domain); info=linphone_auth_info_new(test_username,NULL,test_password,NULL,realm,domain); /*create authentication structure from identity*/ linphone_core_add_auth_info(lc,info); /*add authentication info to LinphoneCore*/ } @@ -46,7 +36,9 @@ static LinphoneCoreManager* create_lcm_with_auth(unsigned int with_auth) { LinphoneCoreManager* mgr=linphone_core_manager_new(NULL); if (with_auth) { - mgr->lc->vtable.auth_info_requested=auth_info_requested; + LinphoneCoreVTable* vtable = linphone_vtable_new(); + vtable->auth_info_requested=auth_info_requested; + linphone_core_add_listener(mgr->lc,vtable); } /*to allow testing with 127.0.0.1*/ @@ -322,6 +314,7 @@ static void ha1_authenticated_register(){ static void authenticated_register_with_no_initial_credentials(){ LinphoneCoreManager *mgr; + LinphoneCoreVTable* vtable = linphone_vtable_new(); stats* counters; char route[256]; @@ -329,7 +322,8 @@ static void authenticated_register_with_no_initial_credentials(){ mgr = linphone_core_manager_new(NULL); - mgr->lc->vtable.auth_info_requested=auth_info_requested; + vtable->auth_info_requested=auth_info_requested; + linphone_core_add_listener(mgr->lc,vtable); counters= get_stats(mgr->lc); counters->number_of_auth_info_requested=0; @@ -387,8 +381,6 @@ static void authenticated_register_with_wrong_credentials_with_params_base(const sprintf(route,"sip:%s",test_route); - mgr->lc->vtable.auth_info_requested=auth_info_requested2; - sal_set_refresher_retry_after(mgr->lc->sal,500); if (user_agent) { linphone_core_set_user_agent(mgr->lc,user_agent,NULL); @@ -467,9 +459,12 @@ static void network_state_change(){ counters = get_stats(lc); register_ok=counters->number_of_LinphoneRegistrationOk; linphone_core_set_network_reachable(lc,FALSE); + CU_ASSERT_TRUE(wait_for(lc,lc,&counters->number_of_NetworkReachableFalse,1)); CU_ASSERT_TRUE(wait_for(lc,lc,&counters->number_of_LinphoneRegistrationNone,register_ok)); linphone_core_set_network_reachable(lc,TRUE); + CU_ASSERT_TRUE(wait_for(lc,lc,&counters->number_of_NetworkReachableTrue,1)); wait_for(lc,lc,&counters->number_of_LinphoneRegistrationOk,2*register_ok); + linphone_core_manager_destroy(mgr); } static int get_number_of_udp_proxy(const LinphoneCore* lc) { diff --git a/tester/tester.c b/tester/tester.c index 7d635eb46..76a909606 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -57,7 +57,15 @@ const char *liblinphone_tester_writable_dir_prefix = "."; #endif const char *userhostsfile = "tester_hosts"; - +static void network_reachable(LinphoneCore *lc, bool_t reachable) { + stats* counters; + ms_message("Network reachable [%s]",reachable?"TRUE":"FALSE"); + counters = get_stats(lc); + if (reachable) + counters->number_of_NetworkReachableTrue++; + else + counters->number_of_NetworkReachableFalse++; +} void liblinphone_tester_clock_start(MSTimeSpec *start){ ms_get_cur_time(start); } @@ -216,6 +224,7 @@ LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_f mgr->v_table.publish_state_changed=linphone_publish_state_changed; mgr->v_table.configuring_status=linphone_configuration_status; mgr->v_table.call_encryption_changed=linphone_call_encryption_changed; + mgr->v_table.network_reachable=network_reachable; reset_counters(&mgr->stat); if (rc_file) rc_path = ms_strdup_printf("rcfiles/%s", rc_file);