From 7db8fc8c965d7c482bec62d84c8030469f2fdef3 Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Fri, 5 Nov 2010 17:29:11 +0100 Subject: [PATCH] Added some comments. --- .../core/tutorials/TutorialBuddyStatus.java | 33 ++++++++++++------- .../core/tutorials/TutorialChatRoom.java | 7 ++-- .../core/tutorials/TutorialHelloWorld.java | 3 +- .../core/tutorials/TutorialNotifier.java | 25 ++++++++++++++ .../core/tutorials/TutorialRegistration.java | 16 ++++++--- 5 files changed, 63 insertions(+), 21 deletions(-) diff --git a/coreapi/help/java/org/linphone/core/tutorials/TutorialBuddyStatus.java b/coreapi/help/java/org/linphone/core/tutorials/TutorialBuddyStatus.java index f85cf88f8..25dae37d7 100644 --- a/coreapi/help/java/org/linphone/core/tutorials/TutorialBuddyStatus.java +++ b/coreapi/help/java/org/linphone/core/tutorials/TutorialBuddyStatus.java @@ -1,7 +1,6 @@ /* -linphone +TutorialBuddyStatus 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 @@ -66,10 +65,11 @@ public class TutorialBuddyStatus implements LinphoneCoreListener { 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(); + lf.edit(); // start editing friend + lf.setIncSubscribePolicy(SubscribePolicy.SPAccept); // accept incoming subscription request for this friend + lf.done(); // commit change try { + // add this new friend to the buddy list lc.addFriend(lf); } catch (LinphoneCoreException e) { write("Error while adding friend [" + lf.getAddress().getUserName() + "] to linphone in the callback"); @@ -104,6 +104,7 @@ public class TutorialBuddyStatus implements LinphoneCoreListener { // Create tutorial object TutorialBuddyStatus tutorial = new TutorialBuddyStatus(); try { + // takes sip uri identity from the command line arguments String userSipAddress = args[1]; tutorial.launchTutorial(userSipAddress); } catch (Exception e) { @@ -123,29 +124,34 @@ public class TutorialBuddyStatus implements LinphoneCoreListener { try { - // Create friend address + // Create friend object from string address LinphoneFriend lf = lcFactory.createLinphoneFriend(sipAddress); if (lf == null) { write("Could not create friend; weird SIP address?"); return; } + // configure this friend to emit SUBSCRIBE message after being added to LinphoneCore lf.enableSubscribes(true); + + // accept incoming subscription request for this friend lf.setIncSubscribePolicy(SubscribePolicy.SPAccept); try { + // add my friend to the buddy list, initiate SUBSCRIBE message lc.addFriend(lf); } catch (LinphoneCoreException e) { write("Error while adding friend " + lf.getAddress().getUserName() + " to linphone"); + return; } - + // set my status to online lc.setPresenceInfo(0, null, OnlineStatus.Online); // main loop for receiving notifications and doing background linphonecore work running = true; while (running) { - lc.iterate(); + lc.iterate(); // first iterate initiates subscription try{ Thread.sleep(50); } catch(InterruptedException ie) { @@ -155,13 +161,16 @@ public class TutorialBuddyStatus implements LinphoneCoreListener { } + // change my presence status to offline lc.setPresenceInfo(0, null, OnlineStatus.Offline); + // just to make sure new status is initiate message is issued lc.iterate(); - lf.edit(); - lf.enableSubscribes(false); - lf.done(); - lc.iterate(); + + lf.edit(); // start editing friend + lf.enableSubscribes(false); // disable subscription for this friend + lf.done(); // commit changes triggering an UNSUBSCRIBE message + lc.iterate(); // just to make sure unsubscribe message is issued } finally { diff --git a/coreapi/help/java/org/linphone/core/tutorials/TutorialChatRoom.java b/coreapi/help/java/org/linphone/core/tutorials/TutorialChatRoom.java index ff6787439..8b8fd341b 100644 --- a/coreapi/help/java/org/linphone/core/tutorials/TutorialChatRoom.java +++ b/coreapi/help/java/org/linphone/core/tutorials/TutorialChatRoom.java @@ -1,7 +1,6 @@ /* -linphone +TutorialChatRoom.java 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 @@ -85,6 +84,7 @@ public class TutorialChatRoom implements LinphoneCoreListener { public static void main(String[] args) { // Check tutorial was called with the right number of arguments + // Takes the sip uri identity from the command line arguments if (args.length != 1) { throw new IllegalArgumentException("Bad number of arguments"); } @@ -108,7 +108,10 @@ public class TutorialChatRoom implements LinphoneCoreListener { LinphoneCore lc = LinphoneCoreFactory.instance().createLinphoneCore(this); try { + // Next step is to create a chat room LinphoneChatRoom chatRoom = lc.createChatRoom(destinationSipAddress); + + // Send message chatRoom.sendMessage("Hello world"); // main loop for receiving notifications and doing background linphonecore work diff --git a/coreapi/help/java/org/linphone/core/tutorials/TutorialHelloWorld.java b/coreapi/help/java/org/linphone/core/tutorials/TutorialHelloWorld.java index e116c3523..12451c940 100644 --- a/coreapi/help/java/org/linphone/core/tutorials/TutorialHelloWorld.java +++ b/coreapi/help/java/org/linphone/core/tutorials/TutorialHelloWorld.java @@ -1,7 +1,6 @@ /* -linphone +TutorialHelloWorld.java 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 diff --git a/coreapi/help/java/org/linphone/core/tutorials/TutorialNotifier.java b/coreapi/help/java/org/linphone/core/tutorials/TutorialNotifier.java index c8138214c..62a540267 100644 --- a/coreapi/help/java/org/linphone/core/tutorials/TutorialNotifier.java +++ b/coreapi/help/java/org/linphone/core/tutorials/TutorialNotifier.java @@ -1,5 +1,30 @@ +/* +TutorialNotifier.java +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. + */ package org.linphone.core.tutorials; +/** + * Notify to the standard output. + * Subclass to define another text output. + * + * @author Guillaume Beraudo + * + */ public class TutorialNotifier { public void notify(String s) { diff --git a/coreapi/help/java/org/linphone/core/tutorials/TutorialRegistration.java b/coreapi/help/java/org/linphone/core/tutorials/TutorialRegistration.java index 0f72594f8..08e3c4ea3 100644 --- a/coreapi/help/java/org/linphone/core/tutorials/TutorialRegistration.java +++ b/coreapi/help/java/org/linphone/core/tutorials/TutorialRegistration.java @@ -1,7 +1,6 @@ /* -linphone +TutorialRegistration.java 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 @@ -93,7 +92,9 @@ public class TutorialRegistration implements LinphoneCoreListener { // Create tutorial object TutorialRegistration tutorial = new TutorialRegistration(); try { + // takes sip uri identity from the command line arguments String userSipAddress = args[1]; + // takes password from the command line arguments String userSipPassword = args[2]; tutorial.launchTutorial(userSipAddress, userSipPassword); } catch (Exception e) { @@ -113,16 +114,20 @@ public class TutorialRegistration implements LinphoneCoreListener { try { + // Parse identity LinphoneAddress address = lcFactory.createLinphoneAddress(sipAddress); String username = address.getUserName(); String domain = address.getDomain(); + if (password != null) { + // create authentication structure from identity and add to linphone lc.addAuthInfo(lcFactory.createAuthInfo(username, password, null)); } - + + // create proxy config LinphoneProxyConfig proxyCfg = lcFactory.createProxyConfig(sipAddress, domain, null, true); - lc.addProxyConfig(proxyCfg); + lc.addProxyConfig(proxyCfg); // add it to linphone lc.setDefaultProxyConfig(proxyCfg); @@ -131,7 +136,7 @@ public class TutorialRegistration implements LinphoneCoreListener { // main loop for receiving notifications and doing background linphonecore work running = true; while (running) { - lc.iterate(); + lc.iterate(); // first iterate initiates registration try{ Thread.sleep(50); } catch(InterruptedException ie) { @@ -141,6 +146,7 @@ public class TutorialRegistration implements LinphoneCoreListener { } + // Automatic unregistration on exit } finally {