2 TutorialHelloWorld.java
3 Copyright (C) 2010 Belledonne Communications SARL
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package org.linphone.core.tutorials;
21 import org.linphone.core.LinphoneAddress;
22 import org.linphone.core.LinphoneCall;
23 import org.linphone.core.LinphoneChatRoom;
24 import org.linphone.core.LinphoneCore;
25 import org.linphone.core.LinphoneCoreException;
26 import org.linphone.core.LinphoneCoreFactory;
27 import org.linphone.core.LinphoneCoreListener;
28 import org.linphone.core.LinphoneFriend;
29 import org.linphone.core.LinphoneProxyConfig;
30 import org.linphone.core.LinphoneCall.State;
31 import org.linphone.core.LinphoneCore.GlobalState;
32 import org.linphone.core.LinphoneCore.RegistrationState;
36 * This program is a _very_ simple usage example of liblinphone.
37 * It just takes a sip-uri as first argument and attempts to call it.
39 * Ported from helloworld.c
41 * @author Guillaume Beraudo
44 public class TutorialHelloWorld implements LinphoneCoreListener {
45 private boolean running;
46 private TutorialNotifier TutorialNotifier;
49 public TutorialHelloWorld(TutorialNotifier TutorialNotifier) {
50 this.TutorialNotifier = TutorialNotifier;
53 public TutorialHelloWorld() {
54 this.TutorialNotifier = new TutorialNotifier();
59 public void show(LinphoneCore lc) {}
60 public void byeReceived(LinphoneCore lc, String from) {}
61 public void authInfoRequested(LinphoneCore lc, String realm, String username) {}
62 public void displayStatus(LinphoneCore lc, String message) {}
63 public void displayMessage(LinphoneCore lc, String message) {}
64 public void displayWarning(LinphoneCore lc, String message) {}
65 public void globalState(LinphoneCore lc, GlobalState state, String message) {}
66 public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg,RegistrationState cstate, String smessage) {}
67 public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf,String url) {}
68 public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) {}
69 public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from, String message) {}
72 * Call state notification listener
74 public void callState(LinphoneCore lc, LinphoneCall call, State cstate, String msg){
75 write("State: " + msg);
77 if (State.CallEnd.equals(cstate))
82 public static void main(String[] args) {
83 // Check tutorial was called with the right number of arguments
84 if (args.length != 1) {
85 throw new IllegalArgumentException("Bad number of arguments");
88 // Create tutorial object
89 TutorialHelloWorld helloWorld = new TutorialHelloWorld();
91 String destinationSipAddress = args[1];
92 helloWorld.launchTutorial(destinationSipAddress);
93 } catch (Exception e) {
100 public void launchTutorial(String destinationSipAddress) throws LinphoneCoreException {
102 // First instantiate the core Linphone object given only a listener.
103 // The listener will react to events in Linphone core.
104 LinphoneCore lc = LinphoneCoreFactory.instance().createLinphoneCore(this);
109 // Send the INVITE message to destination SIP address
110 LinphoneCall call = lc.invite(destinationSipAddress);
112 write("Could not place call to " + destinationSipAddress);
116 write("Call to " + destinationSipAddress + " is in progress...");
120 // main loop for receiving notifications and doing background linphonecore work
126 } catch(InterruptedException ie) {
127 write("Interrupted!\nAborting");
134 if (!State.CallEnd.equals(call.getState())) {
135 write("Terminating the call");
136 lc.terminateCall(call);
139 write("Shutting down...");
140 // You need to destroy the LinphoneCore object when no longer used
147 public void stopMainLoop() {
152 private void write(String s) {
153 TutorialNotifier.notify(s);