Merge branch 'master' of git.linphone.org:linphone-private

This commit is contained in:
Jehan Monnier 2010-11-05 16:04:03 +01:00
commit b4464773fd
6 changed files with 663 additions and 2 deletions

View file

@ -0,0 +1,185 @@
/*
linphone
Copyright (C) 2010 Belledonne Communications SARL
(simon.morlat@linphone.org)
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.
*/
package org.linphone.core.tutorials;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneChatRoom;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneCoreListener;
import org.linphone.core.LinphoneFriend;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.OnlineStatus;
import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCore.GlobalState;
import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.core.LinphoneFriend.SubscribePolicy;
/**
*
* This program is a _very_ simple usage example of liblinphone,
* 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 .
* ex budy_list sip:jehan@sip.linphone.org
* <br>Subscription is cleared on SIGINT
*
* Ported from buddy_status.c
*
* @author Guillaume Beraudo
*
*/
public class TutorialBuddyStatus implements LinphoneCoreListener {
private boolean running;
private TutorialNotifier TutorialNotifier;
public TutorialBuddyStatus(TutorialNotifier TutorialNotifier) {
this.TutorialNotifier = TutorialNotifier;
}
public TutorialBuddyStatus() {
this.TutorialNotifier = new TutorialNotifier();
}
public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf,String url) {
write("["+lf.getAddress().getUserName()+"] wants to see your status, accepting");
lf.edit();
lf.setIncSubscribePolicy(SubscribePolicy.SPAccept);
lf.done();
try {
lc.addFriend(lf);
} catch (LinphoneCoreException e) {
write("Error while adding friend [" + lf.getAddress().getUserName() + "] to linphone in the callback");
}
}
public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) {
write("New state [" + lf.getStatus() +"] for user id ["+lf.getAddress().getUserName()+"]");
}
public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg,RegistrationState cstate, String smessage) {}
public void show(LinphoneCore lc) {}
public void byeReceived(LinphoneCore lc, String from) {}
public void authInfoRequested(LinphoneCore lc, String realm, String username) {}
public void displayStatus(LinphoneCore lc, String message) {}
public void displayMessage(LinphoneCore lc, String message) {}
public void displayWarning(LinphoneCore lc, String message) {}
public void globalState(LinphoneCore lc, GlobalState state, String message) {}
public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from, String message) {}
public void callState(LinphoneCore lc, LinphoneCall call, State cstate, String msg) {}
public static void main(String[] args) {
// Check tutorial was called with the right number of arguments
if (args.length != 1) {
throw new IllegalArgumentException("Bad number of arguments");
}
// Create tutorial object
TutorialBuddyStatus tutorial = new TutorialBuddyStatus();
try {
String userSipAddress = args[1];
tutorial.launchTutorial(userSipAddress);
} catch (Exception e) {
e.printStackTrace();
}
}
public void launchTutorial(String sipAddress) throws LinphoneCoreException {
final LinphoneCoreFactory lcFactory = LinphoneCoreFactory.instance();
// First instantiate the core Linphone object given only a listener.
// The listener will react to events in Linphone core.
LinphoneCore lc = lcFactory.createLinphoneCore(this);
try {
// Create friend address
LinphoneFriend lf = lcFactory.createLinphoneFriend(sipAddress);
if (lf == null) {
write("Could not create friend; weird SIP address?");
return;
}
lf.enableSubscribes(true);
lf.setIncSubscribePolicy(SubscribePolicy.SPAccept);
try {
lc.addFriend(lf);
} catch (LinphoneCoreException e) {
write("Error while adding friend " + lf.getAddress().getUserName() + " to linphone");
}
lc.setPresenceInfo(0, null, OnlineStatus.Online);
// main loop for receiving notifications and doing background linphonecore work
running = true;
while (running) {
lc.iterate();
try{
Thread.sleep(50);
} catch(InterruptedException ie) {
write("Interrupted!\nAborting");
return;
}
}
lc.setPresenceInfo(0, null, OnlineStatus.Offline);
lc.iterate();
lf.edit();
lf.enableSubscribes(false);
lf.done();
lc.iterate();
} finally {
write("Shutting down...");
// You need to destroy the LinphoneCore object when no longer used
lc.destroy();
write("Exited");
}
}
public void stopMainLoop() {
running=false;
}
private void write(String s) {
TutorialNotifier.notify(s);
}
}

