From 7680d58d2ab0d5edc4fcc5214001b3880eb78e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Thu, 10 May 2012 14:11:33 +0200 Subject: Change network discovery in Android app. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit – Activity discovers networks instead of getting SameService to do it. --- .../java/com/orbekk/same/android/SameService.java | 63 +++------------------- 1 file changed, 6 insertions(+), 57 deletions(-) (limited to 'same-android/src/main/java/com/orbekk/same/android/SameService.java') diff --git a/same-android/src/main/java/com/orbekk/same/android/SameService.java b/same-android/src/main/java/com/orbekk/same/android/SameService.java index f369b3a..8d0d83c 100644 --- a/same-android/src/main/java/com/orbekk/same/android/SameService.java +++ b/same-android/src/main/java/com/orbekk/same/android/SameService.java @@ -34,7 +34,6 @@ import android.widget.Toast; import com.google.protobuf.RpcCallback; import com.orbekk.protobuf.Rpc; -import com.orbekk.same.NetworkNotificationListener; import com.orbekk.same.SameController; import com.orbekk.same.Services; import com.orbekk.same.Services.MasterState; @@ -75,19 +74,12 @@ public class SameService extends Service { public final static int OPERATION_STATUS_CALLBACK = 9; public final static int KILL_MASTER = 10; - - // TODO: Remove these and use messengers instead of broadcast intents. - public final static String AVAILABLE_NETWORKS_UPDATE = - "com.orbekk.same.SameService.action.AVAILABLE_NETWORKS_UPDATE"; - public final static String AVAILABLE_NETWORKS = - "com.orbekk.same.SameService.action.AVAILABLE_NETWORKS"; - public final static String NETWORK_URLS = - "com.orbekk.same.SameService.action.NETWORK_URLS"; final static int PPORT = 15070; final static int SERVICE_PORT = 15068; - final static int DISCOVERY_PORT = 15066; - final static String DIRECTORY_URL = "flode.pvv.ntnu.no:15072"; + + final static String DIRECTORY_HOST = "flode.pvv.ntnu.no"; + final static int DIRECTORY_PORT = 15072; private Logger logger = LoggerFactory.getLogger(getClass()); private SameController sameController = null; @@ -97,22 +89,6 @@ public class SameService extends Service { private ArrayList networkNames = new ArrayList(); private ArrayList networkUrls = new ArrayList(); - private NetworkNotificationListener networkListener = - new NetworkNotificationListener() { - @Override - public void notifyNetwork(String networkName, String masterUrl) { - logger.info("notifyNetwork({})", networkName); - networkNames.add(networkName); - networkUrls.add(masterUrl); - Intent intent = new Intent(AVAILABLE_NETWORKS_UPDATE); - intent.putStringArrayListExtra(AVAILABLE_NETWORKS, - networkNames); - intent.putStringArrayListExtra(NETWORK_URLS, - networkUrls); - sendBroadcast(intent); - } - }; - class InterfaceHandler extends Handler { @Override public void handleMessage(Message message) { switch (message.what) { @@ -216,32 +192,7 @@ public class SameService extends Service { } } } - - private void findNetworks() { - logger.info("Looking up networks."); - Services.Directory directory = sameController.getDirectory(); - if (directory == null) { - logger.warn("No discovery service configured."); - return; - } - final Rpc rpc = new Rpc(); - rpc.setTimeout(10000); - RpcCallback done = - new RpcCallback() { - @Override public void run(Services.NetworkDirectory networks) { - if (!rpc.isOk()) { - logger.warn("Unable to find networks: {}", rpc.errorText()); - return; - } - for (Services.MasterState network : networks.getNetworkList()) { - networkListener.notifyNetwork(network.getNetworkName(), - network.getMasterLocation()); - } - } - }; - directory.getNetworks(rpc, Services.Empty.getDefaultInstance(), done); - } - + private void initializeConfiguration() { Properties properties = new Properties(); String localIp = new Networking(this) @@ -251,10 +202,9 @@ public class SameService extends Service { properties.setProperty("pport", ""+PPORT); properties.setProperty("localIp", localIp); properties.setProperty("baseUrl", baseUrl); - properties.setProperty("enableDiscovery", "true"); - properties.setProperty("discoveryPort", ""+DISCOVERY_PORT); + properties.setProperty("directoryLocation", DIRECTORY_HOST + ":" + + DIRECTORY_PORT); properties.setProperty("networkName", "AndroidNetwork"); - properties.setProperty("directoryLocation", DIRECTORY_URL); configuration = new Configuration(properties); } @@ -292,7 +242,6 @@ public class SameService extends Service { sameController.start(); sameController.getClient().getInterface() .addStateListener(stateListener); - findNetworks(); } catch (Exception e) { logger.error("Failed to start server", e); } -- cgit v1.2.3