private Method findCallback(final String name) {
   try {
     return parent.getClass().getMethod(name, this.getClass());
   } catch (Exception e) {
   }
   // Permit callback(Object) as alternative to callback(Serial).
   try {
     return parent.getClass().getMethod(name, Object.class);
   } catch (Exception e) {
   }
   return null;
 }
Exemple #2
0
  /**
   * @param parent typically use "this"
   * @param port port used to transfer data
   * @param host when multiple NICs are in use, the ip (or name) to bind from
   */
  public MyServer(PApplet parent, int port, String host) {
    this.parent = parent;
    this.port = port;

    try {
      if (host == null) {
        server = new ServerSocket(this.port);
      } else {
        server = new ServerSocket(this.port, 10, InetAddress.getByName(host));
      }
      // clients = new Vector();
      clients = new Client[10];

      thread = new Thread(this);
      thread.start();

      parent.registerMethod("dispose", this);

      // reflection to check whether host applet has a call for
      // public void serverEvent(MyServer s, Client c);
      // which is called when a new guy connects
      try {
        serverEventMethod =
            parent.getClass().getMethod("serverEvent", new Class[] {MyServer.class, Client.class});
      } catch (Exception e) {
        // no such method, or an error.. which is fine, just ignore
        serverEventMethod = null;
      }

      try {
        clientValidationMethod =
            parent
                .getClass()
                .getMethod("clientValidation", new Class[] {MyServer.class, Client.class});
      } catch (Exception e) {
        // no such method, or an error.. which is fine, just ignore
        clientValidationMethod = null;
      }

    } catch (IOException e) {
      // e.printStackTrace();
      thread = null;
      throw new RuntimeException(e);
      // errorMessage("<init>", e);
    }
  }
  public XBeeReader(PApplet p, Serial thisPort) {
    running = false;
    port = thisPort;
    parent = p;
    sleepRate = 1;

    try {
      xBeeMethod = parent.getClass().getMethod("xBeeEvent", new Class[] {XBeeReader.class});
    } catch (Exception e) {
      System.out.println("You forgot to implement the xBeeEvent() method.");
    }
  }
  public XBeeReader(PApplet p, String thisFile, long sleepTime) {
    running = false;
    dataFile = thisFile;
    parent = p;
    fileArray = readFile(dataFile);
    fileIndex = 0;
    sleepRate = sleepTime;

    try {
      xBeeMethod = parent.getClass().getMethod("xBeeEvent", new Class[] {XBeeReader.class});
    } catch (Exception e) {
      System.out.println("You forgot to implement the xBeeEvent() method.");
    }
  }