2013-09-16 15:24:21 +02:00
|
|
|
package org.kde.kdeconnect.Backends;
|
2013-06-18 20:04:53 +02:00
|
|
|
|
2013-07-31 19:10:51 +02:00
|
|
|
import android.util.Log;
|
|
|
|
|
2013-09-16 15:24:21 +02:00
|
|
|
import org.kde.kdeconnect.Backends.BaseLink;
|
2013-09-05 01:37:59 +02:00
|
|
|
import org.kde.kdeconnect.NetworkPackage;
|
2013-06-18 20:04:53 +02:00
|
|
|
|
2013-07-31 19:10:51 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public abstract class BaseLinkProvider {
|
|
|
|
|
2014-03-29 01:47:15 +01:00
|
|
|
private final ArrayList<ConnectionReceiver> connectionReceivers = new ArrayList<ConnectionReceiver>();
|
2013-06-18 20:04:53 +02:00
|
|
|
|
|
|
|
public interface ConnectionReceiver {
|
2013-09-16 17:36:26 +02:00
|
|
|
public void onConnectionReceived(NetworkPackage identityPackage, BaseLink link);
|
|
|
|
public void onConnectionLost(BaseLink link);
|
2013-06-18 20:04:53 +02:00
|
|
|
}
|
|
|
|
|
2013-07-31 19:10:51 +02:00
|
|
|
public void addConnectionReceiver(ConnectionReceiver cr) {
|
|
|
|
connectionReceivers.add(cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean removeConnectionReceiver(ConnectionReceiver cr) {
|
|
|
|
return connectionReceivers.remove(cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
//These two should be called when the provider links to a new computer
|
2013-09-16 17:36:26 +02:00
|
|
|
protected void connectionAccepted(NetworkPackage identityPackage, BaseLink link) {
|
2013-09-05 10:48:42 +02:00
|
|
|
Log.i("LinkProvider", "connectionAccepted");
|
2013-07-31 19:10:51 +02:00
|
|
|
for(ConnectionReceiver cr : connectionReceivers) {
|
2013-08-10 05:16:59 +02:00
|
|
|
cr.onConnectionReceived(identityPackage, link);
|
2013-07-31 19:10:51 +02:00
|
|
|
}
|
|
|
|
}
|
2013-09-16 17:36:26 +02:00
|
|
|
protected void connectionLost(BaseLink link) {
|
2013-09-05 10:48:42 +02:00
|
|
|
Log.i("LinkProvider", "connectionLost");
|
2013-07-31 19:10:51 +02:00
|
|
|
for(ConnectionReceiver cr : connectionReceivers) {
|
|
|
|
cr.onConnectionLost(link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:04:53 +02:00
|
|
|
//To override
|
2013-07-31 19:10:51 +02:00
|
|
|
public abstract void onStart();
|
|
|
|
public abstract void onStop();
|
2013-08-07 10:44:52 +02:00
|
|
|
public abstract void onNetworkChange();
|
2013-07-31 19:10:51 +02:00
|
|
|
|
|
|
|
public abstract int getPriority();
|
|
|
|
public abstract String getName();
|
2013-06-18 20:04:53 +02:00
|
|
|
|
|
|
|
}
|