View file

@ -0,0 +1,144 @@
/*
linphone
Copyright (C) 2010 Belledonne Communications SARL
(simon.morlat@linphone.org)
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.
*/
package org.linphone.core.tutorials;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneChatRoom;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneCoreListener;
import org.linphone.core.LinphoneFriend;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCore.GlobalState;
import org.linphone.core.LinphoneCore.RegistrationState;
/**
* This program is a _very_ simple usage example of liblinphone.
* It demonstrates how to send/receive SIP MESSAGE from a sip uri identity
* passed from the command line.
*
* Argument must be like sip:jehan@sip.linphone.org .
*
* ex chatroom sip:jehan@sip.linphone.org
* just takes a sip-uri as first argument and attempts to call it.
*
* Ported from chatroom.c
*
* @author Guillaume Beraudo
*
*/
public class TutorialChatRoom implements LinphoneCoreListener {
private boolean running;
private TutorialNotifier TutorialNotifier;
public TutorialChatRoom(TutorialNotifier TutorialNotifier) {
this.TutorialNotifier = TutorialNotifier;
}
public TutorialChatRoom() {
this.TutorialNotifier = new TutorialNotifier();
}
public void show(LinphoneCore lc) {}
public void byeReceived(LinphoneCore lc, String from) {}
public void authInfoRequested(LinphoneCore lc, String realm, String username) {}
public void displayStatus(LinphoneCore lc, String message) {}
public void displayMessage(LinphoneCore lc, String message) {}
public void displayWarning(LinphoneCore lc, String message) {}
public void globalState(LinphoneCore lc, GlobalState state, String message) {}
public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg,RegistrationState cstate, String smessage) {}
public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf,String url) {}
public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) {}
public void callState(LinphoneCore lc, LinphoneCall call, State cstate, String msg){}
public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from, String message) {
write("Message ["+message+"] received from ["+from.asString()+"]");
}
public static void main(String[] args) {
// Check tutorial was called with the right number of arguments
if (args.length != 1) {
throw new IllegalArgumentException("Bad number of arguments");
}
// Create tutorial object
TutorialChatRoom tutorial = new TutorialChatRoom();
try {
String destinationSipAddress = args[1];
tutorial.launchTutorial(destinationSipAddress);
} catch (Exception e) {
e.printStackTrace();
}
}
public void launchTutorial(String destinationSipAddress) throws LinphoneCoreException {
// First instantiate the core Linphone object given only a listener.
// The listener will react to events in Linphone core.
LinphoneCore lc = LinphoneCoreFactory.instance().createLinphoneCore(this);
try {
LinphoneChatRoom chatRoom = lc.createChatRoom(destinationSipAddress);
chatRoom.sendMessage("Hello world");
// main loop for receiving notifications and doing background linphonecore work
running = true;
while (running) {
lc.iterate();
try{
Thread.sleep(50);
} catch(InterruptedException ie) {
write("Interrupted!\nAborting");
return;
}
}
} finally {
write("Shutting down...");
// You need to destroy the LinphoneCore object when no longer used
lc.destroy();
write("Exited");
}
}
public void stopMainLoop() {
running=false;
}
private void write(String s) {
TutorialNotifier.notify(s);
}
}

View file

