Example #1
0
  protected void setDeviceStats(String USN, String stat_key, long value) {
    String key = "upnp.device.stats." + stat_key;

    PluginConfig pc = plugin_interface.getPluginconfig();

    Map counts = pc.getPluginMapParameter(key, new HashMap());

    counts.put(USN, new Long(value));

    pc.getPluginMapParameter(key, counts);
  }
Example #2
0
  protected void logNoRepeat(String usn, String msg) {
    synchronized (log_no_repeat_map) {
      String last = (String) log_no_repeat_map.get(usn);

      if (last != null && last.equals(msg)) {

        return;
      }

      log_no_repeat_map.put(usn, msg);
    }

    log.log(msg);
  }
Example #3
0
  public void rootDeviceFound(UPnPRootDevice device) {
    incrementDeviceStats(device.getUSN(), "found");

    checkDeviceStats(device);

    try {
      int interesting = processDevice(device.getDevice());

      if (interesting > 0) {

        try {
          this_mon.enter();

          root_info_map.put(device.getLocation(), device.getInfo());

          Iterator<String> it = root_info_map.values().iterator();

          String all_info = "";

          List reported_info = new ArrayList();

          while (it.hasNext()) {

            String info = (String) it.next();

            if (info != null && !reported_info.contains(info)) {

              reported_info.add(info);

              all_info += (all_info.length() == 0 ? "" : ",") + info;
            }
          }

          if (all_info.length() > 0) {

            plugin_interface.getPluginconfig().setPluginParameter("plugin.info", all_info);
          }

        } finally {

          this_mon.exit();
        }
      }
    } catch (Throwable e) {

      log.log("Root device processing fails", e);
    }
  }
Example #4
0
  protected long getDeviceStats(String USN, String stat_key) {
    String key = "upnp.device.stats." + stat_key;

    PluginConfig pc = plugin_interface.getPluginconfig();

    Map counts = pc.getPluginMapParameter(key, new HashMap());

    Long count = (Long) counts.get(USN);

    if (count == null) {

      return (0);
    }

    return (count.longValue());
  }
Example #5
0
  protected void updateIgnoreList() {
    try {
      String param = "";

      if (ignore_bad_devices.getValue()) {

        PluginConfig pc = plugin_interface.getPluginconfig();

        Map ignored = pc.getPluginMapParameter("upnp.device.ignorelist", new HashMap());

        Iterator it = ignored.entrySet().iterator();

        while (it.hasNext()) {

          Map.Entry entry = (Map.Entry) it.next();

          Map value = (Map) entry.getValue();

          param += "\n    " + entry.getKey() + ": " + new String((byte[]) value.get("Location"));
        }

        if (ignored.size() > 0) {

          log.log("Devices currently being ignored: " + param);
        }
      }

      String text =
          plugin_interface
              .getUtilities()
              .getLocaleUtilities()
              .getLocalisedMessageText("upnp.ignorebaddevices.info", new String[] {param});

      ignored_devices_list.setLabelText(text);

    } catch (Throwable e) {

      Debug.printStackTrace(e);
    }
  }
Example #6
0
  protected void ignoreDevice(String USN, URL location) {
    // only take note of this if enabled to do so

    if (ignore_bad_devices.getValue()) {

      try {
        PluginConfig pc = plugin_interface.getPluginconfig();

        Map ignored = pc.getPluginMapParameter("upnp.device.ignorelist", new HashMap());

        Map entry = (Map) ignored.get(USN);

        if (entry == null) {

          entry = new HashMap();

          entry.put("Location", location.toString().getBytes());

          ignored.put(USN, entry);

          pc.setPluginMapParameter("upnp.device.ignorelist", ignored);

          updateIgnoreList();

          String text =
              plugin_interface
                  .getUtilities()
                  .getLocaleUtilities()
                  .getLocalisedMessageText(
                      "upnp.ignorebaddevices.alert", new String[] {location.toString()});

          log.logAlertRepeatable(LoggerChannel.LT_WARNING, text);
        }
      } catch (Throwable e) {

        Debug.printStackTrace(e);
      }
    }
  }
Example #7
0
  protected long incrementDeviceStats(String USN, String stat_key) {
    String key = "upnp.device.stats." + stat_key;

    PluginConfig pc = plugin_interface.getPluginconfig();

    Map counts = pc.getPluginMapParameter(key, new HashMap());

    Long count = (Long) counts.get(USN);

    if (count == null) {

      count = new Long(1);

    } else {

      count = new Long(count.longValue() + 1);
    }

    counts.put(USN, count);

    pc.getPluginMapParameter(key, counts);

    return (count.longValue());
  }