--- a/project.aidl Sat Apr 04 01:22:36 2009 +0200
+++ b/project.aidl Sat Apr 04 09:59:40 2009 +0200
@@ -3,5 +3,6 @@
// action. Do not modify!
parcelable com.beem.project.beem.BeemException
+parcelable com.beem.project.beem.service.Message
parcelable com.beem.project.beem.service.Contact
-parcelable com.beem.project.beem.service.Message
+parcelable com.beem.project.beem.service.PresenceAdapter
--- a/src/com/beem/project/beem/jingle/RTPReceiver.java Sat Apr 04 01:22:36 2009 +0200
+++ b/src/com/beem/project/beem/jingle/RTPReceiver.java Sat Apr 04 09:59:40 2009 +0200
@@ -56,7 +56,7 @@
@Override
public void receiveData(DataFrame frame, Participant participant) {
- byte[] data = frame.getConcatenatedData();
+ //byte[] data = frame.getConcatenatedData();
}
@Override
--- a/src/com/beem/project/beem/jingle/Receiver.java Sat Apr 04 01:22:36 2009 +0200
+++ b/src/com/beem/project/beem/jingle/Receiver.java Sat Apr 04 09:59:40 2009 +0200
@@ -2,10 +2,8 @@
import java.io.IOException;
import java.io.InputStream;
-import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
@@ -53,8 +51,8 @@
// Le client demande les services dispo en face a son roster
// il doit en suite fournir lui meme une liste de feature
- DiscoverInfo di = sdm.discoverInfo("test@nikita-rack/pidgin");
- DiscoverInfo di2 = sdm.discoverInfo("nikita@nikita-rack/Telepathy");
+ //DiscoverInfo di = sdm.discoverInfo("test@nikita-rack/pidgin");
+ //DiscoverInfo di2 = sdm.discoverInfo("nikita@nikita-rack/Telepathy");
} catch (XMPPException e) {
// TODO Auto-generated catch block
@@ -76,20 +74,16 @@
System.out.println("Jingle Session request from "+request.getFrom());
try {
in = request.accept();
- // TODO configure in
in.addListener(new JingleSessionListener() {
@Override
public void sessionRedirected(String redirection,
JingleSession jingleSession) {
- // TODO Auto-generated method stub
-
}
@Override
public void sessionMediaReceived(JingleSession jingleSession,
String participant) {
- // TODO Auto-generated method stub
System.out.println("Session Media received from " + participant);
}
@@ -97,7 +91,6 @@
public void sessionEstablished(PayloadType pt,
TransportCandidate remoteCandidate,
TransportCandidate localCandidate, JingleSession jingleSession) {
- // TODO Auto-generated method stub
System.out.println("Session established");
try{
System.out.println("Je recois sur " + remoteCandidate.getIp() + ":" + remoteCandidate.getPort() );
@@ -123,13 +116,11 @@
@Override
public void sessionClosed(String reason, JingleSession jingleSession) {
- // TODO Auto-generated method stub
System.out.println("Session "+ jingleSession.getResponder() +"closedd because "+ reason);
}
});
in.startIncoming();
} catch (XMPPException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
}
@@ -161,7 +152,6 @@
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
- // TODO Auto-generated method stub
Receiver rec = new Receiver("test2", "test2");
System.out.println("Receiver initialized");
--- a/src/com/beem/project/beem/provider/BeemDatabaseHelper.java Sat Apr 04 01:22:36 2009 +0200
+++ b/src/com/beem/project/beem/provider/BeemDatabaseHelper.java Sat Apr 04 09:59:40 2009 +0200
@@ -23,6 +23,7 @@
public void onCreate(SQLiteDatabase db) {
db.execSQL(this.creationQuery);
}
+
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
--- a/src/com/beem/project/beem/provider/ContactProvider.java Sat Apr 04 01:22:36 2009 +0200
+++ b/src/com/beem/project/beem/provider/ContactProvider.java Sat Apr 04 09:59:40 2009 +0200
@@ -9,7 +9,6 @@
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.UriMatcher;
-import android.content.res.Resources;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
--- a/src/com/beem/project/beem/service/Contact.java Sat Apr 04 01:22:36 2009 +0200
+++ b/src/com/beem/project/beem/service/Contact.java Sat Apr 04 09:59:40 2009 +0200
@@ -3,8 +3,13 @@
*/
package com.beem.project.beem.service;
+import org.jivesoftware.smack.RosterEntry;
+import org.jivesoftware.smack.packet.Presence;
+import org.jivesoftware.smack.packet.Presence.Mode;
+
import android.os.Parcel;
import android.os.Parcelable;
+import android.util.Log;
/**
* This class contains informations on a jabber contact.
@@ -12,140 +17,179 @@
*/
public class Contact implements Parcelable {
- public static final int CONTACT_STATUS_DISCONNECT = 100;
- public static final int CONTACT_STATUS_UNAVAILABLE = 200;
- public static final int CONTACT_STATUS_AWAY = 300;
- public static final int CONTACT_STATUS_BUSY = 400;
- public static final int CONTACT_STATUS_AVAILABLE = 500;
- public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600;
-
-
- /**
- * Parcelable.Creator needs by Android.
- */
- public static final Parcelable.Creator<Contact> CREATOR = new Parcelable.Creator<Contact>() {
+ public static final int CONTACT_STATUS_DISCONNECT = 100;
+ public static final int CONTACT_STATUS_UNAVAILABLE = 200;
+ public static final int CONTACT_STATUS_AWAY = 300;
+ public static final int CONTACT_STATUS_BUSY = 400;
+ public static final int CONTACT_STATUS_AVAILABLE = 500;
+ public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600;
+
+
+ /**
+ * Parcelable.Creator needs by Android.
+ */
+ public static final Parcelable.Creator<Contact> CREATOR = new Parcelable.Creator<Contact>() {
+
+ @Override
+ public Contact createFromParcel(Parcel source) {
+ return new Contact(source);
+ }
+
+ @Override
+ public Contact[] newArray(int size) {
+ return new Contact[size];
+ }
+ };
+ private static final String TAG = "Contact";
+
+ private String mJID;
+ private int mID;
+ private int mStatus;
+
+ /**
+ * @return the mID
+ */
+ public int getID() {
+ return mID;
+ }
- @Override
- public Contact createFromParcel(Parcel source) {
- return new Contact(source);
+ /**
+ * @param mid the mID to set
+ */
+ public void setID(int mid) {
+ mID = mid;
+ }
+
+ /**
+ * @return the mStatus
+ */
+ public int getStatus() {
+ return mStatus;
+ }
+
+ /**
+ * @param status the mStatus to set
+ */
+ public void setStatus(int status) {
+ mStatus = status;
+ }
+
+ /**
+ * @return the mMsgState
+ */
+ public String getMMsgState() {
+ return mMsgState;
+ }
+
+ /**
+ * @param msgState the mMsgState to set
+ */
+ public void setMMsgState(String msgState) {
+ mMsgState = msgState;
+ }
+
+ private String mMsgState;
+
+ /**
+ * Constructor.
+ */
+ public Contact() {
+ // TODO Auto-generated constructor stub
}
- @Override
- public Contact[] newArray(int size) {
- return new Contact[size];
+ /**
+ * Constructor.
+ * @param jid JID of the contact
+ */
+ public Contact(final String jid) {
+ mJID = jid;
}
- };
-
- private String mJID;
- private int mID;
- private int mStatus;
- /**
- * @return the mID
- */
- public int getID() {
- return mID;
- }
-
- /**
- * @param mid the mID to set
- */
- public void setID(int mid) {
- mID = mid;
- }
+ public Contact(RosterEntry entry, Presence presence) {
+ mJID = entry.getUser();
+ Log.w(TAG, "Contact Name: " + entry.getUser());
+ if (presence.getType().equals(Presence.Type.unavailable)) {
+ mStatus = Contact.CONTACT_STATUS_DISCONNECT;
+ Log.w(TAG, "Error while creating Contact");
+ } else {
+ setStatus(presence.getMode());
+ }
+ }
- /**
- * @return the mStatus
- */
- public int getStatus() {
- return mStatus;
- }
-
- /**
- * @param status the mStatus to set
- */
- public void setStatus(int status) {
- mStatus = status;
- }
-
- /**
- * @return the mMsgState
- */
- public String getMMsgState() {
- return mMsgState;
- }
-
- /**
- * @param msgState the mMsgState to set
- */
- public void setMMsgState(String msgState) {
- mMsgState = msgState;
- }
-
- private String mMsgState;
+ /**
+ * @param status the XMPP presence mode
+ */
+ public void setStatus(Mode mode) {
+ switch (mode) {
+ case available:
+ mStatus = Contact.CONTACT_STATUS_AVAILABLE;
+ break;
+ case away:
+ mStatus = Contact.CONTACT_STATUS_AWAY;
+ break;
+ case chat:
+ mStatus = Contact.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
+ break;
+ case dnd:
+ mStatus = Contact.CONTACT_STATUS_BUSY;
+ break;
+ case xa:
+ mStatus = Contact.CONTACT_STATUS_UNAVAILABLE;
+ break;
+ default:
+ Log.e("RosterAdapter", "Status mode non gere");
+ mStatus = Contact.CONTACT_STATUS_DISCONNECT;
+ break;
+ }
+ }
- /**
- * Constructor.
- */
- public Contact() {
- // TODO Auto-generated constructor stub
- }
+ /**
+ * Construct a contact from a parcel.
+ * @param in parcel to use for construction
+ */
+ private Contact(final Parcel in) {
+ mID = in.readInt();
+ mStatus = in.readInt();
+ mJID = in.readString();
+ mMsgState = in.readString();
+ }
- /**
- * Constructor.
- * @param jid JID of the contact
- */
- public Contact(final String jid) {
- mJID = jid;
- }
-
- /**
- * Construct a contact from a parcel.
- * @param in parcel to use for construction
- */
- private Contact(final Parcel in) {
- mID = in.readInt();
- mStatus = in.readInt();
- mJID = in.readString();
- mMsgState = in.readString();
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ // TODO Auto-generated method stub
+ dest.writeInt(mID);
+ dest.writeInt(mStatus);
+ dest.writeString(mJID);
+ dest.writeString(mMsgState);
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- // TODO Auto-generated method stub
- dest.writeInt(mID);
- dest.writeInt(mStatus);
- dest.writeString(mJID);
- dest.writeString(mMsgState);
- }
+ /**
+ * Get the Jabber ID of the contact.
+ * @return the Jabber ID
+ */
+ public String getJID() {
+ return mJID;
+ }
- /**
- * Get the Jabber ID of the contact.
- * @return the Jabber ID
- */
- public String getJID() {
- return mJID;
- }
+ /**
+ * Set the Jabber ID of the contact.
+ * @param mjid the jabber ID to set
+ */
+ public void setJID(String mjid) {
+ mJID = mjid;
+ }
- /**
- * Set the Jabber ID of the contact.
- * @param mjid the jabber ID to set
- */
- public void setJID(String mjid) {
- mJID = mjid;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int describeContents() {
- // TODO Auto-generated method stub
- return 0;
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int describeContents() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/service/PresenceAdapter.java Sat Apr 04 09:59:40 2009 +0200
@@ -0,0 +1,54 @@
+package com.beem.project.beem.service;
+
+import org.jivesoftware.smack.packet.Presence;
+
+import android.os.IBinder;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class PresenceAdapter implements Parcelable {
+
+ private Presence mPresence;
+
+ /**
+ * Parcelable.Creator needs by Android.
+ */
+ public static final Parcelable.Creator<PresenceAdapter> CREATOR = new Parcelable.Creator<PresenceAdapter>() {
+
+ @Override
+ public PresenceAdapter createFromParcel(Parcel source) {
+ return new PresenceAdapter(source);
+ }
+
+ @Override
+ public PresenceAdapter[] newArray(int size) {
+ return new PresenceAdapter[size];
+ }
+ };
+
+ public PresenceAdapter(Presence presence) {
+ mPresence = presence;
+ }
+
+
+ public PresenceAdapter(Parcel source) {
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public int describeContents() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public IBinder asBinder() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
--- a/src/com/beem/project/beem/service/RosterAdapter.java Sat Apr 04 01:22:36 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java Sat Apr 04 09:59:40 2009 +0200
@@ -16,6 +16,9 @@
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;
+import com.beem.project.beem.service.aidl.IBeemRosterListener;
+
+import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Log;
@@ -25,143 +28,208 @@
*/
public class RosterAdapter extends com.beem.project.beem.service.aidl.IRoster.Stub {
- private Roster mAdaptee;
- private Map<String, Contact> mContacts = new HashMap<String, Contact>();
- private RosterListener mRosterListener = new RosterListener() {
+ private static final String TAG = "RosterAdapter";
+ private Roster mAdaptee;
+ private RemoteCallbackList<IBeemRosterListener> mRemoteRosListeners =
+ new RemoteCallbackList<IBeemRosterListener>();
+ private Map<String, Contact> mContacts = new HashMap<String, Contact>();
+
+ private RosterListenerAdapter mRosterListener = new RosterListenerAdapter();
+
+ /**
+ * Constructor.
+ * @param roster the roster to adapt
+ */
+ public RosterAdapter(final Roster roster) {
+ mAdaptee = roster;
+ roster.addRosterListener(mRosterListener);
+ for (RosterEntry entry : roster.getEntries()) {
+ String user = entry.getUser();
+ if ( !mContacts.containsKey(user))
+ mContacts.put(user, new Contact(entry, roster.getPresence(user)));
+ }
+ }
@Override
- public void presenceChanged(Presence presence) {
- String user = presence.getFrom();
- Presence bestPresence = mAdaptee.getPresence(user);
- Contact c = mContacts.get(user);
- if (c == null) {
- c = new Contact(user);
- mContacts.put(user, c);
- }
- int status;
- if (bestPresence.getType().equals(Presence.Type.unavailable))
- status = Contact.CONTACT_STATUS_DISCONNECT;
- else {
- switch (bestPresence.getMode()) {
- case available:
- status = Contact.CONTACT_STATUS_AVAILABLE;
- break;
- case away:
- status = Contact.CONTACT_STATUS_AWAY;
- break;
- case chat:
- status = Contact.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
- break;
- case dnd:
- status = Contact.CONTACT_STATUS_BUSY;
- break;
- case xa:
- status = Contact.CONTACT_STATUS_UNAVAILABLE;
- break;
- default:
- Log.e("RosterAdapter", "Status mode non gere");
- status = Contact.CONTACT_STATUS_DISCONNECT;
- break;
- }
- }
- c.setStatus(status);
+ public void createGroup(String groupname) throws RemoteException {
+ mAdaptee.createGroup(groupname);
}
@Override
- public void entriesUpdated(Collection<String> arg0) {
- // TODO Auto-generated method stub
+ public Contact addContact(String user, String name, String[] groups) throws RemoteException {
+ try {
+ mAdaptee.createEntry(user, name, groups);
+ Contact res = new Contact(user);
+ mContacts.put(user, res);
+ return res;
+ } catch (XMPPException e) {
+ return null;
+ }
+ }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void deleteContact(Contact contact) throws RemoteException {
+ mContacts.remove(contact.getJID());
+ }
+
+ @Override
+ public void addConnectionListener(IBeemRosterListener listen) throws RemoteException {
+ if (listen != null)
+ mRemoteRosListeners.register(listen);
}
@Override
- public void entriesDeleted(Collection<String> arg0) {
- // TODO Auto-generated method stub
-
+ public void removeConnectionListener(IBeemRosterListener listen) throws RemoteException {
+ if (listen != null)
+ mRemoteRosListeners.unregister(listen);
}
@Override
- public void entriesAdded(Collection<String> arg0) {
- // TODO Auto-generated method stub
+ public Contact getContact(String jid) throws RemoteException {
+ return mContacts.get(jid);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<Contact> getContactList() throws RemoteException {
+ List<Contact> res = new ArrayList<Contact>();
+ res.addAll(mContacts.values());
+ return res;
+ }
+
+ private class RosterListenerAdapter implements RosterListener {
+
+ @Override
+ public void entriesAdded(Collection<String> addresses) {
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ List<String> tab = new ArrayList<String>();
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ tab.addAll(addresses);
+ listener.onEntriesAdded(tab);
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while adding roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
+
+ }
+
+ @Override
+ public void entriesDeleted(Collection<String> addresses) {
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ List<String> tab = new ArrayList<String>();
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ tab.addAll(addresses);
+ listener.onEntriesDeleted(tab);
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while deleting roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
+ }
+
+ @Override
+ public void entriesUpdated(Collection<String> addresses) {
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ List<String> tab = new ArrayList<String>();
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ tab.addAll(addresses);
+ listener.onEntriesUpdated(tab);
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while updating roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
+ }
+
+ @Override
+ public void presenceChanged(Presence presence) {
+ Log.w(TAG, "Changement de Presence");
+ /* gestion du roster coter service */
+ String user = presence.getFrom();
+ //Presence bestPresence = mAdaptee.getPresence(user);
+ Contact c = mContacts.get(user);
+ if (c == null) {
+ c = new Contact(user);
+ mContacts.put(user, c);
+ }
+ int status;
+ if (presence.getType().equals(Presence.Type.unavailable))
+ status = Contact.CONTACT_STATUS_DISCONNECT;
+ else {
+ switch (presence.getMode()) {
+ case available:
+ status = Contact.CONTACT_STATUS_AVAILABLE;
+ break;
+ case away:
+ status = Contact.CONTACT_STATUS_AWAY;
+ break;
+ case chat:
+ status = Contact.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
+ break;
+ case dnd:
+ status = Contact.CONTACT_STATUS_BUSY;
+ break;
+ case xa:
+ status = Contact.CONTACT_STATUS_UNAVAILABLE;
+ break;
+ default:
+ Log.e("RosterAdapter", "Status mode non gere");
+ status = Contact.CONTACT_STATUS_DISCONNECT;
+ break;
+ }
+ }
+ c.setStatus(status);
+
+ /* redispatch vers les IBeemRosterListener */
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ listener.onPresenceChanged(new PresenceAdapter(presence));
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while updating roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
+ }
}
- };
- /**
- * Constructor.
- * @param roster the roster to adapt
- */
- public RosterAdapter(final Roster roster) {
- mAdaptee = roster;
- roster.addRosterListener(mRosterListener);
- for (RosterEntry entry : roster.getEntries()) {
- String user = entry.getUser();
- if ( !mContacts.containsKey(user))
- mContacts.put(user, new Contact(user));
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void createGroup(String groupname) throws RemoteException {
- // TODO Auto-generated method stub
- mAdaptee.createGroup(groupname);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Contact addContact(String user, String name, String[] groups) throws RemoteException {
- try {
- mAdaptee.createEntry(user, name, groups);
- Contact res = new Contact(user);
- mContacts.put(user, res);
- return res;
- } catch (XMPPException e) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<String> getGroupsNames() throws RemoteException {
+ Collection<RosterGroup> groups = mAdaptee.getGroups();
+ ArrayList<String> result = new ArrayList<String>(groups.size());
+ for (RosterGroup rosterGroup : groups) {
+ result.add(rosterGroup.getName());
+ }
+ return result;
}
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void deleteContact(Contact contact) throws RemoteException {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Contact getContact(String jid) throws RemoteException {
- return mContacts.get(jid);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List<Contact> getContactList() throws RemoteException {
- List<Contact> res = new ArrayList<Contact>();
- res.addAll(mContacts.values());
- return res;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List<String> getGroupsNames() throws RemoteException {
- Collection<RosterGroup> groups = mAdaptee.getGroups();
- ArrayList<String> result = new ArrayList<String>(groups.size());
- for (RosterGroup rosterGroup : groups) {
- result.add(rosterGroup.getName());
- }
- return result;
- }
}
--- a/src/com/beem/project/beem/service/XMPPConnectionAdapter.java Sat Apr 04 01:22:36 2009 +0200
+++ b/src/com/beem/project/beem/service/XMPPConnectionAdapter.java Sat Apr 04 09:59:40 2009 +0200
@@ -25,313 +25,295 @@
*/
public class XMPPConnectionAdapter extends IXmppConnection.Stub {
- private static final String TAG = "XMPPConnectionAdapter";
- private XMPPConnection mAdaptee;
- private IChatManager mChatManager;
- private BeemException mLastException;
- private String mLogin;
- private String mPassword;
- private RosterAdapter mRoster;
-
- private RemoteCallbackList<IBeemConnectionListener> mRemoteConnListeners =
- new RemoteCallbackList<IBeemConnectionListener>();
- private ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter();
-
- /**
- * Constructor.
- * @param con The connection to adapt
- * @param login The login to use
- * @param password The password to use
- */
- public XMPPConnectionAdapter(final XMPPConnection con, final String login, final String password) {
- mAdaptee = con;
- mLogin = login;
- mPassword = password;
- }
-
- /**
- * Constructor.
- * @param serviceName name of the service to connect to
- * @param login login to use on connect
- * @param password password to use on connect
- */
- public XMPPConnectionAdapter(final String serviceName, final String login, final String password) {
- this(new XMPPConnection(serviceName), login, password);
- }
-
- /**
- * Constructor.
- * @param config Configuration to use in order to connect
- * @param login login to use on connect
- * @param password password to use on connect
- */
- public XMPPConnectionAdapter(final ConnectionConfiguration config, final String login, final String password) {
- this(new XMPPConnection(config), login, password);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean connectSync() throws RemoteException {
- try {
- mAdaptee.connect();
- mAdaptee.addConnectionListener(mConListener);
- mAdaptee.login(mLogin, mPassword, "BEEM");
- mChatManager = new BeemChatManager(mAdaptee.getChatManager());
- // TODO find why this cause a null pointer exception
- // this.initFeatures(); // pour declarer les features xmpp qu'on supporte
- mLastException = null;
- triggerAsynchronousConnectEvent();
- return true;
- } catch (XMPPException e) {
- mLastException = new BeemException(e);
- }
- return false;
- }
+ private static final String TAG = "XMPPConnectionAdapter";
+ private XMPPConnection mAdaptee;
+ private IChatManager mChatManager;
+ private String mLogin;
+ private String mPassword;
+ private RosterAdapter mRoster;
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean disconnect() {
- mAdaptee.disconnect();
- mLastException = null;
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public IRoster getRoster() throws RemoteException {
- if (mRoster != null)
- return mRoster;
- Roster adap = mAdaptee.getRoster();
- if (adap == null)
- return null;
- mRoster = new RosterAdapter(adap);
- return mRoster;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final void connectAsync() throws RemoteException {
- Thread t = new Thread(new Runnable() {
-
- @Override
- public void run() {
- try {
- connectSync();
- } catch (RemoteException e) {
- Log.e(TAG, "Error while connecting", e);
- }
- }
- });
- t.start();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void addConnectionListener(IBeemConnectionListener listen) throws RemoteException {
- if (listen != null)
- mRemoteConnListeners.register(listen);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void removeConnectionListener(IBeemConnectionListener listen) throws RemoteException {
- if (listen != null)
- mRemoteConnListeners.unregister(listen);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public IChatManager getChatManager() throws RemoteException {
- return mChatManager;
- }
-
- /**
- * Trigger Connection event.
- */
- private void triggerAsynchronousConnectEvent() {
- mConListener.onConnect();
- }
-
- /**
- * Listener for XMPP connection events.
- * It will calls the remote listeners for connexion events.
- * @author darisk
- */
- private class ConnexionListenerAdapter implements ConnectionListener {
+ private RemoteCallbackList<IBeemConnectionListener> mRemoteConnListeners =
+ new RemoteCallbackList<IBeemConnectionListener>();
+ private ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter();
+ private Object mLastException;
/**
- * Defaut constructor.
+ * Constructor.
+ * @param con The connection to adapt
+ * @param login The login to use
+ * @param password The password to use
*/
- public ConnexionListenerAdapter() {
- // TODO Auto-generated constructor stub
+ public XMPPConnectionAdapter(final XMPPConnection con, final String login, final String password) {
+ mAdaptee = con;
+ mLogin = login;
+ mPassword = password;
+ }
+
+ /**
+ * Constructor.
+ * @param serviceName name of the service to connect to
+ * @param login login to use on connect
+ * @param password password to use on connect
+ */
+ public XMPPConnectionAdapter(final String serviceName, final String login, final String password) {
+
+ this(new XMPPConnection(serviceName), login, password);
+ XMPPConnection.DEBUG_ENABLED = true;
+ }
+
+ /**
+ * Constructor.
+ * @param config Configuration to use in order to connect
+ * @param login login to use on connect
+ * @param password password to use on connect
+ */
+ public XMPPConnectionAdapter(final ConnectionConfiguration config, final String login, final String password) {
+ this(new XMPPConnection(config), login, password);
}
/**
- * Method to execute when a connection event occurs.
+ * {@inheritDoc}
*/
- public void onConnect() {
- final int n = mRemoteConnListeners.beginBroadcast();
-
- for (int i = 0; i < n; i++) {
- IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+ @Override
+ public boolean connectSync() throws RemoteException {
try {
- listener.onConnect();
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while triggering remote connection listeners", e);
+ mAdaptee.connect();
+ mAdaptee.addConnectionListener(mConListener);
+ mAdaptee.login(mLogin, mPassword, "BEEM");
+ mChatManager = new BeemChatManager(mAdaptee.getChatManager());
+ // TODO find why this cause a null pointer exception
+ //this.initFeatures(); // pour declarer les features xmpp qu'on supporte
+ mLastException = null;
+ triggerAsynchronousConnectEvent();
+ return true;
+ } catch (XMPPException e) {
+ mLastException = new BeemException(e);
}
- }
- mRemoteConnListeners.finishBroadcast();
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean disconnect() {
+ mAdaptee.disconnect();
+ mLastException = null;
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IRoster getRoster() throws RemoteException {
+ if (mRoster != null)
+ return mRoster;
+ Roster adap = mAdaptee.getRoster();
+ if (adap == null)
+ return null;
+ mRoster = new RosterAdapter(adap);
+ return mRoster;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final void connectAsync() throws RemoteException {
+ Thread t = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ connectSync();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error while connecting", e);
+ }
+ }
+ });
+ t.start();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addConnectionListener(IBeemConnectionListener listen) throws RemoteException {
+ if (listen != null)
+ mRemoteConnListeners.register(listen);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void removeConnectionListener(IBeemConnectionListener listen) throws RemoteException {
+ if (listen != null)
+ mRemoteConnListeners.unregister(listen);
}
/**
* {@inheritDoc}
*/
@Override
- public void connectionClosed() {
- final int n = mRemoteConnListeners.beginBroadcast();
-
- for (int i = 0; i < n; i++) {
- IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
- try {
- listener.connectionClosed();
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while triggering remote connection listeners", e);
- }
- }
- mRemoteConnListeners.finishBroadcast();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void connectionClosedOnError(Exception arg0) {
- final int n = mRemoteConnListeners.beginBroadcast();
-
- for (int i = 0; i < n; i++) {
- IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
- try {
- listener.connectionClosedOnError();
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while triggering remote connection listeners", e);
- }
- }
- mRemoteConnListeners.finishBroadcast();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void reconnectingIn(int arg0) {
- final int n = mRemoteConnListeners.beginBroadcast();
-
- for (int i = 0; i < n; i++) {
- IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
- try {
- listener.reconnectingIn(arg0);
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- }
- }
- mRemoteConnListeners.finishBroadcast();
+ public IChatManager getChatManager() throws RemoteException {
+ return mChatManager;
}
/**
- * {@inheritDoc}
+ * Trigger Connection event.
*/
- @Override
- public void reconnectionFailed(Exception arg0) {
- final int r = mRemoteConnListeners.beginBroadcast();
+ private void triggerAsynchronousConnectEvent() {
+ mConListener.onConnect();
+ }
+
+ /**
+ * enregistre les features dispo dans notre version Liste de features que Telepathy supporte.
+ */
+ private void initFeatures() {
+ JingleManager.setJingleServiceEnabled();
+ ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
+ sdm.addFeature("http://jabber.org/protocol/disco#info");
+ // sdm.addFeature("http://jabber.org/protocol/nick");
- for (int i = 0; i < r; i++) {
- IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
- try {
- listener.reconnectionFailed();
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while triggering remote connection listeners", e);
+ }
+
+ /**
+ * Listener for XMPP connection events.
+ * It will calls the remote listeners for connexion events.
+ * @author darisk
+ */
+ private class ConnexionListenerAdapter implements ConnectionListener {
+
+ /**
+ * Defaut constructor.
+ */
+ public ConnexionListenerAdapter() {
+ // TODO Auto-generated constructor stub
}
- }
- mRemoteConnListeners.finishBroadcast();
- }
+
+ /**
+ * Method to execute when a connection event occurs.
+ */
+ public void onConnect() {
+ final int n = mRemoteConnListeners.beginBroadcast();
- /**
- * {@inheritDoc}
- */
- @Override
- public void reconnectionSuccessful() {
- final int n = mRemoteConnListeners.beginBroadcast();
+ for (int i = 0; i < n; i++) {
+ IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+ try {
+ listener.onConnect();
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while triggering remote connection listeners", e);
+ }
+ }
+ mRemoteConnListeners.finishBroadcast();
+ }
- for (int i = 0; i < n; i++) {
- IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
- try {
- listener.reconnectionSuccessful();
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while triggering remote connection listeners", e);
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void connectionClosed() {
+ final int n = mRemoteConnListeners.beginBroadcast();
+
+ for (int i = 0; i < n; i++) {
+ IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+ try {
+ listener.connectionClosed();
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while triggering remote connection listeners", e);
+ }
+ }
+ mRemoteConnListeners.finishBroadcast();
}
- }
- mRemoteConnListeners.finishBroadcast();
- }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void connectionClosedOnError(Exception arg0) {
+ final int n = mRemoteConnListeners.beginBroadcast();
- }
+ for (int i = 0; i < n; i++) {
+ IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+ try {
+ listener.connectionClosedOnError();
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while triggering remote connection listeners", e);
+ }
+ }
+ mRemoteConnListeners.finishBroadcast();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void reconnectingIn(int arg0) {
+ final int n = mRemoteConnListeners.beginBroadcast();
+
+ for (int i = 0; i < n; i++) {
+ IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+ try {
+ listener.reconnectingIn(arg0);
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ }
+ }
+ mRemoteConnListeners.finishBroadcast();
+ }
- /**
- * enregistre les features dispo dans notre version Liste de features que Telepathy supporte.
- * "http://www.google.com/xmpp/protocol/session" "http://www.google.com/transport/p2p"
- * "http://jabber.org/protocol/jingle" "http://jabber.org/protocol/chatstates" "http://jabber.org/protocol/nick"
- * "http://jabber.org/protocol/nick+notify" "http://jabber.org/protocol/si" "ttp://jabber.org/protocol/ibb"
- * "ttp://telepathy.freedesktop.org/xmpp/tubes" "http://www.google.com/xmpp/protocol/voice/v1"
- * "http://jabber.org/protocol/jingle/description/audio" "http://jabber.org/protocol/jingle/description/video" Liste
- * de features que pidgin `supporte' (on notera la cradence de l'annonce): "jabber:iq:last" "jabber:iq:oob"
- * "jabber:iq:time" "jabber:iq:version" "jabber:x:conference" "urn:xmpp:attention:0" "urn:xmpp:bob" "urn:xmpp:ping"
- * "xmpp:urn:time" "http://jabber.org/protocol/bytestreams" "http://jabber.org/protocol/disco#info"
- * "http://jabber.org/protocol/disco#items" "http://jabber.org/protocol/ibb" "http://jabber.org/protocol/muc"
- * "http://jabber.org/protocol/muc#user" "http://jabber.org/protocol/si"
- * "http://jabber.org/protocol/si/profile/file-transfer" "http://jabber.org/protocol/xhtml-im"
- * "http://www.xmpp.org/extensions/xep-0199.html#ns" "http://jabber.org/protocol/mood"
- * "http://jabber.org/protocol/mood+notify" "http://jabber.org/protocol/nick"
- * "http://jabber.org/protocol/nick+notify" "http://jabber.org/protocol/tune"
- * "http://jabber.org/protocol/tune+notify" "http://www.xmpp.org/extensions/xep-0084.html#ns-metadata"
- * "http://www.xmpp.org/extensions/xep-0084.html#ns-data"
- * "http://www.xmpp.org/extensions/xep-0084.html#ns-metadata+notify"
- * "http://www.xmpp.org/extensions/xep-0167.html#ns" << Jingle RTP Sessions
- */
- private void initFeatures() {
- JingleManager.setJingleServiceEnabled();
- ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
- sdm.addFeature("http://jabber.org/protocol/disco#info");
- // sdm.addFeature("http://jabber.org/protocol/nick");
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void reconnectionFailed(Exception arg0) {
+ final int r = mRemoteConnListeners.beginBroadcast();
+
+ for (int i = 0; i < r; i++) {
+ IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+ try {
+ listener.reconnectionFailed();
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while triggering remote connection listeners", e);
+ }
+ }
+ mRemoteConnListeners.finishBroadcast();
+ }
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void reconnectionSuccessful() {
+ final int n = mRemoteConnListeners.beginBroadcast();
- @Override
+ for (int i = 0; i < n; i++) {
+ IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+ try {
+ listener.reconnectionSuccessful();
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while triggering remote connection listeners", e);
+ }
+ }
+ mRemoteConnListeners.finishBroadcast();
+ }
+
+ }
public boolean isAuthentificated() throws RemoteException {
- return mAdaptee.isAuthenticated();
+ return mAdaptee.isAuthenticated();
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/service/aidl/IBeemRosterListener.aidl Sat Apr 04 09:59:40 2009 +0200
@@ -0,0 +1,10 @@
+package com.beem.project.beem.service.aidl;
+
+import com.beem.project.beem.service.PresenceAdapter;
+
+interface IBeemRosterListener {
+ void onEntriesAdded(in List<String> addresses);
+ void onEntriesUpdated(in List<String> addresses);
+ void onEntriesDeleted(in List<String> addresses);
+ void onPresenceChanged(in PresenceAdapter presence);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/service/aidl/IContact.aidl Sat Apr 04 09:59:40 2009 +0200
@@ -0,0 +1,9 @@
+package com.beem.project.beem.service.aidl;
+
+interface IContact {
+
+ String getJID();
+
+ void setJID(String mjid);
+
+}
\ No newline at end of file
--- a/src/com/beem/project/beem/service/aidl/IRoster.aidl Sat Apr 04 01:22:36 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IRoster.aidl Sat Apr 04 09:59:40 2009 +0200
@@ -1,5 +1,6 @@
package com.beem.project.beem.service.aidl;
+import com.beem.project.beem.service.aidl.IBeemRosterListener;
import com.beem.project.beem.service.Contact;
interface IRoster {
@@ -15,5 +16,8 @@
List<Contact> getContactList();
List<String> getGroupsNames();
+
+ void addConnectionListener(in IBeemRosterListener listen);
+ void removeConnectionListener(in IBeemRosterListener listen);
}
\ No newline at end of file