@ -0,0 +1,157 @@
/*
linphone
Copyright (C) 2010 Belledonne Communications SARL
(simon.morlat@linphone.org)
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.
*/
package org.linphone.core.tutorials;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneChatRoom;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneCoreListener;
import org.linphone.core.LinphoneFriend;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCore.GlobalState;
import org.linphone.core.LinphoneCore.RegistrationState;
/**
* This program is a _very_ simple usage example of liblinphone.
* It just takes a sip-uri as first argument and attempts to call it.
*
* Ported from helloworld.c
*
* @author Guillaume Beraudo
*
*/
public class TutorialHelloWorld implements LinphoneCoreListener {
private boolean running;
private TutorialNotifier TutorialNotifier;
public TutorialHelloWorld(TutorialNotifier TutorialNotifier) {
this.TutorialNotifier = TutorialNotifier;
}
public TutorialHelloWorld() {
this.TutorialNotifier = new TutorialNotifier();
}
public void show(LinphoneCore lc) {}
public void byeReceived(LinphoneCore lc, String from) {}
public void authInfoRequested(LinphoneCore lc, String realm, String username) {}
public void displayStatus(LinphoneCore lc, String message) {}
public void displayMessage(LinphoneCore lc, String message) {}
public void displayWarning(LinphoneCore lc, String message) {}
public void globalState(LinphoneCore lc, GlobalState state, String message) {}
public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg,RegistrationState cstate, String smessage) {}
public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf,String url) {}
public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) {}
public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from, String message) {}
/*
* Call state notification listener
*/
public void callState(LinphoneCore lc, LinphoneCall call, State cstate, String msg){
write("State: " + msg);
if (State.CallEnd.equals(cstate))
running = false;
}
public static void main(String[] args) {
// Check tutorial was called with the right number of arguments
if (args.length != 1) {
throw new IllegalArgumentException("Bad number of arguments");
}
// Create tutorial object
TutorialHelloWorld helloWorld = new TutorialHelloWorld();
try {
String destinationSipAddress = args[1];
helloWorld.launchTutorial(destinationSipAddress);
} catch (Exception e) {
e.printStackTrace();
}
}
public void launchTutorial(String destinationSipAddress) throws LinphoneCoreException {
// First instantiate the core Linphone object given only a listener.
// The listener will react to events in Linphone core.
LinphoneCore lc = LinphoneCoreFactory.instance().createLinphoneCore(this);
try {
// Send the INVITE message to destination SIP address
LinphoneCall call = lc.invite(destinationSipAddress);
if (call == null) {
write("Could not place call to " + destinationSipAddress);
write("Aborting");
return;
}
write("Call to " + destinationSipAddress + " is in progress...");
// main loop for receiving notifications and doing background linphonecore work
running = true;
while (running) {
lc.iterate();
try{
Thread.sleep(50);
} catch(InterruptedException ie) {
write("Interrupted!\nAborting");
return;
}
}
if (!State.CallEnd.equals(call.getState())) {
write("Terminating the call");
lc.terminateCall(call);
}
} finally {
write("Shutting down...");
// You need to destroy the LinphoneCore object when no longer used
lc.destroy();
write("Exited");
}
}
public void stopMainLoop() {
running=false;
}
private void write(String s) {
TutorialNotifier.notify(s);
}
}

View file

@ -0,0 +1,8 @@
package org.linphone.core.tutorials;
public class TutorialNotifier {
public void notify(String s) {
System.out.println(s);
}
}

View file

