]> sjero.net Git - linphone/blob - coreapi/help/chatroom.c
Update ms2
[linphone] / coreapi / help / chatroom.c
1
2 /*
3 linphone
4 Copyright (C) 2010  Belledonne Communications SARL 
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 */
20
21 /**
22  * @defgroup chatroom_tuto Chat room and messaging
23  * @ingroup tutorials
24  *This program is a _very_ simple usage example of liblinphone,
25  *desmonstrating how to send/receive  SIP MESSAGE from a sip uri identity passed from the command line.
26  *<br>Argument must be like sip:jehan@sip.linphone.org .
27  *<br>
28  *ex chatroom sip:jehan@sip.linphone.org
29  *<br>
30  *@include chatroom.c
31
32  *
33  */
34
35 #ifdef IN_LINPHONE
36 #include "linphonecore.h"
37 #else
38 #include "linphone/linphonecore.h"
39 #endif
40
41 #include <signal.h>
42
43 static bool_t running=TRUE;
44
45 static void stop(int signum){
46         running=FALSE;
47 }
48 void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
49         printf(" Message [%s] received from [%s] \n",message,linphone_address_as_string (from));
50 }
51
52
53 LinphoneCore *lc;
54 int main(int argc, char *argv[]){
55         LinphoneCoreVTable vtable={0};
56
57         char* dest_friend=NULL;
58
59
60         /* takes   sip uri  identity from the command line arguments */
61         if (argc>1){
62                 dest_friend=argv[1];
63         }
64
65         signal(SIGINT,stop);
66 //#define DEBUG
67 #ifdef DEBUG
68         linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/
69 #endif
70         /* 
71          Fill the LinphoneCoreVTable with application callbacks.
72          All are optional. Here we only use the text_received callback
73          in order to get notifications about incoming message.
74          */
75         vtable.text_received=text_received;
76
77         /*
78          Instantiate a LinphoneCore object given the LinphoneCoreVTable
79         */
80         lc=linphone_core_new(&vtable,NULL,NULL,NULL);
81
82
83         /*Next step is to create a chat root*/
84         LinphoneChatRoom* chat_room = linphone_core_create_chat_room(lc,dest_friend);
85
86         linphone_chat_room_send_message(chat_room,"Hello world"); /*sending message*/
87
88         /* main loop for receiving incoming messages and doing background linphone core work: */
89         while(running){
90                 linphone_core_iterate(lc);
91                 ms_usleep(50000);
92         }
93
94         printf("Shutting down...\n");
95         linphone_chat_room_destroy(chat_room);
96         linphone_core_destroy(lc);
97         printf("Exited\n");
98         return 0;
99 }
100