public void onPeersAvailable(WifiP2pDeviceList peers_list) {
          if (!keepUpdatingPeers) {
            logger.d("Ignoring peers update");
            Collection<WifiP2pDevice> devs = peers_list.getDeviceList();
            for (int i = 0; i < peers.size(); i++) {
              if (devs.contains(peers.get(i))) {
                for (WifiP2pDevice d : devs) {
                  // Update peers in the list
                  if (d.deviceAddress == peers.get(i).deviceAddress) {
                    peers.set(i, d);
                  }
                }
              }
            }
          } else {
            peers = new SynchronizedDevicesList();
            // Adds all found devices
            for (WifiP2pDevice device : peers_list.getDeviceList()) {
              peers.add(device);
            }
          }

          Message msg = new Message();
          msg.obj = peers;
          msg.what = GuiHandlerInterface.UPDATE_PEERS;
          guiHandler.sendMessage(msg);

          logger.d("Peers Added to the List");
        }
  /**
   * Setter method for the map. If current device is the GroupOwner, it sends back to all the
   * devices requestConnectionSent to his group the complete map of all the peers
   *
   * @param map
   */
  public synchronized void setPeersIdIPmap(Map<String, String> map) {

    // If setup was already completed, just do nothing
    if (setupCompleted) {
      return;
    }

    if (peerIdIpMap == null) {
      peerIdIpMap = map;
    } else {
      peerIdIpMap.putAll(map);
    }
    if (peerIdIpMap.containsKey(MAC_ADDRESS)) peerIdIpMap.remove(MAC_ADDRESS);
    // If I'm the group owner and I haven't sent the map to all yet and the map is complete (all
    // peers sent me their ID)
    // Broadcast the map to all, after adding my <ID,IP> to it!
    Map<String, String> mapToBroadcast = null;
    if (isGroupOwner) {
      if (!mapSent && peerIdIpMap.keySet().size() >= peers.size()) {

        setupCompleted = true;
        EventDispatcher.getInstance()
            .triggerEvent(new SetupProviderEvent(0, peerIdIpMap.size() + 1));
        EventDispatcher.getInstance().triggerEvent(new UpdateLocationEvent());
        mapToBroadcast = new HashMap<String, String>(peerIdIpMap);
        mapToBroadcast.put(MAC_ADDRESS, groupOwnerAddress);
        IMessage message = createMapMessage(mapToBroadcast, IPaketSender.BROADCAST_ADDRESS);
        logger.d("Invio la mappa a tutti : ");
        sendBroadcast(message);
        mapSent = true;
        // Now start simulation
        EventDispatcher.getInstance().triggerEvent(new SetupCompletedEvent());
        EventDispatcher.getInstance()
            .triggerEvent(new UpdateStatusEvent("Group owner setup completed"));
      }
    } else {
      // If I'm not the group owner and I'm here, I received the map,
      // so I can start simulation
      setupCompleted = true;
      EventDispatcher.getInstance().triggerEvent(new UpdateLocationEvent());
      EventDispatcher.getInstance().triggerEvent(new SetupCompletedEvent());
      EventDispatcher.getInstance().triggerEvent(new UpdateStatusEvent("Peer Setup completed"));
    }

    if (mapToBroadcast == null) mapToBroadcast = peerIdIpMap;
    String s = "Current MAP:\n";
    for (String k : mapToBroadcast.keySet()) {
      s += k + "  " + mapToBroadcast.get(k) + "\n";
    }
    logger.d("Message received\n" + s);
  }
  /**
   * Constructor
   *
   * @param context
   */
  public AppController(
      Context context, GuiHandlerInterface guiHandlerInterface, TransportSelectorFilter filter) {
    this.context = context;
    this.guiHandler = guiHandlerInterface.getGuiHandler();

    collectionHandler.setWiFiController(this);
    // manager and channel initialization
    manager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE);
    channel = manager.initialize(context, context.getMainLooper(), null);
    // Register intent filter to receive specific intents
    broadcastReceiverIntentFilter = new IntentFilter();
    broadcastReceiverIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
    broadcastReceiverIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
    broadcastReceiverIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    broadcastReceiverIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);

    // Setting static field which contains device MAC address
    MAC_ADDRESS = getDeviceMacAddress();
    logger.d("il MAC address del dispositivo è = " + MAC_ADDRESS);

    // Force creation of TransportManager
    TransmissionManager.getInstance().setFilter(filter);

    register();
  }