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.LinphoneCore.EcCalibratorStatus;
26 import org.linphone.core.LinphoneCoreException;
27 import org.linphone.core.LinphoneCoreFactory;
28 import org.linphone.core.LinphoneCoreListener;
29 import org.linphone.core.LinphoneFriend;
30 import org.linphone.core.LinphoneProxyConfig;
31 import org.linphone.core.LinphoneCall.State;
32 import org.linphone.core.LinphoneCore.GlobalState;
33 import org.linphone.core.LinphoneCore.RegistrationState;
37 * This program is a _very_ simple usage example of liblinphone.
38 * It just takes a sip-uri as first argument and attempts to call it.
40 * Ported from helloworld.c
42 * @author Guillaume Beraudo
45 public class TutorialHelloWorld implements LinphoneCoreListener {
46 private boolean running;
47 private TutorialNotifier TutorialNotifier;
50 public TutorialHelloWorld(TutorialNotifier TutorialNotifier) {
51 this.TutorialNotifier = TutorialNotifier;
54 public TutorialHelloWorld() {
55 this.TutorialNotifier = new TutorialNotifier();
60 public void show(LinphoneCore lc) {}
61 public void byeReceived(LinphoneCore lc, String from) {}
62 public void authInfoRequested(LinphoneCore lc, String realm, String username) {}
63 public void displayStatus(LinphoneCore lc, String message) {}
64 public void displayMessage(LinphoneCore lc, String message) {}
65 public void displayWarning(LinphoneCore lc, String message) {}
66 public void globalState(LinphoneCore lc, GlobalState state, String message) {}
67 public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg,RegistrationState cstate, String smessage) {}
68 public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf,String url) {}
69 public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) {}
70 public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from, String message) {}
71 public void ecCalibrationStatus(LinphoneCore lc, EcCalibratorStatus status,int delay_ms, Object data) {}
72 public void callEncryptionChanged(LinphoneCore lc, LinphoneCall call,boolean encrypted, String authenticationToken) {}
75 * Call state notification listener
77 public void callState(LinphoneCore lc, LinphoneCall call, State cstate, String msg){
78 write("State: " + msg);
80 if (State.CallEnd.equals(cstate))
85 public static void main(String[] args) {
86 // Check tutorial was called with the right number of arguments
87 if (args.length != 1) {
88 throw new IllegalArgumentException("Bad number of arguments");
91 // Create tutorial object
92 TutorialHelloWorld helloWorld = new TutorialHelloWorld();
94 String destinationSipAddress = args[1];
95 helloWorld.launchTutorial(destinationSipAddress);
96 } catch (Exception e) {
103 public void launchTutorial(String destinationSipAddress) throws LinphoneCoreException {
105 // First instantiate the core Linphone object given only a listener.
106 // The listener will react to events in Linphone core.
107 LinphoneCore lc = LinphoneCoreFactory.instance().createLinphoneCore(this);
112 // Send the INVITE message to destination SIP address
113 LinphoneCall call = lc.invite(destinationSipAddress);
115 write("Could not place call to " + destinationSipAddress);
119 write("Call to " + destinationSipAddress + " is in progress...");
123 // main loop for receiving notifications and doing background linphonecore work
129 } catch(InterruptedException ie) {
130 write("Interrupted!\nAborting");
137 if (!State.CallEnd.equals(call.getState())) {
138 write("Terminating the call");
139 lc.terminateCall(call);
142 write("Shutting down...");
143 // You need to destroy the LinphoneCore object when no longer used
150 public void stopMainLoop() {
155 private void write(String s) {
156 TutorialNotifier.notify(s);