Commit b6c3f44d authored by jehan's avatar jehan

add messaging documentation

parent f92683df
......@@ -130,7 +130,7 @@ static void linphonec_new_unknown_subscriber(LinphoneCore *lc,
LinphoneFriend *lf, const char *url);
static void linphonec_text_received(LinphoneCore *lc, LinphoneChatRoom *cr,
const char *from, const char *msg);
const LinphoneAddress *from, const char *msg);
static void linphonec_display_status (LinphoneCore * lc, const char *something);
static void linphonec_dtmf_received(LinphoneCore *lc, LinphoneCall *call, int dtmf);
static void print_prompt(LinphoneCore *opm);
......@@ -371,9 +371,9 @@ static void linphonec_call_state_changed(LinphoneCore *lc, LinphoneCall *call, L
*/
static void
linphonec_text_received(LinphoneCore *lc, LinphoneChatRoom *cr,
const char *from, const char *msg)
const LinphoneAddress *from, const char *msg)
{
printf("%s: %s\n", from, msg);
printf("%s: %s\n", linphone_address_as_string(from), msg);
// TODO: provide mechanism for answering.. ('say' command?)
}
......
......@@ -78,7 +78,7 @@ bool_t linphone_chat_room_matches(LinphoneChatRoom *cr, const LinphoneAddress *f
return FALSE;
}
void linphone_chat_room_text_received(LinphoneChatRoom *cr, LinphoneCore *lc, const char *from, const char *msg){
void linphone_chat_room_text_received(LinphoneChatRoom *cr, LinphoneCore *lc, const LinphoneAddress *from, const char *msg){
if (lc->vtable.text_received!=NULL) lc->vtable.text_received(lc, cr, from, msg);
}
......@@ -102,8 +102,9 @@ void linphone_core_text_received(LinphoneCore *lc, const char *from, const char
/* create a new chat room */
cr=linphone_core_create_chat_room(lc,cleanfrom);
}
linphone_address_destroy(addr);
linphone_chat_room_text_received(cr,lc,cleanfrom,msg);
linphone_chat_room_text_received(cr,lc,cr->peer_url,msg);
ms_free(cleanfrom);
}
......@@ -114,3 +115,6 @@ void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud){
void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr){
return cr->user_data;
}
const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr) {
return cr->peer_url;
}
......@@ -32,7 +32,7 @@ endif
clean-local:
rm -rf doc
noinst_PROGRAMS=helloworld registration buddy_status
noinst_PROGRAMS=helloworld registration buddy_status chatroom
helloworld_SOURCES=helloworld.c
......@@ -42,15 +42,16 @@ helloworld_LDADD=$(top_builddir)/coreapi/liblinphone.la \
registration_SOURCES=registration.c
registration_LDADD=$(top_builddir)/coreapi/liblinphone.la \
$(MEDIASTREAMER_LIBS) \
$(ORTP_LIBS)
registration_LDADD=$(helloworld_LDADD)
buddy_status_SOURCES=buddy_status.c
buddy_status_LDADD=$(top_builddir)/coreapi/liblinphone.la \
$(MEDIASTREAMER_LIBS) \
$(ORTP_LIBS)
buddy_status_LDADD=$(helloworld_LDADD)
chatroom_SOURCES=chatroom.c
chatroom_LDADD=$(helloworld_LDADD)
INCLUDES=-I$(top_srcdir)/coreapi \
......
/*
linphone
buddy_status
Copyright (C) 2010 Belledonne Communications SARL
This program is free software; you can redistribute it and/or
......@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* @defgroup buddy_tutorials Basic buddy status notification
* @ingroup tutorials
*This program is a _very_ simple usage example of liblinphone,
*desmonstrating how to initiate SIP subscriptions and receive notifications from a sip uri identity passed from the command line.
*demonstrating how to initiate SIP subscriptions and receive notifications from a sip uri identity passed from the command line.
*<br>Argument must be like sip:jehan@sip.linphone.org .
*<br>
*ex budy_list sip:jehan@sip.linphone.org
......@@ -82,14 +82,14 @@ int main(int argc, char *argv[]){
#endif
/*
Fill the LinphoneCoreVTable with application callbacks.
All are optional. Here we only use the registration_state_changed callbacks
in order to get notifications about the progress of the registration.
All are optional. Here we only use the both notify_presence_recv and new_subscription_request callbacks
in order to get notifications about friend status.
*/
vtable.notify_presence_recv=notify_presence_recv_updated;
vtable.new_subscription_request=new_subscription_request;
/*
Instanciate a LinphoneCore object given the LinphoneCoreVTable
Instantiate a LinphoneCore object given the LinphoneCoreVTable
*/
lc=linphone_core_new(&vtable,NULL,NULL,NULL);
LinphoneFriend* my_friend=NULL;
......
/*
linphone
Copyright (C) 2010 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* @defgroup chatroom_tuto Chat room and messaging
* @ingroup tutorials
*This program is a _very_ simple usage example of liblinphone,
*desmonstrating how to send/receive SIP MESSAGE from a sip uri identity passed from the command line.
*<br>Argument must be like sip:jehan@sip.linphone.org .
*<br>
*ex chatroom sip:jehan@sip.linphone.org
*<br>
*@include chatroom.c
*
*/
#include "linphonecore.h"
#include <signal.h>
static bool_t running=TRUE;
static void stop(int signum){
running=FALSE;
}
void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
printf(" Message [%s] received from [%s] \n",message,linphone_address_as_string (from));
}
LinphoneCore *lc;
int main(int argc, char *argv[]){
LinphoneCoreVTable vtable={0};
char* dest_friend=NULL;
/* takes sip uri identity from the command line arguments */
if (argc>1){
dest_friend=argv[1];
}
signal(SIGINT,stop);
//#define DEBUG
#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 text_received callback
in order to get notifications about incoming message.
*/
vtable.text_received=text_received;
/*
Instantiate a LinphoneCore object given the LinphoneCoreVTable
*/
lc=linphone_core_new(&vtable,NULL,NULL,NULL);
/*Next step is to create a chat root*/
LinphoneChatRoom* chat_room = linphone_core_create_chat_room(lc,dest_friend);
linphone_chat_room_send_message(chat_room,"Hello world"); /*sending message*/
/* main loop for receiving incoming messages and doing background linphone core work: */
while(running){
linphone_core_iterate(lc);
ms_usleep(50000);
}
printf("Shutting down...\n");
linphone_chat_room_destroy(chat_room);
linphone_core_destroy(lc);
printf("Exited\n");
return 0;
}
......@@ -146,8 +146,29 @@ linphone_friend_done(my_friend); /*commit changes triggering an UNSUBSCRIBE mess
<br> A complete tutorial can be found at : \ref buddy_tutorials "Registration tutorial"
*/
**/
/**
* @defgroup chatroom Chat room and Messaging
<b> Exchanging text messages</b>
<br> Messages are sent using #LinphoneChatRoom object. First step is to create a \link linphone_core_create_chat_room() chat room \endlink
from a peer sip uri.
\code
LinphoneChatRoom* chat_room = linphone_core_create_chat_room(lc,"sip:joe@sip.linphone.org");
\endcode
<br>Once created, messages are sent using function linphone_chat_room_send_message() .
\code
linphone_chat_room_send_message(chat_room,"Hello world"); /*sending message*/
\endcode
<br>Incoming message are received from call back LinphoneCoreVTable.text_received
\code
void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
printf(" Message [%s] received from [%s] \n",message,linphone_address_as_string (from));
}
\endcode
<br> A complete tutorial can be found at : \ref chatroom_tuto "Chat room tutorial"
**/
/**
* @defgroup call_logs Managing call logs
......
......@@ -402,14 +402,48 @@ LinphoneAuthInfo * linphone_auth_info_new_from_config_file(struct _LpConfig *con
struct _LinphoneChatRoom;
/**
* @addtogroup chatroom
* @{
*/
/**
* A chat room is the place where text messages are exchanged.
* <br> Can be created by linphone_core_create_chat_room().
*/
typedef struct _LinphoneChatRoom LinphoneChatRoom;
/**
* Create a new chat room for messaging from a sip uri like sip:joe@sip.linphone.org
* @param lc #LinphoneCore object
* @param to destination address for messages
* @return #LinphoneChatRoom where messaging can take place.
*/
LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to);
/**
* Destructor
* @param cr #LinphoneChatRoom object
*/
void linphone_chat_room_destroy(LinphoneChatRoom *cr);
LinphoneChatRoom * linphone_core_create_chat_room(struct _LinphoneCore *lc, const char *to);
/**
* get peer address \link linphone_core_create_chat_room() associated to \endlink this #LinphoneChatRoom
* @param cr #LinphoneChatRoom object
* @return #LinphoneAddress peer address
*/
const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr);
/**
* send a message to peer member of this chat room.
* @param cr #LinphoneChatRoom object
* @param msg message to be sent
*/
void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg);
void linphone_chat_room_destroy(LinphoneChatRoom *cr);
void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud);
void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr);
/**
* @}
*/
typedef enum _LinphoneGlobalState{
LinphoneGlobalOff,
LinphoneGlobalStartup,
......@@ -464,8 +498,15 @@ typedef void (*NewSubscribtionRequestCb)(struct _LinphoneCore *lc, LinphoneFrien
typedef void (*AuthInfoRequested)(struct _LinphoneCore *lc, const char *realm, const char *username);
/** Callback prototype */
typedef void (*CallLogUpdated)(struct _LinphoneCore *lc, struct _LinphoneCallLog *newcl);
/** Callback prototype */
typedef void (*TextMessageReceived)(struct _LinphoneCore *lc, LinphoneChatRoom *room, const char *from, const char *message);
/**
* Callback prototype
*
* @param lc #LinphoneCore object
* @param room #LinphoneChatRoom involved in this conversation. Can be be created by the framework in case \link #LinphoneAddress the from \endlink is not present in any chat room.
* @param from #LinphoneAddress from
* @param message incoming message
* */
typedef void (*TextMessageReceived)(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message);
/** Callback prototype */
typedef void (*DtmfReceived)(struct _LinphoneCore* lc, LinphoneCall *call, int dtmf);
/** Callback prototype */
......
......@@ -94,13 +94,13 @@ void linphone_gtk_send_text(GtkWidget *button){
}
}
void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const char *from, const char *message){
void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message){
GtkWidget *w=(GtkWidget*)linphone_chat_room_get_user_data(room);
if (w==NULL){
w=linphone_gtk_init_chatroom(room,from);
w=linphone_gtk_init_chatroom(room,linphone_address_as_string_uri_only(from));
}
linphone_gtk_push_text(GTK_TEXT_VIEW(linphone_gtk_get_widget(w,"textlog")),
from,
linphone_address_as_string_uri_only(from),
message,FALSE);
gtk_window_present(GTK_WINDOW(w));
/*gtk_window_set_urgency_hint(GTK_WINDOW(w),TRUE);*/
......
......@@ -61,7 +61,7 @@ void linphone_gtk_set_my_presence(LinphoneOnlineStatus ss);
void linphone_gtk_show_parameters(void);
void linphone_gtk_load_identities(void);
void linphone_gtk_create_chatroom(const char *with);
void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const char *from, const char *message);
void linphone_gtk_text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message);
void linphone_gtk_call_log_update(GtkWidget *w);
void linphone_gtk_create_log_window(void);
void linphone_gtk_log_show(void);
......
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