@ -0,0 +1,164 @@
/*
linphone
Copyright (C) 2010 Belledonne Communications SARL
(simon.morlat@linphone.org)
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.
*/
package org.linphone.core.tutorials;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneChatRoom;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneCoreListener;
import org.linphone.core.LinphoneFriend;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCore.GlobalState;
import org.linphone.core.LinphoneCore.RegistrationState;
/**
* This program is a _very_ simple usage example of liblinphone.
* Demonstrating how to initiate a SIP registration from a sip uri identity
* passed from the command line.
*
* First argument must be like sip:jehan@sip.linphone.org, second must be password.
* <br>
* ex registration sip:jehan@sip.linphone.org secret
*
* Ported from registration.c
*
* @author Guillaume Beraudo
*
*/
public class TutorialRegistration implements LinphoneCoreListener {
private boolean running;
private TutorialNotifier TutorialNotifier;
public TutorialRegistration(TutorialNotifier TutorialNotifier) {
this.TutorialNotifier = TutorialNotifier;
}
public TutorialRegistration() {
this.TutorialNotifier = new TutorialNotifier();
}
/*
* Registration state notification listener
*/
public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg,RegistrationState cstate, String smessage) {
write(cfg.getIdentity() + " : "+smessage+"\n");
if (RegistrationState.RegistrationOk.equals(cstate))
running = false;
}
public void show(LinphoneCore lc) {}
public void byeReceived(LinphoneCore lc, String from) {}
public void authInfoRequested(LinphoneCore lc, String realm, String username) {}
public void displayStatus(LinphoneCore lc, String message) {}
public void displayMessage(LinphoneCore lc, String message) {}
public void displayWarning(LinphoneCore lc, String message) {}
public void globalState(LinphoneCore lc, GlobalState state, String message) {}
public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf,String url) {}
public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) {}
public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from, String message) {}
public void callState(LinphoneCore lc, LinphoneCall call, State cstate, String msg) {}
public static void main(String[] args) {
// Check tutorial was called with the right number of arguments
if (args.length != 2) {
throw new IllegalArgumentException("Bad number of arguments");
}
// Create tutorial object
TutorialRegistration tutorial = new TutorialRegistration();
try {
String userSipAddress = args[1];
String userSipPassword = args[2];
tutorial.launchTutorial(userSipAddress, userSipPassword);
} catch (Exception e) {
e.printStackTrace();
}
}
public void launchTutorial(String sipAddress, String password) throws LinphoneCoreException {
final LinphoneCoreFactory lcFactory = LinphoneCoreFactory.instance();
// First instantiate the core Linphone object given only a listener.
// The listener will react to events in Linphone core.
LinphoneCore lc = lcFactory.createLinphoneCore(this);
try {
LinphoneAddress address = lcFactory.createLinphoneAddress(sipAddress);
String username = address.getUserName();
String domain = address.getDomain();
if (password != null) {
lc.addAuthInfo(lcFactory.createAuthInfo(username, password, null));
}
LinphoneProxyConfig proxyCfg = lcFactory.createProxyConfig(sipAddress, domain, null, true);
lc.addProxyConfig(proxyCfg);
lc.setDefaultProxyConfig(proxyCfg);
// main loop for receiving notifications and doing background linphonecore work
running = true;
while (running) {
lc.iterate();
try{
Thread.sleep(50);
} catch(InterruptedException ie) {
write("Interrupted!\nAborting");
return;
}
}
} finally {
write("Shutting down...");
// You need to destroy the LinphoneCore object when no longer used
lc.destroy();
write("Exited");
}
}
public void stopMainLoop() {
running=false;
}
private void write(String s) {
TutorialNotifier.notify(s);
}
}

View file

@ -21,6 +21,7 @@ package org.linphone.core;
abstract public class LinphoneCoreFactory {
private static String factoryName = "org.linphone.core.LinphoneCoreFactoryImpl";
@ -49,6 +50,8 @@ abstract public class LinphoneCoreFactory {
abstract public LinphoneAuthInfo createAuthInfo(String username,String password, String realm);
abstract public LinphoneCore createLinphoneCore(LinphoneCoreListener listener, String userConfig,String factoryConfig,Object userdata) throws LinphoneCoreException;
abstract public LinphoneCore createLinphoneCore(LinphoneCoreListener listener) throws LinphoneCoreException;
/**
* Constructs a LinphoneAddress object
* @param username
@ -77,12 +80,12 @@ abstract public class LinphoneCoreFactory {
* @param friendUri a buddy address, must be a sip uri like sip:joe@sip.linphone.org
* @return a new LinphoneFriend with address initialized
*/
abstract LinphoneFriend createLinphoneFriend(String friendUri);
abstract public LinphoneFriend createLinphoneFriend(String friendUri);
/**
* Create a new LinphoneFriend
* @return
*/
abstract LinphoneFriend createLinphoneFriend();
abstract public LinphoneFriend createLinphoneFriend();
}